Search in sources :

Example 11 with FlinkException

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));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 12 with FlinkException

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));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletableFuture(java.util.concurrent.CompletableFuture) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ExecutionException(java.util.concurrent.ExecutionException) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 13 with FlinkException

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));
    }
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ExecutionException(java.util.concurrent.ExecutionException) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 14 with FlinkException

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));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletableFuture(java.util.concurrent.CompletableFuture) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ExecutionException(java.util.concurrent.ExecutionException) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 15 with FlinkException

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));
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) ExecutionException(java.util.concurrent.ExecutionException) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Aggregations

FlinkException (org.apache.flink.util.FlinkException)197 Test (org.junit.Test)91 CompletableFuture (java.util.concurrent.CompletableFuture)59 IOException (java.io.IOException)38 ExecutionException (java.util.concurrent.ExecutionException)26 ArrayList (java.util.ArrayList)25 JobID (org.apache.flink.api.common.JobID)24 Collection (java.util.Collection)22 CompletionException (java.util.concurrent.CompletionException)22 Configuration (org.apache.flink.configuration.Configuration)21 TimeoutException (java.util.concurrent.TimeoutException)19 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)19 Time (org.apache.flink.api.common.time.Time)16 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)16 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)16 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)15 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)14 Collections (java.util.Collections)13 List (java.util.List)13 ExecutorService (java.util.concurrent.ExecutorService)13