Search in sources :

Example 1 with MessageDecoder

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

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

Aggregations

Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)2 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)2 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)2 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)2 MessageDecoder (org.apache.qpid.tests.protocol.v1_0.MessageDecoder)2 Test (org.junit.Test)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)1 Received (org.apache.qpid.server.protocol.v1_0.type.messaging.Received)1 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)1 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)1