use of java.util.concurrent.CompletionException in project kafka by apache.
the class KafkaFutureTest method testThenApplyOnFailedFutureTricky2.
@Test
public void testThenApplyOnFailedFutureTricky2() {
KafkaFutureImpl<Integer> future = new KafkaFutureImpl<>();
KafkaFuture<Integer> dependantFuture = future.thenApply(integer -> 2 * integer);
future.completeExceptionally(new CompletionException(new CancellationException()));
assertIsFailed(future);
assertIsFailed(dependantFuture);
awaitAndAssertFailure(future, CompletionException.class, "java.util.concurrent.CancellationException");
awaitAndAssertFailure(dependantFuture, CompletionException.class, "java.util.concurrent.CancellationException");
}
use of java.util.concurrent.CompletionException in project kafka by apache.
the class KafkaFutureTest method testToString.
@Test
public void testToString() {
KafkaFutureImpl<Integer> success = new KafkaFutureImpl<>();
assertEquals("KafkaFuture{value=null,exception=null,done=false}", success.toString());
success.complete(12);
assertEquals("KafkaFuture{value=12,exception=null,done=true}", success.toString());
KafkaFutureImpl<Integer> failure = new KafkaFutureImpl<>();
failure.completeExceptionally(new RuntimeException("foo"));
assertEquals("KafkaFuture{value=null,exception=java.lang.RuntimeException: foo,done=true}", failure.toString());
KafkaFutureImpl<Integer> tricky1 = new KafkaFutureImpl<>();
tricky1.completeExceptionally(new CompletionException(new CancellationException()));
assertEquals("KafkaFuture{value=null,exception=java.util.concurrent.CompletionException: java.util.concurrent.CancellationException,done=true}", tricky1.toString());
KafkaFutureImpl<Integer> cancelled = new KafkaFutureImpl<>();
cancelled.cancel(true);
assertEquals("KafkaFuture{value=null,exception=java.util.concurrent.CancellationException,done=true}", cancelled.toString());
}
use of java.util.concurrent.CompletionException in project kafka by apache.
the class ApiError method fromThrowable.
public static ApiError fromThrowable(Throwable t) {
Throwable throwableToBeEncoded = t;
// completion stage (as might be the case for requests sent to the controller in `ControllerApis`)
if (t instanceof CompletionException || t instanceof ExecutionException) {
throwableToBeEncoded = t.getCause();
}
// Avoid populating the error message if it's a generic one. Also don't populate error
// message for UNKNOWN_SERVER_ERROR to ensure we don't leak sensitive information.
Errors error = Errors.forException(throwableToBeEncoded);
String message = error == Errors.UNKNOWN_SERVER_ERROR || error.message().equals(throwableToBeEncoded.getMessage()) ? null : throwableToBeEncoded.getMessage();
return new ApiError(error, message);
}
use of java.util.concurrent.CompletionException in project flink by apache.
the class StreamTask method cancel.
@Override
public final void cancel() throws Exception {
isRunning = false;
canceled = true;
FlinkSecurityManager.monitorUserSystemExitForCurrentThread();
// closed no matter what
try {
cancelTask();
} finally {
FlinkSecurityManager.unmonitorUserSystemExitForCurrentThread();
getCompletionFuture().whenComplete((unusedResult, unusedError) -> {
// WARN: the method is called from the task thread but the callback
// can be invoked from a different thread
mailboxProcessor.allActionsCompleted();
try {
cancelables.close();
} catch (IOException e) {
throw new CompletionException(e);
}
});
}
}
use of java.util.concurrent.CompletionException in project webpieces by deanhiller.
the class SneakyThrowTest method testSneakCompletionException.
@Test
public void testSneakCompletionException() {
Assert.assertThrows(RuntimeException.class, () -> {
RuntimeException expected = new RuntimeException("expected");
CompletionException ex1 = new CompletionException("ex1", expected);
throw SneakyThrow.sneak(ex1);
});
}
Aggregations