Search in sources :

Example 26 with DeliveryState

use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState 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();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) HashMap(java.util.HashMap) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Ignore(org.junit.Ignore) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 27 with DeliveryState

use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.

the class ResumeDeliveriesTest method resumeSendingLinkSingleUnsettledDelivery.

@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 resumeSendingLinkSingleUnsettledDelivery() throws Exception {
    final String destination = BrokerAdmin.TEST_QUEUE_NAME;
    final Binary deliveryTag = new Binary("testDeliveryTag".getBytes(StandardCharsets.UTF_8));
    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).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachTargetAddress(destination).attach().consumeResponse(Attach.class).assertLatestResponse(Attach.class, this::assumeReceiverSettlesSecond).consumeResponse(Flow.class);
        // 2. send a unsettled delivery
        final Disposition responseDisposition = interaction.transferHandle(linkHandle1).transferDeliveryId(UnsignedInteger.ZERO).transferDeliveryTag(deliveryTag).transferPayloadData(getTestName()).transfer().consumeResponse().getLatestResponse(Disposition.class);
        assertThat(responseDisposition.getRole(), is(Role.RECEIVER));
        assertThat(responseDisposition.getSettled(), is(Boolean.FALSE));
        final DeliveryState remoteDeliveryState = responseDisposition.getState();
        // 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))));
        assertThat(remoteUnsettled.get(deliveryTag).getClass(), typeCompatibleWith(remoteDeliveryState.getClass()));
        assertThat(responseAttach2.getIncompleteUnsettled(), is(anyOf(nullValue(), equalTo(false))));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Ignore(org.junit.Ignore) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 28 with DeliveryState

use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.

the class ResumeDeliveriesTest method resumeSendingLinkWithIncompleteUnsettled.

@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.7.3", description = "If the local unsettled map is too large to be encoded within a frame of the agreed maximum" + " frame size then the session MAY be ended with the frame-size-too-small error. The" + " endpoint SHOULD make use of the ability to send an incomplete unsettled map (see below)" + " to avoid sending an error.")
public void resumeSendingLinkWithIncompleteUnsettled() throws Exception {
    final String destination = BrokerAdmin.TEST_QUEUE_NAME;
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        // 0. Open connection with small max-frame-size
        final Open open = interaction.openMaxFrameSize(UnsignedInteger.valueOf(MIN_MAX_FRAME_SIZE)).negotiateOpen().getLatestResponse(Open.class);
        interaction.begin().consumeResponse(Begin.class);
        // 1. attach with ReceiverSettleMode.SECOND
        final UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
        interaction.attachHandle(linkHandle1).attachRole(Role.SENDER).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachTargetAddress(destination).attach().consumeResponse(Attach.class).assertLatestResponse(Attach.class, this::assumeReceiverSettlesSecond).consumeResponse(Flow.class);
        // 2. send enough unsettled deliveries to cause incomplete-unsettled to be true
        // assume each delivery requires at least 1 byte, therefore max-frame-size deliveries should be enough
        interaction.transferHandle(linkHandle1).transferPayloadData(getTestName());
        Map<Binary, DeliveryState> localUnsettled = new HashMap<>(open.getMaxFrameSize().intValue());
        for (int i = 0; i < open.getMaxFrameSize().intValue(); ++i) {
            final Binary deliveryTag = new Binary(String.valueOf(i).getBytes(StandardCharsets.UTF_8));
            final Disposition responseDisposition = interaction.transferDeliveryId(UnsignedInteger.valueOf(i)).transferDeliveryTag(deliveryTag).transfer().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
            assertThat(responseDisposition.getRole(), is(Role.RECEIVER));
            assertThat(responseDisposition.getSettled(), is(Boolean.FALSE));
            localUnsettled.put(deliveryTag, null);
        }
        // 3. detach the link
        interaction.detach().consumeResponse(Detach.class);
        // 4. resume the link
        final UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
        final Binary sampleLocalUnsettled = localUnsettled.keySet().iterator().next();
        Map<Binary, DeliveryState> unsettled = Collections.singletonMap(sampleLocalUnsettled, localUnsettled.get(sampleLocalUnsettled));
        final Response<?> latestResponse = interaction.attachHandle(linkHandle2).attachUnsettled(unsettled).attachIncompleteUnsettled(true).attach().consumeResponse(End.class, Attach.class).getLatestResponse();
        if (latestResponse.getBody() instanceof End) {
            // 5.a assert session end error
            final End responseEnd = (End) latestResponse.getBody();
            final Error error = responseEnd.getError();
            assertThat(error, is(notNullValue()));
            assertThat(error.getCondition().getValue(), is(equalTo(AmqpError.FRAME_SIZE_TOO_SMALL)));
            assumeTrue("Broker does not support incomplete unsettled", false);
        } else if (latestResponse.getBody() instanceof Attach) {
            // 5.b assert content of unsettled map
            final Attach responseAttach2 = (Attach) latestResponse.getBody();
            assertThat(responseAttach2.getTarget(), is(notNullValue()));
            final Map<Binary, DeliveryState> remoteUnsettled = responseAttach2.getUnsettled();
            assertThat(remoteUnsettled, is(notNullValue()));
            assertThat(remoteUnsettled.keySet(), is(not(empty())));
            for (Binary deliveryTag : remoteUnsettled.keySet()) {
                assertThat(deliveryTag, in(localUnsettled.keySet()));
            }
            assertThat(responseAttach2.getIncompleteUnsettled(), is(equalTo(true)));
        } else {
            fail(String.format("Unexpected response. Expected End or Attach. Got '%s'.", latestResponse.getBody()));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) HashMap(java.util.HashMap) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Map(java.util.Map) HashMap(java.util.HashMap) Ignore(org.junit.Ignore) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)21 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)15 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)14 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)13 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)13 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)13 Test (org.junit.Test)13 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)12 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)10 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)9 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)9 HashMap (java.util.HashMap)8 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)8 Ignore (org.junit.Ignore)7 Map (java.util.Map)6 Rejected (org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected)6 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)6 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)5 TransactionalState (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState)5 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)5