Search in sources :

Example 51 with Transfer

use of org.apache.qpid.server.protocol.v1_0.type.transport.Transfer 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 52 with Transfer

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

the class TransferTest method receiveTransferReceiverIndicatesNonTerminalDeliveryState.

@Test
@SpecificationTest(section = "2.6.12", description = "[...] the receiving application MAY wish to indicate" + " non-terminal delivery states to the sender")
public void receiveTransferReceiverIndicatesNonTerminalDeliveryState() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        Open open = interaction.negotiateProtocol().consumeResponse().openMaxFrameSize(UnsignedInteger.valueOf(4096)).open().consumeResponse().getLatestResponse(Open.class);
        int negotiatedFrameSize = open.getMaxFrameSize().intValue();
        String testMessageData = Stream.generate(() -> "*").limit(negotiatedFrameSize).collect(Collectors.joining());
        getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, testMessageData);
        interaction.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().sync();
        MessageDecoder messageDecoder = new MessageDecoder();
        Transfer first = interaction.consumeResponse(Transfer.class).getLatestResponse(Transfer.class);
        assertThat(first.getMore(), is(equalTo(true)));
        messageDecoder.addTransfer(first);
        final long firstRemaining;
        try (QpidByteBuffer payload = first.getPayload()) {
            firstRemaining = payload.remaining();
        }
        Received state = new Received();
        state.setSectionNumber(UnsignedInteger.ZERO);
        state.setSectionOffset(UnsignedLong.valueOf(firstRemaining + 1));
        interaction.dispositionSettled(false).dispositionRole(Role.RECEIVER).dispositionState(state).disposition().sync();
        Transfer second = interaction.consumeResponse(Transfer.class).getLatestResponse(Transfer.class);
        assertThat(second.getMore(), isOneOf(false, null));
        messageDecoder.addTransfer(second);
        assertThat(messageDecoder.getData(), is(equalTo(testMessageData)));
        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) MessageDecoder(org.apache.qpid.tests.protocol.v1_0.MessageDecoder) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Received(org.apache.qpid.server.protocol.v1_0.type.messaging.Received) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 53 with Transfer

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

the class TransferTest method receiveTransferSenderSettleModeSettled.

@Test
@SpecificationTest(section = "2.7.3", description = "The sender SHOULD respect the receiver’s desired settlement mode if" + " the receiver initiates the attach exchange and the sender supports the desired mode.")
public void receiveTransferSenderSettleModeSettled() 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.FIRST).attachSndSettleMode(SenderSettleMode.SETTLED).attach().consumeResponse(Attach.class);
        Attach attach = interaction.getLatestResponse(Attach.class);
        assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.SETTLED)));
        interaction.flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow();
        List<Transfer> transfers = interaction.receiveDelivery().getLatestDelivery();
        final AtomicBoolean isSettled = new AtomicBoolean();
        transfers.forEach(transfer -> {
            if (Boolean.TRUE.equals(transfer.getSettled())) {
                isSettled.set(true);
            }
        });
        assertThat(isSettled.get(), is(true));
        // verify no unexpected performative received by closing the connection
        interaction.doCloseConnection();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 54 with Transfer

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

the class TransferTest method receiveTransferUnsettled.

@Test
@SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
public void receiveTransferUnsettled() 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).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow();
        MessageDecoder messageDecoder = new MessageDecoder();
        boolean hasMore;
        do {
            Transfer responseTransfer = interaction.consumeResponse().getLatestResponse(Transfer.class);
            messageDecoder.addTransfer(responseTransfer);
            hasMore = Boolean.TRUE.equals(responseTransfer.getMore());
        } while (hasMore);
        Object data = messageDecoder.getData();
        assertThat(data, Is.is(CoreMatchers.equalTo(TEST_MESSAGE_DATA)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) MessageDecoder(org.apache.qpid.tests.protocol.v1_0.MessageDecoder) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 55 with Transfer

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

the class TransferTest method transferMultipleDeliveries.

@Test
@SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
public void transferMultipleDeliveries() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = 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);
        Flow flow = interaction.getLatestResponse(Flow.class);
        assumeThat("insufficient credit for the test", flow.getLinkCredit().intValue(), is(greaterThan(2)));
        interaction.transferDeliveryId(UnsignedInteger.ZERO).transferDeliveryTag(new Binary("A".getBytes(StandardCharsets.UTF_8))).transferPayloadData("test").transfer().transferDeliveryId(UnsignedInteger.ONE).transferDeliveryTag(new Binary("B".getBytes(StandardCharsets.UTF_8))).transferPayloadData("test").transfer().transferDeliveryId(UnsignedInteger.valueOf(2)).transferDeliveryTag(new Binary("C".getBytes(StandardCharsets.UTF_8))).transferPayloadData("test").transfer();
        TreeSet<UnsignedInteger> expectedDeliveryIds = Sets.newTreeSet(Arrays.asList(UnsignedInteger.ZERO, UnsignedInteger.ONE, UnsignedInteger.valueOf(2)));
        assertDeliveries(interaction, expectedDeliveryIds);
        // verify that no unexpected performative is received by closing
        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) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) 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)

Aggregations

Test (org.junit.Test)54 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)53 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)53 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)46 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)36 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)29 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)29 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)26 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)26 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)24 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)21 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)20 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)19 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)19 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)18 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)14 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)13 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)11 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)11 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)11