AmqpMessageCoder extends CustomCoder<Message> { static AmqpMessageCoder of() { return new AmqpMessageCoder(); }  @Override void encode(Message value, OutputStream outStream); @Override Message decode(InputStream inStream);  }
@Test public void encodeDecode() throws Exception { Message message = Message.Factory.create(); message.setBody(new AmqpValue("body")); message.setAddress("address"); message.setSubject("test"); AmqpMessageCoder coder = AmqpMessageCoder.of(); Message clone = CoderUtils.clone(coder, message); assertEquals("AmqpValue{body}", clone.getBody().toString()); assertEquals("address", clone.getAddress()); assertEquals("test", clone.getSubject()); }
@Test public void encodeDecodeTooMuchLargerMessage() throws Exception { thrown.expect(CoderException.class); Message message = Message.Factory.create(); message.setAddress("address"); message.setSubject("subject"); String body = Joiner.on("").join(Collections.nCopies(64 * 1024 * 1024, " ")); message.setBody(new AmqpValue(body)); AmqpMessageCoder coder = AmqpMessageCoder.of(); byte[] encoded = CoderUtils.encodeToByteArray(coder, message); }
@Test public void encodeDecodeLargeMessage() throws Exception { Message message = Message.Factory.create(); message.setAddress("address"); message.setSubject("subject"); String body = Joiner.on("").join(Collections.nCopies(32 * 1024 * 1024, " ")); message.setBody(new AmqpValue(body)); AmqpMessageCoder coder = AmqpMessageCoder.of(); Message clone = CoderUtils.clone(coder, message); clone.getBody().toString().equals(message.getBody().toString()); }