1

我有一个演员层次结构,我想测试错误场景 - 实际上测试应用的主管策略。我需要修改演员的接收方法 - 让演员失败的消息。我找到了一个可堆叠的特征模式,但无法使其工作。我的代码如下:

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]
...

但是仍然没有处理“失败”消息。有什么提示吗?

4

0 回答 0