我有一个演员层次结构,我想测试错误情景 - 实际测试一个应用的主管策略。我需要修改一个actor的receive方法 - 一个消息让actor失败。我发现了一个可堆叠的特征模式但无法使其工作。我的代码如下:
trait FailActor extends Actor {
abstract override def receive = LoggingReceive {
fail.orElse(super.receive)
}
def fail:Receive = {
case "fail" => throw new RuntimeException("Test")
}
}
class AddressTranslatorFailActor(storage: ActorRef) extends AddressTranslatorActor(storage) with FailActor
在测试中通过这个失败的演员:
val probe = TestProbe()
val addressServiceProps = Props {
new AddressServiceActor {
override def translateAddressProps = classOf[AddressTranslatorFailActor]
}
}
其中AddressService acctor的定义如下:
class AddressServiceActor extends Actor with ActorLogging {
def translateAddressProps: Class[_<:AddressTranslatorActor] = classOf[AddressTranslatorActor]
...
但仍然没有得到“失败”的消息。 任何提示?