use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferUnsettledInTransactionToKnownDestination.
@Test
public void transferUnsettledInTransactionToKnownDestination() 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).attachHandle(linkHandle).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination(BrokerAdmin.TEST_QUEUE_NAME)).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(Accepted.class)));
interaction.txnDischarge(txnState, false);
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 transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeNotSupportedBySource.
@Test
public void transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeNotSupportedBySource() 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).attachHandle(linkHandle).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryId(UnsignedInteger.valueOf(1)).transferDeliveryTag(_deliveryTag).transferTransactionalState(txnState.getCurrentTransactionId()).transferSettled(Boolean.FALSE).transfer();
Detach senderLinkDetach = interaction.consumeResponse().getLatestResponse(Detach.class);
Error senderLinkDetachError = senderLinkDetach.getError();
assertThat(senderLinkDetachError, is(notNullValue()));
assertThat(senderLinkDetachError.getCondition(), is(equalTo(AmqpError.NOT_FOUND)));
assertThat(senderLinkDetachError.getInfo(), is(notNullValue()));
assertThat(senderLinkDetachError.getInfo().get(DELIVERY_TAG), is(equalTo(_deliveryTag)));
final Discharge discharge = new Discharge();
discharge.setTxnId(txnState.getCurrentTransactionId());
discharge.setFail(false);
interaction.transferHandle(txnState.getHandle()).transferSettled(Boolean.FALSE).transferDeliveryId(UnsignedInteger.valueOf(2)).transferDeliveryTag(new Binary(("transaction-" + 2).getBytes(StandardCharsets.UTF_8))).transferPayloadData(discharge).transfer();
Disposition dischargeTransactionDisposition = getDispositionForDeliveryId(interaction, UnsignedInteger.valueOf(2));
assertThat(dischargeTransactionDisposition.getSettled(), is(equalTo(true)));
assertThat(dischargeTransactionDisposition.getState(), is(instanceOf(Rejected.class)));
Rejected rejected = (Rejected) dischargeTransactionDisposition.getState();
Error error = rejected.getError();
assertThat(error, is(notNullValue()));
assertThat(error.getCondition(), is(equalTo(TransactionError.TRANSACTION_ROLLBACK)));
}
}
use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferPreSettledToUnknownDestination.
@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." + " [...] the message has already been settled by the sender," + " 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 transferPreSettledToUnknownDestination() 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("Unknown")).transferSettled(Boolean.TRUE).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)));
}
}
use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class FilterTest method selectorFilter.
@Test
@BrokerSpecific(kind = KIND_BROKER_J)
@SpecificationTest(section = "3.5.1", description = "A source can restrict the messages transferred from a source by specifying a filter.")
public void selectorFilter() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
Flow flow = interaction.getLatestResponse(Flow.class);
assumeThat("insufficient credit for the test", flow.getLinkCredit().intValue(), is(greaterThan(1)));
for (int i = 0; i < 2; i++) {
QpidByteBuffer payload = generateMessagePayloadWithApplicationProperties(Collections.singletonMap("index", i), TEST_MESSAGE_CONTENT);
interaction.transferPayload(payload).transferSettled(true).transfer();
}
interaction.detachClose(true).detach().close().sync();
}
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSourceFilter(Collections.singletonMap(Symbol.valueOf("selector-filter"), new JMSSelectorFilter("index=1"))).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow();
Object data = interaction.receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
Map<String, Object> applicationProperties = interaction.getLatestDeliveryApplicationProperties();
assertThat(applicationProperties, is(notNullValue()));
assertThat(applicationProperties.get("index"), is(equalTo(1)));
interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionState(new Accepted()).disposition();
interaction.close().sync();
}
}
use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.
the class TransactionTimeoutTest method transactionalRetirementTimeout.
@Test
public void transactionalRetirementTimeout() throws Exception {
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_CONTENT);
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.RECEIVER).attachHandle(UnsignedInteger.ONE).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attach().consumeResponse(Attach.class).flowIncomingWindow(UnsignedInteger.MAX_VALUE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.MAX_VALUE).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery();
Object data = interaction.getDecodedLatestDelivery();
assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionTransactionalState(txnState.getCurrentTransactionId(), new Accepted()).disposition().sync();
Response<?> response = interaction.consumeResponse(Close.class, Flow.class).getLatestResponse();
Close responseClose;
if (response.getBody() instanceof Close) {
responseClose = (Close) response.getBody();
} else {
responseClose = interaction.consumeResponse().getLatestResponse(Close.class);
}
assertThat(responseClose.getError(), is(Matchers.notNullValue()));
assertThat(responseClose.getError().getCondition(), equalTo(TransactionError.TRANSACTION_TIMEOUT));
}
}
Aggregations