Search in sources :

Example 61 with CompletionException

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");
}
Also used : CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) Test(org.junit.jupiter.api.Test)

Example 62 with CompletionException

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());
}
Also used : CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) Test(org.junit.jupiter.api.Test)

Example 63 with CompletionException

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);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) CompletionException(java.util.concurrent.CompletionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 64 with CompletionException

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);
            }
        });
    }
}
Also used : CompletionException(java.util.concurrent.CompletionException) IOException(java.io.IOException)

Example 65 with CompletionException

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);
    });
}
Also used : CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test)

Aggregations

CompletionException (java.util.concurrent.CompletionException)199 Test (org.junit.Test)80 CompletableFuture (java.util.concurrent.CompletableFuture)62 List (java.util.List)52 ArrayList (java.util.ArrayList)51 IOException (java.io.IOException)45 Map (java.util.Map)39 Collection (java.util.Collection)31 ExecutionException (java.util.concurrent.ExecutionException)31 HashMap (java.util.HashMap)30 Collections (java.util.Collections)24 TimeUnit (java.util.concurrent.TimeUnit)22 Collectors (java.util.stream.Collectors)22 FlinkException (org.apache.flink.util.FlinkException)22 Before (org.junit.Before)21 Duration (java.time.Duration)19 Arrays (java.util.Arrays)19 BeforeClass (org.junit.BeforeClass)19 ExecutorService (java.util.concurrent.ExecutorService)18 Nonnull (javax.annotation.Nonnull)17