Search in sources :

Example 1 with ConnectionTuneBody

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

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

the class ConnectionTest method connectionSecureWithChallengeResponse.

@Test
@SpecificationTest(section = "1.4.2.3", description = "security challenge data")
public void connectionSecureWithChallengeResponse() throws Exception {
    assumeThat(getBrokerAdmin().isSASLMechanismSupported(CRAM_MD5), is(true));
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin(), BrokerAdmin.PortType.AMQP).connect()) {
        final Interaction interaction = transport.newInteraction();
        final ConnectionStartBody start = interaction.negotiateProtocol().consumeResponse().getLatestResponse(ConnectionStartBody.class);
        assertThat(Arrays.asList(new String(start.getMechanisms()).split(" ")), hasItem(CRAM_MD5));
        final ConnectionSecureBody secure = interaction.connection().startOkMechanism(CRAM_MD5).startOk().consumeResponse().getLatestResponse(ConnectionSecureBody.class);
        byte[] response = generateCramMD5ClientResponse(getBrokerAdmin().getValidUsername(), getBrokerAdmin().getValidPassword(), secure.getChallenge());
        final ConnectionTuneBody tune = interaction.connection().secureOk(response).consumeResponse().getLatestResponse(ConnectionTuneBody.class);
        interaction.connection().tuneOkChannelMax(tune.getChannelMax()).tuneOkFrameMax(tune.getFrameMax()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class);
    }
}
Also used : ConnectionStartBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) Matchers.containsString(org.hamcrest.Matchers.containsString) ConnectionSecureBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionSecureBody) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 3 with ConnectionTuneBody

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

use of org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody 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(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ConnectionTuneBody response = interaction.authenticateConnection().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 {
            interaction.consumeResponse().getLatestResponse(ChannelClosedResponse.class);
        } catch (ExecutionException e) {
            Throwable original = e.getCause();
            if (original instanceof IOException) {
            // PASS
            } else {
                throw new RuntimeException(original);
            }
        }
    }
}
Also used : ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ConnectionOpenOkBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionOpenOkBody) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 5 with ConnectionTuneBody

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

the class ConnectionTest method connectionTuneOkAndOpen.

@Test
@SpecificationTest(section = "1.4.2.6", description = "negotiate connection tuning parameters")
public void connectionTuneOkAndOpen() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ConnectionTuneBody response = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
        interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(response.getFrameMax()).tuneOkHeartbeat(response.getHeartbeat()).tuneOk().connection().open().consumeResponse().getLatestResponse(ConnectionOpenOkBody.class);
    }
}
Also used : ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

ConnectionTuneBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody)13 Test (org.junit.Test)12 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)10 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)3 HeartbeatBody (org.apache.qpid.server.protocol.v0_8.transport.HeartbeatBody)3 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)2 BasicConsumeOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody)2 BasicDeliverBody (org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody)2 BasicQosOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody)2 ConnectionOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionOpenOkBody)2 ConnectionSecureBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionSecureBody)2 ConnectionStartBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 AMQDataBlock (org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock)1