Search in sources :

Example 36 with Session

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

the class SessionTest method tryReadSessionRemoteProperties.

private void tryReadSessionRemoteProperties(boolean beginResponse) throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin();
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Connect test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
        SessionOptions options = new SessionOptions().openTimeout(120, TimeUnit.MILLISECONDS);
        Session session = connection.openSession(options);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        Map<String, Object> expectedProperties = new HashMap<>();
        expectedProperties.put("TEST", "test-property");
        if (beginResponse) {
            peer.expectEnd().respond();
            peer.respondToLastBegin().withProperties(expectedProperties).later(10);
        } else {
            peer.expectEnd();
        }
        if (beginResponse) {
            assertNotNull(session.properties(), "Remote should have responded with a remote properties value");
            assertEquals(expectedProperties, session.properties());
        } else {
            try {
                session.properties();
                fail("Should failed to get remote state due to no begin response");
            } catch (ClientException ex) {
                LOG.debug("Caught expected exception from blocking call", ex);
            }
        }
        try {
            session.closeAsync().get();
        } catch (ExecutionException ex) {
            LOG.debug("Caught unexpected exception from close call", ex);
            fail("Should not fail to close when connection not closed and end was sent");
        }
        peer.expectClose().respond();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) HashMap(java.util.HashMap) SessionOptions(org.apache.qpid.protonj2.client.SessionOptions) Connection(org.apache.qpid.protonj2.client.Connection) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) Client(org.apache.qpid.protonj2.client.Client) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session)

Example 37 with Session

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

the class SessionTest method tryReadSessionRemoteOfferedCapabilities.

private void tryReadSessionRemoteOfferedCapabilities(boolean beginResponse) throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin();
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Connect test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
        connection.openFuture().get();
        SessionOptions options = new SessionOptions().openTimeout(125);
        Session session = connection.openSession(options);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        if (beginResponse) {
            peer.expectEnd().respond();
            peer.respondToLastBegin().withOfferedCapabilities("transactions").later(10);
        } else {
            peer.expectEnd();
        }
        if (beginResponse) {
            assertNotNull(session.offeredCapabilities(), "Remote should have responded with a remote offered Capabilities value");
            assertEquals(1, session.offeredCapabilities().length);
            assertEquals("transactions", session.offeredCapabilities()[0]);
        } else {
            try {
                session.offeredCapabilities();
                fail("Should failed to get remote state due to no begin response");
            } catch (ClientException ex) {
                LOG.debug("Caught expected exception from blocking call", ex);
            }
        }
        try {
            session.closeAsync().get();
        } catch (ExecutionException ex) {
            LOG.debug("Caught unexpected exception from close call", ex);
            fail("Should not fail to close when connection not closed and end was sent");
        }
        peer.expectClose().respond();
        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) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) Client(org.apache.qpid.protonj2.client.Client) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session)

Example 38 with Session

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

the class SessionTest method doTestSessionCloseGetsResponseWithErrorThrows.

protected void doTestSessionCloseGetsResponseWithErrorThrows(boolean timeout) throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectEnd().respond().withErrorCondition(AmqpError.INTERNAL_ERROR.toString(), "Something odd happened.");
        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();
        if (timeout) {
            // Should close normally and not throw error as we initiated the close.
            session.closeAsync().get(10, TimeUnit.SECONDS);
        } else {
            // Should close normally and not throw error as we initiated the close.
            session.closeAsync().get();
        }
        connection.closeAsync().get();
        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) Session(org.apache.qpid.protonj2.client.Session)

Example 39 with Session

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

the class SessionTest method tryReadSessionRemoteDesiredCapabilities.

private void tryReadSessionRemoteDesiredCapabilities(boolean beginResponse) throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin();
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Connect test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
        SessionOptions options = new SessionOptions().openTimeout(125);
        Session session = connection.openSession(options);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        if (beginResponse) {
            peer.expectEnd().respond();
            peer.respondToLastBegin().withDesiredCapabilities("Error-Free").later(10);
        } else {
            peer.expectEnd();
        }
        if (beginResponse) {
            assertNotNull(session.desiredCapabilities(), "Remote should have responded with a remote desired Capabilities value");
            assertEquals(1, session.desiredCapabilities().length);
            assertEquals("Error-Free", session.desiredCapabilities()[0]);
        } else {
            try {
                session.desiredCapabilities();
                fail("Should failed to get remote state due to no begin response");
            } catch (ClientException ex) {
                LOG.debug("Caught expected exception from blocking call", ex);
            }
        }
        try {
            session.closeAsync().get();
        } catch (ExecutionException ex) {
            LOG.debug("Caught unexpected exception from close call", ex);
            fail("Should not fail to close when connection not closed and end sent");
        }
        peer.expectClose().respond();
        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) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) Client(org.apache.qpid.protonj2.client.Client) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session)

Example 40 with Session

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

the class SessionTest method doTestCloseWithErrorCondition.

private void doTestCloseWithErrorCondition(boolean sync) throws Exception {
    final String condition = "amqp:precondition-failed";
    final String description = "something bad happened.";
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectEnd().withError(condition, description).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();
        session.openFuture().get();
        assertEquals(session.client(), container);
        if (sync) {
            session.close(ErrorCondition.create(condition, description, null));
        } else {
            session.closeAsync(ErrorCondition.create(condition, description, null));
        }
        connection.closeAsync().get();
        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) 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