public void Action_Stops_On_Stop() { long count = 0; TimerRuntimeService timerService = new TimerRuntimeService(); timerService.AddEvent(new TimerEvent(() => { Interlocked.Increment(ref count); }, TimeSpan.FromMilliseconds(1000))); DeliveryCore deliveryCore = new DirectDeliveryCore(); using (ServiceBusRuntime runtime = new ServiceBusRuntime(deliveryCore, timerService)) { runtime.Start(); Thread.Sleep(1100); long beforeStopCount = Interlocked.Read(ref count); runtime.Stop(); Assert.GreaterOrEqual(beforeStopCount, 0); Thread.Sleep(1100); long afterStopCount = Interlocked.Read(ref count); Assert.GreaterOrEqual(beforeStopCount, afterStopCount); } }
private TimerRuntimeService getTimerService() { try { TimerRuntimeService timerService = Runtime.ServiceLocator.GetInstance <TimerRuntimeService>(); return(timerService); } catch (ActivationException) { throw new InvalidOperationException("A TimerRuntimeService instance must be registered with the bus to use the HeartbeatRuntimeService."); } }
public void Action_Ticks_On_Intervals() { long count = 0; TimerRuntimeService timerService = new TimerRuntimeService(); timerService.AddEvent(new TimerEvent(() => { Interlocked.Increment(ref count); }, TimeSpan.FromMilliseconds(1000))); DeliveryCore deliveryCore = new DirectDeliveryCore(); using (ServiceBusRuntime runtime = new ServiceBusRuntime(deliveryCore, timerService)) { runtime.Start(); Thread.Sleep(9100); long curCount = Interlocked.Read(ref count); runtime.Stop(); Assert.AreEqual(9, curCount); } }
public void Event_Starts_At_Preset_Time() { long count = 0; TimerRuntimeService timerService = new TimerRuntimeService(); timerService.AddEvent(new TimerEvent(() => { Interlocked.Increment(ref count); }, TimeSpan.FromMilliseconds(100), DateTime.Now.AddSeconds(5))); DeliveryCore deliveryCore = new DirectDeliveryCore(); using (ServiceBusRuntime runtime = new ServiceBusRuntime(deliveryCore, timerService)) { runtime.Start(); Thread.Sleep(3000); long curCount = Interlocked.Read(ref count); Assert.AreEqual(0, curCount); Thread.Sleep(3000); curCount = Interlocked.Read(ref count); runtime.Stop(); Assert.GreaterOrEqual(curCount, 0); } }
public void Event_Auto_Starts_When_Running() { long count = 0; TimerRuntimeService timerService = new TimerRuntimeService(); var evt = new TimerEvent(() => { Interlocked.Increment(ref count); }, TimeSpan.FromMilliseconds(100)); DeliveryCore deliveryCore = new DirectDeliveryCore(); using (ServiceBusRuntime runtime = new ServiceBusRuntime(deliveryCore, timerService)) { runtime.Start(); Thread.Sleep(500); long curCount = Interlocked.Read(ref count); Assert.AreEqual(0, curCount); timerService.AddEvent(evt); Thread.Sleep(500); curCount = Interlocked.Read(ref count); runtime.Stop(); Assert.GreaterOrEqual(curCount, 3); } }