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(); } }
public void Now_Should_be_accurate() { using (var sys = ActorSystem.Create("Foo")) { ITimeProvider timeProvider = new HashedWheelTimerScheduler(sys.Settings.Config, sys.Log); try { Math.Abs((timeProvider.Now - DateTimeOffset.Now).TotalMilliseconds).ShouldBeLessThan(20); } finally { timeProvider.AsInstanceOf <IDisposable>().Dispose(); } } }
public void When_ScheduleTellRepeatedly_with_invalid_interval_Then_exception_is_thrown(int invalidInterval) { IScheduler scheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log); try { XAssert.Throws <ArgumentOutOfRangeException>(() => scheduler.ScheduleTellRepeatedly(42, invalidInterval, TestActor, "Test", ActorRefs.NoSender) ); ExpectNoMsg(50); } finally { scheduler.AsInstanceOf <IDisposable>().Dispose(); } }
public void When_ScheduleRepeatedly_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.ScheduleRepeatedly(0, 100, () => 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(); } }
public void When_ScheduleRepeatedly_and_then_canceling_before_they_occur_Then_their_actions_should_not_be_invoked() { // Prepare, set up actions to be fired IActionScheduler scheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log); try { var cancelable = new Cancelable(scheduler); scheduler.ScheduleRepeatedly(100, 2, () => TestActor.Tell("Test"), cancelable); cancelable.Cancel(); //Validate that no messages were sent ExpectNoMsg(150); } finally { scheduler.AsInstanceOf <IDisposable>().Dispose(); } }
public void ScheduleRepeatedly_in_milliseconds_Tests(int initialDelay, int interval) { // Prepare, set up actions to be fired IActionScheduler testScheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log); try { testScheduler.ScheduleRepeatedly(initialDelay, interval, () => TestActor.Tell("Test")); //Just check that we receives more than one message ExpectMsg("Test"); ExpectMsg("Test"); ExpectMsg("Test"); } finally { testScheduler.AsInstanceOf <IDisposable>().Dispose(); } }
public void ScheduleTellRepeatedly_TimeSpan_Tests(int initialDelay, int interval) { //Prepare, set up actions to be fired IScheduler scheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log); try { scheduler.ScheduleTellRepeatedly(TimeSpan.FromMilliseconds(initialDelay), TimeSpan.FromMilliseconds(interval), TestActor, "Test", ActorRefs.NoSender); //Just check that we receives more than one message ExpectMsg("Test"); ExpectMsg("Test"); ExpectMsg("Test"); } finally { scheduler.AsInstanceOf <IDisposable>().Dispose(); } }
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(); } }
public void When_canceling_existing_running_repeaters_Then_their_future_actions_should_not_be_invoked() { // Prepare, set up actions to be fired IScheduler scheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log); try { var cancelable = new Cancelable(scheduler); scheduler.ScheduleTellRepeatedly(0, 150, TestActor, "Test", ActorRefs.NoSender, cancelable); ExpectMsg("Test"); cancelable.Cancel(); //Validate that no more messages were sent ExpectNoMsg(200); } finally { scheduler.AsInstanceOf <IDisposable>().Dispose(); } }
public void When_canceling_existing_running_repeaters_by_scheduling_the_cancellation_ahead_of_time_Then_their_future_actions_should_not_be_invoked() { // Prepare, set up actions to be fired IActionScheduler scheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log); try { var cancelableOdd = new Cancelable(scheduler); scheduler.ScheduleRepeatedly(1, 150, () => TestActor.Tell("Test"), cancelableOdd); cancelableOdd.CancelAfter(50); //Expect one message ExpectMsg("Test"); //Validate that no messages were sent ExpectNoMsg(200); } finally { scheduler.AsInstanceOf <IDisposable>().Dispose(); } }
public void ScheduleTellOnceTests(int[] times) { // Prepare, set up messages to be sent IScheduler scheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log); try { foreach (var time in times) { scheduler.ScheduleTellOnce(time, TestActor, "Test" + time, ActorRefs.NoSender); } ExpectMsg("Test1"); ExpectMsg("Test50"); ExpectMsg("Test110"); ExpectNoMsg(50); } finally { scheduler.AsInstanceOf <IDisposable>().Dispose(); } }
public void When_ScheduleRepeatedly_action_crashes_Then_no_more_calls_will_be_scheduled() { IActionScheduler testScheduler = new HashedWheelTimerScheduler(Sys.Settings.Config, Log); try { var timesCalled = 0; testScheduler.ScheduleRepeatedly(0, 10, () => { Interlocked.Increment(ref timesCalled); throw new Exception("Crash"); }); AwaitCondition(() => timesCalled >= 1); Thread.Sleep(200); //Allow any scheduled actions to be fired. //We expect only one of the scheduled actions to actually fire timesCalled.ShouldBe(1); } finally { testScheduler.AsInstanceOf <IDisposable>().Dispose(); } }