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();
}
}
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) {
}
}
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();
}
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));
}
}
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;
}
Aggregations