use of org.apache.qpid.tests.protocol.ChannelClosedResponse in project qpid-broker-j by apache.
the class ConnectionTest method overlySizedContentBodyFrame.
@Test
@SpecificationTest(section = "4.2.3", description = "A peer MUST NOT send frames larger than the agreed-upon size. A peer that receives an " + "oversized frame MUST signal a connection exception with reply code 501 (frame error).")
public void overlySizedContentBodyFrame() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
ConnectionTuneBody response = interaction.negotiateProtocol().consumeResponse(ConnectionStartBody.class).connection().startOkMechanism(ANONYMOUS).startOk().consumeResponse().getLatestResponse(ConnectionTuneBody.class);
final long frameMax = response.getFrameMax();
// Older Qpid JMS Client 0-x had a defect that meant they could send content body frames that were too
// large. Rather then limiting the user content of each frame to frameSize - 8, it sent frameSize bytes
// of user content meaning the resultant frame was too big. The server accommodates this behaviour
// by reducing the frame-size advertised to the client.
// Should be frameMax - 8 + 1.
final int overlyLargeFrameBodySize = (int) (frameMax + 1);
final byte[] bodyBytes = new byte[overlyLargeFrameBodySize];
interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(frameMax).tuneOkHeartbeat(response.getHeartbeat()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).channel().open().consumeResponse(ChannelOpenOkBody.class).basic().publish().basic().contentHeader(bodyBytes.length).basic().contentBody(bodyBytes);
// Server actually abruptly closes the connection. We might see a graceful TCP/IP close or a broken pipe.
try {
final ChannelClosedResponse closeResponse = interaction.consumeResponse().getLatestResponse(ChannelClosedResponse.class);
} catch (ExecutionException e) {
Throwable original = e.getCause();
if (original instanceof IOException) {
// PASS
} else {
throw new RuntimeException(original);
}
}
}
}
use of org.apache.qpid.tests.protocol.ChannelClosedResponse in project qpid-broker-j by apache.
the class ConnectionTest method heartbeatingNoIncomingTraffic.
@Test
@SpecificationTest(section = "4.2.7", description = " If a peer detects no incoming traffic (i.e. received octets) for two heartbeat intervals " + "or longer, it should close the connection without following the Connection.Close/Close-Ok handshaking")
public void heartbeatingNoIncomingTraffic() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
ConnectionTuneBody response = interaction.negotiateProtocol().consumeResponse(ConnectionStartBody.class).connection().startOkMechanism(ANONYMOUS).startOk().consumeResponse().getLatestResponse(ConnectionTuneBody.class);
final Long heartbeatPeriod = 1L;
interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(response.getFrameMax()).tuneOkHeartbeat(heartbeatPeriod.intValue()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).consumeResponse(HeartbeatBody.class);
// Do not reflect a heartbeat so incoming line will be silent thus
// requiring the broker to close the connection.
Class[] classes = new Class[] { ChannelClosedResponse.class, HeartbeatBody.class };
do {
Response<?> latestResponse = interaction.consumeResponse(classes).getLatestResponse();
if (latestResponse instanceof ChannelClosedResponse) {
break;
}
classes = new Class[] { ChannelClosedResponse.class };
} while (true);
}
}
Aggregations