Search in sources :

Example 1 with HeartbeatBody

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

the class ConnectionTest method heartbeating.

@Test
@SpecificationTest(section = "4.2.7", description = "Heartbeat frames tell the recipient that the sender is still alive. The rate and timing of" + " heartbeat frames is negotiated during connection tuning.")
public void heartbeating() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ConnectionTuneBody response = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
        final Long heartbeatPeriod = 1L;
        interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(response.getFrameMax()).tuneOkHeartbeat(heartbeatPeriod.intValue()).tuneOk();
        final long startTime = System.currentTimeMillis();
        interaction.connection().open().consumeResponse(ConnectionOpenOkBody.class).consumeResponse().getLatestResponse(HeartbeatBody.class);
        final long actualHeartbeatDelay = System.currentTimeMillis() - startTime;
        // Includes wiggle room to allow for slow boxes.
        final long maximumExpectedHeartbeatDelay = heartbeatPeriod * 2 * 2;
        assertThat("Heartbeat not received within expected time frame", actualHeartbeatDelay / 1000, is(both(greaterThanOrEqualTo(heartbeatPeriod)).and(lessThanOrEqualTo(maximumExpectedHeartbeatDelay))));
        interaction.sendPerformative(new HeartbeatBody());
        interaction.consumeResponse(HeartbeatBody.class).sendPerformative(new HeartbeatBody());
    }
}
Also used : HeartbeatBody(org.apache.qpid.server.protocol.v0_8.transport.HeartbeatBody) 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)

Example 2 with HeartbeatBody

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

the class ConnectionTest method heartbeatingIncomingTrafficIsNonHeartbeat.

@Test
@SpecificationTest(section = "4.2.7", description = "Any sent octet is a valid substitute for a heartbeat")
public void heartbeatingIncomingTrafficIsNonHeartbeat() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ConnectionTuneBody response = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
        final Long heartbeatPeriod = 1L;
        interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(response.getFrameMax()).tuneOkHeartbeat(heartbeatPeriod.intValue()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).channel().open().consumeResponse(ChannelOpenOkBody.class).consumeResponse(HeartbeatBody.class).exchange().declarePassive(true).declareNoWait(true).declare().consumeResponse(HeartbeatBody.class).sendPerformative(new HeartbeatBody()).exchange().declarePassive(true).declareNoWait(true).declare();
        interaction.connection().close().consumeResponse().getLatestResponse(ConnectionCloseOkBody.class);
    }
}
Also used : HeartbeatBody(org.apache.qpid.server.protocol.v0_8.transport.HeartbeatBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) 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

ConnectionTuneBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody)2 HeartbeatBody (org.apache.qpid.server.protocol.v0_8.transport.HeartbeatBody)2 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)2 Test (org.junit.Test)2 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)1