use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.
the class MultiTransferTest method multiTransferMessage.
@Test
@SpecificationTest(section = "2.6.14", description = "For messages that are too large to fit within the maximum frame size, additional data MAY" + " be transferred in additional transfer frames by setting the more flag on all" + " but the last transfer frame")
public void multiTransferMessage() 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();
Disposition disposition = 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().transferMore(false).transferPayload(payloads[1]).transfer().consumeResponse().getLatestResponse(Disposition.class);
for (final QpidByteBuffer payload : payloads) {
payload.dispose();
}
assertThat(disposition.getFirst(), is(equalTo(deliveryId)));
assertThat(disposition.getLast(), isOneOf(null, deliveryId));
assertThat(disposition.getSettled(), is(equalTo(false)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.
the class TransferTest method receiveMultipleDeliveries.
@Test
@SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
public void receiveMultipleDeliveries() throws Exception {
int numberOfMessages = 4;
for (int i = 0; i < numberOfMessages; i++) {
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_DATA + "_" + i);
}
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).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.valueOf(numberOfMessages)).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.valueOf(numberOfMessages)).flowHandleFromLinkHandle().flow();
for (int i = 0; i < numberOfMessages; i++) {
interaction.receiveDelivery(Flow.class).decodeLatestDelivery();
Object data = interaction.getDecodedLatestDelivery();
assertThat(data, Is.is(CoreMatchers.equalTo(TEST_MESSAGE_DATA + "_" + i)));
assertThat(interaction.getLatestDeliveryId(), Is.is(equalTo(UnsignedInteger.valueOf(i))));
}
interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionFirst(UnsignedInteger.ZERO).dispositionLast(interaction.getLatestDeliveryId()).dispositionState(new Accepted()).disposition();
// make sure sure the disposition is handled by making drain request
interaction.flowLinkCredit(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.valueOf(numberOfMessages)).flowDrain(Boolean.TRUE).flow().consumeResponse(Flow.class);
if (getBrokerAdmin().isQueueDepthSupported()) {
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
}
}
String messageText = TEST_MESSAGE_DATA + "_" + 4;
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageText);
Object receivedMessage = Utils.receiveMessage(_brokerAddress, BrokerAdmin.TEST_QUEUE_NAME);
assertThat(receivedMessage, is(equalTo(messageText)));
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data 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.server.protocol.v1_0.type.messaging.Data 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.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.
the class TransactionalTransferTest method receiveTransactionalAcquisitionReceiverSettleFirst.
@Test
@SpecificationTest(section = "4.4.2", 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 receiveTransactionalAcquisitionReceiverSettleFirst() 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, false);
assumeThat(getBrokerAdmin().isQueueDepthSupported(), is(true));
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
}
}
Aggregations