These are chat archives for RBMHTechnology/eventuate

29th
Dec 2015
Swayam Narain
@swayam18
Dec 29 2015 02:12
@krasserm is it safe to use TestActorRef to get an underlying EventsourcedActor for synchronous unit testing?
Martin Krasser
@krasserm
Dec 29 2015 08:07
@Tvaroh yes, that's completely fine (if you don't mind that it's lost when the actor restarted)
Alexander Semenov
@Tvaroh
Dec 29 2015 08:08
@krasserm awesome, thanks :)
Martin Krasser
@krasserm
Dec 29 2015 08:12
@swayam18 this is currently not supported. Event-sourced actors have asynchronous communication with an event log, so a different strategy for unit testing is needed (see src/test/scala for examples). We're also planning to provide a test kit later which should make unit testing much easier.
Martin Krasser
@krasserm
Dec 29 2015 08:20
@mikem wip-182 contains a fix which is based on a complete re-implementation of stashing (actually, a much simpler one). It depends on another branch so it may take a few days until it will be merged to master. Please note that user stash operations are only allowed in the command handler (not checked yet but will be). Using user stash operations in the event handler is an error. This however is sufficient to implement, event-sourced (persistent) state machines, for example (once #90 is in place).
Swayam Narain
@swayam18
Dec 29 2015 09:26
@krasserm alright, thank you! @mikem and I are finding ourselves writing a mock implementation of an EventLog to help us with the testing. Looking forward to the testkit :) Also, could you give clarity on why it is an error to do user stash operations in the event handler? We stash commands if our actor is inconsistent in the command handler, and unstash them if it becomes consistent after an event is applied in the event handler.
Martin Krasser
@krasserm
Dec 29 2015 10:31

@swayam18 @mikem awesome, a mock EventLog is an important part of future testkit, I think. Would love to see a PR :smiley:. The EventLogSPI will further change while I'm currently working on #176 but should be rather stable then.

Your proposal of using unstashAll() in the event handler makes absolutely sense to me. It should only be prevented to use stash() inside the event handler, so that only commands can be stashed. I will consider that when finishing #182. Since commands are only processed by Eventsourced* when recovery has completed, unstashAll() will be implemented to have no effect during recovery. Does that fit your use case?

Martin Krasser
@krasserm
Dec 29 2015 17:10
@swayam18 @mikem usage of unstashAll() in event handler is now supported in wip-182.