use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class PublisherConfirmsTest method publishUnroutableMessageWithTransactionalConfirms.
@Test
public void publishUnroutableMessageWithTransactionalConfirms() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.openAnonymousConnection().channel().open().consumeResponse(ChannelOpenOkBody.class).tx().select().consumeResponse(TxSelectOkBody.class).basic().confirmSelect().consumeResponse(ConfirmSelectOkBody.class).basic().publishExchange("").publishRoutingKey("unrouteable").publishMandatory(true).publishMessage().basic().publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).publishMandatory(true).publishMessage();
final BasicNackBody nackBody = interaction.consumeResponse().getLatestResponse(BasicNackBody.class);
assertThat(nackBody.getDeliveryTag(), is(equalTo(1L)));
final BasicAckBody ackBody = interaction.consumeResponse().getLatestResponse(BasicAckBody.class);
assertThat(ackBody.getDeliveryTag(), is(equalTo(2L)));
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
interaction.tx().commit();
final Set<Class<?>> outstanding = Sets.newHashSet(TxCommitOkBody.class, BasicReturnBody.class, ContentHeaderBody.class);
while (!outstanding.isEmpty()) {
final Response<?> response = interaction.consumeResponse(outstanding.toArray(new Class<?>[outstanding.size()])).getLatestResponse();
final boolean remove = outstanding.remove(response.getBody().getClass());
assertThat("" + response, remove, is(equalTo(true)));
}
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
}
}
use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class TransactionTimeoutTest method publishTransactionTimeout.
@Test
public void publishTransactionTimeout() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.openAnonymousConnection().channel().open().consumeResponse(ChannelOpenOkBody.class).tx().select().consumeResponse(TxSelectOkBody.class).basic().contentHeaderPropertiesContentType("text/plain").contentHeaderPropertiesHeaders(Collections.singletonMap("test", "testValue")).contentHeaderPropertiesDeliveryMode((byte) 1).contentHeaderPropertiesPriority((byte) 1).publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).content("Test").publishMessage().exchange().declarePassive(true).declare().consumeResponse(ExchangeDeclareOkBody.class);
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
final ConnectionCloseBody close = interaction.consumeResponse().getLatestResponse(ConnectionCloseBody.class);
assertThat(close.getReplyCode(), is(equalTo(ErrorCodes.RESOURCE_ERROR)));
assertThat(close.getReplyText().toString(), containsString("transaction timed out"));
interaction.connection().closeOk();
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
}
}
use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferPreSettledToKnownDestination.
@SpecificationTest(section = "Using the Anonymous Terminus for Message Routing. 2.2. Sending A Message", description = "Messages sent over links into a routing node will be" + " forwarded to the node referenced in the to field of properties of the message" + " just as if a direct link has been established to that node.")
@Test
public void transferPreSettledToKnownDestination() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
interaction.begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(generateMessagePayloadToDestination(BrokerAdmin.TEST_QUEUE_NAME)).transferSettled(Boolean.TRUE).transferDeliveryTag(_deliveryTag).transfer().sync();
Object receivedMessage = Utils.receiveMessage(_brokerAddress, BrokerAdmin.TEST_QUEUE_NAME);
assertThat(receivedMessage, is(equalTo(TEST_MESSAGE_CONTENT)));
}
}
use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeSupportedBySource.
@Test
public void transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeSupportedBySource() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
final UnsignedInteger linkHandle = UnsignedInteger.ONE;
final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
interaction.begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.SENDER).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attachHandle(linkHandle).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transferTransactionalState(txnState.getCurrentTransactionId()).transferSettled(Boolean.FALSE).transfer();
Disposition disposition = interaction.consumeResponse().getLatestResponse(Disposition.class);
assertThat(disposition.getSettled(), is(true));
DeliveryState dispositionState = disposition.getState();
assertThat(dispositionState, is(instanceOf(TransactionalState.class)));
final TransactionalState receivedTxnState = (TransactionalState) dispositionState;
assertThat(receivedTxnState.getOutcome(), is(instanceOf(Rejected.class)));
final Error rejectedError = ((Rejected) receivedTxnState.getOutcome()).getError();
assertThat(rejectedError.getCondition(), is(equalTo(AmqpError.NOT_FOUND)));
assertThat(rejectedError.getInfo(), is(notNullValue()));
assertThat(rejectedError.getInfo().get(DELIVERY_TAG), is(equalTo(_deliveryTag)));
interaction.txnDischarge(txnState, false);
}
}
use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferUnsettledToUnknownDestinationWhenRejectedOutcomeNotSupportedBySource.
@SpecificationTest(section = "Using the Anonymous Terminus for Message Routing. 2.2.2 Routing Errors", description = "It is possible that a message sent to a routing node has an address in the to field" + " of properties which, if used in the address field of target of an attach," + " would result in an unsuccessful link establishment (for example," + " if the address cannot be resolved to a node). In this case the routing node" + " MUST communicate the error back to the sender of the message." + " [...]" + " If the source of the link does not support the rejected outcome," + " [...] then the routing node MUST detach the link with an error." + " [...] the info field of error MUST contain an entry with symbolic key delivery-tag" + " and binary value of the delivery-tag of the message which caused the failure.")
@Test
public void transferUnsettledToUnknownDestinationWhenRejectedOutcomeNotSupportedBySource() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
interaction.begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transfer();
Detach detach = interaction.consumeResponse().getLatestResponse(Detach.class);
Error error = detach.getError();
assertThat(error, is(notNullValue()));
assertThat(error.getCondition(), is(equalTo(AmqpError.NOT_FOUND)));
assertThat(error.getInfo(), is(notNullValue()));
assertThat(error.getInfo().get(DELIVERY_TAG), is(equalTo(_deliveryTag)));
}
}
Aggregations