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