Search in sources :

Example 16 with DeliveryState

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)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 17 with DeliveryState

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)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 18 with DeliveryState

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())));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) TransactionalState(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 19 with DeliveryState

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)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 20 with DeliveryState

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;
}
Also used : DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Declare(org.apache.qpid.server.protocol.v1_0.type.transaction.Declare) Declared(org.apache.qpid.server.protocol.v1_0.type.transaction.Declared)

Aggregations

DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)21 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)15 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)14 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)13 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)13 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)13 Test (org.junit.Test)13 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)12 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)10 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)9 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)9 HashMap (java.util.HashMap)8 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)8 Ignore (org.junit.Ignore)7 Map (java.util.Map)6 Rejected (org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected)6 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)6 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)5 TransactionalState (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState)5 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)5