use of org.apache.flink.util.FlinkException in project flink by apache.
the class FutureUtilsTest method testHandleUncaughtExceptionWithExceptionallyCompletedFuture.
@Test
public void testHandleUncaughtExceptionWithExceptionallyCompletedFuture() {
final CompletableFuture<String> future = FutureUtils.completedExceptionally(new FlinkException("foobar"));
final TestingUncaughtExceptionHandler uncaughtExceptionHandler = new TestingUncaughtExceptionHandler();
FutureUtils.handleUncaughtException(future, uncaughtExceptionHandler);
assertThat(uncaughtExceptionHandler.hasBeenCalled(), is(true));
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class FutureUtilsTest method testCompleteAllExceptional.
@Test
public void testCompleteAllExceptional() throws Exception {
final CompletableFuture<String> inputFuture1 = new CompletableFuture<>();
final CompletableFuture<Integer> inputFuture2 = new CompletableFuture<>();
final List<CompletableFuture<?>> futuresToComplete = Arrays.asList(inputFuture1, inputFuture2);
final FutureUtils.ConjunctFuture<Void> completeFuture = FutureUtils.completeAll(futuresToComplete);
assertThat(completeFuture.isDone(), is(false));
assertThat(completeFuture.getNumFuturesCompleted(), is(0));
assertThat(completeFuture.getNumFuturesTotal(), is(futuresToComplete.size()));
final FlinkException testException1 = new FlinkException("Test exception 1");
inputFuture1.completeExceptionally(testException1);
assertThat(completeFuture.isDone(), is(false));
assertThat(completeFuture.getNumFuturesCompleted(), is(1));
final FlinkException testException2 = new FlinkException("Test exception 2");
inputFuture2.completeExceptionally(testException2);
assertThat(completeFuture.isDone(), is(true));
assertThat(completeFuture.getNumFuturesCompleted(), is(2));
try {
completeFuture.get();
fail("Expected an exceptional completion");
} catch (ExecutionException ee) {
final Throwable actual = ExceptionUtils.stripExecutionException(ee);
final Throwable[] suppressed = actual.getSuppressed();
final FlinkException suppressedException;
if (actual.equals(testException1)) {
suppressedException = testException2;
} else {
suppressedException = testException1;
}
assertThat(suppressed, is(not(emptyArray())));
assertThat(suppressed, arrayContaining(suppressedException));
}
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class FutureUtilsTest method testSupplyAsyncFailure.
@Test
public void testSupplyAsyncFailure() throws Exception {
final String exceptionMessage = "Test exception";
final FlinkException testException = new FlinkException(exceptionMessage);
final CompletableFuture<Object> future = FutureUtils.supplyAsync(() -> {
throw testException;
}, TestingUtils.defaultExecutor());
try {
future.get();
fail("Expected an exception.");
} catch (ExecutionException e) {
assertThat(ExceptionUtils.findThrowableWithMessage(e, exceptionMessage).isPresent(), is(true));
}
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class FutureUtilsTest method testCompleteAllPartialExceptional.
@Test
public void testCompleteAllPartialExceptional() throws Exception {
final CompletableFuture<String> inputFuture1 = new CompletableFuture<>();
final CompletableFuture<Integer> inputFuture2 = new CompletableFuture<>();
final List<CompletableFuture<?>> futuresToComplete = Arrays.asList(inputFuture1, inputFuture2);
final FutureUtils.ConjunctFuture<Void> completeFuture = FutureUtils.completeAll(futuresToComplete);
assertThat(completeFuture.isDone(), is(false));
assertThat(completeFuture.getNumFuturesCompleted(), is(0));
assertThat(completeFuture.getNumFuturesTotal(), is(futuresToComplete.size()));
final FlinkException testException1 = new FlinkException("Test exception 1");
inputFuture2.completeExceptionally(testException1);
assertThat(completeFuture.isDone(), is(false));
assertThat(completeFuture.getNumFuturesCompleted(), is(1));
inputFuture1.complete("foobar");
assertThat(completeFuture.isDone(), is(true));
assertThat(completeFuture.getNumFuturesCompleted(), is(2));
try {
completeFuture.get();
fail("Expected an exceptional completion");
} catch (ExecutionException ee) {
assertThat(ExceptionUtils.stripExecutionException(ee), is(testException1));
}
}
use of org.apache.flink.util.FlinkException in project flink by apache.
the class FutureUtilsTest method testRunAfterwardsExceptional.
@Test
public void testRunAfterwardsExceptional() throws Exception {
final CompletableFuture<Void> inputFuture = new CompletableFuture<>();
final OneShotLatch runnableLatch = new OneShotLatch();
final FlinkException testException = new FlinkException("Test exception");
final CompletableFuture<Void> runFuture = FutureUtils.runAfterwards(inputFuture, runnableLatch::trigger);
assertThat(runnableLatch.isTriggered(), is(false));
assertThat(runFuture.isDone(), is(false));
inputFuture.completeExceptionally(testException);
assertThat(runnableLatch.isTriggered(), is(true));
assertThat(runFuture.isDone(), is(true));
try {
runFuture.get();
fail("Expected an exceptional completion");
} catch (ExecutionException ee) {
assertThat(ExceptionUtils.stripExecutionException(ee), is(testException));
}
}
Aggregations