Search in sources :

Example 1 with ClientUnsupportedOperationException

use of org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException 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 2 with ClientUnsupportedOperationException

use of org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException in project qpid-protonj2 by apache.

the class ConnectionTest method doTestOpenAnonymousSenderFailsWhenAnonymousRelayNotAdvertisedByRemote.

private void doTestOpenAnonymousSenderFailsWhenAnonymousRelayNotAdvertisedByRemote(boolean openWait) 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());
        // Ensures that the Begin arrives regard of a race on open without anonymous relay support
        connection.defaultSession();
        if (openWait) {
            connection.openFuture().get();
        }
        try {
            connection.openAnonymousSender().openFuture().get();
            fail("Open of Sender should fail as remote did not advertise anonymous relay support: ");
        } catch (ClientUnsupportedOperationException ex) {
        } catch (ExecutionException ex) {
            assertTrue(ex.getCause() instanceof ClientUnsupportedOperationException);
        }
        connection.close();
        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) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) ClientUnsupportedOperationException(org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException)

Example 3 with ClientUnsupportedOperationException

use of org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException in project qpid-protonj2 by apache.

the class ConnectionTest method testCreateDefaultSenderFailsOnConnectionWithoutSupportForAnonymousRelay.

@Test
public void testCreateDefaultSenderFailsOnConnectionWithoutSupportForAnonymousRelay() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer(testServerOptions())) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectClose().respond();
        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(), connectionOptions()).openFuture().get();
        try {
            connection.defaultSender();
            fail("Should not be able to get the default sender when remote does not offer anonymous relay");
        } catch (ClientUnsupportedOperationException unsupported) {
            LOG.info("Caught expected error: ", unsupported);
        }
        connection.close();
        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) Test(org.junit.jupiter.api.Test)

Example 4 with ClientUnsupportedOperationException

use of org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException in project qpid-protonj2 by apache.

the class ConnectionTest method doTestConnectionLevelSendFailsWhenAnonymousRelayNotAdvertisedByRemote.

private void doTestConnectionLevelSendFailsWhenAnonymousRelayNotAdvertisedByRemote(boolean openWait) 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());
        // Ensures that the Begin arrives regard of a race on open without anonymous relay support
        connection.defaultSession();
        if (openWait) {
            connection.openFuture().get();
        }
        try {
            connection.send(Message.create("Hello World"));
            fail("Open of Sender should fail as remote did not advertise anonymous relay support: ");
        } catch (ClientUnsupportedOperationException ex) {
        }
        connection.close();
        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)

Example 5 with ClientUnsupportedOperationException

use of org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException in project qpid-protonj2 by apache.

the class StreamSenderTest method testCannotAssignAnOutputStreamToTheMessageBody.

@Test
public void testCannotAssignAnOutputStreamToTheMessageBody() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        // Hidden session for stream sender
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.remoteFlow().withLinkCredit(10).queue();
        peer.expectDetach().respond();
        peer.expectEnd().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()).openFuture().get();
        StreamSender sender = connection.openStreamSender("test-qos").openFuture().get();
        StreamSenderMessage message = sender.beginMessage();
        try {
            message.body(new ByteArrayOutputStream());
            fail("Should not be able assign an output stream to the message body");
        } catch (ClientUnsupportedOperationException ex) {
        // Expected
        }
        message.abort();
        assertThrows(ClientIllegalStateException.class, () -> message.complete());
        sender.closeAsync().get(10, TimeUnit.SECONDS);
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) Connection(org.apache.qpid.protonj2.client.Connection) StreamSender(org.apache.qpid.protonj2.client.StreamSender) StreamSenderMessage(org.apache.qpid.protonj2.client.StreamSenderMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) ClientUnsupportedOperationException(org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException) Test(org.junit.jupiter.api.Test)

Aggregations

URI (java.net.URI)6 Client (org.apache.qpid.protonj2.client.Client)6 Connection (org.apache.qpid.protonj2.client.Connection)6 ClientUnsupportedOperationException (org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException)6 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)6 Test (org.junit.jupiter.api.Test)4 Session (org.apache.qpid.protonj2.client.Session)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ExecutionException (java.util.concurrent.ExecutionException)1 Sender (org.apache.qpid.protonj2.client.Sender)1 StreamSender (org.apache.qpid.protonj2.client.StreamSender)1 StreamSenderMessage (org.apache.qpid.protonj2.client.StreamSenderMessage)1