Search in sources :

Example 81 with Interaction

use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.

the class TransferTest method receiveMultipleDeliveries.

@Test
@SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
public void receiveMultipleDeliveries() throws Exception {
    int numberOfMessages = 4;
    for (int i = 0; i < numberOfMessages; i++) {
        getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_DATA + "_" + i);
    }
    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).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.valueOf(numberOfMessages)).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.valueOf(numberOfMessages)).flowHandleFromLinkHandle().flow();
        for (int i = 0; i < numberOfMessages; i++) {
            interaction.receiveDelivery(Flow.class).decodeLatestDelivery();
            Object data = interaction.getDecodedLatestDelivery();
            assertThat(data, Is.is(CoreMatchers.equalTo(TEST_MESSAGE_DATA + "_" + i)));
            assertThat(interaction.getLatestDeliveryId(), Is.is(equalTo(UnsignedInteger.valueOf(i))));
        }
        interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionFirst(UnsignedInteger.ZERO).dispositionLast(interaction.getLatestDeliveryId()).dispositionState(new Accepted()).disposition();
        // make sure sure the disposition is handled by making drain request
        interaction.flowLinkCredit(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.valueOf(numberOfMessages)).flowDrain(Boolean.TRUE).flow().consumeResponse(Flow.class);
        if (getBrokerAdmin().isQueueDepthSupported()) {
            assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
        }
    }
    String messageText = TEST_MESSAGE_DATA + "_" + 4;
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageText);
    Object receivedMessage = Utils.receiveMessage(_brokerAddress, BrokerAdmin.TEST_QUEUE_NAME);
    assertThat(receivedMessage, is(equalTo(messageText)));
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) 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 82 with Interaction

use of org.apache.qpid.tests.protocol.v1_0.Interaction in project qpid-broker-j by apache.

the class TransferTest method exceedMaxMessageSizeLimit.

@Test
@SpecificationTest(section = "2.7.3", description = "max-message-size: This field indicates the maximum message size supported by the link" + " endpoint. Any attempt to deliver a message larger than this results in a" + " message-size-exceeded link-error. If this field is zero or unset, there is no maximum" + " size imposed by the link endpoint.")
public void exceedMaxMessageSizeLimit() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Binary deliveryTag = new Binary("testDeliveryTag".getBytes(UTF_8));
        Interaction interaction = transport.newInteraction();
        Open open = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).getLatestResponse(Open.class);
        long maxFrameSize = open.getMaxFrameSize() == null ? Integer.MAX_VALUE : open.getMaxFrameSize().longValue();
        Attach attach = interaction.begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).getLatestResponse(Attach.class);
        final UnsignedLong maxMessageSizeLimit = attach.getMaxMessageSize();
        assumeThat(maxMessageSizeLimit, is(notNullValue()));
        assumeThat(maxMessageSizeLimit.longValue(), is(both(greaterThan(0L)).and(lessThan(MAX_MAX_MESSAGE_SIZE_WE_ARE_WILLING_TO_TEST))));
        Flow flow = interaction.consumeResponse(Flow.class).getLatestResponse(Flow.class);
        assertThat(flow.getLinkCredit().intValue(), is(greaterThan(1)));
        final long chunkSize = Math.min(1024 * 1024, maxFrameSize - 100);
        byte[] payloadChunk = createTestPaload(chunkSize);
        interaction.transferDeliveryId(UnsignedInteger.ZERO).transferDeliveryTag(deliveryTag).transferPayloadData(payloadChunk).transferSettled(true).transferMore(true);
        int payloadSize = 0;
        while (payloadSize < maxMessageSizeLimit.longValue()) {
            payloadSize += chunkSize;
            interaction.transfer().sync();
        }
        while (true) {
            Response<?> response = interaction.consumeResponse(Flow.class, Disposition.class, Detach.class).getLatestResponse();
            if (response != null) {
                if (response.getBody() instanceof Detach) {
                    break;
                } else if (response.getBody() instanceof Disposition) {
                    assertThat(((Disposition) response.getBody()).getState(), is(instanceOf(Rejected.class)));
                    assertThat(((Rejected) ((Disposition) response.getBody()).getState()).getError(), is(notNullValue()));
                    assertThat(((Rejected) ((Disposition) response.getBody()).getState()).getError().getCondition(), is(equalTo(LinkError.MESSAGE_SIZE_EXCEEDED)));
                }
            }
        }
        Detach detach = interaction.getLatestResponse(Detach.class);
        assertThat(detach.getError(), is(notNullValue()));
        assertThat(detach.getError().getCondition(), is(equalTo(LinkError.MESSAGE_SIZE_EXCEEDED)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) UnsignedLong(org.apache.qpid.server.protocol.v1_0.type.UnsignedLong) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 83 with Interaction

use of org.apache.qpid.tests.protocol.v1_0.Interaction 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 84 with Interaction

use of org.apache.qpid.tests.protocol.v1_0.Interaction 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 85 with Interaction

use of org.apache.qpid.tests.protocol.v1_0.Interaction 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)

Aggregations

Test (org.junit.Test)112 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)101 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)100 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)91 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)53 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)48 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)33 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)31 InetSocketAddress (java.net.InetSocketAddress)28 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)28 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)28 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)28 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)24 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)16 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)13 Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)12 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)12 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)11 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)10 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)10