Search in sources :

Example 6 with BasicDeliverBody

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);
    }
}
Also used : ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) BasicQosOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody) ChannelFlowOkBody(org.apache.qpid.server.protocol.v0_8.transport.ChannelFlowOkBody) ChannelOpenOkBody(org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 7 with BasicDeliverBody

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)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v0_8.FrameTransport) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) Interaction(org.apache.qpid.tests.protocol.v0_8.Interaction) TxSelectOkBody(org.apache.qpid.server.protocol.v0_8.transport.TxSelectOkBody) BasicQosOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody) ConnectionCloseBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionCloseBody) BasicConsumeOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody) Test(org.junit.Test)

Aggregations

BasicDeliverBody (org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody)7 Test (org.junit.Test)6 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)5 BasicConsumeOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody)5 ContentBody (org.apache.qpid.server.protocol.v0_8.transport.ContentBody)5 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)5 BasicQosOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody)4 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)4 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)3 HashMap (java.util.HashMap)2 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)2 ConnectionStartBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody)2 ConnectionTuneBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 ChannelFlowOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelFlowOkBody)1 ConnectionCloseBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionCloseBody)1 TxSelectOkBody (org.apache.qpid.server.protocol.v0_8.transport.TxSelectOkBody)1 FrameTransport (org.apache.qpid.tests.protocol.v0_8.FrameTransport)1 Interaction (org.apache.qpid.tests.protocol.v0_8.Interaction)1