dnvriend / akka-persistence-inmemory

Akka-persistence-inmemory is a plugin for akka-persistence that stores journal and snapshot messages memory, which is very useful when testing persistent actors, persistent FSM and akka cluster
Apache License 2.0
134 stars 41 forks source link

eventsByPersistenceId query from an actor makes actor's context = null #38

Open ShahOdin opened 7 years ago

ShahOdin commented 7 years ago

Finally pinpointed the problem. I define a trait:

trait InMemQuerySupport extends Actor {
        import akka.NotUsed
        import akka.persistence.query.{EventEnvelope, PersistenceQuery}
        import akka.stream.scaladsl.Source
        import akka.persistence.inmemory.query.scaladsl.InMemoryReadJournal

        def queryJournal(idToQuery: String, fromSequenceNr: Long = 0L,
                         toSequenceNr: Long = Long.MaxValue): Source[EventEnvelope, NotUsed] = {
          val source = PersistenceQuery(context.system).           
          readJournalFor[InMemoryReadJournal](InMemoryReadJournal.Identifier).
          eventsByPersistenceId(idToQuery, fromSequenceNr, toSequenceNr)
        }

        def queryJournalFrom(idToQuery: String, fromSequenceNr: Long = 0L): Source[EventEnvelope, NotUsed] =
          {
          assert(context != null, "This passes.")
          val source = queryJournal(idToQuery, fromSequenceNr, Long.MaxValue)
          assert(context != null, "This fails.")
          source
           }

      }

which I mix-in with a persistent actor. Calling queryJournalFrom(queryId, offsetForNextFetch) inside the actor in a test during the recovery phase for the actor causes the assertion above to fail. This is the full context of the code above. and although the system works in the demo, integrating it into another project with the same environment fails. This doesn't seem to happen with Cassandra's journal plugin.

dnvriend commented 6 years ago

Will put this on the backlog