mardi 29 mars 2016

Cannot test Play application with junit because of actors

since my (small) team started using actors in Play!, we get this nice error message each time we want to unit-test our application. FYI, the application is being developed in 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)

so let's take a look at the startActors method :

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());
}

Well, I'm not sure this helps a lot. But I also have this onStop method in the Global.java file, which is apparently never called :

@Override
public void onStop(Application app) {
    super.onStop(app);
    RemoteActorsUtils.getInstance().getSystem().shutdown();
    if (!RemoteActorsUtils.getInstance().getSystem().isTerminated()) {
        RemoteActorsUtils.getInstance().getSystem().shutdown();
    }

}

Thanks for the insight.

Aucun commentaire:

Enregistrer un commentaire