use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeNotSupportedBySource.
@Test
public void transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeNotSupportedBySource() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
final UnsignedInteger linkHandle = UnsignedInteger.ONE;
interaction.begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(UnsignedInteger.ZERO, this::coordinatorAttachExpected).txnDeclare().attachRole(Role.SENDER).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attachHandle(linkHandle).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).assertLatestResponse(Flow.class, this::assumeSufficientCredits).transferDeliveryId().transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination(getNonExistingDestinationName())).transferDeliveryId(UnsignedInteger.valueOf(1)).transferDeliveryTag(_deliveryTag).transferTransactionalStateFromCurrentTransaction().transferSettled(Boolean.FALSE).transfer();
final Detach senderLinkDetach = interaction.consume(Detach.class, Flow.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)));
interaction.txnDischarge(false);
DeliveryState txnDischargeDeliveryState = interaction.getCoordinatorLatestDeliveryState();
assertThat(txnDischargeDeliveryState, is(instanceOf(Rejected.class)));
Rejected rejected = (Rejected) txnDischargeDeliveryState;
Error error = rejected.getError();
assertThat(error, is(notNullValue()));
assertThat(error.getCondition(), is(equalTo(TransactionError.TRANSACTION_ROLLBACK)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferUnsettledToUnknownDestinationWhenRejectedOutcomeSupportedBySource.
@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 supports the rejected outcome," + " and the message has not already been settled by the sender, then the routing node" + " MUST reject the message." + " [...] 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 transferUnsettledToUnknownDestinationWhenRejectedOutcomeSupportedBySource() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
interaction.begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).assertLatestResponse(Flow.class, this::assumeSufficientCredits).transferDeliveryId().transferPayload(generateMessagePayloadToDestination(getNonExistingDestinationName())).transferDeliveryTag(_deliveryTag).transfer();
final Disposition disposition = interaction.consume(Disposition.class, Flow.class);
assertThat(disposition.getSettled(), is(true));
DeliveryState dispositionState = disposition.getState();
assertThat(dispositionState, is(instanceOf(Rejected.class)));
Rejected rejected = (Rejected) dispositionState;
Error error = rejected.getError();
assertThat(error, is(notNullValue()));
assertThat(error.getCondition(), is(oneOf(AmqpError.NOT_FOUND, AmqpError.NOT_ALLOWED)));
assertThat(error.getInfo(), is(notNullValue()));
assertThat(error.getInfo().get(DELIVERY_TAG), is(equalTo(_deliveryTag)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferUnsettledInTransactionToKnownDestination.
@Test
public void transferUnsettledInTransactionToKnownDestination() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
final UnsignedInteger linkHandle = UnsignedInteger.ONE;
interaction.begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(UnsignedInteger.ZERO, this::coordinatorAttachExpected).txnDeclare().attachRole(Role.SENDER).attachHandle(linkHandle).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).assertLatestResponse(Flow.class, this::assumeSufficientCredits).transferDeliveryId().transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination(BrokerAdmin.TEST_QUEUE_NAME)).transferDeliveryTag(_deliveryTag).transferTransactionalStateFromCurrentTransaction().transferSettled(Boolean.FALSE).transfer();
final Disposition disposition = interaction.consume(Disposition.class, Flow.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(false);
assertThat(interaction.getCoordinatorLatestDeliveryState(), is(instanceOf(Accepted.class)));
Object receivedMessage = Utils.receiveMessage(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME);
assertThat(receivedMessage, is(equalTo(getTestName())));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeSupportedByTxController.
@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." + " [...]" + " <Not in spec yet>" + " AMQP-140" + " If a message cannot be routed to the destination implied in the \"to:\" field," + " and the source does not allow for the rejected outcome" + " [...] when messages are being sent within a transaction and have been sent pre-settled." + " In this case the behaviour defined for transactions (of essentially marking" + " the transaction as rollback only) should take precedence. " + "" + " AMQP spec 4.3 Discharging a Transaction" + " If the coordinator is unable to complete the discharge, the coordinator MUST convey" + " the error to the controller as a transaction-error. If the source for the link to" + " the coordinator supports the rejected outcome, then the message MUST be rejected" + " with this outcome carrying the transaction-error.")
@Test
public void transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeSupportedByTxController() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final UnsignedInteger linkHandle = UnsignedInteger.ONE;
final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
interaction.begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(UnsignedInteger.ZERO, this::coordinatorAttachExpected).txnDeclare().attachRole(Role.SENDER).attachHandle(linkHandle).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).assertLatestResponse(Flow.class, this::assumeSufficientCredits).transferDeliveryId().transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination(getNonExistingDestinationName())).transferDeliveryTag(_deliveryTag).transferTransactionalStateFromCurrentTransaction().transferSettled(Boolean.TRUE).transfer();
interaction.txnDischarge(false);
DeliveryState txDischargeDeliveryState = interaction.getCoordinatorLatestDeliveryState();
assertThat(txDischargeDeliveryState, is(instanceOf(Rejected.class)));
Rejected rejected = (Rejected) txDischargeDeliveryState;
Error error = rejected.getError();
assertThat(error, is(notNullValue()));
assertThat(error.getCondition(), is(equalTo(TransactionError.TRANSACTION_ROLLBACK)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.
the class Interaction method txnDeclare.
public Interaction txnDeclare() throws Exception {
sendPayloadToCoordinator(new Declare(), _transactionalState.getHandle());
final DeliveryState state = handleCoordinatorResponse();
_transactionalState.setDeliveryState(state);
final Binary transactionId = ((Declared) state).getTxnId();
_transactionalState.setLastTransactionId(transactionId);
return this;
}
Aggregations