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;
}
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);
}
}
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));
}
}
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)));
}
}
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();
}
}
Aggregations