Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Akka testing: it's a good idea to tell your actor system to leave a dead top-level actor dead.
// In real life, it's great that stuff gets restarted when it fails.
// In testing, we'd rather know that it failed.
class DyingActor extends Actor {
def receive = { case "die" => throw new Exception("poo") }
// Default config, everything restarts automatically
val system = ActorSystem("ordinary")
val dyingActor = val system.actorOf(Props(new DyingActor))
// false
dyingActor ! "die"
// false -- no indication that the actor was restarted
// so let's configure one that won't restart it
import com.typesafe.config.ConfigFactory
val stoppingConfigStr = """ = "" """
val stoppingConfig = ConfigFactory.parseString(stoppingConfigStr)
val tenderSystem = ActorSystem("sensitive", stoppingConfig)
val stayingDeadActor = tenderSystem.actorOf(Props(new DyingActor))
// false
stayingDeadActor ! "die"
// true -- this is something we can check in our tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment