public void Should_return_false_if_there_are_no_subscribers() { Fiber fiber = new SynchronousFiber(); Channel <UserUpdate> channel = new BroadcastChannel <UserUpdate>(new Channel <UserUpdate>[] {}); var update = new UserUpdate(); channel.Send(update); // exception here? or just ignore }
public void Should_return_false_if_there_are_no_subscribers() { Fiber fiber = new SynchronousFiber(); Channel<UserUpdate> channel = new BroadcastChannel<UserUpdate>(new Channel<UserUpdate>[] {}); var update = new UserUpdate(); channel.Send(update); // exception here? or just ignore }
public void Should_filter_out_unwanted_messages() { var update = new UserUpdate {LastActivity = DateTime.Now - 5.Minutes()}; Fiber fiber = new SynchronousFiber(); var future = new Future<UserUpdate>(); var filter = new FilterChannel<UserUpdate>(fiber, future, x => x.LastActivity > DateTime.Now); Channel<UserUpdate> channel = new PublishSubscribeChannel<UserUpdate>(fiber, new[] {filter}); channel.Send(update); Assert.IsFalse(future.WaitUntilCompleted(1.Seconds())); }
public void Should_filter_out_unwanted_messages() { var update = new UserUpdate { LastActivity = DateTime.Now - 5.Minutes() }; Fiber fiber = new SynchronousFiber(); var future = new FutureChannel <UserUpdate>(); var filter = new FilterChannel <UserUpdate>(fiber, future, x => x.LastActivity > DateTime.Now); Channel <UserUpdate> channel = new BroadcastChannel <UserUpdate>(new[] { filter }); channel.Send(update); Assert.IsFalse(future.WaitUntilCompleted(1.Seconds())); }
public void Schedule() { var fiber = new SynchronousFiber(); var count = 0; var reset = new AutoResetEvent(false); Action one = () => Assert.AreEqual(0, count++); Action two = () => Assert.AreEqual(1, count++); Action three = delegate { Assert.AreEqual(2, count++); reset.Set(); }; var thread = new TimerScheduler(fiber); thread.Schedule(50, fiber, three); thread.Schedule(1, fiber, one); thread.Schedule(1, fiber, two); Assert.IsTrue(reset.WaitOne(10000, false)); }
public void Should_schedule_events() { var update = new UserUpdate {LastActivity = DateTime.Now - 5.Minutes()}; Fiber fiber = new SynchronousFiber(); var future = new Future<UserUpdate>(); Channel<UserUpdate> channel = new PublishSubscribeChannel<UserUpdate>(fiber, new Channel<UserUpdate>[] {future}); var scheduler = new TimerFiberScheduler(fiber); scheduler.Schedule(1000, fiber, () => channel.Send(update)); Thread.Sleep(500); Assert.IsFalse(future.WaitUntilCompleted(0.Seconds())); Assert.IsTrue(future.WaitUntilCompleted(1.Seconds())); }
public void Should_schedule_events() { var update = new UserUpdate { LastActivity = DateTime.Now - 5.Minutes() }; Fiber fiber = new SynchronousFiber(); var future = new FutureChannel <UserUpdate>(); Channel <UserUpdate> channel = new BroadcastChannel <UserUpdate>(new Channel <UserUpdate>[] { future }); var scheduler = new TimerScheduler(fiber); scheduler.Schedule(1000, fiber, () => channel.Send(update)); Thread.Sleep(500); Assert.IsFalse(future.WaitUntilCompleted(0.Seconds())); Assert.IsTrue(future.WaitUntilCompleted(1.Seconds())); }
public void Should_deliver_the_messages_at_once() { var queue = new SynchronousFiber(); var scheduler = new TimerScheduler(new SynchronousFiber()); var called = new Future <ICollection <MyMessage> >(); var consumer = new ConsumerChannel <ICollection <MyMessage> >(queue, called.Complete); var channel = new IntervalChannel <MyMessage>(queue, scheduler, 2.Seconds(), consumer); for (int i = 0; i < 5; i++) { channel.Send(new MyMessage()); } called.WaitUntilCompleted(4.Seconds()).ShouldBeTrue(); channel.Dispose(); called.Value.ShouldNotBeNull(); called.Value.Count.ShouldEqual(5); }
public void Should_deliver_the_messages_at_once() { var queue = new SynchronousFiber(); var scheduler = new TimerFiberScheduler(new SynchronousFiber()); var called = new Future<ICollection<MyMessage>>(); var consumer = new ConsumerChannel<ICollection<MyMessage>>(queue, called.Complete); var channel = new IntervalChannel<MyMessage>(queue, scheduler, 2.Seconds(), consumer); for (int i = 0; i < 5; i++) { channel.Send(new MyMessage()); } called.WaitUntilCompleted(4.Seconds()).ShouldBeTrue(); channel.Dispose(); called.Value.ShouldNotBeNull(); called.Value.Count.ShouldEqual(5); }
public void Schedule1000In1ms() { var fiber = new SynchronousFiber(); var count = 0; var reset = new AutoResetEvent(false); Action one = delegate { count++; if (count == 1000) { reset.Set(); } }; var thread = new TimerScheduler(fiber); { for (var i = 0; i < 1000; i++) { thread.Schedule(i, fiber, one); } Assert.IsTrue(reset.WaitOne(1200, false)); } }
public void Schedule1000In1ms() { var fiber = new SynchronousFiber(); var count = 0; var reset = new AutoResetEvent(false); Action one = delegate { count++; if (count == 1000) { reset.Set(); } }; var thread = new TimerScheduler(fiber); { for (var i = 0; i < 1000; i++) { thread.Schedule(i, fiber,one); } Assert.IsTrue(reset.WaitOne(1200, false)); } }
public void Setup() { _fiber = new SynchronousFiber(); _timeout = 100.Milliseconds(); }