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)));
}
}
Aggregations