Adding more robust tests to HotSwapSpec
This commit is contained in:
parent
8b3dbc2f7c
commit
1f38866b5b
1 changed files with 54 additions and 7 deletions
|
|
@ -6,10 +6,60 @@ package akka.actor
|
|||
|
||||
import akka.testkit._
|
||||
|
||||
object HotSwapSpec {
|
||||
abstract class Becomer extends Actor {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
|
||||
class HotSwapSpec extends AkkaSpec with ImplicitSender {
|
||||
import HotSwapSpec.Becomer
|
||||
|
||||
"An Actor" must {
|
||||
"be able to become in its constructor" in {
|
||||
val a = system.actorOf(Props(new Becomer {
|
||||
context.become { case always ⇒ sender ! always }
|
||||
def receive = { case always ⇒ sender ! "FAILURE" }
|
||||
}))
|
||||
a ! "pigdog"
|
||||
expectMsg("pigdog")
|
||||
}
|
||||
|
||||
"be able to become multiple times in its constructor" in {
|
||||
val a = system.actorOf(Props(new Becomer {
|
||||
for (i ← 1 to 4) context.become({ case always ⇒ sender ! i + ":" + always })
|
||||
def receive = { case always ⇒ sender ! "FAILURE" }
|
||||
}))
|
||||
a ! "pigdog"
|
||||
expectMsg("4:pigdog")
|
||||
}
|
||||
|
||||
"be able to become with stacking in its constructor" in {
|
||||
val a = system.actorOf(Props(new Becomer {
|
||||
context.become({ case always ⇒ sender ! "pigdog:" + always; context.unbecome() }, false)
|
||||
def receive = { case always ⇒ sender ! "badass:" + always }
|
||||
}))
|
||||
a ! "pigdog"
|
||||
expectMsg("pigdog:pigdog")
|
||||
a ! "badass"
|
||||
expectMsg("badass:badass")
|
||||
}
|
||||
|
||||
"be able to become, with stacking, multiple times in its constructor" in {
|
||||
val a = system.actorOf(Props(new Becomer {
|
||||
for (i ← 1 to 4) context.become({ case always ⇒ sender ! i + ":" + always; context.unbecome() }, false)
|
||||
def receive = { case always ⇒ sender ! "FAILURE" }
|
||||
}))
|
||||
a ! "pigdog"
|
||||
a ! "pigdog"
|
||||
a ! "pigdog"
|
||||
a ! "pigdog"
|
||||
expectMsg("4:pigdog")
|
||||
expectMsg("3:pigdog")
|
||||
expectMsg("2:pigdog")
|
||||
expectMsg("1:pigdog")
|
||||
}
|
||||
|
||||
"be able to hotswap its behavior with become(..)" in {
|
||||
val a = system.actorOf(Props(new Actor {
|
||||
|
|
@ -30,13 +80,10 @@ class HotSwapSpec extends AkkaSpec with ImplicitSender {
|
|||
val a = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "init" ⇒ sender ! "init"
|
||||
case "swap" ⇒
|
||||
context.become({
|
||||
case "swapped" ⇒
|
||||
sender ! "swapped"
|
||||
case "revert" ⇒
|
||||
context.unbecome()
|
||||
})
|
||||
case "swap" ⇒ context.become({
|
||||
case "swapped" ⇒ sender ! "swapped"
|
||||
case "revert" ⇒ context.unbecome()
|
||||
})
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue