diff options
Diffstat (limited to 'qpid/java/common/src/test')
| -rw-r--r-- | qpid/java/common/src/test/java/org/apache/qpid/codec/AMQDecoderTest.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/codec/AMQDecoderTest.java b/qpid/java/common/src/test/java/org/apache/qpid/codec/AMQDecoderTest.java index 51f3ce1113..e597192766 100644 --- a/qpid/java/common/src/test/java/org/apache/qpid/codec/AMQDecoderTest.java +++ b/qpid/java/common/src/test/java/org/apache/qpid/codec/AMQDecoderTest.java @@ -25,17 +25,22 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.Arrays; import java.util.List; +import java.util.Random; import junit.framework.TestCase; +import org.apache.qpid.framing.AMQBody; import org.apache.qpid.framing.AMQDataBlock; import org.apache.qpid.framing.AMQFrame; import org.apache.qpid.framing.AMQFrameDecodingException; import org.apache.qpid.framing.AMQProtocolVersionException; +import org.apache.qpid.framing.ContentBody; import org.apache.qpid.framing.FrameCreatingMethodProcessor; import org.apache.qpid.framing.HeartbeatBody; import org.apache.qpid.framing.ProtocolVersion; +import org.apache.qpid.util.BytesDataOutput; public class AMQDecoderTest extends TestCase { @@ -72,6 +77,35 @@ public class AMQDecoderTest extends TestCase fail("decode was not a frame"); } } + + + 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"); + } + } public void testPartialFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException { |
