1

I have a actor hierarchy which I would like to test for error scenarios - actually test a applied supervisors strategies. I need to modify an actor's receive method - for a message to fail the actor. I found a stackable trait pattern but cannot make it work. My code follows:

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

And in the test passing this failing actor:

val probe = TestProbe()
  val addressServiceProps = Props {
    new AddressServiceActor {
      override def translateAddressProps = classOf[AddressTranslatorFailActor]
    }
  }

where AddressService acctor is defined as follows:

class AddressServiceActor extends Actor with ActorLogging {

  def translateAddressProps: Class[_<:AddressTranslatorActor] = classOf[AddressTranslatorActor]
...

But still getting the "fail" message un-handeled. Any hints?

jaksky
  • 3,305
  • 4
  • 35
  • 68
  • I don't know if it helps, but I had a similar problem some time ago, and using props like in `Props[YourActorClass with YourBehaviorTrait]` doesn't stack the behavior while `Props(new YourActorClass with YourBehaviorTrait)` does stack the behavior into receive. – ale64bit Feb 13 '15 at 14:39
  • Overriding Props(... ) that I was trying to avoid because passing several arguments etc. So I tried just to pass a Class and construct props in the parent actor who actually creates this one. Seems that there is no way to avoid that. – jaksky Feb 13 '15 at 14:46
  • @kaktusito I tried the suggested approach: override def AddressTranslatorProps(adr: Address) = Props(new AddressTranslatorFailActor(storage)) but still getting AddressTranslatorFailActor] akka://testsystem/user/AddressService/$a - received unhandled message fail Redefined AddressServiceActor to def AddressTranslatorProps(adr: Address) = Props(classOf[AddressTranslatorActor], storage) Seems like I cannot find a single way to do it – jaksky Feb 13 '15 at 16:37
  • Take a look at the answer that I gave here: http://stackoverflow.com/questions/28341337/strategy-pattern-in-akka. It's not the accepted answer, but it might be something close to what you need. – cmbaxter Feb 13 '15 at 18:24
  • @cmbaxter Thanks. One thing is not still clear to me: Why it doesn't work? – jaksky Feb 16 '15 at 08:26

0 Answers0