1

I'm testing an actor which spawns and coordinates child worker actors. In order to do so I've substituted child actor creation with TestProbes which are used to observe and simulate exchanged messages.

However I've ran into a problem when trying to test actor's supervision strategy. I was able to simulate an exception generated within child actor by setting up an AutoPilot on a TestProbe. But it turned out that TestProbes are supervised by system guardian by default and my test actor does not receive error notifications.

One idea that came into mind is to set up an intermediate ForwarderActors layer that will be supervised by test actor and generate test exception, but otherwise forward messages between TestProbe and test actor, like this:

case class GenerateException(exception: Exception)

class ForwarderActor(phase: Phase) extends Actor {
  val probe  = TestProbe(phase.toString)

  override def receive: Receive = {
    case GenerateException(e) => throw e
    case msg if sender() == probe.ref => context.parent ! msg
    case msg => probe.ref ! msg
  }
}

This way actor will supervised properly but messages can still be inspected with TestProbes.

I wonder if there is an easier way of accomplishing this?

Vasiliy Ivashin
  • 425
  • 2
  • 12

0 Answers0