Let’s check out some testing code which tests out the following different set of actors
- Echo Actor – responds back with whatever is passed to the actor
- Forwarding Actor – forwards the message to another actor
- Sequencing Actor – replies back in a series of messages but assuming we are interested in one
- Filtering Actor – replies back for certain messages and ignores the others
- Boom Actor – throws an exception when a message is send
- Supervisor Actor – manages an another worker actor, and based on the exception thrown by the worker actor, applies the appropriate supervisor strategy
The code base for the program is available at the following location - https://github.com/write2munish/Akka-Essentials under the AkkaUnitTest
I moved your two tests from src/main/java to src/test/java and get the following error:
ReplyDeletecom.typesafe.config.ConfigException$Missing: No configuration setting found for key 'TestSys'
Is there supposed to be an application.conf in the classpath?
Yes, there is one and you will find the same under src/main/resource.
ReplyDeleteI forgot to say a big thank you for publishing these examples.
ReplyDeleteMy attempted at doing a git push failed, so here are the changes I made:
ReplyDelete- Moved all of your test classes to src/test/java/org.../actors
- Renamed UnitTestExample.java to ExampleUnitTest.java
- Renamed resource/ to resources/
Now I can run mvn clean install and all tests are executed.
Robin
Thanks Robin. I will make the changes and push them out.
ReplyDeleteI think there's are an issue preventing testSupervisorStrategy1() from actually testing what it wants to test: While child.tell(123) will cause the "child" actor to eventually blow up and be restarted by its supervisor, Akka gives no guarantee as to when this happens.
ReplyDeleteThus the final assertFalse(child.isTerminated()) can potentially be executed before the child has reacted to the 123 message, causing isTerminated() to yield false regardless of whether the supervision strategy is working properly or not.
When you make use of TestActorRef, it sets the dispatcher to CallingThreadDispatcher and sets the receiveTimeout to None
ReplyDelete