I am familiar with the Akka testing approaches defined here:
http://doc.akka.io/docs/akka/snapshot/scala/testing.html
I understand how to use TestKit, TestActorRef, TestProbe etc. I also understand that my core domain logic should be extracted and tested in isolation from Akka.
My question is about strategies for doing TDD on Akka Persistence actors i.e. PersistentActor and PersistentView.
I want to be able to test the following types of scenarios in a reasonably low overhead, efficient manner i.e. as close to a unit test as possible:
- Did the persistent actor persist an event with the correct id?
- Does my snapshot recovery restore state properly?
- Does my view read the correct event?
If anyone knows of a project which can help me see this in action, I would be grateful.
One approach I can think of is to have a test PersistentView which can be used to verify a PersitentActor did its job. Seems a bit convoluted though.
This is not about testing Akka persistence framework itself, but to test that my Actors have been setup properly to use it and the behaviour is as expected.
Ad.1 Reusable solution for that would be some kind of in-memory journal with event bus publishing feature. This way you could create a test probe to listen on event bus for published events and assert them.
Ad.2 and Ad.3 are more about if my actor responds correctly after restore, I have a reason to believe that it's in correct state. This way you can not only validate if it's internal fields are correctly set, but also if it receive method has been restored correctly due to
become
changes.Optionally to check state distinctly have some message type that returns actor's state back to sender. It can be made generic by using traits and overrides on receive methods.