I'm testing an actor which spawns and coordinates child worker actors. In order to do so I've substituted child actor creation with TestProbe
s 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 TestProbe
s 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 ForwarderActor
s 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 TestProbe
s.
I wonder if there is an easier way of accomplishing this?