0

I'am trying to test persistence actor, but behavior is wierd.

My tested actor:

public class PredictionManager : ReceivePersistentActor
{
    public override string PersistenceId => _persistanceId;

    public PredictionManager(string persistenceId)
    {
        _persistanceId = persistenceId;
        Command<AddPredictionRequest>(OnPrediction);
        Recover<SnapshotOffer>(x => OnRecover((PredictionManagerState)x.Snapshot), x => x.Snapshot is PredictionManagerState);
    }
    private void OnPrediction(AddPredictionRequest request)
    {
       /* some code */
        _state.Add(request);
        SaveSnapshot(_state);
    }
    private void OnRecover(PredictionManagerState state)
    {
        foreach(var request in state.RequestMap)
        {
            OnPrediction(request.Value);
        }
    }
}

My state save all messages and deletes them after manager actor recieve some message. When I try to debug my test, Recover function called first and after this called OnPrediction. My question is - how it's possible? If data stores in momory, why it have SnapshotOffer? Also I have tried to generate new percistenceId from Guid.NewGuid() but it doesn't work.

        public void AddPrediction_PassToChild_CreateNewManager_PassToChild()
        {
            var sender = CreateTestProbe(Sys);
            var persistanceId = "AddPrediction_PassToChild_CreateNewManager_PassToChild";
            var props = Props.Create(() => new PredictionManager(Mock.Of<IEventBus>(), persistanceId));
            var predictionManager = ActorOf(props);
            var message = new PredictionManager.AddPredictionRequest(Props.Create(() => new ChildTestActor(sender.Ref)), 
                new StartPrediction<IPredictionParameter>("a", 1, "a", new Param() ));
            
            //Act
            predictionManager.Tell(message, sender);
            sender.ExpectMsg<string>(x => x == "ok", TimeSpan.FromSeconds(15));
            
            Sys.Stop(predictionManager);
            predictionManager = Sys.ActorOf(props);

            sender.ExpectMsg<string>(x => x == "ok", TimeSpan.FromSeconds(15));
            Sys.Stop(predictionManager);
        }
lobstar
  • 310
  • 4
  • 8

1 Answers1

0

I found out that default storage for snapshots is LocalStorage not MemoryStorage. So it stores snapshots in files, and this is why it has SnapshotOffer after app restart. But I still can't get why Guid.NewGuid() as persistanceId is not working.

lobstar
  • 310
  • 4
  • 8