Esempio n. 1
0
        public void CanProperlySnapshot()
        {
            using (var state = new PersistentState("self", StorageEnvironmentOptions.CreateMemoryOnly(), CancellationToken.None)
            {
                CommandSerializer = new JsonCommandSerializer()
            })
            {
                state.UpdateTermTo(null, 1);
                state.AppendToLeaderLog(new NopCommand());
                for (int i = 0; i < 5; i++)
                {
                    state.AppendToLeaderLog(new DictionaryCommand.Set
                    {
                        Key   = i.ToString(),
                        Value = i
                    });
                }

                state.MarkSnapshotFor(6, 1, 5);

                state.AppendToLeaderLog(new DictionaryCommand.Set
                {
                    Key   = "1",
                    Value = 4
                });

                var lastLogEntry = state.LastLogEntry();

                Assert.Equal(7, lastLogEntry.Index);
            }
        }