Search in sources :

Example 6 with Disposition

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

the class MultiTransferTest method multiTransferInterleaved.

@Test
@SpecificationTest(section = "2.6.14", description = "[...]messages being transferred along different links MAY be interleaved")
public void multiTransferInterleaved() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        QpidByteBuffer[] messagePayload1 = Utils.splitPayload("testData1", 2);
        QpidByteBuffer[] messagePayload2 = Utils.splitPayload("testData2", 2);
        UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
        UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
        Binary deliveryTag1 = new Binary("testTransfer1".getBytes(UTF_8));
        Binary deliveryTag2 = new Binary("testTransfer2".getBytes(UTF_8));
        UnsignedInteger deliverId1 = UnsignedInteger.ZERO;
        UnsignedInteger deliveryId2 = UnsignedInteger.ONE;
        Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachName("testLink1").attachHandle(linkHandle1).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).attachName("testLink2").attachHandle(linkHandle2).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle1).transferDeliveryId(deliverId1).transferDeliveryTag(deliveryTag1).transferMore(true).transferPayload(messagePayload1[0]).transfer().sync().transferHandle(linkHandle2).transferDeliveryId(deliveryId2).transferDeliveryTag(deliveryTag2).transferMore(true).transferPayload(messagePayload2[0]).transfer().sync().transferHandle(linkHandle1).transferDeliveryId(deliverId1).transferDeliveryTag(deliveryTag1).transferMore(false).transferPayload(messagePayload1[1]).transfer().sync().transferHandle(linkHandle2).transferDeliveryId(deliveryId2).transferDeliveryTag(deliveryTag2).transferMore(false).transferPayload(messagePayload2[1]).transfer().sync();
        for (final QpidByteBuffer payload : messagePayload1) {
            payload.dispose();
        }
        for (final QpidByteBuffer payload : messagePayload2) {
            payload.dispose();
        }
        Map<UnsignedInteger, Disposition> dispositionMap = new HashMap<>();
        for (int i = 0; i < 2; i++) {
            Disposition disposition = interaction.consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
            dispositionMap.put(disposition.getFirst(), disposition);
            assertThat(disposition.getLast(), isOneOf(null, disposition.getFirst()));
            assertThat(disposition.getSettled(), is(equalTo(false)));
            assertThat(disposition.getState(), is(instanceOf(Accepted.class)));
        }
        assertThat("Unexpected number of dispositions", dispositionMap.size(), equalTo(2));
        assertThat(dispositionMap.containsKey(deliverId1), is(true));
        assertThat(dispositionMap.containsKey(deliveryId2), is(true));
    }
}
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) 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) 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 7 with Disposition

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

the class TransferTest method durableTransferWithRejectedOutcome.

@Test
@SpecificationTest(section = "3.2.1", description = "Durable messages MUST NOT be lost even if an intermediary is unexpectedly terminated and " + "restarted. A target which is not capable of fulfilling this guarantee MUST NOT accept messages " + "where the durable header is set to true: if the source allows the rejected outcome then the " + "message SHOULD be rejected with the precondition-failed error, otherwise the link MUST be " + "detached by the receiver with the same error.")
public void durableTransferWithRejectedOutcome() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        MessageEncoder messageEncoder = new MessageEncoder();
        final Header header = new Header();
        header.setDurable(true);
        messageEncoder.setHeader(header);
        messageEncoder.addData("foo");
        final Disposition receivedDisposition = transport.newInteraction().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, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(messageEncoder.getPayload()).transferRcvSettleMode(ReceiverSettleMode.FIRST).transfer().consumeResponse().getLatestResponse(Disposition.class);
        assertThat(receivedDisposition.getSettled(), is(true));
        assertThat(receivedDisposition.getState(), is(instanceOf(Outcome.class)));
        if (getBrokerAdmin().supportsRestart()) {
            assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Accepted.ACCEPTED_SYMBOL));
        } else {
            assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Rejected.REJECTED_SYMBOL));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) MessageEncoder(org.apache.qpid.tests.protocol.v1_0.MessageEncoder) 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 8 with Disposition

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

the class TransferTest method durableTransferWithoutRejectedOutcome.

@Test
@SpecificationTest(section = "3.2.1", description = "Durable messages MUST NOT be lost even if an intermediary is unexpectedly terminated and " + "restarted. A target which is not capable of fulfilling this guarantee MUST NOT accept messages " + "where the durable header is set to true: if the source allows the rejected outcome then the " + "message SHOULD be rejected with the precondition-failed error, otherwise the link MUST be " + "detached by the receiver with the same error.")
public void durableTransferWithoutRejectedOutcome() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        MessageEncoder messageEncoder = new MessageEncoder();
        final Header header = new Header();
        header.setDurable(true);
        messageEncoder.setHeader(header);
        messageEncoder.addData("foo");
        final Response<?> response = transport.newInteraction().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(messageEncoder.getPayload()).transferRcvSettleMode(ReceiverSettleMode.FIRST).transfer().consumeResponse().getLatestResponse();
        if (getBrokerAdmin().supportsRestart()) {
            assertThat(response, is(notNullValue()));
            assertThat(response.getBody(), is(instanceOf(Disposition.class)));
            final Disposition receivedDisposition = (Disposition) response.getBody();
            assertThat(receivedDisposition.getSettled(), is(true));
            assertThat(receivedDisposition.getState(), is(instanceOf(Outcome.class)));
            assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Accepted.ACCEPTED_SYMBOL));
        } else {
            assertThat(response, is(notNullValue()));
            assertThat(response.getBody(), is(instanceOf(Detach.class)));
            final Detach receivedDetach = (Detach) response.getBody();
            assertThat(receivedDetach.getError(), is(notNullValue()));
            assertThat(receivedDetach.getError().getCondition(), is(AmqpError.PRECONDITION_FAILED));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) MessageEncoder(org.apache.qpid.tests.protocol.v1_0.MessageEncoder) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) 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 9 with Disposition

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

the class TransferTest method receiveTransferReceiverSettleSecond.

@Test
@SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
public void receiveTransferReceiverSettleSecond() 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).attachRcvSettleMode(ReceiverSettleMode.SECOND).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery();
        Object data = interaction.getDecodedLatestDelivery();
        assertThat(data, Is.is(CoreMatchers.equalTo(TEST_MESSAGE_DATA)));
        Disposition disposition = interaction.dispositionSettled(false).dispositionRole(Role.RECEIVER).dispositionState(new Accepted()).disposition().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
        assertThat(disposition.getSettled(), is(true));
        interaction.consumeResponse(null, Flow.class);
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 10 with Disposition

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

the class TransferTest method receiveTransferReceiverSettleSecondWithImplicitDispositionState.

@Ignore
@Test
@SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
public void receiveTransferReceiverSettleSecondWithImplicitDispositionState() 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).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes().attachSourceDefaultOutcome(null).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery();
        Object data = interaction.getDecodedLatestDelivery();
        assertThat(data, Is.is(CoreMatchers.equalTo(TEST_MESSAGE_DATA)));
        Disposition disposition = interaction.dispositionSettled(false).dispositionRole(Role.RECEIVER).dispositionState(null).disposition().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
        assertThat(disposition.getSettled(), is(true));
        interaction.consumeResponse(null, Flow.class);
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Ignore(org.junit.Ignore) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)44 Test (org.junit.Test)44 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)42 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)40 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)37 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)29 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)23 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)20 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)20 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)18 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)17 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)17 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)16 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)12 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)10 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)10 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)9 Ignore (org.junit.Ignore)9 Rejected (org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected)8 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)8