use of org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody 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