Search in sources :

Example 1 with BasicDeliverBody

use of org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody in project qpid-broker-j by apache.

the class LargeMessageTest method multiBodyMessage.

@Test
public void multiBodyMessage() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        String consumerTag = "A";
        String queueName = "testQueue";
        ConnectionTuneBody connTune = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
        byte[] messageContent = new byte[(int) connTune.getFrameMax()];
        IntStream.range(0, messageContent.length).forEach(i -> {
            messageContent[i] = (byte) (i & 0xFF);
        });
        interaction.connection().tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).channel().open().consumeResponse(ChannelOpenOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(queueName).consumeNoAck(true).consume().consumeResponse(BasicConsumeOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().publishExchange("").publishRoutingKey(queueName).content(messageContent).publishMessage().consumeResponse(BasicDeliverBody.class);
        BasicDeliverBody delivery = interaction.getLatestResponse(BasicDeliverBody.class);
        assertThat(delivery.getConsumerTag(), is(equalTo(AMQShortString.valueOf(consumerTag))));
        ContentHeaderBody header = interaction.consumeResponse(ContentHeaderBody.class).getLatestResponse(ContentHeaderBody.class);
        assertThat(header.getBodySize(), is(equalTo((long) messageContent.length)));
        byte[] receivedContent = new byte[messageContent.length];
        ContentBody content1 = interaction.consumeResponse(ContentBody.class).getLatestResponse(ContentBody.class);
        ContentBody content2 = interaction.consumeResponse(ContentBody.class).getLatestResponse(ContentBody.class);
        try (QpidByteBuffer allContent = QpidByteBuffer.concatenate(content1.getPayload(), content2.getPayload())) {
            allContent.get(receivedContent);
        }
        assertThat(receivedContent, is(equalTo(messageContent)));
    }
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) BasicQosOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) BasicConsumeOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody) ChannelOpenOkBody(org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody) Test(org.junit.Test)

Example 2 with BasicDeliverBody

use of org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody in project qpid-broker-j by apache.

the class LargeHeadersTest method headersFillContentHeaderFrame.

@Test
public /**
 * Tests boundary case where headers exactly fill the content header frame
 */
void headersFillContentHeaderFrame() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        String consumerTag = "A";
        ConnectionTuneBody connTune = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
        final String headerName = "test";
        final int headerValueSize = (int) (connTune.getFrameMax() - calculateContentHeaderFramingOverhead(headerName));
        final String headerValue = generateLongString(headerValueSize);
        final Map<String, Object> messageHeaders = Collections.singletonMap(headerName, headerValue);
        interaction.connection().tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).channel().open().consumeResponse(ChannelOpenOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consumeNoAck(true).consume().consumeResponse(BasicConsumeOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().contentHeaderPropertiesHeaders(messageHeaders).publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).publishMessage().consumeResponse(BasicDeliverBody.class);
        BasicDeliverBody delivery = interaction.getLatestResponse(BasicDeliverBody.class);
        assertThat(delivery.getConsumerTag(), is(equalTo(AMQShortString.valueOf(consumerTag))));
        ContentHeaderBody header = interaction.consumeResponse(ContentHeaderBody.class).getLatestResponse(ContentHeaderBody.class);
        assertThat(header.getBodySize(), is(equalTo(0L)));
        BasicContentHeaderProperties properties = header.getProperties();
        Map<String, Object> receivedHeaders = new HashMap<>(properties.getHeadersAsMap());
        assertThat(receivedHeaders, is(equalTo(new HashMap<>(messageHeaders))));
    }
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) HashMap(java.util.HashMap) BasicConsumeOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) BasicQosOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody) ChannelOpenOkBody(org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody) Test(org.junit.Test)

Example 3 with BasicDeliverBody

use of org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody in project qpid-broker-j by apache.

the class MalformedMessageTest method consumeMalformedMessage.

@Test
public void consumeMalformedMessage() throws Exception {
    final FieldTable malformedHeader = createHeadersWithMalformedLongString();
    final byte[] contentBytes = CONTENT_TEXT.getBytes(StandardCharsets.UTF_8);
    final String content2 = "message2";
    final byte[] content2Bytes = content2.getBytes(StandardCharsets.UTF_8);
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        String consumerTag = "A";
        interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consume().consumeResponse(BasicConsumeOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).contentHeaderPropertiesHeaders(malformedHeader).content(contentBytes).publishMessage().basic().publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).contentHeaderPropertiesContentType("text/plain").contentHeaderPropertiesHeaders(Collections.emptyMap()).content(content2Bytes).publishMessage();
        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) content2Bytes.length)));
        BasicContentHeaderProperties properties = header.getProperties();
        Map<String, Object> receivedHeaders = new HashMap<>(properties.getHeadersAsMap());
        assertThat(receivedHeaders.isEmpty(), is(equalTo(true)));
        String receivedContent = interaction.consumeResponse(ContentBody.class).getLatestResponseContentBodyAsString();
        assertThat(receivedContent, is(equalTo(content2)));
        interaction.channel().close().consumeResponse(ChannelCloseOkBody.class, ChannelFlowOkBody.class);
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v0_8.FrameTransport) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) HashMap(java.util.HashMap) Interaction(org.apache.qpid.tests.protocol.v0_8.Interaction) 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) BasicQosOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody) ChannelFlowOkBody(org.apache.qpid.server.protocol.v0_8.transport.ChannelFlowOkBody) ChannelOpenOkBody(org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody) Test(org.junit.Test)

Example 4 with BasicDeliverBody

use of org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody in project qpid-broker-j by apache.

the class BasicTest method consumeMessage.

@Test
@SpecificationTest(section = "1.8.3.3", description = "start a queue consumer")
public void consumeMessage() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        String messageContent = "Test";
        String consumerTag = "A";
        String queueName = BrokerAdmin.TEST_QUEUE_NAME;
        Map<String, Object> messageHeaders = Collections.singletonMap("test", "testValue");
        String messageContentType = "text/plain";
        byte deliveryMode = (byte) 1;
        byte priority = (byte) 2;
        interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(queueName).consume().consumeResponse(BasicConsumeOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().contentHeaderPropertiesContentType(messageContentType).contentHeaderPropertiesHeaders(messageHeaders).contentHeaderPropertiesDeliveryMode(deliveryMode).contentHeaderPropertiesPriority(priority).publishExchange("").publishRoutingKey(queueName).content(messageContent).publishMessage().consumeResponse(BasicDeliverBody.class);
        BasicDeliverBody delivery = interaction.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(queueName))));
        ContentHeaderBody header = interaction.consumeResponse(ContentHeaderBody.class).getLatestResponse(ContentHeaderBody.class);
        assertThat(header.getBodySize(), is(equalTo((long) messageContent.length())));
        BasicContentHeaderProperties properties = header.getProperties();
        Map<String, Object> receivedHeaders = new HashMap<>(properties.getHeadersAsMap());
        assertThat(receivedHeaders, is(equalTo(new HashMap<>(messageHeaders))));
        assertThat(properties.getContentTypeAsString(), is(equalTo(messageContentType)));
        assertThat(properties.getPriority(), is(equalTo(priority)));
        assertThat(properties.getDeliveryMode(), is(equalTo(deliveryMode)));
        interaction.consumeResponse(ContentBody.class);
        String receivedContent = interaction.getLatestResponseContentBodyAsString();
        assertThat(receivedContent, is(equalTo(messageContent)));
        assertThat(getBrokerAdmin().getQueueDepthMessages(queueName), is(equalTo(1)));
        interaction.basic().ackDeliveryTag(delivery.getDeliveryTag()).ack().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) BasicConsumeOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 5 with BasicDeliverBody

use of org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody in project qpid-broker-j by apache.

the class BasicTest method qosBytesSizeQosDoesNotPreventFirstMessage.

@Test
@SpecificationTest(section = "1.8.3.3", description = "The server MUST ignore this setting when the client is not processing any messages - i.e. " + "the prefetch size does not limit the transfer of single messages to a client, only " + "the sending in advance of more messages while the client still has one or more " + "unacknowledged messages.")
public void qosBytesSizeQosDoesNotPreventFirstMessage() throws Exception {
    String messageContent = String.join("", Collections.nCopies(1024, "*"));
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent);
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        String consumerTag = "A";
        interaction.negotiateOpen().channel().open().consumeResponse(ChannelOpenOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().qosPrefetchSize(512).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consume().consumeResponse(BasicConsumeOkBody.class).consumeResponse(BasicDeliverBody.class);
        BasicDeliverBody delivery = interaction.getLatestResponse(BasicDeliverBody.class);
        ContentHeaderBody header = interaction.consumeResponse().getLatestResponse(ContentHeaderBody.class);
        assertThat(header.getBodySize(), is(equalTo((long) messageContent.length())));
        ContentBody content = interaction.consumeResponse().getLatestResponse(ContentBody.class);
        String receivedContent = getContent(content);
        assertThat(receivedContent, is(equalTo(messageContent)));
        interaction.basic().ackDeliveryTag(delivery.getDeliveryTag()).ack().channel().close().consumeResponse(ChannelCloseOkBody.class);
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
    }
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) BasicConsumeOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody) 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

BasicDeliverBody (org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody)9 Test (org.junit.Test)8 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)7 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)7 BasicConsumeOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody)6 ContentBody (org.apache.qpid.server.protocol.v0_8.transport.ContentBody)6 BasicQosOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody)5 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)5 HashMap (java.util.HashMap)4 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)4 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)3 FrameTransport (org.apache.qpid.tests.protocol.v0_8.FrameTransport)3 Interaction (org.apache.qpid.tests.protocol.v0_8.Interaction)3 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 ChannelFlowOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelFlowOkBody)2 ConnectionTuneBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody)2 FieldTable (org.apache.qpid.server.protocol.v0_8.FieldTable)1 ConnectionCloseBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionCloseBody)1 QueueDeclareOkBody (org.apache.qpid.server.protocol.v0_8.transport.QueueDeclareOkBody)1 TxSelectOkBody (org.apache.qpid.server.protocol.v0_8.transport.TxSelectOkBody)1