Exemple #1
0
        public void with_both_window_and_buffer_size_values_can_be_ignored_by_window()
        {
            ManualScheduler scheduler = new ManualScheduler();

            ReplaySubject <int> subject =
                new ReplaySubject <int>(3, TimeSpan.FromMilliseconds(10), scheduler);

            StatsObserver <int> stats = new StatsObserver <int>();

            DateTime start = DateTime.UtcNow;

            scheduler.Now = start; // ignored by window
            subject.OnNext(1);

            scheduler.Now = start.AddMilliseconds(5);
            subject.OnNext(2);

            scheduler.Now = start.AddMilliseconds(8);
            subject.OnCompleted();

            scheduler.Now = start.AddMilliseconds(11);
            subject.Subscribe(stats);

            scheduler.RunAll();

            Assert.AreEqual(1, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 2 }));
            Assert.IsTrue(stats.CompletedCalled);
        }
Exemple #2
0
        public void values_cannot_be_replayed_out_of_order()
        {
            ManualScheduler scheduler = new ManualScheduler();

            ReplaySubject <int> subject = new ReplaySubject <int>(scheduler);

            StatsObserver <int> stats = new StatsObserver <int>();

            subject.OnNext(1);
            subject.OnNext(2);

            subject.Subscribe(stats);

            Assert.IsFalse(stats.NextCalled);

            scheduler.RunNext();
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 1 }));

            subject.OnNext(3);

            scheduler.RunNext();
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 1, 2 }));

            scheduler.RunNext();
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 1, 2, 3 }));

            subject.OnCompleted();

            scheduler.RunNext();
            Assert.IsTrue(stats.CompletedCalled);
        }
Exemple #3
0
        public void honours_window_for_replays_with_priority_to_most_recent()
        {
            ManualScheduler scheduler = new ManualScheduler();

            ReplaySubject <int> subject =
                new ReplaySubject <int>(TimeSpan.FromMilliseconds(10), scheduler);

            StatsObserver <int> stats = new StatsObserver <int>();

            DateTime start = DateTime.UtcNow;

            scheduler.Now = start;
            subject.OnNext(1);

            scheduler.Now = start.AddMilliseconds(5);
            subject.OnNext(2);

            scheduler.Now = start.AddMilliseconds(10);
            subject.OnNext(3);

            scheduler.Now = start.AddMilliseconds(11);
            subject.Subscribe(stats);

            scheduler.RunAll();

            Assert.AreEqual(2, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 2, 3 }));
            Assert.IsFalse(stats.CompletedCalled);
        }
Exemple #4
0
        public void window_includes_onerror()
        {
            ManualScheduler scheduler = new ManualScheduler();

            ReplaySubject <int> subject =
                new ReplaySubject <int>(TimeSpan.FromMilliseconds(10), scheduler);

            StatsObserver <int> stats = new StatsObserver <int>();

            DateTime start = DateTime.UtcNow;

            scheduler.Now = start;
            subject.OnNext(1);

            scheduler.Now = start.AddMilliseconds(5);
            subject.OnNext(2);

            scheduler.Now = start.AddMilliseconds(10);
            subject.OnError(new Exception());

            scheduler.Now = start.AddMilliseconds(11);
            subject.Subscribe(stats);

            scheduler.RunAll();

            Assert.AreEqual(1, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 2 }));
            Assert.IsTrue(stats.ErrorCalled);
        }
Exemple #5
0
        public static void SubSystemOrderTest()
        {
            Application   a   = new Application();
            Scene         s   = new Scene();
            TestSubSystem ss0 = new TestSubSystem0()
            {
                Order = 2, Log = true
            };
            TestSubSystem ss1 = new TestSubSystem1()
            {
                Order = 0, Log = true
            };
            TestSubSystem ss2 = new TestSubSystem2()
            {
                Order = 1, Log = true
            };

            s.AddSubSystem(ss0);
            s.AddSubSystem(ss1);
            s.AddSubSystem(ss2);

            a.LoadScene(s);
            ManualScheduler sc = new ManualScheduler();

            a.Scheduler = sc;

            a.Start();

            a.Stop();
        }
Exemple #6
0
        public void live_values_are_sent_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            BehaviorSubject <int> subject = new BehaviorSubject <int>(0, scheduler);

            StatsObserver <int> stats = new StatsObserver <int>();

            subject.Subscribe(stats);

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnCompleted();

            Assert.IsFalse(stats.NextCalled);

            scheduler.RunNext();
            Assert.AreEqual(1, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0 }));
            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.AreEqual(2, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1 }));
            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.AreEqual(3, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 0, 1, 2 }));
            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.IsTrue(stats.CompletedCalled);
        }
Exemple #7
0
        public void time_offset_excludes_values_of_exact_offset()
        {
            var stats = new StatsObserver <IList <int> >();

            var valueScheduler  = new ManualScheduler();
            var bufferScheduler = new ManualScheduler();

            DateTimeOffset startTime = DateTimeOffset.UtcNow;

            Observable.Range(0, 5, valueScheduler)
            .BufferWithTime(TimeSpan.FromMilliseconds(30), TimeSpan.FromMilliseconds(20), bufferScheduler)
            .Subscribe(stats);

            Assert.IsFalse(stats.NextCalled);

            bufferScheduler.Now = startTime.AddMilliseconds(10);
            valueScheduler.RunNext();

            bufferScheduler.Now = startTime.AddMilliseconds(20); // exact offset value
            valueScheduler.RunNext();

            bufferScheduler.Now = startTime.AddMilliseconds(30);
            valueScheduler.RunNext();

            bufferScheduler.RunNext();
            bufferScheduler.RunNext();

            Assert.AreEqual(2, stats.NextCount);
            Assert.AreEqual(1, stats.NextValues[1].Count);
        }
Exemple #8
0
        public void each_subscriber_is_scheduled_individually()
        {
            ManualScheduler scheduler = new ManualScheduler();

            AsyncSubject <int> subject = new AsyncSubject <int>(scheduler);

            StatsObserver <int> statsA = new StatsObserver <int>();
            StatsObserver <int> statsB = new StatsObserver <int>();

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnCompleted();

            subject.Subscribe(statsA);
            subject.Subscribe(statsB);


            scheduler.RunNext();

            Assert.IsTrue(statsA.NextCalled);
            Assert.IsFalse(statsB.NextCalled);

            scheduler.RunNext();

            Assert.IsTrue(statsB.NextCalled);
        }
Exemple #9
0
        public void errors_do_not_wait_for_interval()
        {
            var scheduler = new ManualScheduler();

            var stats = new StatsObserver <int>();

            Observable.Throw <int>(new ApplicationException())
            .Sample(TimeSpan.FromSeconds(1), scheduler)
            .Subscribe(stats);

            Assert.IsTrue(stats.ErrorCalled);
        }
Exemple #10
0
        public void errors_cancel_interval()
        {
            var scheduler = new ManualScheduler();

            var stats = new StatsObserver <int>();

            Observable.Throw <int>(new ApplicationException())
            .Sample(TimeSpan.FromSeconds(1), scheduler)
            .Subscribe(stats);

            Assert.AreEqual(0, scheduler.QueueSize);
        }
Exemple #11
0
        public void completion_occurs_after_interval()
        {
            var scheduler = new ManualScheduler();
            var stats     = new StatsObserver <int>();

            Observable.Empty <int>()
            .Sample(TimeSpan.FromSeconds(1), scheduler)
            .Subscribe(stats);

            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();
            Assert.IsTrue(stats.CompletedCalled);
        }
Exemple #12
0
        public static void SchedulerTest()
        {
            Application a = new Application();
            Scene       s = new Scene();

            a.LoadScene(s);
            ManualScheduler sc = new ManualScheduler();

            sc.Log      = true;
            a.Scheduler = sc;

            a.Start();
            a.Stop();
        }
Exemple #13
0
        public void scheduler_is_used_for_completion_when_take_is_zero()
        {
            var scheduler = new ManualScheduler();

            var stats = new StatsObserver <int>();

            new Subject <int>().Take(0, scheduler).Subscribe(stats);

            Assert.IsFalse(stats.CompletedCalled);

            scheduler.RunNext();

            Assert.IsTrue(stats.CompletedCalled);
        }
Exemple #14
0
        public void publishing_is_run_through_publishing_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            obs = Observable.Empty <int>(scheduler);

            bool completed = false;

            var subs = obs.Subscribe(x => { }, () => completed = true);

            Assert.IsFalse(completed);

            scheduler.RunAll();

            Assert.IsTrue(completed);
        }
Exemple #15
0
        public void buffer_is_flushed_on_error()
        {
            var stats = new StatsObserver <IList <int> >();

            var bufferScheduler = new ManualScheduler();

            DateTimeOffset startTime = DateTimeOffset.UtcNow;

            Observable.Range(0, 5).Concat(Observable.Throw <int>(new Exception()))
            .BufferWithTime(TimeSpan.FromMilliseconds(30), bufferScheduler)
            .Subscribe(stats);

            Assert.IsTrue(stats.ErrorCalled);
            Assert.AreEqual(1, stats.NextCount);
            Assert.AreEqual(5, stats.NextValues[0].Count);
        }
Exemple #16
0
        public void zero_length_list_is_emitted_when_no_values_are_available()
        {
            var stats = new StatsObserver <IList <int> >();

            var scheduler = new ManualScheduler();

            var manObs = Observable.Never <int>()
                         .BufferWithTime(TimeSpan.FromMilliseconds(1), scheduler)
                         .Take(1)
                         .Subscribe(stats);

            scheduler.RunNext();

            Assert.AreEqual(1, stats.NextCount);
            Assert.AreEqual(0, stats.NextValues[0].Count);
        }
Exemple #17
0
        public void scheduler_is_not_used_when_count_great_than_zero()
        {
            var scheduler = new ManualScheduler();

            var subject = new StatsSubject <int>();

            var stats = new StatsObserver <int>();

            subject.Take(3, scheduler).Subscribe(stats);

            subject.OnNext(0);
            subject.OnNext(1);
            subject.OnNext(2);

            Assert.AreEqual(0, scheduler.QueueSize);
        }
Exemple #18
0
        public void Setup()
        {
            tmpFiles = new FileCleaner();
            config   = FixtureSetup.Config;
            client   = TestClient.CreateNaked(session);
            session.Save(client);

            user       = session.Load <User>(client.Users[0].Id);
            controller = new MainController {
                Request     = new HttpRequestMessage(),
                Session     = session,
                CurrentUser = user,
                Config      = config,
            };
            scheduler            = new ManualScheduler();
            RequestLog.Scheduler = scheduler;
        }
Exemple #19
0
        public void errors_are_sent_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            BehaviorSubject <int> subject = new BehaviorSubject <int>(0, scheduler);

            StatsObserver <int> stats = new StatsObserver <int>();

            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.IsFalse(stats.ErrorCalled);

            scheduler.RunNext();
            Assert.IsTrue(stats.ErrorCalled);
        }
Exemple #20
0
        public void scheduler_is_used_for_first_subscription()
        {
            var sourceA = new StatsSubject <int>();
            var sourceB = Observable.Empty <int>();

            var scheduler = new ManualScheduler();
            var stats     = new StatsObserver <int>();

            sourceA.Concat(sourceB, scheduler).Subscribe(stats);

            Assert.AreEqual(0, sourceA.SubscriptionCount);
            Assert.AreEqual(1, scheduler.QueueSize);

            scheduler.RunNext();

            Assert.AreEqual(1, sourceA.SubscriptionCount);
            Assert.AreEqual(0, scheduler.QueueSize);
        }
Exemple #21
0
        public void complete_is_sent_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            BehaviorSubject <int> subject = new BehaviorSubject <int>(0, scheduler);

            StatsObserver <int> stats = new StatsObserver <int>();

            subject.OnCompleted();

            subject.Subscribe(stats);

            Assert.IsFalse(stats.NextCalled);

            scheduler.RunNext();
            Assert.AreEqual(0, stats.NextCount);
            Assert.IsTrue(stats.CompletedCalled);
        }
Exemple #22
0
        public void catch_with_observer_subscribes_to_first_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            StatsObserver <IEvent <EventArgs> > observer = new StatsObserver <IEvent <EventArgs> >();

            EventOwner owner = new EventOwner();

            Observable.FromEvent <EventArgs>(x => owner.Event += x, x => owner.Event -= x)
            .Catch(Observable.Empty <IEvent <EventArgs> >(), scheduler)
            .Subscribe(observer);

            Assert.IsFalse(owner.HasSubscriptions);

            scheduler.RunAll();

            Assert.IsTrue(owner.HasSubscriptions);
        }
Exemple #23
0
        public static void EventLifecycleTest()
        {
            Application        a = new Application();
            Scene              s = new Scene();
            SimulationObject   o = s.AddObject();
            LifeCycleComponent c = o.AddComponent <LifeCycleComponent>();

            c.Log = true;

            a.LoadScene(s);
            ManualScheduler sc = new ManualScheduler();

            a.Scheduler = sc;

            a.Start();
            sc.ManualUpdate();
            a.Stop();
        }
Exemple #24
0
        public static void EventSubsystemToComponentTest()
        {
            Application a = new Application();
            Scene       s = new Scene();

            s.AddSubSystem(new TestSubSystem());
            SimulationObject   o = s.AddObject();
            LifeCycleComponent c = o.AddComponent <LifeCycleComponent>();

            a.LoadScene(s);
            ManualScheduler sc = new ManualScheduler();

            a.Scheduler = sc;

            a.Start();
            sc.ManualUpdate();
            a.Stop();
        }
Exemple #25
0
        public void interval_is_cancelled_on_completion()
        {
            var subject = new Subject <int>();

            var stats = new StatsObserver <int>();

            var scheduler = new ManualScheduler();

            subject
            .Sample(TimeSpan.FromSeconds(1), scheduler)
            .Subscribe(stats);

            subject.OnNext(0);
            subject.OnCompleted();
            scheduler.RunNext();

            Assert.AreEqual(0, scheduler.QueueSize);
        }
Exemple #26
0
        public static void SubSystemTest()
        {
            Application a = new Application();
            Scene       s = new Scene();

            s.AddSubSystem(new TestSubSystem()
            {
                Log = true
            });

            a.LoadScene(s);
            ManualScheduler sc = new ManualScheduler();

            a.Scheduler = sc;

            a.Start();

            a.Stop();
        }
Exemple #27
0
        public void no_value_is_emitted_if_sampled_value_hasnt_changed()
        {
            var subject = new Subject <int>();

            var stats = new StatsObserver <int>();

            var scheduler = new ManualScheduler();

            subject
            .Sample(TimeSpan.FromSeconds(1), scheduler)
            .Subscribe(stats);

            stats.OnNext(0);

            scheduler.RunNext();
            scheduler.RunNext();

            Assert.AreEqual(1, stats.NextCount);
        }
Exemple #28
0
        public void next_and_complete_are_scheduled_together()
        {
            ManualScheduler scheduler = new ManualScheduler();

            AsyncSubject <int> subject = new AsyncSubject <int>(scheduler);

            StatsObserver <int> statsA = new StatsObserver <int>();

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnCompleted();

            subject.Subscribe(statsA);

            scheduler.RunNext();

            Assert.IsTrue(statsA.NextCalled);
            Assert.IsTrue(statsA.CompletedCalled);
        }
Exemple #29
0
        public void uses_scheduler_to_schedule_samples()
        {
            var subject = new Subject <int>();

            var stats = new StatsObserver <int>();

            var scheduler = new ManualScheduler();

            subject
            .Sample(TimeSpan.FromSeconds(1), scheduler)
            .Subscribe(stats);

            Assert.AreEqual(1, scheduler.QueueSize);

            subject.OnNext(0);
            scheduler.RunNext();

            Assert.AreEqual(1, scheduler.QueueSize);
            Assert.AreEqual(1, stats.NextCount);
            Assert.AreEqual(0, stats.NextValues[0]);
        }
Exemple #30
0
        public void scheduler_is_used_to_distribute_values()
        {
            ManualScheduler scheduler = new ManualScheduler();

            AsyncSubject <int> subject = new AsyncSubject <int>(scheduler);

            StatsObserver <int> statsA = new StatsObserver <int>();

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnCompleted();

            subject.Subscribe(statsA);

            Assert.IsFalse(statsA.NextCalled);

            scheduler.RunNext();

            Assert.IsTrue(statsA.NextCalled);
        }