use of org.apache.qpid.tests.protocol.v0_8.FrameTransport in project qpid-broker-j by apache.
the class TransferTest method receiveTransferReceiverIndicatesNonTerminalDeliveryState.
@Test
@SpecificationTest(section = "2.6.12", description = "[...] the receiving application MAY wish to indicate" + " non-terminal delivery states to the sender")
public void receiveTransferReceiverIndicatesNonTerminalDeliveryState() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
Open open = interaction.negotiateProtocol().consumeResponse().openMaxFrameSize(UnsignedInteger.valueOf(4096)).open().consumeResponse().getLatestResponse(Open.class);
int negotiatedFrameSize = open.getMaxFrameSize().intValue();
String testMessageData = Stream.generate(() -> "*").limit(negotiatedFrameSize).collect(Collectors.joining());
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, testMessageData);
interaction.begin().consumeResponse().attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().sync();
MessageDecoder messageDecoder = new MessageDecoder();
Transfer first = interaction.consumeResponse(Transfer.class).getLatestResponse(Transfer.class);
assertThat(first.getMore(), is(equalTo(true)));
messageDecoder.addTransfer(first);
final long firstRemaining;
try (QpidByteBuffer payload = first.getPayload()) {
firstRemaining = payload.remaining();
}
Received state = new Received();
state.setSectionNumber(UnsignedInteger.ZERO);
state.setSectionOffset(UnsignedLong.valueOf(firstRemaining + 1));
interaction.dispositionSettled(false).dispositionRole(Role.RECEIVER).dispositionState(state).disposition().sync();
Transfer second = interaction.consumeResponse(Transfer.class).getLatestResponse(Transfer.class);
assertThat(second.getMore(), isOneOf(false, null));
messageDecoder.addTransfer(second);
assertThat(messageDecoder.getData(), is(equalTo(testMessageData)));
Disposition disposition = interaction.dispositionSettled(false).dispositionRole(Role.RECEIVER).dispositionState(new Accepted()).disposition().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
assertThat(disposition.getSettled(), is(true));
interaction.consumeResponse(null, Flow.class);
}
}
use of org.apache.qpid.tests.protocol.v0_8.FrameTransport in project qpid-broker-j by apache.
the class TransferTest method receiveTransferSenderSettleModeSettled.
@Test
@SpecificationTest(section = "2.7.3", description = "The sender SHOULD respect the receiver’s desired settlement mode if" + " the receiver initiates the attach exchange and the sender supports the desired mode.")
public void receiveTransferSenderSettleModeSettled() 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).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSndSettleMode(SenderSettleMode.SETTLED).attach().consumeResponse(Attach.class);
Attach attach = interaction.getLatestResponse(Attach.class);
assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.SETTLED)));
interaction.flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow();
List<Transfer> transfers = interaction.receiveDelivery().getLatestDelivery();
final AtomicBoolean isSettled = new AtomicBoolean();
transfers.forEach(transfer -> {
if (Boolean.TRUE.equals(transfer.getSettled())) {
isSettled.set(true);
}
});
assertThat(isSettled.get(), is(true));
// verify no unexpected performative received by closing the connection
interaction.doCloseConnection();
}
}
use of org.apache.qpid.tests.protocol.v0_8.FrameTransport in project qpid-broker-j by apache.
the class TransferTest method presettledPipelined.
@Test
@SpecificationTest(section = "", description = "Pipelined message send")
public void presettledPipelined() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
interaction.negotiateProtocol().open().begin().attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().transferPayloadData("testData").transferSettled(true).transfer().close().sync();
final byte[] protocolResponse = interaction.consumeResponse().getLatestResponse(byte[].class);
assertThat(protocolResponse, is(equalTo("AMQP\0\1\0\0".getBytes(UTF_8))));
interaction.consumeResponse().getLatestResponse(Open.class);
interaction.consumeResponse().getLatestResponse(Begin.class);
interaction.consumeResponse().getLatestResponse(Attach.class);
interaction.consumeResponse().getLatestResponse(Flow.class);
interaction.consumeResponse().getLatestResponse(Close.class);
}
}
use of org.apache.qpid.tests.protocol.v0_8.FrameTransport 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.apache.qpid.tests.protocol.v0_8.FrameTransport 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);
}
}
Aggregations