Search in sources :

Example 11 with QueueDeclareOkBody

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

the class QueueTest method queueDeclareUsingRealQueueAttributesInWireArguments.

@Test
public void queueDeclareUsingRealQueueAttributesInWireArguments() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        QueueDeclareOkBody response = interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).queue().declareName(BrokerAdmin.TEST_QUEUE_NAME).declareArguments(Collections.singletonMap("defaultFilters", "{\"selector\":{\"x-filter-jms-selector\":[\"id=2\"]}}")).declare().consumeResponse().getLatestResponse(QueueDeclareOkBody.class);
        assertThat(response.getQueue(), is(equalTo(AMQShortString.valueOf(BrokerAdmin.TEST_QUEUE_NAME))));
        assertThat(response.getMessageCount(), is(equalTo(0L)));
        assertThat(response.getConsumerCount(), is(equalTo(0L)));
        // make sure that wire arguments took effect
        // by publishing messages and consuming message matching filter
        String consumerTag = "test";
        interaction.basic().qosPrefetchCount(2).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consume().consumeResponse(BasicConsumeOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class);
        String content2 = "Test Content 2";
        Map<String, Object> messageHeaders2 = Collections.singletonMap("id", 2);
        String contentType = "text/plain";
        // first message is not matching queue default filter
        interaction.basic().publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).publishMandatory(true).contentHeaderPropertiesContentType(contentType).contentHeaderPropertiesHeaders(Collections.singletonMap("id", 1)).content("Test1").publishMessage().basic().publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).publishMandatory(true).contentHeaderPropertiesContentType(contentType).contentHeaderPropertiesHeaders(messageHeaders2).content(content2).publishMessage();
        // second message should be received
        BasicDeliverBody delivery = interaction.consumeResponse(BasicDeliverBody.class).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(BrokerAdmin.TEST_QUEUE_NAME))));
        ContentHeaderBody header = interaction.consumeResponse(ContentHeaderBody.class).getLatestResponse(ContentHeaderBody.class);
        assertThat(header.getBodySize(), is(equalTo((long) content2.length())));
        BasicContentHeaderProperties properties = header.getProperties();
        Map<String, Object> receivedHeaders = new HashMap<>(properties.getHeadersAsMap());
        assertThat(receivedHeaders, is(equalTo(new HashMap<>(messageHeaders2))));
        assertThat(properties.getContentTypeAsString(), is(equalTo(contentType)));
        ContentBody content = interaction.consumeResponse(ContentBody.class).getLatestResponse(ContentBody.class);
        QpidByteBuffer payload = content.getPayload();
        byte[] contentData = new byte[payload.remaining()];
        payload.get(contentData);
        payload.dispose();
        String receivedContent = new String(contentData, StandardCharsets.UTF_8);
        assertThat(receivedContent, is(equalTo(receivedContent)));
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(2)));
        interaction.basic().ackDeliveryTag(delivery.getDeliveryTag()).ack().channel().close().consumeResponse(ChannelCloseOkBody.class);
        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) HashMap(java.util.HashMap) Interaction(org.apache.qpid.tests.protocol.v0_8.Interaction) BasicConsumeOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) QueueDeclareOkBody(org.apache.qpid.server.protocol.v0_8.transport.QueueDeclareOkBody) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody) Test(org.junit.Test)

Aggregations

QueueDeclareOkBody (org.apache.qpid.server.protocol.v0_8.transport.QueueDeclareOkBody)11 Test (org.junit.Test)11 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)9 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)5 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)3 ChannelCloseBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelCloseBody)3 BasicConsumeOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody)2 FrameTransport (org.apache.qpid.tests.protocol.v0_8.FrameTransport)2 Interaction (org.apache.qpid.tests.protocol.v0_8.Interaction)2 Matchers.emptyString (org.hamcrest.Matchers.emptyString)2 HashMap (java.util.HashMap)1 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)1 BasicDeliverBody (org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody)1 ConnectionCloseBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionCloseBody)1 ContentBody (org.apache.qpid.server.protocol.v0_8.transport.ContentBody)1 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)1 QueuePurgeOkBody (org.apache.qpid.server.protocol.v0_8.transport.QueuePurgeOkBody)1 Ignore (org.junit.Ignore)1