Search in sources :

Example 31 with Session

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

the class SenderTest method testCreateAnonymousSenderWhenRemoteDoesNotOfferSupportForIt.

@Test
public void testCreateAnonymousSenderWhenRemoteDoesNotOfferSupportForIt() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().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().openFuture().get();
        try {
            session.openAnonymousSender();
            fail("Should not be able to open an anonymous sender when remote does not offer anonymous relay");
        } catch (ClientUnsupportedOperationException unsupported) {
            LOG.info("Caught expected error: ", unsupported);
        }
        connection.closeAsync();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : 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) ClientUnsupportedOperationException(org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 32 with Session

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

the class SenderTest method testSendBlockedForCreditFailsWhenLinkRemotelyClosed.

@Test
public void testSendBlockedForCreditFailsWhenLinkRemotelyClosed() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.remoteDetach().withErrorCondition(AmqpError.RESOURCE_DELETED.toString(), "Link was deleted").afterDelay(25).queue();
        peer.expectDetach();
        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());
        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 (ClientResourceRemotelyClosedException cliEx) {
        // Expected send to throw indicating that the remote closed the link
        }
        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) ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) 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 33 with Session

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

the class SenderTest method testAwaitSettlementFailedOnConnectionDropped.

@Test
public void testAwaitSettlementFailedOnConnectionDropped() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().withTarget().withAddress("test").and().respond();
        peer.remoteFlow().withLinkCredit(1).queue();
        peer.expectTransfer();
        peer.dropAfterLastHandler(30);
        peer.start();
        URI remoteURI = peer.getServerURI();
        Message<String> message = Message.create("test-message");
        Client container = Client.create();
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
        Session session = connection.openSession();
        Sender sender = session.openSender("test");
        Tracker tracker = null;
        try {
            tracker = sender.send(message);
        } catch (ClientConnectionRemotelyClosedException cliEx) {
            fail("Send should not fail with remotely closed error after remote drops");
        }
        // the drop completes waiting callers.
        try {
            tracker.awaitSettlement();
            fail("Wait for settlement should fail with remotely closed error after remote drops");
        } catch (ClientConnectionRemotelyClosedException cliRCEx) {
        }
        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) 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 34 with Session

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

the class SenderTest method testSenderOpenRejectedByRemote.

@Test
public void testSenderOpenRejectedByRemote() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().respond().withNullTarget();
        peer.remoteDetach().withErrorCondition(AmqpError.UNAUTHORIZED_ACCESS.toString(), "Cannot read from this address").queue();
        peer.expectDetach();
        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");
        try {
            sender.openFuture().get(10, TimeUnit.SECONDS);
            fail("Open of sender should fail due to remote indicating pending close.");
        } catch (ExecutionException exe) {
            assertNotNull(exe.getCause());
            assertTrue(exe.getCause() instanceof ClientLinkRemotelyClosedException);
            ClientLinkRemotelyClosedException linkClosed = (ClientLinkRemotelyClosedException) exe.getCause();
            assertNotNull(linkClosed.getErrorCondition());
            assertEquals(AmqpError.UNAUTHORIZED_ACCESS.toString(), linkClosed.getErrorCondition().condition());
        }
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        // Should not result in any close being sent now, already closed.
        sender.closeAsync().get(10, TimeUnit.SECONDS);
        peer.expectClose().respond();
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(1, TimeUnit.SECONDS);
    }
}
Also used : Sender(org.apache.qpid.protonj2.client.Sender) ClientLinkRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRemotelyClosedException) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) 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)

Example 35 with Session

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

the class SessionTest method doTestSessionCloseTimeoutWhenNoRemoteEndArrives.

private void doTestSessionCloseTimeoutWhenNoRemoteEndArrives(boolean timeout) throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectEnd();
        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());
        SessionOptions options = new SessionOptions();
        options.closeTimeout(75);
        Session session = connection.openSession(options).openFuture().get();
        try {
            if (timeout) {
                session.closeAsync().get(10, TimeUnit.SECONDS);
            } else {
                session.closeAsync().get();
            }
            fail("Close should throw an error if the Session end doesn't arrive in time");
        } catch (Throwable error) {
            LOG.info("Session close failed with error: ", error);
        }
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) SessionOptions(org.apache.qpid.protonj2.client.SessionOptions) 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