Search in sources :

Example 26 with ContentHeaderBody

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)));
    }
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) HashMap(java.util.HashMap) 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) QueueDeclareOkBody(org.apache.qpid.server.protocol.v0_8.transport.QueueDeclareOkBody) 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)

Aggregations

ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)23 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)13 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)11 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)6 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)5 ContentBody (org.apache.qpid.server.protocol.v0_8.transport.ContentBody)5 Test (org.junit.Test)5 MessageMetaData (org.apache.qpid.server.protocol.v0_8.MessageMetaData)4 BasicConsumeOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody)4 BasicDeliverBody (org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody)4 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)4 HashMap (java.util.HashMap)3 AMQBody (org.apache.qpid.server.protocol.v0_8.transport.AMQBody)3 AMQFrame (org.apache.qpid.server.protocol.v0_8.transport.AMQFrame)3 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)3 LinkedHashMap (java.util.LinkedHashMap)2 MessageReference (org.apache.qpid.server.message.MessageReference)2 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)2 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)2 BasicQosOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody)2