Yup, that's one way to do it - cheers!

On Thu, Oct 13, 2016 at 10:07 PM, Spencer Judge <sushisou...@gmail.com>
wrote:

> I can answered my own question here. It pretty much just came down to my
> lack of knowledge around the streams API, which I hadn't used yet. Changing
> the test to this works perfectly:
>
> test("test journal backwards compatibility", EndToEndTest) {
>   val readJournal = 
> PersistenceQuery(system).readJournalFor[LeveldbReadJournal](
>     LeveldbReadJournal.Identifier)
>   implicit val mat = ActorMaterializer()(system)
>   val allPersistenceIDs = readJournal.currentPersistenceIds().map { pid =>
>     val eventsForID = readJournal.currentEventsByPersistenceId(pid)
>     val res = eventsForID.runWith(Sink.foreach { e => e.event })
>     // Simply waiting for the result will blow up with an exception if we 
> couldn't deserialize.
>     Await.result(res, 300.millis)
>   }
>   Await.result(allPersistenceIDs.runWith(Sink.seq), 5.seconds)
> }
>
>
>
> On Wednesday, October 12, 2016 at 4:43:39 PM UTC-7, Spencer Judge wrote:
>>
>> Hello all,
>>
>> In order to test that no unaccounted-for serialization changes have
>> happen before we deploy our service, I need some way for us to *attempt* to
>> deserialize all currently stored events in our event journal and snapshots.
>>
>> Currently, we just use the local leveldb plugin with local snapshot
>> storage, which has been totally adequate for our purpose.
>>
>> I'm trying to do this by using a PersistenceQuery, but I'm totally unable
>> to get the persistence query to actually... return anything. My code is
>> pasted below. The things hidden behind the "PersistentTestKit" object just
>> handle some data cleaning before the tests, etc, and when I call
>> getNewConfig, that's just modifying the akka config to use the location of
>> the stored journal/snapshots we want to test against.
>>
>> As you can see, I added a simple persistent actor just to test if I could
>> get the query to return events from something not even related to the
>> existing data, and even it doesn't show up in the query (nothing does).
>> This is the output:
>>
>> Recover persisted a thing!  // As many times as I've already run the
>> test, as expected.
>> Recover RecoveryCompleted
>> Persisting a thing!
>> Found persistence IDs:
>> Found persistence IDs:
>> Found persistence IDs:
>>
>> Clearly, I'm missing something, but I'm not sure what. If I inspect the
>> config given to the system, everything looks right. The storage locations
>> are right, the plugins are right, etc. Can someone point me in the right
>> direction?
>>
>> Alternatively, is there a better way to do this? I will happily do
>> something else entirely if PersistenceQuery isn't the right fit.
>>
>>
>> object PersistCompatIT {
>>   val persistBackupLoc = ".exported_state"
>>   val dumpFile = new File(PersistentTestKit.findRoot(), 
>> persistBackupLoc).getAbsoluteFile
>>   val absPathToBackup = dumpFile.toPath.toString
>>   val systemConfig = PersistentTestKit.getNewConfig(true, (cfg) => {
>>     cfg.withValue("akka.persistence.snapshot-store.local.dir",
>>                   ConfigValueFactory
>>                     
>> .fromAnyRef(s"$absPathToBackup/boxsrv-snapshots/local-snapshots"))
>>       .withValue("akka.persistence.journal.leveldb.dir",
>>                  
>> ConfigValueFactory.fromAnyRef(s"$absPathToBackup/boxsrv-journal/leveldb-journal"))
>>   })
>>
>>   val lamePersistActorID = "imastupidpersistactor"
>>   class LamePersistActor extends PersistentActor {
>>     override def receiveRecover: Receive = {
>>       case m: Any => println(s"Recover $m")
>>     }
>>     override def receiveCommand: Receive = {
>>       case 'whoapersist =>
>>         println("Persisting a thing!")
>>         persist("persisted a thing!") { _ => () }
>>       case m: Any => println(s"Command $m")
>>     }
>>     override def persistenceId: String = lamePersistActorID
>>   }
>> }
>>
>> /**
>>   * Tests backwards compatibility for journaling / snapshots
>>   */
>> class PersistCompatIT extends TestKit(ActorSystem("PersistCompatSys",
>>                                                   
>> PersistCompatIT.systemConfig)) with FunSuiteLike {
>>
>>   test("test journal backwards compatibility", EndToEndTest) {
>>     val lameActor = system.actorOf(Props(new LamePersistActor))
>>     lameActor ! 'whoapersist
>>     Thread.sleep(1000)
>>     val readJournal = 
>> PersistenceQuery(system).readJournalFor[LeveldbReadJournal](
>>       LeveldbReadJournal.Identifier)
>>     implicit val mat = ActorMaterializer()(system)
>>     for (i <- 1 to 3) {
>>       Thread.sleep(2000)
>>       val allPersistenceIDs = readJournal.allPersistenceIds()
>>       val dafuq = 
>> readJournal.eventsByPersistenceId(PersistCompatIT.lamePersistActorID)
>>       println("Found persistence IDs:")
>>       allPersistenceIDs.map { e =>
>>         println(e)
>>         e
>>       }
>>       dafuq.map { e =>
>>         println(e.event)
>>         e
>>       }
>>     }
>>   }
>> }
>>
>>
>> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/
> current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to akka-user+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Akka Team
Lightbend <http://www.lightbend.com/> - Reactive apps on the JVM
Twitter: @akkateam

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to