public void CanLoadStateFromSnapshotStore() { const string ACTOR_NAME = "test-actorX"; const string EXPECTED_STATE = "Ken Hartley Reed"; var snapshots = InMemoryPersistence.Get(Sys).SnapshotSource; snapshots.Add(new SnapshotEntry() { Id = ACTOR_NAME + "_0", PersistenceId = ACTOR_NAME, SequenceNr = 0, Snapshot = new TestActorState() { State = EXPECTED_STATE }, Timestamp = 1 }); // verify the SnapshotOffer was triggered when we create our actor EventFilter.Info(message: "SnapshotOffer received.").ExpectOne(() => { var snapshotActor = Sys.ActorOf(Props.Create(() => new PersistBySnapshotTestActor()), ACTOR_NAME); snapshotActor.Tell(new GetStateCommand()); }); ExpectMsg <string>(msg => msg == EXPECTED_STATE); }
protected override void PreStart() { base.PreStart(); _journalCollection = InMemoryPersistence.Get(Context.System).JournalSource; _metadataCollection = InMemoryPersistence.Get(Context.System).MetadataSource; }
public void CanStoreToJournal() { const string ACTOR_NAME = "test-actor"; const string EXPECTED_STATE01 = "Bob was here"; const string EXPECTED_STATE02 = "So was Red"; var actor = Sys.ActorOf(Props.Create(() => new PersistByJournalTestActor()), ACTOR_NAME); actor.Tell(new SetStateCommand(EXPECTED_STATE01)); ExpectNoMsg(); actor.Tell(new SetStateCommand(EXPECTED_STATE02)); ExpectNoMsg(); var journal = InMemoryPersistence.Get(Sys).JournalSource; Assert.Equal(2, journal.Count); Assert.Equal(ACTOR_NAME, journal[0].PersistenceId); Assert.Equal(EXPECTED_STATE01, (journal[0].Payload as SetStateCommand).NewState); Assert.Equal(ACTOR_NAME, journal[1].PersistenceId); Assert.Equal(EXPECTED_STATE02, (journal[1].Payload as SetStateCommand).NewState); var metadata = InMemoryPersistence.Get(Sys).MetadataSource; Assert.Equal(1, metadata.Count); Assert.Equal(2, metadata[0].SequenceNr); Assert.Equal(ACTOR_NAME, metadata[0].PersistenceId); }
public void CanSaveStateToSnapshotStore() { const string EXPECTED_STATE = "Bob was here"; var snapshotActor = Sys.ActorOf(Props.Create(() => new PersistBySnapshotTestActor()), "test-actor"); snapshotActor.Tell(new SetStateCommand(EXPECTED_STATE)); ExpectNoMsg(); var snapshots = InMemoryPersistence.Get(Sys).SnapshotSource; Assert.Equal(1, snapshots.Count); Assert.IsType(typeof(TestActorState), snapshots[0].Snapshot); Assert.Equal(EXPECTED_STATE, (snapshots[0].Snapshot as TestActorState).State); }
public void CanLoadFromJournal() { const string ACTOR_NAME = "test-actor"; const string EXPECTED_STATE01 = "State01"; const string EXPECTED_STATE02 = "State02"; var journal = InMemoryPersistence.Get(Sys).JournalSource; var metadata = InMemoryPersistence.Get(Sys).MetadataSource; journal.Add(new JournalEntry() { Id = ACTOR_NAME + "_2", PersistenceId = ACTOR_NAME, SequenceNr = 2, Manifest = "", Payload = new SetStateCommand(EXPECTED_STATE02) }); journal.Add(new JournalEntry() { Id = ACTOR_NAME + "_1", PersistenceId = ACTOR_NAME, SequenceNr = 1, Manifest = "", Payload = new SetStateCommand(EXPECTED_STATE01) }); metadata.Add(new MetadataEntry() { Id = ACTOR_NAME, PersistenceId = ACTOR_NAME, SequenceNr = 2 }); EventFilter.Info(message: "Recovering SetStateCommand.").Expect(2, () => { var actor = Sys.ActorOf(Props.Create(() => new PersistByJournalTestActor()), ACTOR_NAME); actor.Tell(new GetStateCommand()); ExpectMsg <string>(msg => msg == EXPECTED_STATE02); }); }
public InMemoryJournal() { _settings = InMemoryPersistence.Get(Context.System).JournalSettings; }
protected override void PreStart() { base.PreStart(); _snapshotCollection = InMemoryPersistence.Get(Context.System).SnapshotSource; }
public InMemorySnapshotStore() { _settings = InMemoryPersistence.Get(Context.System).SnapshotStoreSettings; }