Search in sources :

Example 6 with ConnectionTune

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

the class ConnectionTest method heartbeating.

@Test
@SpecificationTest(section = "9.connection", description = "The heartbeat control may be used to generate artificial network traffic when a connection " + "is idle.")
public void heartbeating() 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();
        final long startTime = System.currentTimeMillis();
        interaction.connection().open().consumeResponse(ConnectionOpenOk.class).consumeResponse().getLatestResponse(ConnectionHeartbeat.class);
        final long actualHeartbeatDelay = System.currentTimeMillis() - startTime;
        // Includes wiggle room to allow for slow boxes.
        final int maximumExpectedHeartbeatDelay = heartbeatPeriod * 2 * 2;
        assertThat("Heartbeat not received within expected time frame", ((int) actualHeartbeatDelay / 1000), is(both(greaterThanOrEqualTo(heartbeatPeriod)).and(lessThanOrEqualTo(maximumExpectedHeartbeatDelay))));
        interaction.connection().heartbeat();
        interaction.consumeResponse(ConnectionHeartbeat.class).connection().heartbeat();
    }
}
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