我正在尝试记录TestKit TestProbe收到的所有消息,事实证明这有些困难。我知道文档中的Actor Logging部分,其中说应该将debug.receive
选项与LogginReceive
块结合使用。但是,当我无法控制参与者的实现时,这将无法正常工作。
我唯一的想法是将akka.testkit.TestActor
子类化以使用LoggingReceive
,然后再将TestKit
子类化以使其创建我的TestActor
子类的实例,但这没有用,因为大多数功能是akka
命名空间专用的(并且出于充分的理由,我认为)。
最佳答案
抱歉,刚开始您的问题有点错误,所以这是我的方法。
创建一个包装器actor,记录消息:
class LoggingActor(fac: => Actor) extends Actor {
val underlying = context.system.actorOf(Props(fac))
def receive = {
LoggingReceive {
case x ⇒ underlying.tell(x, sender)
}
}
}
然后只用包裹在
TestActorRef
中的actor来创建LoggingActor
: val echo = TestActorRef(new LoggingActor(new FooActor))
echo ! "hello world"
关于scala - 记录所有发送到Akka TestKit TestProbe的消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13420809/