Search in sources :

Example 6 with ConnectionTuneBody

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

the class ConnectionTest method tooSmallFrameSize.

@Test
@SpecificationTest(section = "1.4.2.6", description = "[...] the minimum negotiated value for frame-max is also" + " frame-min-size [4096].")
public void tooSmallFrameSize() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ConnectionTuneBody response = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
        interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(1024).tuneOkHeartbeat(response.getHeartbeat()).tuneOk().connection().open().consumeResponse(ConnectionCloseBody.class, ChannelClosedResponse.class);
    }
}
Also used : 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 7 with ConnectionTuneBody

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

the class ConnectionTest method tooLargeFrameSize.

@Test
@SpecificationTest(section = "1.4.2.6.2.", description = "If the client specifies a frame max that is higher than" + " the value provided by the server, the server MUST" + " close the connection without attempting a negotiated" + " close. The server may report the error in some fashion" + " to assist implementors.")
public void tooLargeFrameSize() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ConnectionTuneBody response = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
        interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(Long.MAX_VALUE).tuneOkHeartbeat(response.getHeartbeat()).tuneOk().connection().open().consumeResponse(ConnectionCloseBody.class, ChannelClosedResponse.class);
    }
}
Also used : 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 8 with ConnectionTuneBody

use of org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody 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 9 with ConnectionTuneBody

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

the class ConnectionTest method connectionSecure.

@Test
@SpecificationTest(section = "1.4.2.3", description = "security challenge data")
public void connectionSecure() throws Exception {
    assumeThat(getBrokerAdmin().isSASLMechanismSupported(PLAIN), is(true));
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin(), BrokerAdmin.PortType.AMQP).connect()) {
        final byte[] initialResponse = String.format("\0%s\0%s", getBrokerAdmin().getValidUsername(), getBrokerAdmin().getValidPassword()).getBytes(StandardCharsets.US_ASCII);
        final Interaction interaction = transport.newInteraction();
        final ConnectionStartBody start = interaction.negotiateProtocol().consumeResponse().getLatestResponse(ConnectionStartBody.class);
        assertThat(Arrays.asList(new String(start.getMechanisms()).split(" ")), hasItem(PLAIN));
        final ConnectionSecureBody secure = interaction.connection().startOkMechanism(PLAIN).startOk().consumeResponse().getLatestResponse(ConnectionSecureBody.class);
        assertThat(secure.getChallenge(), is(anyOf(nullValue(), equalTo(new byte[0]))));
        final ConnectionTuneBody tune = interaction.connection().secureOk(initialResponse).consumeResponse().getLatestResponse(ConnectionTuneBody.class);
        interaction.connection().tuneOkChannelMax(tune.getChannelMax()).tuneOkFrameMax(tune.getFrameMax()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class);
    }
}
Also used : ConnectionStartBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) Matchers.containsString(org.hamcrest.Matchers.containsString) ConnectionSecureBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionSecureBody) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 10 with ConnectionTuneBody

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

the class ConnectionTest method connectionOpenUnknownVirtualHost.

@Test
@SpecificationTest(section = "1.4.2.7", description = "The client tried to work with an unknown virtual host.")
public void connectionOpenUnknownVirtualHost() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ConnectionTuneBody tune = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
        ConnectionCloseBody close = interaction.connection().tuneOkChannelMax(tune.getChannelMax()).tuneOkFrameMax(tune.getFrameMax()).tuneOkHeartbeat(tune.getHeartbeat()).tuneOk().connection().openVirtualHost("unknown-virtualhost").open().consumeResponse().getLatestResponse(ConnectionCloseBody.class);
        // Spec requires INVALID_PATH, but implementation uses NOT_FOUND
        assertThat(close.getReplyCode(), is(anyOf(equalTo(ErrorCodes.NOT_FOUND), equalTo(ErrorCodes.INVALID_PATH))));
        assertThat(String.valueOf(close.getReplyText()).toLowerCase(), containsString("unknown virtual host"));
    }
}
Also used : ConnectionCloseBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionCloseBody) 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)

Aggregations

ConnectionTuneBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody)13 Test (org.junit.Test)12 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)10 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)3 HeartbeatBody (org.apache.qpid.server.protocol.v0_8.transport.HeartbeatBody)3 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)2 BasicConsumeOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody)2 BasicDeliverBody (org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody)2 BasicQosOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody)2 ConnectionOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionOpenOkBody)2 ConnectionSecureBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionSecureBody)2 ConnectionStartBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 AMQDataBlock (org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock)1