use of org.apache.qpid.server.protocol.v1_0.type.transport.Transfer in project qpid-broker-j by apache.
the class MultiTransferTest method abortMultiTransferMessage.
//
@Test
@SpecificationTest(section = "2.6.14", description = "The sender MAY indicate an aborted attempt to deliver a message by setting the abort flag on the last transfer." + "In this case the receiver MUST discard the message data that was transferred prior to the abort.")
public void abortMultiTransferMessage() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
QpidByteBuffer[] payloads = Utils.splitPayload("testData", 2);
final UnsignedInteger deliveryId = UnsignedInteger.ZERO;
final Binary deliveryTag = new Binary("testTransfer".getBytes(UTF_8));
Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(payloads[0]).transferDeliveryId(deliveryId).transferDeliveryTag(deliveryTag).transferMore(true).transfer().sync().transferPayload(null).transferMore(null).transferAborted(true).transfer();
for (final QpidByteBuffer payload : payloads) {
payload.dispose();
}
Response<?> latestResponse = interaction.consumeResponse(new Class<?>[] { null }).getLatestResponse();
assertThat(latestResponse, is(nullValue()));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Transfer in project qpid-broker-j by apache.
the class MultiTransferTest method multiTransferInterleaved.
@Test
@SpecificationTest(section = "2.6.14", description = "[...]messages being transferred along different links MAY be interleaved")
public void multiTransferInterleaved() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
QpidByteBuffer[] messagePayload1 = Utils.splitPayload("testData1", 2);
QpidByteBuffer[] messagePayload2 = Utils.splitPayload("testData2", 2);
UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
Binary deliveryTag1 = new Binary("testTransfer1".getBytes(UTF_8));
Binary deliveryTag2 = new Binary("testTransfer2".getBytes(UTF_8));
UnsignedInteger deliverId1 = UnsignedInteger.ZERO;
UnsignedInteger deliveryId2 = UnsignedInteger.ONE;
Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachName("testLink1").attachHandle(linkHandle1).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).attachName("testLink2").attachHandle(linkHandle2).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle1).transferDeliveryId(deliverId1).transferDeliveryTag(deliveryTag1).transferMore(true).transferPayload(messagePayload1[0]).transfer().sync().transferHandle(linkHandle2).transferDeliveryId(deliveryId2).transferDeliveryTag(deliveryTag2).transferMore(true).transferPayload(messagePayload2[0]).transfer().sync().transferHandle(linkHandle1).transferDeliveryId(deliverId1).transferDeliveryTag(deliveryTag1).transferMore(false).transferPayload(messagePayload1[1]).transfer().sync().transferHandle(linkHandle2).transferDeliveryId(deliveryId2).transferDeliveryTag(deliveryTag2).transferMore(false).transferPayload(messagePayload2[1]).transfer().sync();
for (final QpidByteBuffer payload : messagePayload1) {
payload.dispose();
}
for (final QpidByteBuffer payload : messagePayload2) {
payload.dispose();
}
Map<UnsignedInteger, Disposition> dispositionMap = new HashMap<>();
for (int i = 0; i < 2; i++) {
Disposition disposition = interaction.consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
dispositionMap.put(disposition.getFirst(), disposition);
assertThat(disposition.getLast(), isOneOf(null, disposition.getFirst()));
assertThat(disposition.getSettled(), is(equalTo(false)));
assertThat(disposition.getState(), is(instanceOf(Accepted.class)));
}
assertThat("Unexpected number of dispositions", dispositionMap.size(), equalTo(2));
assertThat(dispositionMap.containsKey(deliverId1), is(true));
assertThat(dispositionMap.containsKey(deliveryId2), is(true));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Transfer in project qpid-broker-j by apache.
the class TransferTest method durableTransferWithRejectedOutcome.
@Test
@SpecificationTest(section = "3.2.1", description = "Durable messages MUST NOT be lost even if an intermediary is unexpectedly terminated and " + "restarted. A target which is not capable of fulfilling this guarantee MUST NOT accept messages " + "where the durable header is set to true: if the source allows the rejected outcome then the " + "message SHOULD be rejected with the precondition-failed error, otherwise the link MUST be " + "detached by the receiver with the same error.")
public void durableTransferWithRejectedOutcome() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
MessageEncoder messageEncoder = new MessageEncoder();
final Header header = new Header();
header.setDurable(true);
messageEncoder.setHeader(header);
messageEncoder.addData("foo");
final Disposition receivedDisposition = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(messageEncoder.getPayload()).transferRcvSettleMode(ReceiverSettleMode.FIRST).transfer().consumeResponse().getLatestResponse(Disposition.class);
assertThat(receivedDisposition.getSettled(), is(true));
assertThat(receivedDisposition.getState(), is(instanceOf(Outcome.class)));
if (getBrokerAdmin().supportsRestart()) {
assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Accepted.ACCEPTED_SYMBOL));
} else {
assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Rejected.REJECTED_SYMBOL));
}
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Transfer in project qpid-broker-j by apache.
the class TransferTest method transferWithoutDeliveryTag.
@Test
@SpecificationTest(section = "2.7.5", description = "[delivery-tag] MUST be specified for the first transfer " + "[...] and can only be omitted for continuation transfers.")
public void transferWithoutDeliveryTag() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
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).transferDeliveryTag(null).transferPayloadData("testData").transfer();
interaction.consumeResponse(Detach.class, End.class, Close.class);
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Transfer in project qpid-broker-j by apache.
the class TransferTest method transferReceiverSettleModeCannotBeSecondWhenLinkModeIsFirst.
@Test
@SpecificationTest(section = "2.7.5", description = "If the negotiated link value is first, then it is illegal to set this field to second.")
public void transferReceiverSettleModeCannotBeSecondWhenLinkModeIsFirst() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
Detach detach = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayloadData("testData").transferRcvSettleMode(ReceiverSettleMode.SECOND).transfer().consumeResponse().getLatestResponse(Detach.class);
Error error = detach.getError();
assertThat(error, is(notNullValue()));
assertThat(error.getCondition(), is(equalTo(AmqpError.INVALID_FIELD)));
}
}
Aggregations