Example #1
0
        public void When_ScheduleOnce_many_at_the_same_time_Then_all_fires(int[] times)
        {
            // Prepare, set up actions to be fired
            IActionScheduler scheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log);

            try
            {
                foreach (var time in times)
                {
                    var t = time;
                    scheduler.ScheduleOnce(time, () => TestActor.Tell("Test" + t));
                }

                //Perform the test
                ExpectMsg("Test1");
                ExpectMsg("Test1");
                ExpectMsg("Test50");
                ExpectMsg("Test50");
                ExpectMsg("Test100");
                ExpectMsg("Test100");
                ExpectNoMsg(50);
            }
            finally
            {
                scheduler.AsInstanceOf <IDisposable>().Dispose();
            }
        }
Example #2
0
        public void ScheduleOnceTests()
        {
            // Prepare, set up actions to be fired
            IActionScheduler testScheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log);

            try
            {
                testScheduler.ScheduleOnce(50, () => TestActor.Tell("Test1"));
                testScheduler.ScheduleOnce(100, () => TestActor.Tell("Test2"));

                ExpectMsg("Test1");
                ExpectMsg("Test2");

                ExpectNoMsg(100);
            }
            finally
            {
                testScheduler.AsInstanceOf <IDisposable>().Dispose();
            }
        }
Example #3
0
        public void When_ScheduleOnce_with_invalid_delay_Then_exception_is_thrown(int invalidTime)
        {
            IActionScheduler testScheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log);

            try
            {
                XAssert.Throws <ArgumentOutOfRangeException>(() =>
                                                             testScheduler.ScheduleOnce(invalidTime, () => { })
                                                             );
            }
            finally
            {
                testScheduler.AsInstanceOf <IDisposable>().Dispose();
            }
        }
Example #4
0
        public void When_ScheduleOnce_with_0_delay_Then_action_is_executed_immediately()
        {
            IActionScheduler testScheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log);

            try
            {
                var manualResetEvent = new ManualResetEventSlim();
                manualResetEvent.IsSet.ShouldBeFalse();
                testScheduler.ScheduleOnce(0, () => manualResetEvent.Set());

                manualResetEvent.Wait(500).ShouldBeTrue();
            }
            finally
            {
                testScheduler.AsInstanceOf <IDisposable>().Dispose();
            }
        }
        public void When_ScheduleOnce_using_canceled_Cancelable_Then_their_actions_should_not_be_invoked()
        {
            // Prepare, set up actions to be fired
            IActionScheduler scheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log);

            try
            {
                var canceled = Cancelable.CreateCanceled();
                scheduler.ScheduleOnce(0, () => TestActor.Tell("Test"), canceled);

                //Validate that no messages were sent
                ExpectNoMsg(100);
            }
            finally
            {
                scheduler.AsInstanceOf <IDisposable>().Dispose();
            }
        }