use of org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody 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);
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody in project qpid-broker-j by apache.
the class TransactionTimeoutTest method consumeTransactionTimeout.
@Test
public void consumeTransactionTimeout() throws Exception {
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, "message");
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
interaction.openAnonymousConnection().channel().open().consumeResponse(ChannelOpenOkBody.class).tx().select().consumeResponse(TxSelectOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().consumeConsumerTag("A").consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consume().consumeResponse(BasicConsumeOkBody.class).consumeResponse(BasicDeliverBody.class);
BasicDeliverBody delivery = interaction.getLatestResponse(BasicDeliverBody.class);
interaction.consumeResponse(ContentHeaderBody.class).consumeResponse(ContentBody.class);
interaction.basic().ackDeliveryTag(delivery.getDeliveryTag()).ack().exchange().declarePassive(true).declare().consumeResponse(ExchangeDeclareOkBody.class);
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
final ConnectionCloseBody close = interaction.consumeResponse().getLatestResponse(ConnectionCloseBody.class);
assertThat(close.getReplyCode(), is(equalTo(ErrorCodes.RESOURCE_ERROR)));
assertThat(close.getReplyText().toString(), containsString("transaction timed out"));
interaction.connection().closeOk();
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
}
}
Aggregations