Search in sources :

Example 1 with ConnectionHeartbeat

use of org.apache.qpid.server.protocol.v0_10.transport.ConnectionHeartbeat 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)

Aggregations

ConnectionHeartbeat (org.apache.qpid.server.protocol.v0_10.transport.ConnectionHeartbeat)1 ConnectionTune (org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune)1 ChannelClosedResponse (org.apache.qpid.tests.protocol.ChannelClosedResponse)1 Response (org.apache.qpid.tests.protocol.Response)1 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)1 Test (org.junit.Test)1