Search in sources :

Example 76 with Session

use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.

the class MessageSendTest method testSendMessageWithDeliveryAnnotationsPopulated.

@Test
public void testSendMessageWithDeliveryAnnotationsPopulated() 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();
        DeliveryAnnotationsMatcher daMatcher = new DeliveryAnnotationsMatcher(true);
        daMatcher.withEntry("one", Matchers.equalTo(1));
        daMatcher.withEntry("two", Matchers.equalTo(2));
        daMatcher.withEntry("three", Matchers.equalTo(3));
        EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher("Hello World");
        TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
        payloadMatcher.setDeliveryAnnotationsMatcher(daMatcher);
        payloadMatcher.setMessageContentMatcher(bodyMatcher);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectTransfer().withPayload(payloadMatcher).accept();
        peer.expectDetach().respond();
        peer.expectClose().respond();
        final Message<String> message = Message.create("Hello World");
        // Populate delivery annotations
        Map<String, Object> deliveryAnnotations = new HashMap<>();
        deliveryAnnotations.put("one", 1);
        deliveryAnnotations.put("two", 2);
        deliveryAnnotations.put("three", 3);
        final Tracker tracker = sender.send(message, deliveryAnnotations);
        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) DeliveryAnnotationsMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.DeliveryAnnotationsMatcher) HashMap(java.util.HashMap) Connection(org.apache.qpid.protonj2.client.Connection) EncodedAmqpValueMatcher(org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher) TransferPayloadCompositeMatcher(org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher) URI(java.net.URI) Sender(org.apache.qpid.protonj2.client.Sender) Client(org.apache.qpid.protonj2.client.Client) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 77 with Session

use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.

the class MessageSendTest method testSendMessageWithPropertiesValuesPopulated.

@Test
public void testSendMessageWithPropertiesValuesPopulated() 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();
        PropertiesMatcher propertiesMatcher = new PropertiesMatcher(true);
        propertiesMatcher.withMessageId("ID:12345");
        propertiesMatcher.withUserId("user".getBytes(StandardCharsets.UTF_8));
        propertiesMatcher.withTo("the-management");
        propertiesMatcher.withSubject("amqp");
        propertiesMatcher.withReplyTo("the-minions");
        propertiesMatcher.withCorrelationId("abc");
        propertiesMatcher.withContentEncoding("application/json");
        propertiesMatcher.withContentEncoding("gzip");
        propertiesMatcher.withAbsoluteExpiryTime(123);
        propertiesMatcher.withCreationTime(1);
        propertiesMatcher.withGroupId("disgruntled");
        propertiesMatcher.withGroupSequence(8192);
        propertiesMatcher.withReplyToGroupId("/dev/null");
        EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher("Hello World");
        TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
        payloadMatcher.setPropertiesMatcher(propertiesMatcher);
        payloadMatcher.setMessageContentMatcher(bodyMatcher);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectTransfer().withPayload(payloadMatcher).accept();
        peer.expectDetach().respond();
        peer.expectClose().respond();
        final Message<String> message = Message.create("Hello World");
        // Populate all Properties values
        message.messageId("ID:12345");
        message.userId("user".getBytes(StandardCharsets.UTF_8));
        message.to("the-management");
        message.subject("amqp");
        message.replyTo("the-minions");
        message.correlationId("abc");
        message.contentEncoding("application/json");
        message.contentEncoding("gzip");
        message.absoluteExpiryTime(123);
        message.creationTime(1);
        message.groupId("disgruntled");
        message.groupSequence(8192);
        message.replyToGroupId("/dev/null");
        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) EncodedAmqpValueMatcher(org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher) TransferPayloadCompositeMatcher(org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher) URI(java.net.URI) Sender(org.apache.qpid.protonj2.client.Sender) Client(org.apache.qpid.protonj2.client.Client) PropertiesMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.PropertiesMatcher) ApplicationPropertiesMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.ApplicationPropertiesMatcher) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 78 with Session

use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.

the class MessageSendTest method testSendMessageWithMessageAnnotationsPopulated.

@Test
public void testSendMessageWithMessageAnnotationsPopulated() 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();
        MessageAnnotationsMatcher maMatcher = new MessageAnnotationsMatcher(true);
        maMatcher.withEntry("one", Matchers.equalTo(1));
        maMatcher.withEntry("two", Matchers.equalTo(2));
        maMatcher.withEntry("three", Matchers.equalTo(3));
        EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher("Hello World");
        TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
        payloadMatcher.setMessageAnnotationsMatcher(maMatcher);
        payloadMatcher.setMessageContentMatcher(bodyMatcher);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectTransfer().withPayload(payloadMatcher).accept();
        peer.expectDetach().respond();
        peer.expectClose().respond();
        final Message<String> message = Message.create("Hello World");
        // Populate message annotations
        message.annotation("one", 1);
        message.annotation("two", 2);
        message.annotation("three", 3);
        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) MessageAnnotationsMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.MessageAnnotationsMatcher) Connection(org.apache.qpid.protonj2.client.Connection) EncodedAmqpValueMatcher(org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher) TransferPayloadCompositeMatcher(org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher) URI(java.net.URI) Sender(org.apache.qpid.protonj2.client.Sender) Client(org.apache.qpid.protonj2.client.Client) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 79 with Session

use of com.swiftmq.amqp.v100.client.Session 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 80 with Session

use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.

the class ConnectionTest method testRemotelyCloseConnectionDuringSessionCreation.

@Test
public void testRemotelyCloseConnectionDuringSessionCreation() throws Exception {
    final String BREAD_CRUMB = "ErrorMessageBreadCrumb";
    try (ProtonTestServer peer = new ProtonTestServer(testServerOptions())) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin();
        peer.remoteClose().withErrorCondition(AmqpError.NOT_ALLOWED.toString(), BREAD_CRUMB).queue();
        peer.expectClose();
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), connectionOptions());
        connection.openFuture().get();
        Session session = connection.openSession();
        try {
            session.openFuture().get();
            fail("Open should throw error when waiting for remote open and connection remotely closed.");
        } catch (ExecutionException error) {
            LOG.info("Session open failed with error: ", error);
            assertNotNull(error.getMessage(), "Expected exception to have a message");
            assertTrue(error.getMessage().contains(BREAD_CRUMB), "Expected breadcrumb to be present in message");
            assertNotNull(error.getCause(), "Execution error should convey the cause");
            assertTrue(error.getCause() instanceof ClientConnectionRemotelyClosedException);
        }
        session.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) Connection(org.apache.qpid.protonj2.client.Connection) Client(org.apache.qpid.protonj2.client.Client) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Aggregations

Session (org.apache.qpid.protonj2.client.Session)167 Client (org.apache.qpid.protonj2.client.Client)165 Connection (org.apache.qpid.protonj2.client.Connection)165 URI (java.net.URI)163 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)163 Test (org.junit.jupiter.api.Test)109 Sender (org.apache.qpid.protonj2.client.Sender)66 Receiver (org.apache.qpid.protonj2.client.Receiver)64 ExecutionException (java.util.concurrent.ExecutionException)35 ConnectionOptions (org.apache.qpid.protonj2.client.ConnectionOptions)35 Tracker (org.apache.qpid.protonj2.client.Tracker)32 ClientException (org.apache.qpid.protonj2.client.exceptions.ClientException)29 SenderOptions (org.apache.qpid.protonj2.client.SenderOptions)28 ReceiverOptions (org.apache.qpid.protonj2.client.ReceiverOptions)25 TransferPayloadCompositeMatcher (org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher)20 ClientConnectionRemotelyClosedException (org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException)18 HashMap (java.util.HashMap)17 ClientIllegalStateException (org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException)16 EncodedAmqpValueMatcher (org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher)14 Delivery (org.apache.qpid.protonj2.client.Delivery)13