/// <summary>
                /// Called when the state was persisted.
                /// </summary>
                public void OnSaved()
                {
                    _registry.TruncateLoggedEntities(_snapshot);

                    foreach (var entity in _snapshot.Entities)
                    {
                        entity.OnPersisted();
                    }

                    foreach (var subject in _snapshot.Subjects.Values)
                    {
                        if (subject.Instance is IStatefulOperator op)
                        {
                            op.OnStateSaved();
                        }
                    }

                    foreach (var subscription in _snapshot.Subscriptions.Values)
                    {
                        var instance = subscription.Instance;
                        if (instance != null)
                        {
                            SubscriptionStateVisitor.OnStateSaved(instance);
                        }
                    }
                }
Пример #2
0
        public void SubscriptionStateVisitor_Basics()
        {
            var state         = new MockOperatorStateContainer();
            var writerFactory = state.CreateWriter();
            var readerFactory = state.CreateReader();

            var xs = new SimpleSubject <int>();
            var o  = xs.CreateObserver();

            var ys = new Take <int>(xs, 5);

            {
                var s1 = ys.Subscribe(Observer.Create <int>(_ => { }, _ => { }, () => { }));
                var v  = new SubscriptionInitializeVisitor(s1);
                v.Subscribe();
                v.Start();

                o.OnNext(42);
                o.OnNext(43);

                var sv = new SubscriptionStateVisitor(s1);

                Assert.IsTrue(sv.HasStateChanged());

                sv.SaveState(writerFactory);

                Assert.IsTrue(sv.HasStateChanged());

                sv.OnStateSaved();

                Assert.IsFalse(sv.HasStateChanged());

                o.OnNext(44);
                o.OnNext(45);

                Assert.IsTrue(sv.HasStateChanged());
            }

            {
                var done = false;

                var s2 = ys.Subscribe(Observer.Create <int>(_ => { }, _ => { }, () => { done = true; }));

                var sv = new SubscriptionStateVisitor(s2);

                sv.LoadState(readerFactory);

                var v = new SubscriptionInitializeVisitor(s2);
                v.Subscribe();
                v.Start();

                o.OnNext(46);
                Assert.IsFalse(done);

                o.OnNext(47);
                Assert.IsFalse(done);

                o.OnNext(48);
                Assert.IsTrue(done);
            }
        }