File tree Expand file tree Collapse file tree
chapter04/src/test/scala/com/reactivedesignpatterns/chapter4 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .reactivedesignpatterns .chapter4
2+
3+ import org .scalatest ._
4+ import akka .actor ._
5+ import akka .actor .SupervisorStrategy .Restart
6+ import akka .testkit .TestProbe
7+
8+ class StepParentSpec extends WordSpec with Matchers with BeforeAndAfterAll {
9+ " An actor that throws an exception" must {
10+ " Result in the supervisor returning a reference to that actor" in {
11+ implicit val system = ActorSystem ()
12+ val testProbe = TestProbe ()
13+ val parent = system.actorOf(Props (new StepParent (testProbe.ref)), " stepParent" )
14+ parent.tell(Props [MyActor ], testProbe.ref)
15+ val child = testProbe.expectMsgType[ActorRef ]
16+ child ! TestMessage
17+ }
18+ }
19+ }
20+
21+ case object TestMessage
22+
23+ class StepParent (target : ActorRef ) extends Actor {
24+ override val supervisorStrategy = OneForOneStrategy () {
25+ case thr : Throwable => target ! thr; Restart
26+ }
27+ def receive = {
28+ case p : Props =>
29+ sender ! context.actorOf(p, " child" )
30+ }
31+ }
32+
33+ class MyActor extends Actor {
34+ def receive = {
35+ case _ => throw new NullPointerException
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments