Search in sources :

Example 31 with FlinkException

use of org.apache.flink.util.FlinkException in project flink by apache.

the class DispatcherResourceManagerComponentTest method unexpectedResourceManagerTermination_failsFatally.

@Test
public void unexpectedResourceManagerTermination_failsFatally() {
    final CompletableFuture<Void> terminationFuture = new CompletableFuture<>();
    final TestingFatalErrorHandler fatalErrorHandler = new TestingFatalErrorHandler();
    final TestingResourceManagerService resourceManagerService = TestingResourceManagerService.newBuilder().setTerminationFuture(terminationFuture).build();
    createDispatcherResourceManagerComponent(fatalErrorHandler, resourceManagerService);
    final FlinkException expectedException = new FlinkException("Expected test exception.");
    terminationFuture.completeExceptionally(expectedException);
    final Throwable error = fatalErrorHandler.getException();
    assertThat(error, containsCause(expectedException));
}
Also used : TestingFatalErrorHandler(org.apache.flink.runtime.util.TestingFatalErrorHandler) CompletableFuture(java.util.concurrent.CompletableFuture) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 32 with FlinkException

use of org.apache.flink.util.FlinkException in project flink by apache.

the class DispatcherResourceManagerComponentTest method unexpectedResourceManagerTermination_ifNotRunning_doesNotFailFatally.

@Test
public void unexpectedResourceManagerTermination_ifNotRunning_doesNotFailFatally() {
    final TestingFatalErrorHandler fatalErrorHandler = new TestingFatalErrorHandler();
    final CompletableFuture<Void> terminationFuture = new CompletableFuture<>();
    final TestingResourceManagerService resourceManagerService = TestingResourceManagerService.newBuilder().setTerminationFuture(terminationFuture).withManualTerminationFutureCompletion().build();
    final DispatcherResourceManagerComponent dispatcherResourceManagerComponent = createDispatcherResourceManagerComponent(fatalErrorHandler, resourceManagerService);
    dispatcherResourceManagerComponent.closeAsync();
    final FlinkException expectedException = new FlinkException("Expected test exception.");
    terminationFuture.completeExceptionally(expectedException);
    final CompletableFuture<Throwable> errorFuture = fatalErrorHandler.getErrorFuture();
    assertThat(errorFuture, willNotComplete(Duration.ofMillis(10L)));
}
Also used : TestingFatalErrorHandler(org.apache.flink.runtime.util.TestingFatalErrorHandler) CompletableFuture(java.util.concurrent.CompletableFuture) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 33 with FlinkException

use of org.apache.flink.util.FlinkException in project flink by apache.

the class SupervisorActorTest method completesTerminationFutureExceptionallyIfActorFails.

@Test
public void completesTerminationFutureExceptionallyIfActorFails() throws Exception {
    final ActorSystem actorSystem = actorSystemResource.getActorSystem();
    final ActorRef supervisor = SupervisorActor.startSupervisorActor(actorSystem, actorSystem.getDispatcher());
    final SupervisorActor.ActorRegistration actorRegistration = startAkkaRpcActor(supervisor, "foobar");
    final CompletableFuture<Void> terminationFuture = actorRegistration.getTerminationFuture();
    assertThat(terminationFuture.isDone(), is(false));
    final CompletableFuture<Terminated> actorSystemTerminationFuture = actorSystem.getWhenTerminated().toCompletableFuture();
    final FlinkException cause = new FlinkException("Test cause.");
    actorRegistration.getActorRef().tell(Fail.exceptionally(cause), ActorRef.noSender());
    try {
        terminationFuture.get();
        fail("Expected the termination future being completed exceptionally");
    } catch (ExecutionException expected) {
        ExceptionUtils.findThrowable(expected, e -> e.equals(cause)).orElseThrow(() -> new FlinkException("Unexpected exception", expected));
    }
    // make sure that the supervisor actor has stopped --> terminating the actor system
    actorSystemTerminationFuture.join();
}
Also used : ActorSystem(akka.actor.ActorSystem) ActorRef(akka.actor.ActorRef) ExecutionException(java.util.concurrent.ExecutionException) Terminated(akka.actor.Terminated) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 34 with FlinkException

use of org.apache.flink.util.FlinkException in project flink by apache.

the class SupervisorActorTest method completesTerminationFutureExceptionallyIfActorStopsExceptionally.

@Test
public void completesTerminationFutureExceptionallyIfActorStopsExceptionally() throws Exception {
    final ActorSystem actorSystem = actorSystemResource.getActorSystem();
    final ActorRef supervisor = SupervisorActor.startSupervisorActor(actorSystem, actorSystem.getDispatcher());
    final SupervisorActor.ActorRegistration actorRegistration = startAkkaRpcActor(supervisor, "foobar");
    final CompletableFuture<Void> terminationFuture = actorRegistration.getTerminationFuture();
    assertThat(terminationFuture.isDone(), is(false));
    final FlinkException cause = new FlinkException("Test cause.");
    actorRegistration.getActorRef().tell(TerminateWithFutureCompletion.exceptionally(cause), ActorRef.noSender());
    try {
        terminationFuture.get();
        fail("Expected the termination future being completed exceptionally");
    } catch (ExecutionException expected) {
        ExceptionUtils.findThrowable(expected, e -> e.equals(cause)).orElseThrow(() -> new FlinkException("Unexpected exception", expected));
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) ActorRef(akka.actor.ActorRef) ExecutionException(java.util.concurrent.ExecutionException) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 35 with FlinkException

use of org.apache.flink.util.FlinkException in project flink by apache.

the class OperatorCoordinatorHolder method completeCheckpointOnceEventsAreDone.

private void completeCheckpointOnceEventsAreDone(final long checkpointId, final CompletableFuture<byte[]> checkpointFuture, final byte[] checkpointResult) {
    final Collection<CompletableFuture<?>> pendingEvents = unconfirmedEvents.getCurrentIncompleteAndReset();
    if (pendingEvents.isEmpty()) {
        checkpointFuture.complete(checkpointResult);
        return;
    }
    LOG.info("Coordinator checkpoint {} for coordinator {} is awaiting {} pending events", checkpointId, operatorId, pendingEvents.size());
    final CompletableFuture<?> conjunct = FutureUtils.waitForAll(pendingEvents);
    conjunct.whenComplete((success, failure) -> {
        if (failure == null) {
            checkpointFuture.complete(checkpointResult);
        } else {
            // if we reach this situation, then anyways the checkpoint cannot
            // complete because
            // (a) the target task really is down
            // (b) we have a potentially lost RPC message and need to
            // do a task failover for the receiver to restore consistency
            checkpointFuture.completeExceptionally(new FlinkException("Failing OperatorCoordinator checkpoint because some OperatorEvents " + "before this checkpoint barrier were not received by the target tasks."));
        }
    });
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) FlinkException(org.apache.flink.util.FlinkException)

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