Akka - checking a specific log entry
I am writing unit tests for Akka actors and I want to check the log entries; for example test xyz wrote in the error category. (You know, let's say I send an actor a message via! Instead of ?.)
In the role of an actor, I will write for the error log or information or debug, etc. depending on the result of the message processed by "receive".
For akka 1.2 or 1.3, how should i do this? Example: add a new listener to EventHandler? Any other ideas?
Thanks in advance Todd
source to share
John already has the basics, which he already answered (Id testActor
hooks up the message to instead of using TestLatch, but that's a matter of taste). I know this does not suit your requirements, but maybe the following could lure you into Akka 2.0?
EventFilter.error(message = "some message", occurrences = 1) intercept {
// do something which should trigger such a log message
}
These funds come from akka-testkit, in particular akka.testkit.TestEventListener
and akka.testkit.EventFilter
. The code shown above will wait up to three seconds (configurable in "akka.test.filter-leeway") for the message to appear and give an informative error message if it doesn't.
source to share