Search in sources :

Example 6 with ContentBody

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

the class ConnectionTest method overlySizedContentBodyFrame.

@Test
@SpecificationTest(section = "4.2.3", description = "A peer MUST NOT send frames larger than the agreed-upon size. A peer that receives an " + "oversized frame MUST signal a connection exception with reply code 501 (frame error).")
public void overlySizedContentBodyFrame() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        ConnectionTuneBody response = interaction.negotiateProtocol().consumeResponse(ConnectionStartBody.class).connection().startOkMechanism(ANONYMOUS).startOk().consumeResponse().getLatestResponse(ConnectionTuneBody.class);
        final long frameMax = response.getFrameMax();
        // Older Qpid JMS Client 0-x had a defect that meant they could send content body frames that were too
        // large.  Rather then limiting the user content of each frame to frameSize - 8, it sent frameSize bytes
        // of user content meaning the resultant frame was too big.  The server accommodates this behaviour
        // by reducing the frame-size advertised to the client.
        // Should be frameMax - 8 + 1.
        final int overlyLargeFrameBodySize = (int) (frameMax + 1);
        final byte[] bodyBytes = new byte[overlyLargeFrameBodySize];
        interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(frameMax).tuneOkHeartbeat(response.getHeartbeat()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).channel().open().consumeResponse(ChannelOpenOkBody.class).basic().publish().basic().contentHeader(bodyBytes.length).basic().contentBody(bodyBytes);
        // Server actually abruptly closes the connection.  We might see a graceful TCP/IP close or a broken pipe.
        try {
            final ChannelClosedResponse closeResponse = interaction.consumeResponse().getLatestResponse(ChannelClosedResponse.class);
        } catch (ExecutionException e) {
            Throwable original = e.getCause();
            if (original instanceof IOException) {
            // PASS
            } else {
                throw new RuntimeException(original);
            }
        }
    }
}
Also used : ConnectionStartBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody) IOException(java.io.IOException) ChannelClosedResponse(org.apache.qpid.tests.protocol.ChannelClosedResponse) ConnectionOpenOkBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionOpenOkBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 7 with ContentBody

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

the class LargeMessageTest method multiBodyMessage.

@Test
public void multiBodyMessage() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        String consumerTag = "A";
        String queueName = "testQueue";
        ConnectionTuneBody connTune = interaction.negotiateProtocol().consumeResponse(ConnectionStartBody.class).connection().startOkMechanism("ANONYMOUS").startOk().consumeResponse(ConnectionTuneBody.class).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) ConnectionStartBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody) BasicConsumeOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) 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) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) 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 8 with ContentBody

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

the class AMQDecoderTest method testDecodeWithManyBuffers.

public void testDecodeWithManyBuffers() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
    Random random = new Random();
    final byte[] payload = new byte[2048];
    random.nextBytes(payload);
    final AMQBody body = new ContentBody(ByteBuffer.wrap(payload));
    AMQFrame frame = new AMQFrame(1, body);
    TestSender sender = new TestSender();
    frame.writePayload(sender);
    ByteBuffer allData = combine(sender.getSentBuffers());
    for (int i = 0; i < allData.remaining(); i++) {
        byte[] minibuf = new byte[1];
        minibuf[0] = allData.get(i);
        _decoder.decodeBuffer(ByteBuffer.wrap(minibuf));
    }
    List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
    if (frames.get(0) instanceof AMQFrame) {
        assertEquals(ContentBody.TYPE, ((AMQFrame) frames.get(0)).getBodyFrame().getFrameType());
        ContentBody decodedBody = (ContentBody) ((AMQFrame) frames.get(0)).getBodyFrame();
        byte[] bodyBytes;
        try (QpidByteBuffer payloadBuffer = decodedBody.getPayload()) {
            bodyBytes = new byte[payloadBuffer.remaining()];
            payloadBuffer.get(bodyBytes);
        }
        assertTrue("Body was corrupted", Arrays.equals(payload, bodyBytes));
    } else {
        fail("decode was not a frame");
    }
}
Also used : AMQDataBlock(org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock) Random(java.util.Random) ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) AMQBody(org.apache.qpid.server.protocol.v0_8.transport.AMQBody) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AMQFrame(org.apache.qpid.server.protocol.v0_8.transport.AMQFrame) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 9 with ContentBody

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

the class BasicTest method receiveDeliveryHeaderAndBody.

private long receiveDeliveryHeaderAndBody(final Interaction interaction, String expectedMessageContent) throws Exception {
    BasicDeliverBody delivery = interaction.consumeResponse().getLatestResponse(BasicDeliverBody.class);
    ContentBody content = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
    assertThat(getContent(content), is(equalTo(expectedMessageContent)));
    return delivery.getDeliveryTag();
}
Also used : ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody)

Example 10 with ContentBody

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

the class BasicTest method qosBytesPrefetch.

@Test
@SpecificationTest(section = "1.8.3.3", description = "This field specifies the prefetch window size in octets. The server will send a message " + "in advance if it is equal to or smaller in size than the available prefetch size (and " + "also falls into other prefetch limits).")
public void qosBytesPrefetch() throws Exception {
    String messageContent1 = String.join("", Collections.nCopies(128, "1"));
    String messageContent2 = String.join("", Collections.nCopies(128, "2"));
    String messageContent3 = String.join("", Collections.nCopies(256, "3"));
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        String consumerTag = "A";
        interaction.openAnonymousConnection().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).content(messageContent1).publishMessage().basic().content(messageContent2).publishMessage().basic().content(messageContent3).publishMessage().channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().qosPrefetchSize(256).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consume().consumeResponse(BasicConsumeOkBody.class);
        BasicDeliverBody delivery1 = interaction.consumeResponse().getLatestResponse(BasicDeliverBody.class);
        ContentBody content1 = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
        BasicDeliverBody delivery2 = interaction.consumeResponse().getLatestResponse(BasicDeliverBody.class);
        ContentBody content2 = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
        assertThat(getContent(content1), is(equalTo(messageContent1)));
        assertThat(getContent(content2), is(equalTo(messageContent2)));
        ensureSync(interaction);
        // Ack first.  There will be insufficient bytes credit for the third to be sent.
        interaction.basic().ackDeliveryTag(delivery1.getDeliveryTag()).ack();
        ensureSync(interaction);
        // Ack second.  Now there will be sufficient bytes credit so expect the third.
        interaction.basic().ackDeliveryTag(delivery2.getDeliveryTag()).ack();
        BasicDeliverBody delivery3 = interaction.consumeResponse().getLatestResponse(BasicDeliverBody.class);
        ContentBody content3 = interaction.consumeResponse(ContentHeaderBody.class).consumeResponse().getLatestResponse(ContentBody.class);
        assertThat(getContent(content3), is(equalTo(messageContent3)));
        interaction.basic().ackDeliveryTag(delivery3.getDeliveryTag()).ack().channel().close().consumeResponse(ChannelCloseOkBody.class);
    }
}
Also used : ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) BasicQosOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) 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) 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