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 .Stop
6+ import akka .testkit .TestProbe
7+
8+ class FailureParentSpec extends WordSpec with Matchers with BeforeAndAfterAll {
9+ " Using a FailureParent" must {
10+ " Result in failures being collected and returned" in {
11+ implicit val system = ActorSystem ()
12+ val failures = TestProbe ()
13+ val failureParent = system.actorOf(Props (new FailureParent (failures.ref)))
14+ failureParent ! TestFailureParentMessage
15+ failures.expectMsgType[NullPointerException ]
16+ }
17+ }
18+ }
19+
20+ case object TestFailureParentMessage
21+
22+ class FailureParent (failures : ActorRef ) extends Actor {
23+ val props = Props [MyFailureParentActor ]
24+ val child = context.actorOf(props, " child" )
25+ override val supervisorStrategy = OneForOneStrategy () {
26+ case f => failures ! f; Stop
27+ }
28+ def receive = {
29+ case msg => child forward msg
30+ }
31+ }
32+
33+ class MyFailureParentActor extends Actor {
34+ def receive = {
35+ case _ => throw new NullPointerException
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments