Search in sources :

Example 71 with Connection

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

the class SaslConnectionTest method testSaslExternalConnection.

@Test
public void testSaslExternalConnection() throws Exception {
    ProtonTestServerOptions serverOptions = serverOptions();
    serverOptions.setKeyStoreLocation(BROKER_JKS_KEYSTORE);
    serverOptions.setKeyStorePassword(PASSWORD);
    serverOptions.setVerifyHost(false);
    serverOptions.setTrustStoreLocation(BROKER_JKS_TRUSTSTORE);
    serverOptions.setTrustStorePassword(PASSWORD);
    serverOptions.setNeedClientAuth(true);
    serverOptions.setSecure(true);
    try (ProtonTestServer peer = new ProtonTestServer(serverOptions)) {
        peer.expectSaslExternalConnect();
        peer.expectOpen().respond();
        peer.expectClose().respond();
        peer.start();
        URI remoteURI = peer.getServerURI();
        ConnectionOptions clientOptions = connectionOptions();
        clientOptions.sslOptions().sslEnabled(true).keyStoreLocation(CLIENT_JKS_KEYSTORE).keyStorePassword(PASSWORD).trustStoreLocation(CLIENT_JKS_TRUSTSTORE).trustStorePassword(PASSWORD);
        Client container = Client.create();
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), clientOptions);
        connection.openFuture().get(10, TimeUnit.SECONDS);
        assertTrue(peer.hasSecureConnection());
        assertTrue(peer.isConnectionVerified());
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) ProtonTestServerOptions(org.apache.qpid.protonj2.test.driver.ProtonTestServerOptions) 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) Test(org.junit.jupiter.api.Test)

Example 72 with Connection

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

the class SenderTest method testRemotelyCloseSenderLinkWithRedirect.

@Test
public void testRemotelyCloseSenderLinkWithRedirect() throws Exception {
    final String redirectVhost = "vhost";
    final String redirectNetworkHost = "localhost";
    final String redirectAddress = "redirect-queue";
    final int redirectPort = 5677;
    final String redirectScheme = "wss";
    final String redirectPath = "/websockets";
    // Tell the test peer to close the connection when executing its last handler
    final Map<String, Object> errorInfo = new HashMap<>();
    errorInfo.put(ClientConstants.OPEN_HOSTNAME.toString(), redirectVhost);
    errorInfo.put(ClientConstants.NETWORK_HOST.toString(), redirectNetworkHost);
    errorInfo.put(ClientConstants.PORT.toString(), redirectPort);
    errorInfo.put(ClientConstants.SCHEME.toString(), redirectScheme);
    errorInfo.put(ClientConstants.PATH.toString(), redirectPath);
    errorInfo.put(ClientConstants.ADDRESS.toString(), redirectAddress);
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond().withNullTarget();
        peer.remoteDetach().withClosed(true).withErrorCondition(LinkError.REDIRECT.toString(), "Not accepting links here", errorInfo).queue();
        peer.expectDetach();
        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");
        try {
            sender.openFuture().get();
            fail("Should not be able to create sender since the remote is redirecting.");
        } catch (Exception ex) {
            LOG.debug("Received expected exception from sender open: {}", ex.getMessage());
            Throwable cause = ex.getCause();
            assertTrue(cause instanceof ClientLinkRedirectedException);
            ClientLinkRedirectedException linkRedirect = (ClientLinkRedirectedException) ex.getCause();
            assertEquals(redirectVhost, linkRedirect.getHostname());
            assertEquals(redirectNetworkHost, linkRedirect.getNetworkHost());
            assertEquals(redirectPort, linkRedirect.getPort());
            assertEquals(redirectScheme, linkRedirect.getScheme());
            assertEquals(redirectPath, linkRedirect.getPath());
            assertEquals(redirectAddress, linkRedirect.getAddress());
            URI redirect = linkRedirect.getRedirectionURI();
            assertEquals(redirectNetworkHost, redirect.getHost());
            assertEquals(redirectPort, redirect.getPort());
            assertEquals(redirectScheme, redirect.getScheme());
            assertEquals(redirectPath, redirect.getPath());
        }
        connection.close();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) HashMap(java.util.HashMap) Connection(org.apache.qpid.protonj2.client.Connection) URI(java.net.URI) ClientDeliveryStateException(org.apache.qpid.protonj2.client.exceptions.ClientDeliveryStateException) ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) ClientLinkRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRemotelyClosedException) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) ClientUnsupportedOperationException(org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) ClientSendTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientSendTimedOutException) ClientLinkRedirectedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRedirectedException) ExecutionException(java.util.concurrent.ExecutionException) Sender(org.apache.qpid.protonj2.client.Sender) ClientLinkRedirectedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRedirectedException) Client(org.apache.qpid.protonj2.client.Client) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 73 with Connection

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

the class SenderTest method testAutoFlushDuringWriteThatExceedConfiguredBufferLimitSessionCreditLimitOnTransfer.

@Test
void testAutoFlushDuringWriteThatExceedConfiguredBufferLimitSessionCreditLimitOnTransfer() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().withNextOutgoingId(0).respond();
        peer.expectAttach().ofSender().respond();
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        ConnectionOptions options = new ConnectionOptions().maxFrameSize(1024);
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), options);
        Sender sender = connection.openSender("test-queue");
        final byte[] payload = new byte[4800];
        Arrays.fill(payload, (byte) 1);
        final AtomicBoolean sendFailed = new AtomicBoolean();
        ForkJoinPool.commonPool().execute(() -> {
            try {
                sender.send(Message.create(payload));
            } catch (Exception e) {
                LOG.info("send failed with error: ", e);
                sendFailed.set(true);
            }
        });
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectTransfer().withNonNullPayload().withMore(true).withFrameSize(1024);
        peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(1).withLinkCredit(10).queue();
        peer.expectTransfer().withNonNullPayload().withMore(true).withFrameSize(1024);
        peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(2).withLinkCredit(10).queue();
        peer.expectTransfer().withNonNullPayload().withMore(true).withFrameSize(1024);
        peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(3).withLinkCredit(10).queue();
        peer.expectTransfer().withNonNullPayload().withMore(true).withFrameSize(1024);
        peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(4).withLinkCredit(10).queue();
        peer.expectTransfer().withNonNullPayload().withMore(false).accept();
        // Grant the credit to start meeting the above expectations
        peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(0).withLinkCredit(10).now();
        peer.waitForScriptToComplete(500, TimeUnit.SECONDS);
        peer.expectDetach().respond();
        peer.expectClose().respond();
        assertFalse(sendFailed.get());
        sender.closeAsync().get();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : Sender(org.apache.qpid.protonj2.client.Sender) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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) ClientDeliveryStateException(org.apache.qpid.protonj2.client.exceptions.ClientDeliveryStateException) ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) ClientLinkRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRemotelyClosedException) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) ClientUnsupportedOperationException(org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) ClientSendTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientSendTimedOutException) ClientLinkRedirectedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRedirectedException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 74 with Connection

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

the class SenderTest method testAutoFlushDuringWriteWithRollingIncomingWindowUpdates.

@Test
void testAutoFlushDuringWriteWithRollingIncomingWindowUpdates() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().withNextOutgoingId(0).respond();
        peer.expectAttach().ofSender().respond();
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        ConnectionOptions options = new ConnectionOptions().maxFrameSize(1024);
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), options);
        Sender sender = connection.openSender("test-queue");
        final byte[] payload = new byte[4800];
        Arrays.fill(payload, (byte) 1);
        final AtomicBoolean sendFailed = new AtomicBoolean();
        ForkJoinPool.commonPool().execute(() -> {
            try {
                sender.send(Message.create(payload));
            } catch (Exception e) {
                LOG.info("send failed with error: ", e);
                sendFailed.set(true);
            }
        });
        // Credit should will be refilling as transfers arrive vs being exhausted on each
        // incoming transfer and the send awaiting more credit.
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectTransfer().withNonNullPayload().withMore(true);
        peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(2).withLinkCredit(10).queue();
        peer.expectTransfer().withNonNullPayload().withMore(true);
        peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(3).withLinkCredit(10).queue();
        peer.expectTransfer().withNonNullPayload().withMore(true);
        peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(4).withLinkCredit(10).queue();
        peer.expectTransfer().withNonNullPayload().withMore(true);
        peer.expectTransfer().withNonNullPayload().withMore(false).accept();
        // Grant the credit to start meeting the above expectations
        peer.remoteFlow().withIncomingWindow(2).withNextIncomingId(0).withLinkCredit(10).now();
        peer.waitForScriptToComplete(500, TimeUnit.SECONDS);
        peer.expectDetach().respond();
        peer.expectClose().respond();
        assertFalse(sendFailed.get());
        sender.closeAsync().get();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : Sender(org.apache.qpid.protonj2.client.Sender) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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) ClientDeliveryStateException(org.apache.qpid.protonj2.client.exceptions.ClientDeliveryStateException) ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) ClientLinkRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRemotelyClosedException) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) ClientUnsupportedOperationException(org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) ClientSendTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientSendTimedOutException) ClientLinkRedirectedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRedirectedException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 75 with Connection

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

the class SenderTest method doTestCloseOrDetachWithErrorCondition.

public void doTestCloseOrDetachWithErrorCondition(boolean close) throws Exception {
    final String condition = "amqp:link:detach-forced";
    final String description = "something bad happened.";
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.expectDetach().withClosed(close).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();
        Sender sender = session.openSender("test-sender");
        sender.openFuture().get();
        if (close) {
            sender.closeAsync(ErrorCondition.create(condition, description, null));
        } else {
            sender.detachAsync(ErrorCondition.create(condition, description, null));
        }
        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) 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

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