UPDATE /溶液
问题更多的是受孕问题而不是其他问题。 我们可以通过使用Application.isTest()方法解决它,如果我们对程序进行单元测试,则不要启动/结束actor。
原始邮寄
你好,
因为我的(小)团队开始在Play!中使用actor,所以每次我们想要对我们的应用程序进行单元测试时,我们会得到这个很好的错误消息。仅供参考,该应用程序正在用Java开发。
[error] Test utils.JsonUtilsTest.testBuildingJsonResponseWithPermissionsThrowsNullPointerException failed: java.lang.IllegalStateException: cannot create children while terminating or terminated, took 0.48 sec
[error] at akka.actor.dungeon.Children$class.makeChild(Children.scala:266)
...
[error] at Global.startActors(Global.java:1248)
让我们来看看Global类中的startActors方法,它扩展了GlobalSettings:
private void startActors() {
ActorRef measureFrequencyMaster = RemoteActorsUtils.getInstance().getSystem()
.actorOf(Props.create(MeasureFrequencyMaster.class), "MeasureFrequencyMaster");
BatchMessage msg = new BatchMessage();
msg.setMessage(MSG.GO_SCHEDULE);
RemoteActorsUtils.getInstance().getBatchMonitor().tell(msg, ActorRef.noSender());
}
嗯,我不确定这会有多大帮助。但是我在Global.java文件中也有这个onStop方法,显然从未调用过:
@Override
public void onStop(Application app) {
super.onStop(app);
RemoteActorsUtils.getInstance().getSystem().shutdown();
if (!RemoteActorsUtils.getInstance().getSystem().isTerminated()) {
RemoteActorsUtils.getInstance().getSystem().shutdown();
}
}
感谢您的见解。