我遇到了一个扩展Stash的actor的问题,并且在一个简单的ActorSystem中使用actorOf实例化它时效果非常好.现在我真的想在我的程序中使用它们之前为我的存储演员编写一些测试.但是我无法找到在我的测试套件中使用TestActorRef和这个actor的方法.
有效的代码如下所示:
import akka.actor.{Stash, Actor, ActorSystem, Props}
import com.typesafe.config.ConfigFactory
object StashTest {
val config = ConfigFactory.parseString(
"""
|akka.actor.default-mailbox {
| mailbox-type = "akka.dispatch.UnboundedDequeBasedMailbox"
|}
""".stripMargin)
}
class StashTestActor extends Stash {
def receive: Actor.Receive = {
case "unstash" =>
unstashAll()
context become print
case msg => stash()
}
def print: Actor.Receive = {
case msg => println(s"Unstashed message: $msg")
}
}
val system = ActorSystem("stashSystem", StashTest.config)
val ref = system.actorOf(Props[StashTestActor])
ref ! "stash me"
ref ! "blah"
ref ! "unstash" …Run Code Online (Sandbox Code Playgroud)