Rewriting DeathWatchSpec and FSMTransitionSpec to do the startsMonitoring inside the Actor

This commit is contained in:
Viktor Klang 2011-10-20 11:46:13 +02:00
parent 4fc108027e
commit 6a2f203d26
2 changed files with 30 additions and 19 deletions

View file

@ -30,12 +30,12 @@ class DeathWatchSpec extends AkkaSpec with BeforeAndAfterEach with ImplicitSende
}
"notify with all monitors with one Terminated message when an Actor is stopped" in {
val monitor1, monitor2 = actorOf(Props(context { case t: Terminated testActor ! t }))
val terminal = actorOf(Props(context { case _ }))
monitor1 startsMonitoring terminal
monitor2 startsMonitoring terminal
testActor startsMonitoring terminal
val monitor1, monitor2, monitor3 =
actorOf(Props(new Actor {
self startsMonitoring terminal
def receive = { case t: Terminated testActor ! t }
}))
terminal ! PoisonPill
@ -45,20 +45,24 @@ class DeathWatchSpec extends AkkaSpec with BeforeAndAfterEach with ImplicitSende
monitor1.stop()
monitor2.stop()
monitor3.stop()
}
"notify with _current_ monitors with one Terminated message when an Actor is stopped" in {
val monitor1, monitor2 = actorOf(Props(context {
case t: Terminated testActor ! t
case "ping" context.channel ! "pong"
}))
val terminal = actorOf(Props(context { case _ }))
monitor1 startsMonitoring terminal
monitor2 startsMonitoring terminal
testActor startsMonitoring terminal
monitor2 stopsMonitoring terminal
val monitor1, monitor3 =
actorOf(Props(new Actor {
self startsMonitoring terminal
def receive = { case t: Terminated testActor ! t }
}))
val monitor2 = actorOf(Props(new Actor {
self startsMonitoring terminal
self stopsMonitoring terminal
def receive = {
case "ping" sender ! "pong"
case t: Terminated testActor ! t
}
}))
monitor2 ! "ping"
@ -71,14 +75,17 @@ class DeathWatchSpec extends AkkaSpec with BeforeAndAfterEach with ImplicitSende
monitor1.stop()
monitor2.stop()
monitor3.stop()
}
"notify with a Terminated message once when an Actor is stopped but not when restarted" in {
filterException[ActorKilledException] {
val supervisor = actorOf(Props(context { case _ }).withFaultHandler(OneForOneStrategy(List(classOf[Exception]), Some(2))))
val terminal = actorOf(Props(context { case x context.channel ! x }).withSupervisor(supervisor))
testActor startsMonitoring terminal
val monitor = actorOf(Props(new Actor {
self startsMonitoring terminal
def receive = { case t: Terminated testActor ! t }
}).withSupervisor(supervisor))
terminal ! Kill
terminal ! Kill

View file

@ -55,8 +55,12 @@ class FSMTransitionSpec extends AkkaSpec with ImplicitSender {
"not fail when listener goes away" in {
val forward = actorOf(new Forwarder(testActor))
val sup = actorOf(Props[Supervisor].withFaultHandler(OneForOneStrategy(List(classOf[Throwable]), None, None)))
val fsm = sup startsMonitoring actorOf(new MyFSM(testActor))
val fsm = actorOf(new MyFSM(testActor))
val sup = actorOf(Props(new Actor {
self startsMonitoring fsm
def receive = { case _ }
}).withFaultHandler(OneForOneStrategy(List(classOf[Throwable]), None, None)))
within(300 millis) {
fsm ! SubscribeTransitionCallBack(forward)
expectMsg(CurrentState(fsm, 0))