use of org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock in project qpid-broker-j by apache.
the class AMQDecoderTest method testMultiplePartialFrameDecode.
public void testMultiplePartialFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
ByteBuffer msgA = getHeartbeatBodyBuffer();
ByteBuffer msgB = getHeartbeatBodyBuffer();
ByteBuffer msgC = getHeartbeatBodyBuffer();
ByteBuffer sliceA = ByteBuffer.allocate(msgA.remaining() + msgB.remaining() / 2);
sliceA.put(msgA);
int limit = msgB.limit();
int pos = msgB.remaining() / 2;
msgB.limit(pos);
sliceA.put(msgB);
sliceA.flip();
msgB.limit(limit);
msgB.position(pos);
ByteBuffer sliceB = ByteBuffer.allocate(msgB.remaining() + pos);
sliceB.put(msgB);
msgC.limit(pos);
sliceB.put(msgC);
sliceB.flip();
msgC.limit(limit);
_decoder.decodeBuffer(sliceA);
List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
assertEquals(1, frames.size());
frames.clear();
_decoder.decodeBuffer(sliceB);
assertEquals(1, frames.size());
frames.clear();
_decoder.decodeBuffer(msgC);
assertEquals(1, frames.size());
for (AMQDataBlock frame : frames) {
if (frame instanceof AMQFrame) {
assertEquals(HeartbeatBody.FRAME.getBodyFrame().getFrameType(), ((AMQFrame) frame).getBodyFrame().getFrameType());
} else {
fail("decode was not a frame");
}
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock in project qpid-broker-j by apache.
the class AMQDecoderTest method testPartialFrameDecode.
public void testPartialFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
ByteBuffer msg = getHeartbeatBodyBuffer();
ByteBuffer msgA = msg.slice();
int msgbPos = msg.remaining() / 2;
int msgaLimit = msg.remaining() - msgbPos;
msgA.limit(msgaLimit);
msg.position(msgbPos);
ByteBuffer msgB = msg.slice();
_decoder.decodeBuffer(msgA);
List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
assertEquals(0, frames.size());
_decoder.decodeBuffer(msgB);
assertEquals(1, frames.size());
if (frames.get(0) instanceof AMQFrame) {
assertEquals(HeartbeatBody.FRAME.getBodyFrame().getFrameType(), ((AMQFrame) frames.get(0)).getBodyFrame().getFrameType());
} else {
fail("decode was not a frame");
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock in project qpid-broker-j by apache.
the class AMQDecoderTest method testDecodeWithManyBuffers.
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(ByteBuffer.wrap(payload));
AMQFrame frame = new AMQFrame(1, body);
TestSender sender = new TestSender();
frame.writePayload(sender);
ByteBuffer allData = combine(sender.getSentBuffers());
for (int i = 0; i < allData.remaining(); i++) {
byte[] minibuf = new byte[1];
minibuf[0] = allData.get(i);
_decoder.decodeBuffer(ByteBuffer.wrap(minibuf));
}
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();
byte[] bodyBytes;
try (QpidByteBuffer payloadBuffer = decodedBody.getPayload()) {
bodyBytes = new byte[payloadBuffer.remaining()];
payloadBuffer.get(bodyBytes);
}
assertTrue("Body was corrupted", Arrays.equals(payload, bodyBytes));
} else {
fail("decode was not a frame");
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock in project qpid-broker-j by apache.
the class AMQDecoderTest method testSingleFrameDecode.
public void testSingleFrameDecode() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
ByteBuffer msg = getHeartbeatBodyBuffer();
_decoder.decodeBuffer(msg);
List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
if (frames.get(0) instanceof AMQFrame) {
assertEquals(HeartbeatBody.FRAME.getBodyFrame().getFrameType(), ((AMQFrame) frames.get(0)).getBodyFrame().getFrameType());
} else {
fail("decode was not a frame");
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock in project qpid-broker-j by apache.
the class AMQDecoderTest method testContentHeaderPropertiesFrame.
public void testContentHeaderPropertiesFrame() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
final FieldTable table = new FieldTable();
table.setString("hello", "world");
table.setInteger("1+1=", 2);
props.setHeaders(table);
final AMQBody body = new ContentHeaderBody(props);
AMQFrame frame = new AMQFrame(1, body);
TestSender sender = new TestSender();
frame.writePayload(sender);
ByteBuffer msg = combine(sender.getSentBuffers());
_decoder.decodeBuffer(msg);
List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
AMQDataBlock firstFrame = frames.get(0);
if (firstFrame instanceof AMQFrame) {
assertEquals(ContentHeaderBody.TYPE, ((AMQFrame) firstFrame).getBodyFrame().getFrameType());
BasicContentHeaderProperties decodedProps = ((ContentHeaderBody) ((AMQFrame) firstFrame).getBodyFrame()).getProperties();
final FieldTable headers = decodedProps.getHeaders();
assertEquals("world", headers.getString("hello"));
} else {
fail("decode was not a frame");
}
}
Aggregations