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());
}
}
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);
}
}
Aggregations