Search in sources :

Example 41 with Detach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach 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("testData1", 2);
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).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();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) 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) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) 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 42 with Detach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach 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(_brokerAddress).connect()) {
        final UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class);
        // 1. attach with ReceiverSettleMode.SECOND
        interaction.attachHandle(linkHandle1).attachRole(Role.SENDER).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachTargetAddress(destination).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
        // 2. send a unsettled delivery
        final Disposition responseDisposition = interaction.transferHandle(linkHandle1).transferDeliveryId(UnsignedInteger.ZERO).transferDeliveryTag(deliveryTag).transferPayloadData(TEST_MESSAGE_CONTENT).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)

Aggregations

Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)27 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)27 Test (org.junit.Test)27 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)24 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)23 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)21 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)13 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)12 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)11 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)11 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)10 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)10 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)9 End (org.apache.qpid.server.protocol.v1_0.type.transport.End)9 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)8 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)8 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)7 Ignore (org.junit.Ignore)7 HashMap (java.util.HashMap)5 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)4