use of org.apache.qpid.server.protocol.v0_8.transport.ContentBody in project qpid-broker-j by apache.
the class BasicTest method getNoAck.
@Test
@SpecificationTest(section = "1.8.3.10", description = "direct access to a queue")
public void getNoAck() throws Exception {
String messageContent = "message";
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent);
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.openAnonymousConnection().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().getQueueName(BrokerAdmin.TEST_QUEUE_NAME).getNoAck(true).get().consumeResponse(BasicGetOkBody.class);
ContentBody content = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
String receivedContent = getContent(content);
assertThat(receivedContent, is(equalTo(messageContent)));
interaction.channel().close().consumeResponse(ChannelCloseOkBody.class);
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.ContentBody in project qpid-broker-j by apache.
the class BasicTest method getContent.
private String getContent(final ContentBody content) {
QpidByteBuffer payload = content.getPayload();
byte[] contentData = new byte[payload.remaining()];
payload.get(contentData);
payload.dispose();
return new String(contentData, StandardCharsets.UTF_8);
}
use of org.apache.qpid.server.protocol.v0_8.transport.ContentBody in project qpid-broker-j by apache.
the class BasicTest method messagePersistence.
@Test
@SpecificationTest(section = "1.8", description = "The server SHOULD respect the persistent property of basic messages and SHOULD make a best " + "effort to hold persistent basic messages on a reliable storage mechanism.")
public void messagePersistence() throws Exception {
String queueName = "durableQueue";
String messageContent = "Test";
String messageContentType = "text/plain";
byte deliveryMode = (byte) 2;
Map<String, Object> messageHeaders = Collections.singletonMap("test", "testValue");
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.openAnonymousConnection().channel().open().consumeResponse(ChannelOpenOkBody.class).queue().declareName(queueName).declareDurable(true).declare().consumeResponse(QueueDeclareOkBody.class).basic().contentHeaderPropertiesContentType(messageContentType).contentHeaderPropertiesHeaders(messageHeaders).contentHeaderPropertiesDeliveryMode(deliveryMode).publishExchange("").publishRoutingKey(queueName).content(messageContent).publishMessage().channel().close().consumeResponse(ChannelCloseOkBody.class);
assertThat(getBrokerAdmin().getQueueDepthMessages(queueName), is(equalTo(1)));
}
assumeThat(getBrokerAdmin().supportsRestart(), Matchers.is(true));
getBrokerAdmin().restart();
assertThat(getBrokerAdmin().getQueueDepthMessages(queueName), is(equalTo(1)));
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.openAnonymousConnection().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().getQueueName(queueName).getNoAck(true).get().consumeResponse(BasicGetOkBody.class);
ContentHeaderBody header = interaction.consumeResponse().getLatestResponse(ContentHeaderBody.class);
ContentBody content = interaction.consumeResponse().getLatestResponse(ContentBody.class);
String receivedContent = getContent(content);
BasicContentHeaderProperties properties = header.getProperties();
assertThat(receivedContent, is(equalTo(messageContent)));
Map<String, Object> receivedHeaders = new HashMap<>(FieldTable.convertToMap(properties.getHeaders()));
assertThat(receivedHeaders, is(equalTo(new HashMap<>(messageHeaders))));
assertThat(properties.getContentTypeAsString(), is(equalTo(messageContentType)));
assertThat(properties.getDeliveryMode(), is(equalTo(deliveryMode)));
interaction.channel().close().consumeResponse(ChannelCloseOkBody.class);
assertThat(getBrokerAdmin().getQueueDepthMessages(queueName), is(equalTo(0)));
}
}
Aggregations