Search in sources :

Example 11 with ContentBody

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)));
    }
}
Also used : ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) 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)

Example 12 with ContentBody

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);
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString)

Example 13 with ContentBody

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

ContentBody (org.apache.qpid.server.protocol.v0_8.transport.ContentBody)11 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)9 Test (org.junit.Test)9 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)8 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)6 BasicDeliverBody (org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody)5 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)5 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)3 BasicConsumeOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody)3 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)3 HashMap (java.util.HashMap)2 AMQFrame (org.apache.qpid.server.protocol.v0_8.transport.AMQFrame)2 BasicQosOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody)2 ConnectionStartBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody)2 ConnectionTuneBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 ExecutionException (java.util.concurrent.ExecutionException)1