use of org.apache.qpid.server.protocol.v1_0.type.transport.Flow in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method resumeReceivingLinkEmptyUnsettled.
@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 resumeReceivingLinkEmptyUnsettled() throws Exception {
Utils.putMessageOnQueue(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME, getTestName());
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction().negotiateOpen().begin().consumeResponse().attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flowNextIncomingIdFromPeerLatestSessionBeginAndDeliveryCount().flow().receiveDelivery().decodeLatestDelivery();
Object data = interaction.getDecodedLatestDelivery();
assertThat(data, is(equalTo(getTestName())));
interaction.dispositionSettled(true).dispositionState(new Accepted()).dispositionFirstFromLatestDelivery().dispositionRole(Role.RECEIVER).disposition();
Detach detach = interaction.detach().consume(Detach.class, Flow.class);
assertThat(detach.getClosed(), anyOf(nullValue(), equalTo(false)));
interaction.attachUnsettled(new HashMap<>()).attach().consumeResponse(Attach.class);
Attach attach = interaction.getLatestResponse(Attach.class);
Map<Binary, DeliveryState> unsettled = attach.getUnsettled();
assumeThat(unsettled, notNullValue());
assertThat(unsettled.entrySet(), empty());
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Flow in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method resumeSendingLinkSinglePartialDelivery.
@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 resumeSendingLinkSinglePartialDelivery() throws Exception {
final String destination = BrokerAdmin.TEST_QUEUE_NAME;
final Binary deliveryTag = new Binary("testDeliveryTag".getBytes(StandardCharsets.UTF_8));
QpidByteBuffer[] messagePayload = Utils.splitPayload(getTestName(), 2);
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
final Interaction interaction = transport.newInteraction();
interaction.negotiateOpen().begin().consumeResponse(Begin.class);
// 1. attach with ReceiverSettleMode.SECOND
interaction.attachHandle(linkHandle1).attachRole(Role.SENDER).attachTargetAddress(destination).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
// 2. send a partial delivery
interaction.transferHandle(linkHandle1).transferDeliveryId(UnsignedInteger.ZERO).transferDeliveryTag(deliveryTag).transferMore(true).transferPayload(messagePayload[0]).transfer();
// 3. detach the link
interaction.detach().consumeResponse(Detach.class);
// 4. resume the link
final UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
final Attach responseAttach2 = interaction.attachHandle(linkHandle2).attachUnsettled(Collections.singletonMap(deliveryTag, null)).attach().consumeResponse().getLatestResponse(Attach.class);
// 5. assert content of unsettled map
assertThat(responseAttach2.getTarget(), is(notNullValue()));
final Map<Binary, DeliveryState> remoteUnsettled = responseAttach2.getUnsettled();
assertThat(remoteUnsettled, is(notNullValue()));
assertThat(remoteUnsettled.keySet(), is(equalTo(Collections.singleton(deliveryTag))));
interaction.transferHandle(linkHandle2).transferResume(true).transfer().sync().transferMore(false).transferPayload(messagePayload[1]).transfer();
for (final QpidByteBuffer payload : messagePayload) {
payload.dispose();
}
boolean settled = false;
do {
interaction.consumeResponse();
Response<?> response = interaction.getLatestResponse();
assertThat(response, is(notNullValue()));
Object body = response.getBody();
if (body instanceof Disposition) {
Disposition disposition = (Disposition) body;
assertThat(disposition.getSettled(), is(Matchers.equalTo(true)));
assertThat(disposition.getFirst(), equalTo(UnsignedInteger.ZERO));
settled = true;
} else if (!(body instanceof Flow)) {
fail("Unexpected response " + body);
}
} while (!settled);
interaction.doCloseConnection();
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Flow in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method incompleteUnsettledReceiving.
@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 incompleteUnsettledReceiving() throws Exception {
for (int i = 0; i < MIN_MAX_FRAME_SIZE; i++) {
Utils.putMessageOnQueue(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME, getTestName() + "-" + i);
}
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
// 1. open with small max-frame=512, begin, attach receiver with
// with rcv-settle-mode=second, snd-settle-mode=unsettled,
// flow with incoming-window=MAX_INTEGER and link-credit=MAX_INTEGER
final Interaction interaction = transport.newInteraction();
interaction.openMaxFrameSize(UnsignedInteger.valueOf(MIN_MAX_FRAME_SIZE)).negotiateOpen().begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSndSettleMode(SenderSettleMode.UNSETTLED).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).assertLatestResponse(Attach.class, this::assumeReceiverSettlesSecond);
Attach attach = interaction.getLatestResponse(Attach.class);
assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.UNSETTLED)));
interaction.flowIncomingWindow(UnsignedInteger.valueOf(Integer.MAX_VALUE)).flowLinkCredit(UnsignedInteger.valueOf(Integer.MAX_VALUE)).flowHandleFromLinkHandle().flow();
// 2. Receive transfers
final Map<Binary, DeliveryState> localUnsettled = new HashMap<>();
for (int i = 0; i < MIN_MAX_FRAME_SIZE; ) {
Response<?> response = interaction.consumeResponse().getLatestResponse();
if (response.getBody() instanceof Transfer) {
assertThat(response.getBody(), Matchers.is(instanceOf(Transfer.class)));
Transfer responseTransfer = (Transfer) response.getBody();
assertThat(responseTransfer.getMore(), is(not(equalTo(true))));
assertThat(responseTransfer.getSettled(), is(not(equalTo(true))));
localUnsettled.putIfAbsent(responseTransfer.getDeliveryTag(), responseTransfer.getState());
i++;
} else if (response.getBody() instanceof Flow || response.getBody() instanceof Disposition) {
// ignore
} else {
fail("Unexpected frame " + response.getBody());
}
}
// 3. detach the link
interaction.detach().consumeResponse(Detach.class);
// 4. resume the link
final Binary sampleLocalUnsettled = localUnsettled.keySet().iterator().next();
Map<Binary, DeliveryState> unsettled = Collections.singletonMap(sampleLocalUnsettled, localUnsettled.get(sampleLocalUnsettled));
final UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
Response<?> latestResponse = interaction.attachHandle(linkHandle2).attachUnsettled(unsettled).attachIncompleteUnsettled(true).attach().consumeResponse(End.class, Attach.class).getLatestResponse();
assumeThat(latestResponse.getBody(), is(instanceOf(Attach.class)));
final Attach resumingAttach = (Attach) latestResponse.getBody();
final Map<Binary, DeliveryState> remoteUnsettled = resumingAttach.getUnsettled();
assertThat(remoteUnsettled, is(notNullValue()));
assertThat(remoteUnsettled.keySet(), is(not(empty())));
for (Binary deliveryTag : remoteUnsettled.keySet()) {
assertThat(deliveryTag, in(localUnsettled.keySet()));
}
assertThat(resumingAttach.getIncompleteUnsettled(), is(equalTo(true)));
interaction.flowHandle(linkHandle2).flow();
boolean received = false;
while (!received) {
Response<?> nextResponse = interaction.consumeResponse().getLatestResponse();
assertThat(nextResponse, is(notNullValue()));
if (nextResponse.getBody() instanceof Transfer) {
assertThat(nextResponse.getBody(), is(instanceOf(Transfer.class)));
Transfer responseTransfer = (Transfer) nextResponse.getBody();
assertThat(responseTransfer.getMore(), is(not(equalTo(true))));
assertThat(responseTransfer.getSettled(), is(not(equalTo(true))));
assertThat(responseTransfer.getDeliveryTag(), is(equalTo(sampleLocalUnsettled)));
received = true;
} else if (nextResponse.getBody() instanceof Flow || nextResponse.getBody() instanceof Disposition) {
// ignore
} else {
fail("Unexpected frame " + nextResponse.getBody());
}
}
interaction.doCloseConnection();
}
}
Aggregations