use of org.apache.qpid.server.protocol.v0_8.transport.ContentBody in project qpid-broker-j by apache.
the class ConnectionTest method overlySizedContentBodyFrame.
@Test
@SpecificationTest(section = "4.2.3", description = "A peer MUST NOT send frames larger than the agreed-upon size. A peer that receives an " + "oversized frame MUST signal a connection exception with reply code 501 (frame error).")
public void overlySizedContentBodyFrame() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
ConnectionTuneBody response = interaction.negotiateProtocol().consumeResponse(ConnectionStartBody.class).connection().startOkMechanism(ANONYMOUS).startOk().consumeResponse().getLatestResponse(ConnectionTuneBody.class);
final long frameMax = response.getFrameMax();
// Older Qpid JMS Client 0-x had a defect that meant they could send content body frames that were too
// large. Rather then limiting the user content of each frame to frameSize - 8, it sent frameSize bytes
// of user content meaning the resultant frame was too big. The server accommodates this behaviour
// by reducing the frame-size advertised to the client.
// Should be frameMax - 8 + 1.
final int overlyLargeFrameBodySize = (int) (frameMax + 1);
final byte[] bodyBytes = new byte[overlyLargeFrameBodySize];
interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(frameMax).tuneOkHeartbeat(response.getHeartbeat()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).channel().open().consumeResponse(ChannelOpenOkBody.class).basic().publish().basic().contentHeader(bodyBytes.length).basic().contentBody(bodyBytes);
// Server actually abruptly closes the connection. We might see a graceful TCP/IP close or a broken pipe.
try {
final ChannelClosedResponse closeResponse = interaction.consumeResponse().getLatestResponse(ChannelClosedResponse.class);
} catch (ExecutionException e) {
Throwable original = e.getCause();
if (original instanceof IOException) {
// PASS
} else {
throw new RuntimeException(original);
}
}
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.ContentBody in project qpid-broker-j by apache.
the class LargeMessageTest method multiBodyMessage.
@Test
public void multiBodyMessage() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
String consumerTag = "A";
String queueName = "testQueue";
ConnectionTuneBody connTune = interaction.negotiateProtocol().consumeResponse(ConnectionStartBody.class).connection().startOkMechanism("ANONYMOUS").startOk().consumeResponse(ConnectionTuneBody.class).getLatestResponse(ConnectionTuneBody.class);
byte[] messageContent = new byte[(int) connTune.getFrameMax()];
IntStream.range(0, messageContent.length).forEach(i -> {
messageContent[i] = (byte) (i & 0xFF);
});
interaction.connection().tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).channel().open().consumeResponse(ChannelOpenOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(queueName).consumeNoAck(true).consume().consumeResponse(BasicConsumeOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().publishExchange("").publishRoutingKey(queueName).content(messageContent).publishMessage().consumeResponse(BasicDeliverBody.class);
BasicDeliverBody delivery = interaction.getLatestResponse(BasicDeliverBody.class);
assertThat(delivery.getConsumerTag(), is(equalTo(AMQShortString.valueOf(consumerTag))));
ContentHeaderBody header = interaction.consumeResponse(ContentHeaderBody.class).getLatestResponse(ContentHeaderBody.class);
assertThat(header.getBodySize(), is(equalTo((long) messageContent.length)));
byte[] receivedContent = new byte[messageContent.length];
ContentBody content1 = interaction.consumeResponse(ContentBody.class).getLatestResponse(ContentBody.class);
ContentBody content2 = interaction.consumeResponse(ContentBody.class).getLatestResponse(ContentBody.class);
try (QpidByteBuffer allContent = QpidByteBuffer.concatenate(content1.getPayload(), content2.getPayload())) {
allContent.get(receivedContent);
}
assertThat(receivedContent, is(equalTo(messageContent)));
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.ContentBody 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.ContentBody in project qpid-broker-j by apache.
the class BasicTest method receiveDeliveryHeaderAndBody.
private long receiveDeliveryHeaderAndBody(final Interaction interaction, String expectedMessageContent) throws Exception {
BasicDeliverBody delivery = interaction.consumeResponse().getLatestResponse(BasicDeliverBody.class);
ContentBody content = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
assertThat(getContent(content), is(equalTo(expectedMessageContent)));
return delivery.getDeliveryTag();
}
use of org.apache.qpid.server.protocol.v0_8.transport.ContentBody in project qpid-broker-j by apache.
the class BasicTest method qosBytesPrefetch.
@Test
@SpecificationTest(section = "1.8.3.3", description = "This field specifies the prefetch window size in octets. The server will send a message " + "in advance if it is equal to or smaller in size than the available prefetch size (and " + "also falls into other prefetch limits).")
public void qosBytesPrefetch() throws Exception {
String messageContent1 = String.join("", Collections.nCopies(128, "1"));
String messageContent2 = String.join("", Collections.nCopies(128, "2"));
String messageContent3 = String.join("", Collections.nCopies(256, "3"));
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
String consumerTag = "A";
interaction.openAnonymousConnection().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).content(messageContent1).publishMessage().basic().content(messageContent2).publishMessage().basic().content(messageContent3).publishMessage().channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().qosPrefetchSize(256).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consume().consumeResponse(BasicConsumeOkBody.class);
BasicDeliverBody delivery1 = interaction.consumeResponse().getLatestResponse(BasicDeliverBody.class);
ContentBody content1 = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
BasicDeliverBody delivery2 = interaction.consumeResponse().getLatestResponse(BasicDeliverBody.class);
ContentBody content2 = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
assertThat(getContent(content1), is(equalTo(messageContent1)));
assertThat(getContent(content2), is(equalTo(messageContent2)));
ensureSync(interaction);
// Ack first. There will be insufficient bytes credit for the third to be sent.
interaction.basic().ackDeliveryTag(delivery1.getDeliveryTag()).ack();
ensureSync(interaction);
// Ack second. Now there will be sufficient bytes credit so expect the third.
interaction.basic().ackDeliveryTag(delivery2.getDeliveryTag()).ack();
BasicDeliverBody delivery3 = interaction.consumeResponse().getLatestResponse(BasicDeliverBody.class);
ContentBody content3 = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
assertThat(getContent(content3), is(equalTo(messageContent3)));
interaction.basic().ackDeliveryTag(delivery3.getDeliveryTag()).ack().channel().close().consumeResponse(ChannelCloseOkBody.class);
}
}
Aggregations