예제 #1
0
        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
        }
예제 #2
0
        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()));
        }
예제 #3
0
        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()));
        }
예제 #4
0
		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);
		}