use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class TransactionalTransferTest method sendTransactionalPostingReceiverSettlesSecond.
@Test
@SpecificationTest(section = "4.4.4", description = "Transactional Posting[...]the transaction controller wishes to associate an outgoing" + " transfer with a transaction, it MUST set the state of the transfer with a" + "transactional-state carrying the appropriate transaction identifier.")
public void sendTransactionalPostingReceiverSettlesSecond() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final UnsignedInteger linkHandle = UnsignedInteger.ONE;
final Interaction interaction = transport.newInteraction();
final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
Disposition responseDisposition = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachHandle(linkHandle).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayloadData(TEST_MESSAGE_CONTENT).transferTransactionalState(txnState.getCurrentTransactionId()).transfer().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
assertThat(responseDisposition.getRole(), is(Role.RECEIVER));
assertThat(responseDisposition.getSettled(), is(Boolean.FALSE));
assertThat(responseDisposition.getState(), is(instanceOf(TransactionalState.class)));
assertThat(((TransactionalState) responseDisposition.getState()).getOutcome(), is(instanceOf(Accepted.class)));
interaction.dispositionRole(Role.SENDER).dispositionSettled(true).dispositionTransactionalState(txnState.getCurrentTransactionId(), new Accepted()).disposition();
interaction.txnDischarge(txnState, false);
}
}
use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class OpenTest method failOpenOnChannelNotZero.
@Test
@SpecificationTest(section = "2.4.1", description = "The open frame can only be sent on channel 0. ยง2.7.1: A peer that receives a channel number outside the supported range MUST close the connection with the framing-error error-code.")
public void failOpenOnChannelNotZero() throws Exception {
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
final Interaction interaction = transport.newInteraction();
Open responseOpen = interaction.negotiateProtocol().consumeResponse().openContainerId("testContainerId").connectionChannel(UnsignedShort.valueOf((short) 1)).open().consumeResponse().getLatestResponse(Open.class);
assertThat(responseOpen.getContainerId(), is(notNullValue()));
Close responseClose = interaction.consumeResponse().getLatestResponse(Close.class);
assertThat(responseClose.getError(), is(notNullValue()));
assertThat(responseClose.getError().getCondition(), equalTo(ConnectionError.FRAMING_ERROR));
}
}
use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class OpenTest method emptyFrame.
@Test
@SpecificationTest(section = "2.4.5", description = "Implementations MUST be prepared to handle empty frames arriving on any valid channel")
public void emptyFrame() throws Exception {
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().consumeResponse().openContainerId("testContainerId").open().consumeResponse(Open.class).emptyFrame().doCloseConnection();
}
}
use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class OpenTest method idleTimeout.
@Test
@SpecificationTest(section = "2.4.5", description = "Connections are subject to an idle timeout threshold.")
public void idleTimeout() throws Exception {
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
Interaction interaction = transport.newInteraction();
final int idleTimeOut = 1000;
Open responseOpen = interaction.negotiateProtocol().consumeResponse().openContainerId("testContainerId").openIdleTimeOut(idleTimeOut).open().consumeResponse().getLatestResponse(Open.class);
final int peerIdleTimeOut = responseOpen.getIdleTimeOut().intValue();
assertThat(peerIdleTimeOut, is(either(equalTo(0)).or(greaterThanOrEqualTo(idleTimeOut))));
final long startTime = System.currentTimeMillis();
interaction.consumeResponse(EmptyResponse.class);
final long actualHeartbeatDelay = System.currentTimeMillis() - startTime;
assertThat("Empty frame not received within expected time frame", ((int) actualHeartbeatDelay / 1000), is(both(greaterThanOrEqualTo(peerIdleTimeOut)).and(lessThanOrEqualTo(peerIdleTimeOut * 2))));
if (peerIdleTimeOut > 0) {
interaction.emptyFrame();
}
interaction.doCloseConnection();
}
}
use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class OpenTest method successfulOpen.
@Test
@SpecificationTest(section = "2.4.1", description = "Each AMQP connection begins with an exchange of capabilities and limitations, " + "including the maximum frame size.")
public void successfulOpen() throws Exception {
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
Interaction interaction = transport.newInteraction();
Open responseOpen = interaction.negotiateProtocol().consumeResponse().openContainerId("testContainerId").open().consumeResponse().getLatestResponse(Open.class);
assertThat(responseOpen.getContainerId(), is(notNullValue()));
assertThat(responseOpen.getMaxFrameSize().longValue(), is(both(greaterThanOrEqualTo(0L)).and(lessThan(UnsignedInteger.MAX_VALUE.longValue()))));
assertThat(responseOpen.getChannelMax().intValue(), is(both(greaterThanOrEqualTo(0)).and(lessThan(UnsignedShort.MAX_VALUE.intValue()))));
interaction.doCloseConnection();
}
}
Aggregations