Can someone help in write a test case for this following abstract Akka actor pseudo code.
Problem I'm facing is all the supervisions strategy messages (send as part of test case )are being consumed by the parent actor rather than applying its supervision strategy to its children.
Parent Abstract actor creates children .
Abstract class Parent extends UntypedActor {
String name;
int noOfChildActors;
//this set is used to manage the children i.e noOfChildActors = children.size()
Set<ActorRef> children;
public Parent(String name, int noOfChildActors, Props childProps){
this.name=name;
this.noOfChildActors = noOfChildActors;
createChildern(childProps);
}
public void createChildern(Props props){
for(int i = 0 ; i< no_of_child_actors;i++)
final ActorRef actor = getContext().actorOf(props, "worker"+i);
getContext().watch(actor);
children.add(actor);
}
@Override
public void onReceive(final Object message) {
//actor functionalities goes here.
}
@Override
public SupervisorStrategy supervisorStrategy() {
return defaultSupervisorStrategy();
}
private SupervisorStrategy defaultSupervisorStrategy() {
return new AllForOneStrategy(-1, Duration.Inf(), new Strategy());
}
private class Strategy implements Function<Throwable, Directive> {
@Override
public Directive apply(final Throwable t) {
//my own strategies.
}
}
//child managing methods.
//Abstract functions
}
Child class which extends Parent class
class Child extends Parent{
String name;
public static Props props(final String name, int noOfChildActors, Props childProps) {
return Props.create(Child.class, name, noOfChildActors, childProps);
}
public Child(String name, int noOfChildActors, Props childProps){
super(name, noOfChildActors, childProps);
}
//followed by my abstract function definition
}
//Test case
private static final FiniteDuration WAIT_TIME = Duration.create(5, TimeUnit.SECONDS);
JavaTestKit sender = new JavaTestKit(system);
final Props props = Child.Props("name", 3, Props.empty());
ActorRef consumer = system.actorOf(props, "test-supervision");
final TestProbe probe = new TestProbe(system);
probe.watch(consumer);
consumer.tell(ActorInitializationException.class, sender.getRef());
probe.expectMsgClass(WAIT_TIME, Terminated.class);