These are chat archives for RBMHTechnology/eventuate

29th
Feb 2016
Daniel Bimschas
@danbim
Feb 29 2016 07:13

Hi everyone!

I have a question regarding unit testing. I'm trying to test the recovery behavior of an EventSourcedActor. In order to replay messages on startup of the actor I followed the examples in EventsourcedActorSpec and I leverage the EventsourcingProtocol:

def createCrawlerSchedulerUnrecovered(): ActorRef = {
    eventLog = TestProbe("eventLogProbe")
    val actorProps: Props = CrawlerScheduler.props(eventLog.ref)
    val actor: ActorRef = system.actorOf(actorProps, CrawlerScheduler.actorName + "_" + lastId)
    lastId += 1
    actor
  }

def recover(actor: ActorRef, events: List[Any] = Nil): ActorRef = {
    val emitterIdA = "crawlerScheduler"
    val instanceId = 1 // ???
    val durableEvents: List[DurableEvent] = events.map(DurableEvent(_, emitterIdA))
    eventLog.expectMsg(LoadSnapshot(emitterIdA, instanceId))
    eventLog.sender() ! LoadSnapshotSuccess(None, instanceId)
    eventLog.expectMsg(Replay(1L, Some(actor), Some(CrawlerScheduler.aggregateId), instanceId))
    actor ! ReplaySuccess(durableEvents, durableEvents.size, instanceId)
    actor ! ReplaySuccess(Nil, durableEvents.size, instanceId)
    actor
  }

Now here's the problem: the field instanceId in LoadSnapshot, LoadSnapshotSuccess, Replay and ReplaySuccess refers to a private field in EventSourcedView. As I can't access the field my assertions will fail. For EventsourcedActorSpec it works as it uses package-private direct access to the internal API to access the value:

override def beforeEach(): Unit = {
    instanceId = EventsourcedView.instanceIdCounter.get
    ...
  }

Do you have any straight-forward idea on how to make my scenario work without building nasty workarounds or changing the Eventsourced API?

Martin Krasser
@krasserm
Feb 29 2016 07:47
HI @danbim, good catch. I just created RBMHTechnology/eventuate#227. In the meantime, write your own accessor and put it package com.rbmhtechnology.eventuate. Does that help?
Daniel Bimschas
@danbim
Feb 29 2016 08:01
@krasserm yes, this should help, thanks!
Martin Krasser
@krasserm
Feb 29 2016 08:03
@danbim great, should be in master soon.
Daniel Bimschas
@danbim
Feb 29 2016 08:04
@krasserm: do you have some concrete ideas for RBMHTechnology/eventuate#198 already? maybe I could be of help, even if I’m just getting started using Eventuate :)
Martin Krasser
@krasserm
Feb 29 2016 08:07
@danbim only very high-level ideas. Would be really great if you could help improving the test infrastructure towards a teskit. Let me know if you have any questions. Cheers!
Daniel Bimschas
@danbim
Feb 29 2016 08:09
hmm... I guess for now I could try to extract everything that is reusable which I create for testing my small learning application at hand. let’s see how much that will be
Martin Krasser
@krasserm
Feb 29 2016 08:13
That sounds like a reasonable first step. A complete testkit should finally abstract over the EventsourcingProtocol and instanceIds and provide methods expectmessages (snapshots, events, ...) from event-sourced actors and send messages to them.
Daniel Bimschas
@danbim
Feb 29 2016 08:23
true. I’d start with some rather simple “helper methods” as you already have internally in EventsourcedViewSpec that would already help as a starting point. These would allow setting an eventsourced actor to a well-defined state (which snapshot is loaded, which events to replay on startup). The next step could probably be help to verify which events are being generated for which commands (didn’t do that, yet). WDYT?
Martin Krasser
@krasserm
Feb 29 2016 08:24
:+1: and thanks a lot for working on it!