Search in sources :

Example 16 with End

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

the class MessageFormat method differentMessageFormatOnSameDeliveryFails.

@Test
@SpecificationTest(section = "2.7.5", description = "message-format: " + "This field MUST be specified for the first transfer of a multi-transfer message and can " + "only be omitted for continuation transfers. It is an error if the message-format on a " + "continuation transfer differs from the message-format on the first transfer of a delivery.")
public void differentMessageFormatOnSameDeliveryFails() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        QpidByteBuffer[] payloads = Utils.splitPayload("testData", 2);
        final Response<?> latestResponse = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferMore(true).transferMessageFormat(UnsignedInteger.ZERO).transferPayload(payloads[0]).transfer().consumeResponse(null, Flow.class, Disposition.class).transferDeliveryTag(null).transferDeliveryId(null).transferMore(false).transferMessageFormat(UnsignedInteger.ONE).transferPayload(payloads[1]).transfer().consumeResponse(Detach.class, End.class, Close.class).getLatestResponse();
        for (final QpidByteBuffer payload : payloads) {
            payload.dispose();
        }
        assertThat(latestResponse, is(notNullValue()));
        final Object responseBody = latestResponse.getBody();
        final Error error;
        if (responseBody instanceof Detach) {
            error = ((Detach) responseBody).getError();
        } else if (responseBody instanceof End) {
            error = ((End) responseBody).getError();
        } else if (responseBody instanceof Close) {
            error = ((Close) responseBody).getError();
        } else {
            fail(String.format("Expected response of either Detach, End, or Close. Got '%s'", responseBody));
            error = null;
        }
        assertThat(error, is(notNullValue()));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 17 with End

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

the class TransferTest method deliveryTagCanBeReusedAfterDeliveryIsSettled.

@Test
@SpecificationTest(section = "2.6.12", description = "The delivery-tag MUST be unique amongst all deliveries that" + " could be considered unsettled by either end of the link.")
public void deliveryTagCanBeReusedAfterDeliveryIsSettled() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Binary deliveryTag = new Binary("testDeliveryTag".getBytes(UTF_8));
        Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
        Flow flow = interaction.getLatestResponse(Flow.class);
        assertThat(flow.getLinkCredit().intValue(), is(greaterThan(1)));
        interaction.transferDeliveryId(UnsignedInteger.ZERO).transferDeliveryTag(deliveryTag).transferPayloadData("test").transferSettled(true).transfer().sync().transferDeliveryTag(deliveryTag).transferDeliveryId(UnsignedInteger.ONE).transferPayloadData("test2").transfer().sync();
        interaction.doCloseConnection();
        assumeThat(getBrokerAdmin().isQueueDepthSupported(), is(true));
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(2)));
    }
}
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) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 18 with End

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

the class FlowTest method flowWithUnknownHandle.

@Test
@SpecificationTest(section = "2.7.4", description = "If set to a handle that is not currently associated with an attached link, the recipient" + " MUST respond by ending the session with an unattached-handle session error.")
public void flowWithUnknownHandle() throws Exception {
    final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
    try (FrameTransport transport = new FrameTransport(addr).connect()) {
        End responseEnd = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).flowEcho(true).flowHandle(UnsignedInteger.ONE).flow().consumeResponse().getLatestResponse(End.class);
        assertThat(responseEnd.getError(), is(notNullValue()));
        assertThat(responseEnd.getError().getCondition(), is(equalTo(SessionError.UNATTACHED_HANDLE)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InetSocketAddress(java.net.InetSocketAddress) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 19 with End

use of org.apache.qpid.server.protocol.v1_0.type.transport.End 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(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse();
        // 0. Open connection with small max-frame-size
        final Open open = interaction.openMaxFrameSize(UnsignedInteger.valueOf(MIN_MAX_FRAME_SIZE)).open().consumeResponse().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).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(TEST_MESSAGE_CONTENT);
        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, isIn(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

End (org.apache.qpid.server.protocol.v1_0.type.transport.End)15 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)11 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)8 Test (org.junit.Test)8 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)7 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)6 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)6 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)5 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)5 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)5 LinkError (org.apache.qpid.server.protocol.v1_0.type.transport.LinkError)5 SessionError (org.apache.qpid.server.protocol.v1_0.type.transport.SessionError)5 Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)4 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)4 InetSocketAddress (java.net.InetSocketAddress)3 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)3 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DeliveryRegistry (org.apache.qpid.server.protocol.v1_0.delivery.DeliveryRegistry)2