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;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations