use of org.apache.qpid.server.protocol.v1_0.type.transport.Disposition in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method resumeReceivingLinkWithSingleUnsettledAccepted.
@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.6.13", description = "When a suspended link having unsettled deliveries is resumed," + " the unsettled field from the attach frame will carry" + " the delivery-tags and delivery state of all deliveries" + " considered unsettled by the issuing link endpoint.")
public void resumeReceivingLinkWithSingleUnsettledAccepted() throws Exception {
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_CONTENT);
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse().begin().consumeResponse().attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSndSettleMode(SenderSettleMode.UNSETTLED).attach().consumeResponse();
Attach attach = interaction.getLatestResponse(Attach.class);
assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.UNSETTLED)));
interaction.flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
List<Transfer> transfers = interaction.getLatestDelivery();
assertThat(transfers, hasSize(1));
Transfer transfer = transfers.get(0);
Binary deliveryTag = transfer.getDeliveryTag();
assertThat(deliveryTag, is(notNullValue()));
assertThat(transfer.getSettled(), is(not(equalTo(true))));
Object data = interaction.decodeLatestDelivery().getDecodedLatestDelivery();
assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
Detach detach = interaction.detach().consumeResponse().getLatestResponse(Detach.class);
assertThat(detach.getClosed(), anyOf(nullValue(), equalTo(false)));
interaction.attachUnsettled(Collections.singletonMap(deliveryTag, new Accepted())).attach().consumeResponse(Attach.class);
Attach resumeAttach = interaction.getLatestResponse(Attach.class);
Map<Binary, DeliveryState> unsettled = resumeAttach.getUnsettled();
assertThat(unsettled, is(notNullValue()));
assertThat(unsettled.entrySet(), hasSize(1));
Map.Entry<Binary, DeliveryState> entry = unsettled.entrySet().iterator().next();
assertThat(entry.getKey(), is(equalTo(deliveryTag)));
interaction.flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
transfers = interaction.getLatestDelivery();
assertThat(transfers, hasSize(1));
Transfer resumeTransfer = transfers.get(0);
assertThat(resumeTransfer.getResume(), is(equalTo(true)));
assertThat(resumeTransfer.getDeliveryTag(), is(equalTo(deliveryTag)));
assertThat(resumeTransfer.getPayload(), is(nullValue()));
if (!Boolean.TRUE.equals(resumeTransfer.getSettled())) {
interaction.dispositionSettled(true).dispositionState(new Accepted()).dispositionRole(Role.RECEIVER).disposition();
}
interaction.doCloseConnection();
if (getBrokerAdmin().isQueueDepthSupported()) {
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
}
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Disposition in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method resumeReceivingLinkOneUnsettledWithNoOutcome.
@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.6.13", description = "When a suspended link having unsettled deliveries is resumed," + " the unsettled field from the attach frame will carry" + " the delivery-tags and delivery state of all deliveries" + " considered unsettled by the issuing link endpoint.")
public void resumeReceivingLinkOneUnsettledWithNoOutcome() throws Exception {
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_CONTENT);
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse().begin().consumeResponse().attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSndSettleMode(SenderSettleMode.UNSETTLED).attach().consumeResponse();
Attach attach = interaction.getLatestResponse(Attach.class);
assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.UNSETTLED)));
interaction.flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
List<Transfer> transfers = interaction.getLatestDelivery();
assertThat(transfers, hasSize(1));
Transfer transfer = transfers.get(0);
Binary deliveryTag = transfer.getDeliveryTag();
assertThat(deliveryTag, is(notNullValue()));
Object data = interaction.decodeLatestDelivery().getDecodedLatestDelivery();
assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
Detach detach = interaction.detach().consumeResponse(Detach.class).getLatestResponse(Detach.class);
assertThat(detach.getClosed(), anyOf(nullValue(), equalTo(false)));
interaction.attachUnsettled(Collections.singletonMap(deliveryTag, null)).attach().consumeResponse(Attach.class);
Attach resumeAttach = interaction.getLatestResponse(Attach.class);
Map<Binary, DeliveryState> unsettled = resumeAttach.getUnsettled();
assertThat(unsettled, is(notNullValue()));
assertThat(unsettled.entrySet(), hasSize(1));
Map.Entry<Binary, DeliveryState> entry = unsettled.entrySet().iterator().next();
assertThat(entry.getKey(), is(equalTo(deliveryTag)));
interaction.flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
transfers = interaction.getLatestDelivery();
assertThat(transfers, hasSize(1));
Transfer resumeTransfer = transfers.get(0);
assertThat(resumeTransfer.getResume(), is(equalTo(true)));
assertThat(resumeTransfer.getDeliveryTag(), is(equalTo(deliveryTag)));
assertThat(resumeTransfer.getPayload(), is(notNullValue()));
interaction.dispositionSettled(true).dispositionState(new Accepted()).dispositionRole(Role.RECEIVER).disposition();
interaction.doCloseConnection();
if (getBrokerAdmin().isQueueDepthSupported()) {
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), Matchers.is(Matchers.equalTo(0)));
}
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Disposition in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method rejectNewDeliveryWhilstUnsettledIncomplete.
@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.7.3", description = "If set to true [incomplete-unsettled] indicates that the unsettled map provided is not complete. " + "When the map is incomplete the recipient of the map cannot take the absence of a delivery tag from " + "the map as evidence of settlement. On receipt of an incomplete unsettled map a sending endpoint MUST " + "NOT send any new deliveries (i.e. deliveries where resume is not set to true) to its partner (and " + "a receiving endpoint which sent an incomplete unsettled map MUST detach with an error on " + "receiving a transfer which does not have the resume flag set to true).")
public void rejectNewDeliveryWhilstUnsettledIncomplete() throws Exception {
final String destination = BrokerAdmin.TEST_QUEUE_NAME;
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().consumeResponse();
// 0. Open connection with small max-frame-size
final Open open = interaction.openMaxFrameSize(UnsignedInteger.valueOf(MIN_MAX_FRAME_SIZE)).open().consumeResponse().getLatestResponse(Open.class);
interaction.begin().consumeResponse(Begin.class);
// 1. attach with ReceiverSettleMode.SECOND
final UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
interaction.attachHandle(linkHandle1).attachRole(Role.SENDER).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachTargetAddress(destination).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
// 2. send enough unsettled deliverys to cause incomplete-unsettled to be true
// assume each delivery requires at least 1 byte, therefore max-frame-size deliveries should be enough
interaction.transferHandle(linkHandle1).transferPayloadData(TEST_MESSAGE_CONTENT);
Map<Binary, DeliveryState> localUnsettled = new HashMap<>(open.getMaxFrameSize().intValue());
for (int i = 0; i < open.getMaxFrameSize().intValue(); ++i) {
final Binary deliveryTag = new Binary(String.valueOf(i).getBytes(StandardCharsets.UTF_8));
final Disposition responseDisposition = interaction.transferDeliveryId(UnsignedInteger.valueOf(i)).transferDeliveryTag(deliveryTag).transfer().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
assertThat(responseDisposition.getRole(), is(Role.RECEIVER));
assertThat(responseDisposition.getSettled(), is(Boolean.FALSE));
localUnsettled.put(deliveryTag, null);
}
// 3. detach the link
interaction.detach().consumeResponse(Detach.class);
// 4. resume the link
final UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
final Binary sampleLocalUnsettled = localUnsettled.keySet().iterator().next();
Map<Binary, DeliveryState> unsettled = Collections.singletonMap(sampleLocalUnsettled, localUnsettled.get(sampleLocalUnsettled));
final Response<?> latestResponse = interaction.attachHandle(linkHandle2).attachUnsettled(unsettled).attachIncompleteUnsettled(true).attach().consumeResponse(End.class, Attach.class).getLatestResponse();
assumeThat(latestResponse.getBody(), is(instanceOf(Attach.class)));
// 5. ensure attach has incomplete-unsettled
final Attach responseAttach = (Attach) latestResponse.getBody();
assertThat(responseAttach.getIncompleteUnsettled(), is(equalTo(true)));
// 6. send new transfer
final Binary newDeliveryTag = new Binary("newTransfer".getBytes(StandardCharsets.UTF_8));
final Detach detachWithError = interaction.transferHandle(linkHandle2).transferDeliveryId(UnsignedInteger.ONE).transferDeliveryTag(newDeliveryTag).transfer().consumeResponse().getLatestResponse(Detach.class);
assertThat(detachWithError.getError(), is(notNullValue()));
final Error detachError = detachWithError.getError();
assertThat(detachError.getCondition(), is(equalTo(AmqpError.ILLEGAL_STATE)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Disposition 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.transport.Disposition 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));
}
}
Aggregations