Search in sources :

Example 1 with org.apache.qpid.server.protocol.v0_8.transport

use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.

the class BasicTest method consumeMessage.

@Test
@SpecificationTest(section = "1.8.3.3", description = "start a queue consumer")
public void consumeMessage() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        String messageContent = "Test";
        String consumerTag = "A";
        String queueName = BrokerAdmin.TEST_QUEUE_NAME;
        Map<String, Object> messageHeaders = Collections.singletonMap("test", "testValue");
        String messageContentType = "text/plain";
        byte deliveryMode = (byte) 1;
        byte priority = (byte) 2;
        interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(queueName).consume().consumeResponse(BasicConsumeOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().contentHeaderPropertiesContentType(messageContentType).contentHeaderPropertiesHeaders(messageHeaders).contentHeaderPropertiesDeliveryMode(deliveryMode).contentHeaderPropertiesPriority(priority).publishExchange("").publishRoutingKey(queueName).content(messageContent).publishMessage().consumeResponse(BasicDeliverBody.class);
        BasicDeliverBody delivery = interaction.getLatestResponse(BasicDeliverBody.class);
        assertThat(delivery.getConsumerTag(), is(equalTo(AMQShortString.valueOf(consumerTag))));
        assertThat(delivery.getConsumerTag(), is(notNullValue()));
        assertThat(delivery.getRedelivered(), is(equalTo(false)));
        assertThat(delivery.getExchange(), is(nullValue()));
        assertThat(delivery.getRoutingKey(), is(equalTo(AMQShortString.valueOf(queueName))));
        ContentHeaderBody header = interaction.consumeResponse(ContentHeaderBody.class).getLatestResponse(ContentHeaderBody.class);
        assertThat(header.getBodySize(), is(equalTo((long) messageContent.length())));
        BasicContentHeaderProperties properties = header.getProperties();
        Map<String, Object> receivedHeaders = new HashMap<>(properties.getHeadersAsMap());
        assertThat(receivedHeaders, is(equalTo(new HashMap<>(messageHeaders))));
        assertThat(properties.getContentTypeAsString(), is(equalTo(messageContentType)));
        assertThat(properties.getPriority(), is(equalTo(priority)));
        assertThat(properties.getDeliveryMode(), is(equalTo(deliveryMode)));
        interaction.consumeResponse(ContentBody.class);
        String receivedContent = interaction.getLatestResponseContentBodyAsString();
        assertThat(receivedContent, is(equalTo(messageContent)));
        assertThat(getBrokerAdmin().getQueueDepthMessages(queueName), is(equalTo(1)));
        interaction.basic().ackDeliveryTag(delivery.getDeliveryTag()).ack().channel().close().consumeResponse(ChannelCloseOkBody.class);
        assertThat(getBrokerAdmin().getQueueDepthMessages(queueName), is(equalTo(0)));
    }
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) HashMap(java.util.HashMap) BasicConsumeOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 2 with org.apache.qpid.server.protocol.v0_8.transport

use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.

the class BasicTest method qosBytesSizeQosDoesNotPreventFirstMessage.

@Test
@SpecificationTest(section = "1.8.3.3", description = "The server MUST ignore this setting when the client is not processing any messages - i.e. " + "the prefetch size does not limit the transfer of single messages to a client, only " + "the sending in advance of more messages while the client still has one or more " + "unacknowledged messages.")
public void qosBytesSizeQosDoesNotPreventFirstMessage() throws Exception {
    String messageContent = String.join("", Collections.nCopies(1024, "*"));
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent);
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        String consumerTag = "A";
        interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().qosPrefetchSize(512).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consume().consumeResponse(BasicConsumeOkBody.class).consumeResponse(BasicDeliverBody.class);
        BasicDeliverBody delivery = interaction.getLatestResponse(BasicDeliverBody.class);
        ContentHeaderBody header = interaction.consumeResponse().getLatestResponse(ContentHeaderBody.class);
        assertThat(header.getBodySize(), is(equalTo((long) messageContent.length())));
        ContentBody content = interaction.consumeResponse().getLatestResponse(ContentBody.class);
        String receivedContent = getContent(content);
        assertThat(receivedContent, is(equalTo(messageContent)));
        interaction.basic().ackDeliveryTag(delivery.getDeliveryTag()).ack().channel().close().consumeResponse(ChannelCloseOkBody.class);
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
    }
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) BasicConsumeOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody) 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 3 with org.apache.qpid.server.protocol.v0_8.transport

use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.

the class BasicTest method publishUnrouteableMandatoryMessage.

@Test
@SpecificationTest(section = "1.8.3.7", description = "This flag [mandatory] tells the server how to react if the message cannot be routed to a " + "queue. If this flag is set, the server will return an unroutable message with a " + "Return method.")
public void publishUnrouteableMandatoryMessage() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        String messageContent = "Test";
        BasicReturnBody returned = interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().publishExchange("").publishRoutingKey("unrouteable").publishMandatory(true).content(messageContent).publishMessage().consumeResponse().getLatestResponse(BasicReturnBody.class);
        assertThat(returned.getReplyCode(), is(equalTo(ErrorCodes.NO_ROUTE)));
        ContentBody content = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
        assertThat(getContent(content), is(equalTo(messageContent)));
        interaction.channel().close().consumeResponse(ChannelCloseOkBody.class);
    }
}
Also used : BasicReturnBody(org.apache.qpid.server.protocol.v0_8.transport.BasicReturnBody) ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 4 with org.apache.qpid.server.protocol.v0_8.transport

use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.

the class BasicTest method get.

@Test
@SpecificationTest(section = "1.8.3.10", description = "direct access to a queue")
public void get() throws Exception {
    String messageContent = "message";
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent);
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        BasicGetOkBody response = interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().getQueueName(BrokerAdmin.TEST_QUEUE_NAME).get().consumeResponse().getLatestResponse(BasicGetOkBody.class);
        long deliveryTag = response.getDeliveryTag();
        ContentBody content = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
        String receivedContent = getContent(content);
        assertThat(receivedContent, is(equalTo(messageContent)));
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
        interaction.basic().ackDeliveryTag(deliveryTag).ack().channel().close().consumeResponse(ChannelCloseOkBody.class);
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
    }
}
Also used : ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicGetOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicGetOkBody) 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 5 with org.apache.qpid.server.protocol.v0_8.transport

use of org.apache.qpid.server.protocol.v0_8.transport in project qpid-broker-j by apache.

the class BasicTest method qosCountResized.

/**
 * The Qpid JMS AMQP 0-x client relies on being able to raise and lower qos count during a channels lifetime
 * to prevent channel starvation. This test supports this qos use-case.
 */
@Test
public void qosCountResized() throws Exception {
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, "A", "B", "C", "D", "E", "F");
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        String consumerTag = "A";
        interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().qosPrefetchCount(3).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consume().consumeResponse(BasicConsumeOkBody.class);
        final long deliveryTagA = receiveDeliveryHeaderAndBody(interaction, "A");
        receiveDeliveryHeaderAndBody(interaction, "B");
        final long deliveryTagC = receiveDeliveryHeaderAndBody(interaction, "C");
        ensureSync(interaction);
        // Raise qos count by one, expect D to arrive
        interaction.basic().qosPrefetchCount(4).qos().consumeResponse(BasicQosOkBody.class);
        long deliveryTagD = receiveDeliveryHeaderAndBody(interaction, "D");
        ensureSync(interaction);
        // Ack A, expect E to arrive
        interaction.basic().ackDeliveryTag(deliveryTagA).ack();
        receiveDeliveryHeaderAndBody(interaction, "E");
        ensureSync(interaction);
        // Lower qos back to 2 and ensure no more messages arrive (message credit will be negative at this point).
        interaction.basic().qosPrefetchCount(2).qos().consumeResponse(BasicQosOkBody.class);
        ensureSync(interaction);
        // Ack B and C and ensure still no more messages arrive (message credit will now be zero)
        interaction.basic().ackMultiple(true).ackDeliveryTag(deliveryTagC).ack();
        ensureSync(interaction);
        // Ack D and ensure F delivery arrives
        interaction.basic().ackMultiple(false).ackDeliveryTag(deliveryTagD).ack();
        receiveDeliveryHeaderAndBody(interaction, "F");
        interaction.channel().close().consumeResponse(ChannelCloseOkBody.class);
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(2)));
    }
}
Also used : BasicQosOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) ChannelFlowOkBody(org.apache.qpid.server.protocol.v0_8.transport.ChannelFlowOkBody) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

Test (org.junit.Test)88 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)72 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)44 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)32 Interaction (org.apache.qpid.tests.protocol.v0_8.Interaction)21 FrameTransport (org.apache.qpid.tests.protocol.v0_8.FrameTransport)20 Matchers.emptyString (org.hamcrest.Matchers.emptyString)18 ChannelCloseBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelCloseBody)17 QueueDeclareOkBody (org.apache.qpid.server.protocol.v0_8.transport.QueueDeclareOkBody)15 ConnectionCloseBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionCloseBody)13 ConnectionTuneBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody)12 ExchangeBoundOkBody (org.apache.qpid.server.protocol.v0_8.transport.ExchangeBoundOkBody)11 ExchangeDeclareOkBody (org.apache.qpid.server.protocol.v0_8.transport.ExchangeDeclareOkBody)11 ContentBody (org.apache.qpid.server.protocol.v0_8.transport.ContentBody)9 BasicConsumeOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody)8 BasicDeliverBody (org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody)8 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)8 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)7 ConnectionStartBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody)7 BasicQosOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody)6