Search in sources :

Example 1 with EncodedAmqpSequenceMatcher

use of org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpSequenceMatcher in project qpid-protonj2 by apache.

the class MessageSendTest method testSendMessageWithMultipleAmqpSequenceSections.

@Test
public void testSendMessageWithMultipleAmqpSequenceSections() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.remoteFlow().withLinkCredit(10).queue();
        // Open a receiver to ensure sender link has processed
        peer.expectAttach().respond();
        // the inbound flow frame we sent previously before send.
        peer.expectFlow();
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Sender test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort()).openFuture().get();
        Session session = connection.openSession().openFuture().get();
        SenderOptions options = new SenderOptions().deliveryMode(DeliveryMode.AT_MOST_ONCE);
        Sender sender = session.openSender("test-qos", options);
        // Gates send on remote flow having been sent and received
        session.openReceiver("dummy").openFuture().get();
        List<String> list1 = new ArrayList<>();
        list1.add("1");
        List<String> list2 = new ArrayList<>();
        list2.add("21");
        list2.add("22");
        List<String> list3 = new ArrayList<>();
        list3.add("31");
        list3.add("32");
        list3.add("33");
        EncodedAmqpSequenceMatcher bodyMatcher1 = new EncodedAmqpSequenceMatcher(list1, true);
        EncodedAmqpSequenceMatcher bodyMatcher2 = new EncodedAmqpSequenceMatcher(list2, true);
        EncodedAmqpSequenceMatcher bodyMatcher3 = new EncodedAmqpSequenceMatcher(list3, false);
        TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
        payloadMatcher.addMessageContentMatcher(bodyMatcher1);
        payloadMatcher.addMessageContentMatcher(bodyMatcher2);
        payloadMatcher.addMessageContentMatcher(bodyMatcher3);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectTransfer().withPayload(payloadMatcher).accept();
        peer.expectDetach().respond();
        peer.expectClose().respond();
        final AdvancedMessage<List<String>> message = AdvancedMessage.create();
        message.addBodySection(new AmqpSequence<>(list1));
        message.addBodySection(new AmqpSequence<>(list2));
        message.addBodySection(new AmqpSequence<>(list3));
        final Tracker tracker = sender.send(message);
        assertNotNull(tracker);
        assertNotNull(tracker.settlementFuture().isDone());
        assertNotNull(tracker.settlementFuture().get().settled());
        sender.closeAsync().get(10, TimeUnit.SECONDS);
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : Tracker(org.apache.qpid.protonj2.client.Tracker) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) SenderOptions(org.apache.qpid.protonj2.client.SenderOptions) Connection(org.apache.qpid.protonj2.client.Connection) ArrayList(java.util.ArrayList) TransferPayloadCompositeMatcher(org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher) URI(java.net.URI) Sender(org.apache.qpid.protonj2.client.Sender) EncodedAmqpSequenceMatcher(org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpSequenceMatcher) ArrayList(java.util.ArrayList) List(java.util.List) Client(org.apache.qpid.protonj2.client.Client) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 2 with EncodedAmqpSequenceMatcher

use of org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpSequenceMatcher in project qpid-protonj2 by apache.

the class MessageSendTest method doTestSendMessageWithListPayloadArrivesWithAMQPSequenceBody.

private void doTestSendMessageWithListPayloadArrivesWithAMQPSequenceBody(boolean useSetter) throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.remoteFlow().withLinkCredit(10).queue();
        // Open a receiver to ensure sender link has processed
        peer.expectAttach().respond();
        // the inbound flow frame we sent previously before send.
        peer.expectFlow();
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Sender test started, peer listening on: {}", remoteURI);
        final List<UUID> payload = new ArrayList<>();
        payload.add(UUID.randomUUID());
        payload.add(UUID.randomUUID());
        payload.add(UUID.randomUUID());
        Client container = Client.create();
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort()).openFuture().get();
        Session session = connection.openSession().openFuture().get();
        SenderOptions options = new SenderOptions().deliveryMode(DeliveryMode.AT_MOST_ONCE);
        Sender sender = session.openSender("test-qos", options);
        // Gates send on remote flow having been sent and received
        session.openReceiver("dummy").openFuture().get();
        EncodedAmqpSequenceMatcher bodyMatcher = new EncodedAmqpSequenceMatcher(payload);
        TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
        payloadMatcher.setMessageContentMatcher(bodyMatcher);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectTransfer().withPayload(payloadMatcher).accept();
        peer.expectDetach().respond();
        peer.expectClose().respond();
        final Message<List<UUID>> message;
        if (useSetter) {
            message = Message.<List<UUID>>create().body(payload);
        } else {
            message = Message.create(payload);
        }
        final Tracker tracker = sender.send(message);
        assertNotNull(tracker);
        assertNotNull(tracker.settlementFuture().isDone());
        assertNotNull(tracker.settlementFuture().get().settled());
        sender.closeAsync().get(10, TimeUnit.SECONDS);
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : Tracker(org.apache.qpid.protonj2.client.Tracker) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) SenderOptions(org.apache.qpid.protonj2.client.SenderOptions) ArrayList(java.util.ArrayList) Connection(org.apache.qpid.protonj2.client.Connection) TransferPayloadCompositeMatcher(org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher) URI(java.net.URI) Sender(org.apache.qpid.protonj2.client.Sender) EncodedAmqpSequenceMatcher(org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpSequenceMatcher) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) Client(org.apache.qpid.protonj2.client.Client) Session(org.apache.qpid.protonj2.client.Session)

Aggregations

URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Client (org.apache.qpid.protonj2.client.Client)2 Connection (org.apache.qpid.protonj2.client.Connection)2 Sender (org.apache.qpid.protonj2.client.Sender)2 SenderOptions (org.apache.qpid.protonj2.client.SenderOptions)2 Session (org.apache.qpid.protonj2.client.Session)2 Tracker (org.apache.qpid.protonj2.client.Tracker)2 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)2 TransferPayloadCompositeMatcher (org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher)2 EncodedAmqpSequenceMatcher (org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpSequenceMatcher)2 UUID (java.util.UUID)1 Test (org.junit.jupiter.api.Test)1