【发布时间】:2014-05-11 11:17:51
【问题描述】:
我是 Akka 和演员模型的新手,我在尝试测试演员时遇到了困难。
从Akka documentation,您可以创建一个简单的参与者,将自己绑定到本地端口并使用以下代码侦听传入连接:
class Server extends Actor {
import Tcp._
import context.system
IO(Tcp) ! Bind(self, new InetSocketAddress("localhost", 12345))
def receive = {
case b @ Bound(localAddress) =>
// do some logging or setup ...
// rest omitted for brevity
}
}
我想编写一个测试来创建一个Server 演员,然后验证该演员是否已收到来自IO(Tcp) 的Bound 消息。我想这是可能的,但我想我错过了一些东西。我对expectMsg 的理解是,这适用于向您正在测试的参与者发送消息的参与者,接收返回的内容并断言它已收到的内容。我真的可以检查我创建的演员收到了什么吗?
【问题讨论】: