/// <summary>
                /// Predicate defining whether the subscription state should be included in the checkpoint.
                /// </summary>
                /// <param name="entity">The entity.</param>
                /// <returns>
                /// True if should be included.
                /// </returns>
                protected override bool ShouldSaveSubscriptionState(SubscriptionEntity entity)
                {
                    Debug.Assert(entity != null, "Entity should not be null.");

                    var instance = entity.Instance;

                    if (instance != null)
                    {
                        return(SubscriptionStateVisitor.HasStateChanged(instance));
                    }

                    return(false);
                }
Пример #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);
            }
        }