Search in sources :

Example 11 with Discharge

use of org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge in project qpid-broker-j by apache.

the class TransferTest method transferMixtureOfTransactionalAndNonTransactionalDeliveries.

@Test
@SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
public void transferMixtureOfTransactionalAndNonTransactionalDeliveries() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction().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(2)));
        final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ONE);
        interaction.txnAttachCoordinatorLink(txnState).txnDeclare(txnState);
        interaction.transferDeliveryId(UnsignedInteger.ONE).transferDeliveryTag(new Binary("A".getBytes(StandardCharsets.UTF_8))).transferPayloadData("test").transfer().transferDeliveryId(UnsignedInteger.valueOf(2)).transferDeliveryTag(new Binary("B".getBytes(StandardCharsets.UTF_8))).transferPayloadData("test").transfer().transferDeliveryId(UnsignedInteger.valueOf(3)).transferDeliveryTag(new Binary("C".getBytes(StandardCharsets.UTF_8))).transferTransactionalState(txnState.getCurrentTransactionId()).transferPayloadData("test").transfer();
        final Discharge discharge = new Discharge();
        discharge.setTxnId(txnState.getCurrentTransactionId());
        discharge.setFail(false);
        interaction.transferHandle(txnState.getHandle()).transferDeliveryId(UnsignedInteger.valueOf(4)).transferDeliveryTag(new Binary(("transaction-" + 4).getBytes(StandardCharsets.UTF_8))).transferPayloadData(discharge).transfer();
        assertDeliveries(interaction, Sets.newTreeSet(Arrays.asList(UnsignedInteger.ONE, UnsignedInteger.valueOf(2), UnsignedInteger.valueOf(3), UnsignedInteger.valueOf(4))));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) 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) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Discharge(org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 12 with Discharge

use of org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge in project qpid-broker-j by apache.

the class DischargeTest method dischargeUnknownTransactionIdWhenSourceSupportsRejectedOutcome.

@Test
@SpecificationTest(section = "4.3", description = "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.")
public void dischargeUnknownTransactionIdWhenSourceSupportsRejectedOutcome() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        final Disposition disposition = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachSourceOutcomes(Rejected.REJECTED_SYMBOL).attachTarget(new Coordinator()).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayloadData(new Declare()).transfer().consumeResponse().getLatestResponse(Disposition.class);
        assertThat(disposition.getSettled(), is(equalTo(true)));
        assertThat(disposition.getState(), is(instanceOf(Declared.class)));
        assertThat(((Declared) disposition.getState()).getTxnId(), is(notNullValue()));
        interaction.consumeResponse(Flow.class);
        final Discharge discharge = new Discharge();
        discharge.setTxnId(new Binary("nonExistingTransaction".getBytes(UTF_8)));
        final Disposition dischargeDisposition = interaction.transferDeliveryId(UnsignedInteger.ONE).transferDeliveryTag(new Binary("discharge".getBytes(UTF_8))).transferPayloadData(discharge).transfer().consumeResponse().getLatestResponse(Disposition.class);
        assertThat(dischargeDisposition.getState(), is(instanceOf(Rejected.class)));
        final Error error = ((Rejected) dischargeDisposition.getState()).getError();
        assertThat(error, is(notNullValue()));
        assertThat(error.getCondition(), is(equalTo(TransactionError.UNKNOWN_ID)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) Coordinator(org.apache.qpid.server.protocol.v1_0.type.transaction.Coordinator) Declare(org.apache.qpid.server.protocol.v1_0.type.transaction.Declare) Discharge(org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 13 with Discharge

use of org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge in project qpid-broker-j by apache.

the class DischargeTest method dischargeUnknownTransactionIdWhenSourceDoesNotSupportRejectedOutcome.

@Test
@SpecificationTest(section = "4.3", description = "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 does not support " + "the rejected outcome, the transactional resource MUST detach the link to the coordinator, with the detach " + "performative carrying the transaction-error.")
public void dischargeUnknownTransactionIdWhenSourceDoesNotSupportRejectedOutcome() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        final Disposition disposition = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attachTarget(new Coordinator()).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayloadData(new Declare()).transfer().consumeResponse().getLatestResponse(Disposition.class);
        assertThat(disposition.getSettled(), is(equalTo(true)));
        assertThat(disposition.getState(), is(instanceOf(Declared.class)));
        assertThat(((Declared) disposition.getState()).getTxnId(), is(notNullValue()));
        interaction.consumeResponse(Flow.class);
        final Discharge discharge = new Discharge();
        discharge.setTxnId(new Binary("nonExistingTransaction".getBytes(UTF_8)));
        final Detach detachResponse = interaction.transferDeliveryId(UnsignedInteger.ONE).transferDeliveryTag(new Binary("discharge".getBytes(UTF_8))).transferPayloadData(discharge).transfer().consumeResponse(Detach.class).getLatestResponse(Detach.class);
        Error error = detachResponse.getError();
        assertThat(error, is(notNullValue()));
        assertThat(error.getCondition(), is(equalTo(TransactionError.UNKNOWN_ID)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Coordinator(org.apache.qpid.server.protocol.v1_0.type.transaction.Coordinator) Declare(org.apache.qpid.server.protocol.v1_0.type.transaction.Declare) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Discharge(org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 14 with Discharge

use of org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge in project qpid-broker-j by apache.

the class Interaction method txnDischarge.

public Interaction txnDischarge(final InteractionTransactionalState txnState, boolean failed) throws Exception {
    final Discharge discharge = new Discharge();
    discharge.setTxnId(txnState.getCurrentTransactionId());
    discharge.setFail(failed);
    Transfer transfer = createTransactionTransfer(txnState.getHandle());
    transferPayload(transfer, discharge);
    sendPerformativeAndChainFuture(transfer, _sessionChannel);
    Disposition declareTransactionDisposition = null;
    Flow coordinatorFlow = null;
    do {
        consumeResponse(Disposition.class, Flow.class);
        Response<?> response = getLatestResponse();
        if (response.getBody() instanceof Disposition) {
            declareTransactionDisposition = (Disposition) response.getBody();
        }
        if (response.getBody() instanceof Flow) {
            final Flow flowResponse = (Flow) response.getBody();
            if (flowResponse.getHandle().equals(txnState.getHandle())) {
                coordinatorFlow = flowResponse;
            }
        }
    } while (declareTransactionDisposition == null || coordinatorFlow == null);
    assertThat(declareTransactionDisposition.getSettled(), is(equalTo(true)));
    assertThat(declareTransactionDisposition.getState(), is(instanceOf(Accepted.class)));
    txnState.setLastTransactionId(null);
    return this;
}
Also used : Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Discharge(org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow)

Aggregations

SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)11 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)11 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)11 Test (org.junit.Test)11 Discharge (org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge)9 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)9 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)7 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)7 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)7 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)7 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)7 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)6 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)6 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)5 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)4 Rejected (org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected)4 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)4 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)4 Coordinator (org.apache.qpid.server.protocol.v1_0.type.transaction.Coordinator)3 Declare (org.apache.qpid.server.protocol.v1_0.type.transaction.Declare)3