Search in sources :

Example 81 with Connection

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

the class SenderTest method testSendBlockedForCreditFailsWhenConnectionDrops.

@Test
public void testSendBlockedForCreditFailsWhenConnectionDrops() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.dropAfterLastHandler(25);
        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");
        sender.openFuture().get();
        Message<String> message = Message.create("Hello World");
        try {
            sender.send(message);
            fail("Send should have timed out.");
        } catch (ClientConnectionRemotelyClosedException cliEx) {
        // Expected send to throw indicating that the remote closed unexpectedly
        }
        connection.closeAsync().get();
        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) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 82 with Connection

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

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

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

use of com.swiftmq.amqp.v100.client.Connection 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)

Aggregations

Connection (org.apache.qpid.protonj2.client.Connection)368 Client (org.apache.qpid.protonj2.client.Client)367 URI (java.net.URI)354 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)352 Test (org.junit.jupiter.api.Test)250 Session (org.apache.qpid.protonj2.client.Session)166 ConnectionOptions (org.apache.qpid.protonj2.client.ConnectionOptions)112 Sender (org.apache.qpid.protonj2.client.Sender)89 Receiver (org.apache.qpid.protonj2.client.Receiver)79 ExecutionException (java.util.concurrent.ExecutionException)72 StreamReceiver (org.apache.qpid.protonj2.client.StreamReceiver)65 ClientException (org.apache.qpid.protonj2.client.exceptions.ClientException)60 StreamSender (org.apache.qpid.protonj2.client.StreamSender)49 StreamDelivery (org.apache.qpid.protonj2.client.StreamDelivery)46 TransferPayloadCompositeMatcher (org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher)44 Tracker (org.apache.qpid.protonj2.client.Tracker)41 StreamSenderMessage (org.apache.qpid.protonj2.client.StreamSenderMessage)38 ReceiverOptions (org.apache.qpid.protonj2.client.ReceiverOptions)34 SenderOptions (org.apache.qpid.protonj2.client.SenderOptions)33 OutputStream (java.io.OutputStream)31