use of org.sbolstandard.core2.Interaction in project qpid-broker-j by apache.
the class TransferTest method receiveTransferUnsettled.
@Test
@SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
public void receiveTransferUnsettled() throws Exception {
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_DATA);
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).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow();
MessageDecoder messageDecoder = new MessageDecoder();
boolean hasMore;
do {
Transfer responseTransfer = interaction.consumeResponse().getLatestResponse(Transfer.class);
messageDecoder.addTransfer(responseTransfer);
hasMore = Boolean.TRUE.equals(responseTransfer.getMore());
} while (hasMore);
Object data = messageDecoder.getData();
assertThat(data, Is.is(CoreMatchers.equalTo(TEST_MESSAGE_DATA)));
}
}
use of org.sbolstandard.core2.Interaction in project qpid-broker-j by apache.
the class TransferTest method receiveTransferReceiverSettleSecondWithRejectedOutcome.
@Test
@SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
public void receiveTransferReceiverSettleSecondWithRejectedOutcome() throws Exception {
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_DATA);
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).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attachRcvSettleMode(ReceiverSettleMode.SECOND).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow();
Object data = interaction.receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
assertThat(data, is(equalTo(TEST_MESSAGE_DATA)));
interaction.dispositionSettled(false).dispositionRole(Role.RECEIVER).dispositionState(new Rejected()).disposition().consumeResponse(Disposition.class, Flow.class);
Response<?> response = interaction.getLatestResponse();
if (response.getBody() instanceof Flow) {
interaction.consumeResponse(Disposition.class);
}
Disposition disposition = interaction.getLatestResponse(Disposition.class);
assertThat(disposition.getSettled(), is(true));
interaction.consumeResponse(null, Flow.class);
}
}
use of org.sbolstandard.core2.Interaction in project qpid-broker-j by apache.
the class TransferTest method transferMultipleDeliveries.
@Test
@SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
public void transferMultipleDeliveries() 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)));
interaction.transferDeliveryId(UnsignedInteger.ZERO).transferDeliveryTag(new Binary("A".getBytes(StandardCharsets.UTF_8))).transferPayloadData("test").transfer().transferDeliveryId(UnsignedInteger.ONE).transferDeliveryTag(new Binary("B".getBytes(StandardCharsets.UTF_8))).transferPayloadData("test").transfer().transferDeliveryId(UnsignedInteger.valueOf(2)).transferDeliveryTag(new Binary("C".getBytes(StandardCharsets.UTF_8))).transferPayloadData("test").transfer();
TreeSet<UnsignedInteger> expectedDeliveryIds = Sets.newTreeSet(Arrays.asList(UnsignedInteger.ZERO, UnsignedInteger.ONE, UnsignedInteger.valueOf(2)));
assertDeliveries(interaction, expectedDeliveryIds);
// verify that no unexpected performative is received by closing
interaction.doCloseConnection();
}
}
use of org.sbolstandard.core2.Interaction 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)));
}
}
use of org.sbolstandard.core2.Interaction 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)));
}
}
Aggregations