Search in sources :

Example 26 with Session

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

the class SenderTest method doTestSentMessageGetsAutoSettledAfterRemoteSettles.

private void doTestSentMessageGetsAutoSettledAfterRemoteSettles(boolean trySend) throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.remoteFlow().withDeliveryCount(0).withLinkCredit(10).withIncomingWindow(1024).withOutgoingWindow(10).withNextIncomingId(0).withNextOutgoingId(1).queue();
        peer.expectAttach().ofReceiver().respond();
        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());
        connection.openFuture().get(10, TimeUnit.SECONDS);
        Session session = connection.openSession();
        Sender sender = session.openSender("test-queue");
        sender.openFuture().get(10, TimeUnit.SECONDS);
        // This ensures that the flow to sender is processed before we try-send
        Receiver receiver = session.openReceiver("test-queue", new ReceiverOptions().creditWindow(0));
        receiver.openFuture().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectTransfer().withNonNullPayload().respond().withSettled(true).withState().accepted();
        peer.expectDetach().respond();
        peer.expectClose().respond();
        Message<String> message = Message.create("Hello World");
        final Tracker tracker;
        if (trySend) {
            tracker = sender.trySend(message);
        } else {
            tracker = sender.send(message);
        }
        assertNotNull(tracker);
        assertNotNull(tracker.settlementFuture().get(5, TimeUnit.SECONDS));
        assertEquals(tracker.remoteState().getType(), DeliveryState.Type.ACCEPTED);
        sender.closeAsync();
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : Sender(org.apache.qpid.protonj2.client.Sender) Tracker(org.apache.qpid.protonj2.client.Tracker) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) Connection(org.apache.qpid.protonj2.client.Connection) Receiver(org.apache.qpid.protonj2.client.Receiver) ReceiverOptions(org.apache.qpid.protonj2.client.ReceiverOptions) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session)

Example 27 with Session

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

the class SenderTest method testTrySendWhenNoCreditAvailable.

@Test
public void testTrySendWhenNoCreditAvailable() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.expectDetach().respond();
        peer.expectClose().respond();
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Sender test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        ConnectionOptions options = new ConnectionOptions();
        options.sendTimeout(1);
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), options);
        Session session = connection.openSession();
        Sender sender = session.openSender("test-queue");
        sender.openFuture().get(10, TimeUnit.SECONDS);
        Message<String> message = Message.create("Hello World");
        assertNull(sender.trySend(message));
        sender.closeAsync().get(10, TimeUnit.SECONDS);
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : Sender(org.apache.qpid.protonj2.client.Sender) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) Connection(org.apache.qpid.protonj2.client.Connection) ConnectionOptions(org.apache.qpid.protonj2.client.ConnectionOptions) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 28 with Session

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

the class SenderTest method testCreateSenderWithDefaultSourceAndTargetOptions.

@Test
public void testCreateSenderWithDefaultSourceAndTargetOptions() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().withSource().withAddress(notNullValue()).withDistributionMode(nullValue()).withDefaultTimeout().withDurable(TerminusDurability.NONE).withExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH).withDefaultOutcome(nullValue()).withCapabilities(nullValue()).withFilter(nullValue()).withOutcomes("amqp:accepted:list", "amqp:rejected:list", "amqp:released:list", "amqp:modified:list").also().withTarget().withAddress("test-queue").withCapabilities(nullValue()).withDurable(nullValue()).withExpiryPolicy(nullValue()).withDefaultTimeout().withDynamic(anyOf(nullValue(), equalTo(false))).withDynamicNodeProperties(nullValue()).and().respond();
        peer.expectDetach().respond();
        peer.expectEnd().respond();
        peer.expectClose().respond();
        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());
        Session session = connection.openSession();
        Sender sender = session.openSender("test-queue").openFuture().get();
        sender.close();
        session.close();
        connection.close();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : Sender(org.apache.qpid.protonj2.client.Sender) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) Connection(org.apache.qpid.protonj2.client.Connection) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 29 with Session

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

the class SenderTest method doTestOpenSenderWaitFailsWhenConnectionDrops.

private void doTestOpenSenderWaitFailsWhenConnectionDrops(boolean timeout) throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender();
        peer.dropAfterLastHandler(10);
        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());
        Session session = connection.openSession();
        Sender sender = session.openSender("test-queue");
        Thread.sleep(10);
        try {
            if (timeout) {
                sender.openFuture().get(10, TimeUnit.SECONDS);
            } else {
                sender.openFuture().get();
            }
            fail("Should not complete the open future without an error");
        } catch (ExecutionException exe) {
            Throwable cause = exe.getCause();
            LOG.trace("Caught exception caused by: {}", exe);
            assertTrue(cause instanceof ClientConnectionRemotelyClosedException);
        }
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : Sender(org.apache.qpid.protonj2.client.Sender) 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)

Example 30 with Session

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

the class SenderTest method doTestCreateSenderAndCloseOrDetachWithErrorSync.

private void doTestCreateSenderAndCloseOrDetachWithErrorSync(boolean close) throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.expectDetach().withError("amqp-resource-deleted", "an error message").withClosed(close).respond();
        peer.expectClose().respond();
        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());
        connection.openFuture().get(10, TimeUnit.SECONDS);
        Session session = connection.openSession();
        session.openFuture().get(10, TimeUnit.SECONDS);
        Sender sender = session.openSender("test-queue");
        sender.openFuture().get(10, TimeUnit.SECONDS);
        if (close) {
            sender.close(ErrorCondition.create("amqp-resource-deleted", "an error message", null));
        } else {
            sender.detach(ErrorCondition.create("amqp-resource-deleted", "an error message", null));
        }
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : Sender(org.apache.qpid.protonj2.client.Sender) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) Connection(org.apache.qpid.protonj2.client.Connection) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session)

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