Search in sources :

Example 1 with ChannelClosedResponse

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);
            }
        }
    }
}
Also used : ConnectionStartBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody) IOException(java.io.IOException) ChannelClosedResponse(org.apache.qpid.tests.protocol.ChannelClosedResponse) ConnectionOpenOkBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionOpenOkBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 2 with ChannelClosedResponse

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);
    }
}
Also used : HeartbeatBody(org.apache.qpid.server.protocol.v0_8.transport.HeartbeatBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) ConnectionStartBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody) ChannelClosedResponse(org.apache.qpid.tests.protocol.ChannelClosedResponse) ConnectionOpenOkBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionOpenOkBody) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

ConnectionOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionOpenOkBody)2 ConnectionStartBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody)2 ConnectionTuneBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody)2 ChannelClosedResponse (org.apache.qpid.tests.protocol.ChannelClosedResponse)2 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 HeartbeatBody (org.apache.qpid.server.protocol.v0_8.transport.HeartbeatBody)1