You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
deflog(m: =>String) = println(s"${Thread.currentThread} - $m")
deflogReceived(m: =>Any)(implicitself: ActorRef) = log(s"$self received: $m")
classAextendsActor {
defreceive= {
case x => logReceived(x)
}
}
classBextendsActor {
privatevala= context.actorOf(Props(newA))
defreceive= {
case x => logReceived(x); a ! x
}
}
vala=TestActorRef(newA, "a")
log("Send a message to a")
a !"message"valb=TestActorRef(newB, "b")
log("Send a message to b")
b !"message"
akka 提供了
TestActorRef
帮助我们同步测试Actor
.但运行完上面的完整代码, 打印输出结果会告诉你 :
a
发消息时, 收到消息的打印是同步执行的b
发消息时, 但a
收到消息的打印却是异步的实际开发中, 总会有如
B
对A
的依赖, 那么针对B
的单元测试怎么做好呢?The text was updated successfully, but these errors were encountered: