Search in sources :

Example 36 with ActorSystem

use of akka.actor.ActorSystem in project flink by apache.

the class AkkaActorSystemTest method askTerminatedActorFailsWithRecipientTerminatedException.

@Test
public void askTerminatedActorFailsWithRecipientTerminatedException() {
    final ActorSystem actorSystem = AkkaUtils.createLocalActorSystem(new Configuration());
    final Duration timeout = Duration.ofSeconds(10L);
    try {
        final ActorRef actorRef = actorSystem.actorOf(Props.create(SimpleActor.class));
        // wait for the actor's termination
        Patterns.gracefulStop(actorRef, timeout).toCompletableFuture().join();
        final CompletionStage<Object> result = Patterns.ask(actorRef, new Object(), timeout);
        try {
            result.toCompletableFuture().get();
            fail("Expected a recipient terminated exception.");
        } catch (Exception e) {
            assertTrue(AkkaRpcServiceUtils.isRecipientTerminatedException(ExceptionUtils.stripExecutionException(e)));
        }
    } finally {
        AkkaUtils.terminateActorSystem(actorSystem).join();
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) Configuration(org.apache.flink.configuration.Configuration) ActorRef(akka.actor.ActorRef) Duration(java.time.Duration) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 37 with ActorSystem

use of akka.actor.ActorSystem in project flink by apache.

the class SupervisorActorTest method completesTerminationFutureExceptionallyIfActorStopsWithoutReason.

@Test
public void completesTerminationFutureExceptionallyIfActorStopsWithoutReason() throws InterruptedException {
    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));
    actorRegistration.getActorRef().tell(Terminate.INSTANCE, ActorRef.noSender());
    try {
        terminationFuture.get();
        fail("Expected the termination future being completed exceptionally");
    } catch (ExecutionException expected) {
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) ActorRef(akka.actor.ActorRef) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 38 with ActorSystem

use of akka.actor.ActorSystem 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 39 with ActorSystem

use of akka.actor.ActorSystem 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 40 with ActorSystem

use of akka.actor.ActorSystem in project flink by apache.

the class AkkaBootstrapTools method startActorSystem.

/**
 * Starts an Actor System with given Akka config.
 *
 * @param akkaConfig Config of the started ActorSystem.
 * @param actorSystemName Name of the started ActorSystem.
 * @param logger The logger to output log information.
 * @return The ActorSystem which has been started.
 */
private static ActorSystem startActorSystem(Config akkaConfig, String actorSystemName, Logger logger) {
    logger.debug("Using akka configuration\n {}", akkaConfig);
    ActorSystem actorSystem = AkkaUtils.createActorSystem(actorSystemName, akkaConfig);
    logger.info("Actor system started at {}", AkkaUtils.getAddress(actorSystem));
    return actorSystem;
}
Also used : ActorSystem(akka.actor.ActorSystem)

Aggregations

ActorSystem (akka.actor.ActorSystem)91 ActorRef (akka.actor.ActorRef)54 Test (org.junit.Test)51 Configuration (org.apache.flink.configuration.Configuration)27 FiniteDuration (scala.concurrent.duration.FiniteDuration)12 File (java.io.File)11 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)11 LeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService)11 Props (akka.actor.Props)10 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)10 TestActorRef (akka.testkit.TestActorRef)8 IOException (java.io.IOException)8 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)8 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)8 Deadline (scala.concurrent.duration.Deadline)8 AddressFromURIString (akka.actor.AddressFromURIString)7 ActorMaterializer (akka.stream.ActorMaterializer)7 Materializer (akka.stream.Materializer)7 Sink (akka.stream.javadsl.Sink)7 Source (akka.stream.javadsl.Source)7