public void testDecodeWithManyBuffers() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException
{
Random random = new Random();
final byte[] payload = new byte[2048];
random.nextBytes(payload);
final AMQBody body = new ContentBody(payload);
AMQFrame frame = new AMQFrame(1, body);
byte[] outputBuf = new byte[4096];
BytesDataOutput dataOutput = new BytesDataOutput(outputBuf);
frame.writePayload(dataOutput);
for(int i = 0 ; i < dataOutput.length(); i++)
{
_decoder.decodeBuffer(ByteBuffer.wrap(outputBuf, i, 1));
}
List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
if (frames.get(0) instanceof AMQFrame)
{
assertEquals(ContentBody.TYPE, ((AMQFrame) frames.get(0)).getBodyFrame().getFrameType());
ContentBody decodedBody = (ContentBody) ((AMQFrame) frames.get(0)).getBodyFrame();
assertTrue("Body was corrupted", Arrays.equals(payload, decodedBody.getPayload()));
}
else
{
fail("decode was not a frame");
}