Search in sources :

Example 1 with ConnectionTune

use of org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune in project qpid-broker-j by apache.

the class LargeApplicationHeadersTest method applicationHeadersSentOverManyFrames.

@Test
public void applicationHeadersSentOverManyFrames() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        final String subscriberName = "testSubscriber";
        byte[] sessionName = "test".getBytes(UTF_8);
        final ConnectionTune tune = interaction.authenticateConnection().getLatestResponse(ConnectionTune.class);
        int headerPropertySize = ((1 << 16) - 1);
        Map<String, Object> applicationHeaders = createApplicationHeadersThatExceedSingleFrame(headerPropertySize, tune.getMaxFrameSize());
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setApplicationHeaders(applicationHeaders);
        interaction.connection().tuneOk().connection().open().consumeResponse(ConnectionOpenOk.class);
        interaction.channelId(1).attachSession(sessionName).message().subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().message().flowId(1).flowDestination(subscriberName).flowUnit(MessageCreditUnit.MESSAGE).flowValue(1).flow().message().flowId(2).flowDestination(subscriberName).flowUnit(MessageCreditUnit.BYTE).flowValue(-1).flow().message().transferDestination(BrokerAdmin.TEST_QUEUE_NAME).transferHeader(null, messageProperties).transferId(0).transfer().session().flushCompleted().flush().consumeResponse().getLatestResponse(SessionCompleted.class);
        MessageTransfer transfer = interaction.consume(MessageTransfer.class, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class);
        assertThat(transfer.getBodySize(), is(0));
        Header header = transfer.getHeader();
        assertThat(header, is(notNullValue()));
        MessageProperties receivedMessageProperties = header.getMessageProperties();
        assertThat(receivedMessageProperties, is(notNullValue()));
        Map<String, Object> receivedApplicationHeaders = receivedMessageProperties.getApplicationHeaders();
        assertThat(receivedApplicationHeaders, is(notNullValue()));
        assertThat(receivedApplicationHeaders, is(equalTo(applicationHeaders)));
    }
}
Also used : Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) ConnectionTune(org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) SessionCommandPoint(org.apache.qpid.server.protocol.v0_10.transport.SessionCommandPoint) Test(org.junit.Test)

Example 2 with ConnectionTune

use of org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune in project qpid-broker-j by apache.

the class ConnectionTest method heartbeatingIncomingIdle.

@Test
@SpecificationTest(section = "9.connection", description = "If a connection is idle for more than twice the negotiated heartbeat delay, the peers MAY " + "be considered disconnected.")
public void heartbeatingIncomingIdle() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ConnectionTune response = interaction.authenticateConnection().getLatestResponse(ConnectionTune.class);
        assumeThat(response.hasHeartbeatMin(), is(true));
        assumeThat(response.hasHeartbeatMax(), is(true));
        assumeThat(response.getHeartbeatMin(), is(greaterThanOrEqualTo(0)));
        assumeThat(response.getHeartbeatMax(), is(greaterThanOrEqualTo(1)));
        final int heartbeatPeriod = 1;
        interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkMaxFrameSize(response.getMaxFrameSize()).tuneOkHeartbeat(heartbeatPeriod).tuneOk().connection().open().consumeResponse(ConnectionOpenOk.class);
        interaction.consumeResponse().getLatestResponse(ConnectionHeartbeat.class);
        // the server might be able to send two heartbeats
        Response latestResponse = interaction.consumeResponse().getLatestResponse();
        if (latestResponse != null && latestResponse.getBody() instanceof ConnectionHeartbeat) {
            latestResponse = interaction.consumeResponse().getLatestResponse();
        }
        assertThat(latestResponse, instanceOf(ChannelClosedResponse.class));
    }
}
Also used : ChannelClosedResponse(org.apache.qpid.tests.protocol.ChannelClosedResponse) Response(org.apache.qpid.tests.protocol.Response) ConnectionHeartbeat(org.apache.qpid.server.protocol.v0_10.transport.ConnectionHeartbeat) ConnectionTune(org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune) ChannelClosedResponse(org.apache.qpid.tests.protocol.ChannelClosedResponse) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 3 with ConnectionTune

use of org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune in project qpid-broker-j by apache.

the class LargeMessageBodyTest method messageBodyOverManyFrames.

@Test
public void messageBodyOverManyFrames() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        final String subscriberName = "testSubscriber";
        byte[] sessionName = "test".getBytes(UTF_8);
        final ConnectionTune tune = interaction.authenticateConnection().getLatestResponse(ConnectionTune.class);
        final byte[] messageContent = new byte[tune.getMaxFrameSize() * 2];
        IntStream.range(0, messageContent.length).forEach(i -> {
            messageContent[i] = (byte) (i & 0xFF);
        });
        interaction.connection().tuneOk().connection().open().consumeResponse(ConnectionOpenOk.class);
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setContentLength(messageContent.length);
        interaction.channelId(1).attachSession(sessionName).message().subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().message().flowId(1).flowDestination(subscriberName).flowUnit(MessageCreditUnit.MESSAGE).flowValue(1).flow().message().flowId(2).flowDestination(subscriberName).flowUnit(MessageCreditUnit.BYTE).flowValue(-1).flow().message().transferDestination(BrokerAdmin.TEST_QUEUE_NAME).transferBody(messageContent).transferHeader(null, messageProperties).transferId(3).transfer().session().flushCompleted().flush().consumeResponse().getLatestResponse(SessionCompleted.class);
        MessageTransfer transfer = interaction.consume(MessageTransfer.class, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class);
        assertThat(transfer.getBodySize(), is(equalTo(messageContent.length)));
        QpidByteBuffer receivedBody = transfer.getBody();
        byte[] receivedBytes = new byte[receivedBody.remaining()];
        receivedBody.get(receivedBytes);
        assertThat(receivedBytes, is(equalTo(messageContent)));
    }
}
Also used : MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) ConnectionTune(org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) Test(org.junit.Test)

Example 4 with ConnectionTune

use of org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune in project qpid-broker-j by apache.

the class ConnectionTest method tooSmallFrameSize.

@Test
@SpecificationTest(section = "9.connection.tune-ok.minimum", description = "[...] the minimum negotiated value for max-frame-size is also MIN-MAX-FRAME-SIZE [4096]")
public void tooSmallFrameSize() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ConnectionTune response = interaction.authenticateConnection().getLatestResponse(ConnectionTune.class);
        interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkMaxFrameSize(1024).tuneOk().connection().open().consumeResponse(ConnectionClose.class, ChannelClosedResponse.class);
    }
}
Also used : ConnectionTune(org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 5 with ConnectionTune

use of org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune in project qpid-broker-j by apache.

the class ConnectionTest method tooLargeFrameSize.

@Test
@SpecificationTest(section = "9.connection.tune-ok.max-frame-size", description = "If the client specifies a channel max that is higher than the value provided by the server," + " the server MUST close the connection without attempting a negotiated close." + " The server may report the error in some fashion to assist implementers.")
public void tooLargeFrameSize() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ConnectionTune response = interaction.authenticateConnection().getLatestResponse(ConnectionTune.class);
        assumeThat(response.hasMaxFrameSize(), is(true));
        assumeThat(response.getMaxFrameSize(), is(lessThan(0xFFFF)));
        interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkMaxFrameSize(response.getMaxFrameSize() + 1).tuneOk().connection().open().consumeResponse(ConnectionClose.class, ChannelClosedResponse.class);
    }
}
Also used : ConnectionTune(org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

ConnectionTune (org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune)6 Test (org.junit.Test)6 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)4 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)2 MessageTransfer (org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 ConnectionHeartbeat (org.apache.qpid.server.protocol.v0_10.transport.ConnectionHeartbeat)1 Header (org.apache.qpid.server.protocol.v0_10.transport.Header)1 SessionCommandPoint (org.apache.qpid.server.protocol.v0_10.transport.SessionCommandPoint)1 ChannelClosedResponse (org.apache.qpid.tests.protocol.ChannelClosedResponse)1 Response (org.apache.qpid.tests.protocol.Response)1