我有以下父子关系
public class ParentActor extends UntypedActor {
@Override
public void onReceive(Object msg) throws Exception {
if (msg instanceof Command) {
final String data = ((Command) msg).getData();
final Event event = new Event(data, UUID.randomUUID().toString());
ActorRef childActor = getContext().actorOf(Props.create(ChildActor.class), "child-actor");
childActor.tell(event, getSelf());
} else if (msg.equals("echo")) {
log.info("ECHO!");
}
}
}
public class ChildActor extends UntypedActor {
@Override
public void onReceive(Object msg) {
log.info("Received Event: " + msg);
//PoisonPill and kill self
}
}
如何在向父母发送消息后,编写一个观察和验证儿童演员死亡的测试?
我有以下结果导致断言超时
@Before
childProps = Props.create(ForwarderActor.class, childProbe.getRef());
childRef = TestActorRef.create(system, childProps);
@Test
public void myTest () {
underTest.tell("send parent message);
childProbe.expectMsgClass(Terminated.class);
}
和货运代理人
import akka.actor.ActorRef;
import akka.actor.UntypedActor;
public class ForwarderActor extends UntypedActor {
final ActorRef target;
public ForwarderActor(ActorRef target) {
this.target = target;
}
public void onReceive(Object msg) {
target.forward(msg, getContext());
}
}
我想这里的问题是我的孩子演员不是通过道具传递的,而是在父演员本身中初始化,这是一个糟糕的设计吗?我该如何测试这个设置?