Esempio n. 1
0
        public void Schedule1000In1ms()
        {
            var queue = new SynchronousCommandQueue();
            queue.Run();

            var count = 0;
            var reset = new AutoResetEvent(false);
            Action one = delegate
                {
                    count++;
                    if (count == 1000)
                    {
                        reset.Set();
                    }
                };

            using (var thread = new ThreadPoolScheduler())
            {
                for (var i = 0; i < 1000; i++)
                {
                    thread.Schedule(i, () => queue.Enqueue(one));
                }
                Assert.IsTrue(reset.WaitOne(1200, false));
            }
        }
Esempio n. 2
0
        public void Timer_Based_Demo()
        {
            ThreadPoolScheduler scheduler = new ThreadPoolScheduler();
            scheduler.Schedule(0, 1000, () =>
                {
                    Trace.WriteLine("Starting it up");
                    _ping.Start(10, _pong);
                });

            Thread.Sleep(6000);
        }
Esempio n. 3
0
 public void TimeTilNext()
 {
     var queue = new SynchronousCommandQueue();
     queue.Run();
     Action action = () => Assert.Fail("Should not execute");
     using (var timer = new ThreadPoolScheduler())
     {
         long now = 0;
         long span = 0;
         timer.QueueEvent(new SingleEvent(500, () => queue.Enqueue(action), now));
         Assert.IsTrue(timer.GetNextScheduledTime(ref span, 0));
         Assert.AreEqual(500, span);
         Assert.IsTrue(timer.GetNextScheduledTime(ref span, 499));
         Assert.AreEqual(1, span);
         Assert.IsFalse(timer.GetNextScheduledTime(ref span, 500));
         Assert.AreEqual(0, span);
     }
 }
Esempio n. 4
0
        public void Should_schedule_events()
        {
            Channel<UserUpdate> channel = new SynchronousChannel<UserUpdate>();

            var update = new UserUpdate {LastActivity = DateTime.Now - 5.Minutes()};

            CommandQueue queue = new SynchronousCommandQueue();

            var scheduler = new ThreadPoolScheduler();

            var future = new Future<UserUpdate>();

            channel.Subscribe(queue, future.Complete);

            scheduler.Schedule(1000, () => channel.Publish(update));

            Thread.Sleep(500);

            Assert.IsFalse(future.IsAvailable(0.Seconds()));

            Assert.IsTrue(future.IsAvailable(1.Seconds()));
        }
Esempio n. 5
0
        public void Schedule()
        {
            var queue = new SynchronousCommandQueue();

            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();
                };

            using (var thread = new ThreadPoolScheduler())
            {
                thread.Schedule(50, () => queue.Enqueue(three));
                thread.Schedule(1, () => queue.Enqueue(one));
                thread.Schedule(1, () => queue.Enqueue(two));
                Assert.IsTrue(reset.WaitOne(10000, false));
            }
        }
Esempio n. 6
0
 public void TimeTilNextNothingQueued()
 {
     using (var timer = new ThreadPoolScheduler())
     {
         long result = 0;
         Assert.IsFalse(timer.GetNextScheduledTime(ref result, 100));
         Assert.AreEqual(0, result);
     }
 }