Search in sources :

Example 1 with TransactionalState

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

the class Interaction method txnAttachCoordinatorLink.

// ///////////////
// transaction //
// //////////////
public Interaction txnAttachCoordinatorLink(InteractionTransactionalState transactionalState) throws Exception {
    Attach attach = new Attach();
    attach.setName("testTransactionCoordinator-" + transactionalState.getHandle());
    attach.setHandle(transactionalState.getHandle());
    attach.setInitialDeliveryCount(UnsignedInteger.ZERO);
    attach.setTarget(new Coordinator());
    attach.setRole(Role.SENDER);
    Source source = new Source();
    attach.setSource(source);
    source.setOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL);
    sendPerformativeAndChainFuture(attach, _sessionChannel);
    consumeResponse(Attach.class);
    consumeResponse(Flow.class);
    return this;
}
Also used : Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Coordinator(org.apache.qpid.server.protocol.v1_0.type.transaction.Coordinator) BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source)

Example 2 with TransactionalState

use of org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState 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);
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) 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) 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) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) TransactionalState(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 3 with TransactionalState

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

the class TransactionTimeoutTest method transactionalPostingTimeout.

@Test
public void transactionalPostingTimeout() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final UnsignedInteger linkHandle = UnsignedInteger.ONE;
        final Interaction interaction = transport.newInteraction();
        final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
        Disposition responseDisposition = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachHandle(linkHandle).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayloadData(TEST_MESSAGE_CONTENT).transferTransactionalState(txnState.getCurrentTransactionId()).transfer().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
        assertThat(responseDisposition.getRole(), is(Role.RECEIVER));
        assertThat(responseDisposition.getSettled(), is(Boolean.TRUE));
        assertThat(responseDisposition.getState(), is(instanceOf(TransactionalState.class)));
        assertThat(((TransactionalState) responseDisposition.getState()).getOutcome(), is(instanceOf(Accepted.class)));
        Close responseClose = interaction.consumeResponse().getLatestResponse(Close.class);
        assertThat(responseClose.getError(), is(Matchers.notNullValue()));
        assertThat(responseClose.getError().getCondition(), equalTo(TransactionError.TRANSACTION_TIMEOUT));
    }
}
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) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Test(org.junit.Test)

Example 4 with TransactionalState

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

the class TransactionalTransferTest method receiveTransactionalAcquisitionDischargeFail.

@Test
@SpecificationTest(section = "4.4.3", description = "Transactional Acquisition[...]In the case of the flow frame," + " the transactional work is not necessarily directly" + " initiated or entirely determined when the flow frame" + " arrives at the resource, but can in fact occur at some " + " later point and in ways not necessarily" + " anticipated by the controller.")
public void receiveTransactionalAcquisitionDischargeFail() 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.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flowProperties(Collections.singletonMap(Symbol.valueOf("txn-id"), txnState.getCurrentTransactionId())).flow().receiveDelivery();
        List<Transfer> transfers = interaction.getLatestDelivery();
        assertThat(transfers.size(), is(equalTo(1)));
        Transfer transfer = transfers.get(0);
        assertThat(transfer.getState(), is(instanceOf(TransactionalState.class)));
        assertThat(((TransactionalState) transfer.getState()).getTxnId(), is(equalTo(txnState.getCurrentTransactionId())));
        Object data = interaction.decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
        interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionTransactionalState(txnState.getCurrentTransactionId(), new Accepted()).disposition().txnDischarge(txnState, true);
        assumeThat(getBrokerAdmin().isQueueDepthSupported(), is(true));
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
    }
}
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) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 5 with TransactionalState

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

the class AbstractReceivingLinkEndpoint method updateDispositions.

void updateDispositions(final Set<Binary> deliveryTags, final DeliveryState state, final boolean settled) {
    final Set<Binary> unsettledKeys = new HashSet<>(_unsettled.keySet());
    unsettledKeys.retainAll(deliveryTags);
    final int settledDeliveryCount = deliveryTags.size() - unsettledKeys.size();
    if (!unsettledKeys.isEmpty()) {
        boolean outcomeUpdate = false;
        Outcome outcome = null;
        if (state instanceof Outcome) {
            outcome = (Outcome) state;
        } else if (state instanceof TransactionalState) {
            outcome = ((TransactionalState) state).getOutcome();
        }
        if (outcome != null) {
            for (final Binary deliveryTag : unsettledKeys) {
                if (!(_unsettled.get(deliveryTag) instanceof Outcome)) {
                    Object oldOutcome = _unsettled.put(deliveryTag, outcome);
                    outcomeUpdate = outcomeUpdate || !outcome.equals(oldOutcome);
                }
            }
        }
        if (outcomeUpdate || settled) {
            getSession().updateDisposition(getRole(), unsettledKeys, state, settled);
        }
        if (settled) {
            int credit = 0;
            for (final Binary deliveryTag : unsettledKeys) {
                if (settled(deliveryTag)) {
                    if (!isDetached() && _creditWindow) {
                        credit++;
                    }
                }
            }
            if (credit > 0) {
                setLinkCredit(getLinkCredit().add(UnsignedInteger.valueOf(credit)));
                sendFlowConditional();
            } else {
                getSession().sendFlowConditional();
            }
        }
    }
    if (settledDeliveryCount > 0 && _creditWindow) {
        setLinkCredit(getLinkCredit().add(UnsignedInteger.ONE));
        sendFlowConditional();
    }
}
Also used : Outcome(org.apache.qpid.server.protocol.v1_0.type.Outcome) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) HashSet(java.util.HashSet) TransactionalState(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState)

Aggregations

Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)10 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)9 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)9 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)9 Test (org.junit.Test)9 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)8 TransactionalState (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState)8 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)8 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)7 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)5 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)4 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)4 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)4 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)3 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)3 Outcome (org.apache.qpid.server.protocol.v1_0.type.Outcome)3 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)3 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)3 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)3 Rejected (org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected)2