Search in sources :

Example 1 with ClientOperationTimedOutException

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

the class ClientReceiver method drain.

@Override
public Future<Receiver> drain() throws ClientException {
    checkClosedOrFailed();
    final ClientFuture<Receiver> drainComplete = session.getFutureFactory().createFuture();
    executor.execute(() -> {
        if (notClosedOrFailed(drainComplete)) {
            if (protonReceiver.isDraining()) {
                drainComplete.failed(new ClientIllegalStateException("Receiver is already draining"));
                return;
            }
            try {
                if (protonReceiver.drain()) {
                    drainingFuture = drainComplete;
                    drainingTimeout = session.scheduleRequestTimeout(drainingFuture, options.drainTimeout(), () -> new ClientOperationTimedOutException("Timed out waiting for remote to respond to drain request"));
                } else {
                    drainComplete.complete(this);
                }
            } catch (Exception ex) {
                drainComplete.failed(ClientExceptionSupport.createNonFatalOrPassthrough(ex));
            }
        }
    });
    return drainComplete;
}
Also used : ClientIllegalStateException(org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException) Receiver(org.apache.qpid.protonj2.client.Receiver) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) ClientIllegalStateException(org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException) ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException)

Example 2 with ClientOperationTimedOutException

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

the class StreamReceiverTest method testDrainFutureSignalsFailureWhenDrainTimeoutExceeded.

@Test
public void testDrainFutureSignalsFailureWhenDrainTimeoutExceeded() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofReceiver().respond();
        peer.expectFlow();
        peer.expectFlow().withDrain(true);
        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());
        StreamReceiverOptions receiverOptions = new StreamReceiverOptions().drainTimeout(15);
        StreamReceiver receiver = connection.openStreamReceiver("test-queue", receiverOptions).openFuture().get();
        try {
            receiver.drain().get();
            fail("Drain call should fail timeout exceeded.");
        } catch (ExecutionException cliEx) {
            LOG.debug("Receiver threw error on drain call", cliEx);
            assertTrue(cliEx.getCause() instanceof ClientOperationTimedOutException);
        }
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) StreamReceiver(org.apache.qpid.protonj2.client.StreamReceiver) StreamReceiverOptions(org.apache.qpid.protonj2.client.StreamReceiverOptions) Connection(org.apache.qpid.protonj2.client.Connection) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) Client(org.apache.qpid.protonj2.client.Client) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 3 with ClientOperationTimedOutException

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

the class SenderTest method doTestCloseOrDetachSenderTimesOutWhenNoCloseResponseReceived.

private void doTestCloseOrDetachSenderTimesOutWhenNoCloseResponseReceived(boolean close, boolean timeout) throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.expectDetach();
        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.closeTimeout(10);
        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);
        try {
            if (close) {
                if (timeout) {
                    sender.closeAsync().get(10, TimeUnit.SECONDS);
                } else {
                    sender.closeAsync().get();
                }
            } else {
                if (timeout) {
                    sender.detachAsync().get(10, TimeUnit.SECONDS);
                } else {
                    sender.detachAsync().get();
                }
            }
            fail("Should not complete the close or detach future without an error");
        } catch (ExecutionException exe) {
            Throwable cause = exe.getCause();
            assertTrue(cause instanceof ClientOperationTimedOutException);
        }
        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) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) Client(org.apache.qpid.protonj2.client.Client) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session)

Example 4 with ClientOperationTimedOutException

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

the class StreamReceiverTest method testDrainFutureSignalsFailureWhenConnectionDrainTimeoutExceeded.

@Test
public void testDrainFutureSignalsFailureWhenConnectionDrainTimeoutExceeded() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofReceiver().respond();
        peer.expectFlow();
        peer.expectFlow().withDrain(true);
        peer.expectClose().respond();
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        ConnectionOptions connectionOptions = new ConnectionOptions().drainTimeout(20);
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), connectionOptions);
        StreamReceiver receiver = connection.openStreamReceiver("test-queue").openFuture().get();
        try {
            receiver.drain().get();
            fail("Drain call should fail timeout exceeded.");
        } catch (ExecutionException cliEx) {
            LOG.debug("Receiver threw error on drain call", cliEx);
            assertTrue(cliEx.getCause() instanceof ClientOperationTimedOutException);
        }
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) StreamReceiver(org.apache.qpid.protonj2.client.StreamReceiver) Connection(org.apache.qpid.protonj2.client.Connection) ConnectionOptions(org.apache.qpid.protonj2.client.ConnectionOptions) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) Client(org.apache.qpid.protonj2.client.Client) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 5 with ClientOperationTimedOutException

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

the class ReceiverTest method testDrainFutureSignalsFailureWhenConnectionDrainTimeoutExceeded.

@Test
public void testDrainFutureSignalsFailureWhenConnectionDrainTimeoutExceeded() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofReceiver().respond();
        peer.expectFlow();
        peer.expectFlow().withDrain(true);
        peer.expectClose().respond();
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        ConnectionOptions connectionOptions = new ConnectionOptions().drainTimeout(20);
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), connectionOptions);
        Session session = connection.openSession();
        Receiver receiver = session.openReceiver("test-queue").openFuture().get();
        try {
            receiver.drain().get();
            fail("Drain call should fail timeout exceeded.");
        } catch (ExecutionException cliEx) {
            LOG.debug("Receiver threw error on drain call", cliEx);
            assertTrue(cliEx.getCause() instanceof ClientOperationTimedOutException);
        }
        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) Receiver(org.apache.qpid.protonj2.client.Receiver) ConnectionOptions(org.apache.qpid.protonj2.client.ConnectionOptions) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) 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)

Aggregations

ClientOperationTimedOutException (org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException)12 URI (java.net.URI)9 ExecutionException (java.util.concurrent.ExecutionException)9 Client (org.apache.qpid.protonj2.client.Client)9 Connection (org.apache.qpid.protonj2.client.Connection)9 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)9 Session (org.apache.qpid.protonj2.client.Session)7 Receiver (org.apache.qpid.protonj2.client.Receiver)6 Test (org.junit.jupiter.api.Test)6 ConnectionOptions (org.apache.qpid.protonj2.client.ConnectionOptions)4 StreamReceiver (org.apache.qpid.protonj2.client.StreamReceiver)3 ReceiverOptions (org.apache.qpid.protonj2.client.ReceiverOptions)2 Sender (org.apache.qpid.protonj2.client.Sender)2 ClientException (org.apache.qpid.protonj2.client.exceptions.ClientException)2 ClientIllegalStateException (org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException)2 ClientResourceRemotelyClosedException (org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException)2 TimeoutException (java.util.concurrent.TimeoutException)1 SenderOptions (org.apache.qpid.protonj2.client.SenderOptions)1 SessionOptions (org.apache.qpid.protonj2.client.SessionOptions)1 StreamReceiverOptions (org.apache.qpid.protonj2.client.StreamReceiverOptions)1