use of org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune in project qpid-broker-j by apache.
the class LargeApplicationHeadersTest method applicationHeadersSentOverManyFrames.
@Test
public void applicationHeadersSentOverManyFrames() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
final String subscriberName = "testSubscriber";
byte[] sessionName = "test".getBytes(UTF_8);
final ConnectionTune tune = interaction.authenticateConnection().getLatestResponse(ConnectionTune.class);
int headerPropertySize = ((1 << 16) - 1);
Map<String, Object> applicationHeaders = createApplicationHeadersThatExceedSingleFrame(headerPropertySize, tune.getMaxFrameSize());
MessageProperties messageProperties = new MessageProperties();
messageProperties.setApplicationHeaders(applicationHeaders);
interaction.connection().tuneOk().connection().open().consumeResponse(ConnectionOpenOk.class);
interaction.channelId(1).attachSession(sessionName).message().subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().message().flowId(1).flowDestination(subscriberName).flowUnit(MessageCreditUnit.MESSAGE).flowValue(1).flow().message().flowId(2).flowDestination(subscriberName).flowUnit(MessageCreditUnit.BYTE).flowValue(-1).flow().message().transferDestination(BrokerAdmin.TEST_QUEUE_NAME).transferHeader(null, messageProperties).transferId(0).transfer().session().flushCompleted().flush().consumeResponse().getLatestResponse(SessionCompleted.class);
MessageTransfer transfer = interaction.consume(MessageTransfer.class, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class);
assertThat(transfer.getBodySize(), is(0));
Header header = transfer.getHeader();
assertThat(header, is(notNullValue()));
MessageProperties receivedMessageProperties = header.getMessageProperties();
assertThat(receivedMessageProperties, is(notNullValue()));
Map<String, Object> receivedApplicationHeaders = receivedMessageProperties.getApplicationHeaders();
assertThat(receivedApplicationHeaders, is(notNullValue()));
assertThat(receivedApplicationHeaders, is(equalTo(applicationHeaders)));
}
}
use of org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune in project qpid-broker-j by apache.
the class ConnectionTest method heartbeatingIncomingIdle.
@Test
@SpecificationTest(section = "9.connection", description = "If a connection is idle for more than twice the negotiated heartbeat delay, the peers MAY " + "be considered disconnected.")
public void heartbeatingIncomingIdle() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
ConnectionTune response = interaction.authenticateConnection().getLatestResponse(ConnectionTune.class);
assumeThat(response.hasHeartbeatMin(), is(true));
assumeThat(response.hasHeartbeatMax(), is(true));
assumeThat(response.getHeartbeatMin(), is(greaterThanOrEqualTo(0)));
assumeThat(response.getHeartbeatMax(), is(greaterThanOrEqualTo(1)));
final int heartbeatPeriod = 1;
interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkMaxFrameSize(response.getMaxFrameSize()).tuneOkHeartbeat(heartbeatPeriod).tuneOk().connection().open().consumeResponse(ConnectionOpenOk.class);
interaction.consumeResponse().getLatestResponse(ConnectionHeartbeat.class);
// the server might be able to send two heartbeats
Response latestResponse = interaction.consumeResponse().getLatestResponse();
if (latestResponse != null && latestResponse.getBody() instanceof ConnectionHeartbeat) {
latestResponse = interaction.consumeResponse().getLatestResponse();
}
assertThat(latestResponse, instanceOf(ChannelClosedResponse.class));
}
}
use of org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune in project qpid-broker-j by apache.
the class LargeMessageBodyTest method messageBodyOverManyFrames.
@Test
public void messageBodyOverManyFrames() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
final String subscriberName = "testSubscriber";
byte[] sessionName = "test".getBytes(UTF_8);
final ConnectionTune tune = interaction.authenticateConnection().getLatestResponse(ConnectionTune.class);
final byte[] messageContent = new byte[tune.getMaxFrameSize() * 2];
IntStream.range(0, messageContent.length).forEach(i -> {
messageContent[i] = (byte) (i & 0xFF);
});
interaction.connection().tuneOk().connection().open().consumeResponse(ConnectionOpenOk.class);
MessageProperties messageProperties = new MessageProperties();
messageProperties.setContentLength(messageContent.length);
interaction.channelId(1).attachSession(sessionName).message().subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().message().flowId(1).flowDestination(subscriberName).flowUnit(MessageCreditUnit.MESSAGE).flowValue(1).flow().message().flowId(2).flowDestination(subscriberName).flowUnit(MessageCreditUnit.BYTE).flowValue(-1).flow().message().transferDestination(BrokerAdmin.TEST_QUEUE_NAME).transferBody(messageContent).transferHeader(null, messageProperties).transferId(3).transfer().session().flushCompleted().flush().consumeResponse().getLatestResponse(SessionCompleted.class);
MessageTransfer transfer = interaction.consume(MessageTransfer.class, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class);
assertThat(transfer.getBodySize(), is(equalTo(messageContent.length)));
QpidByteBuffer receivedBody = transfer.getBody();
byte[] receivedBytes = new byte[receivedBody.remaining()];
receivedBody.get(receivedBytes);
assertThat(receivedBytes, is(equalTo(messageContent)));
}
}
use of org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune in project qpid-broker-j by apache.
the class ConnectionTest method tooSmallFrameSize.
@Test
@SpecificationTest(section = "9.connection.tune-ok.minimum", description = "[...] the minimum negotiated value for max-frame-size is also MIN-MAX-FRAME-SIZE [4096]")
public void tooSmallFrameSize() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
ConnectionTune response = interaction.authenticateConnection().getLatestResponse(ConnectionTune.class);
interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkMaxFrameSize(1024).tuneOk().connection().open().consumeResponse(ConnectionClose.class, ChannelClosedResponse.class);
}
}
use of org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune in project qpid-broker-j by apache.
the class ConnectionTest method tooLargeFrameSize.
@Test
@SpecificationTest(section = "9.connection.tune-ok.max-frame-size", description = "If the client specifies a channel 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 implementers.")
public void tooLargeFrameSize() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
ConnectionTune response = interaction.authenticateConnection().getLatestResponse(ConnectionTune.class);
assumeThat(response.hasMaxFrameSize(), is(true));
assumeThat(response.getMaxFrameSize(), is(lessThan(0xFFFF)));
interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkMaxFrameSize(response.getMaxFrameSize() + 1).tuneOk().connection().open().consumeResponse(ConnectionClose.class, ChannelClosedResponse.class);
}
}
Aggregations