Exemplo n.º 1
0
        public void ShouldOnlyExecuteActionsQueuedWhileNotStopped()
        {
            var mockery = new MockRepository();
            var action1 = mockery.CreateMock<Action>();
            var action2 = mockery.CreateMock<Action>();
            var action3 = mockery.CreateMock<Action>();

            using (mockery.Record())
            {
                action1();
                action2();
            }

            using (mockery.Playback())
            {
                var queue = new DefaultQueue();
                queue.Enqueue(action1);

                var run = new Thread(queue.Run);

                run.Start();
                Thread.Sleep(100);
                queue.Enqueue(action2);
                queue.Stop();
                queue.Enqueue(action3);
                Thread.Sleep(100);
                run.Join();
            }
        }
Exemplo n.º 2
0
        private static void Run(long n, bool useSameThread)
        {
            AutoResetEvent done1 = new AutoResetEvent(false), done2 = new AutoResetEvent(false);

            IQueue q1 = new DefaultQueue(), q2 = new DefaultQueue();
            IFiber f1 = new ThreadFiber(q1), f2 = useSameThread ? f1 : new ThreadFiber(q2);
            IChannel<long> c1 = new Channel<long>(), c2 = new Channel<long>();

            c2.Subscribe(f2, (x) =>
                {
                    if (x < n)
                    {
                        c1.Publish(++x);
                    }
                    if (x >= n)
                    {
                        done2.Set();
                    }
                }
            );

            c1.Subscribe(f1, (x) =>
                {
                    if (x < n)
                    {
                        c2.Publish(++x);
                    }
                    if (x >= n)
                    {
                        done1.Set();
                    }
                }
            );

            f1.Start();
            if (!useSameThread) f2.Start();

            c1.Publish(0);
            EventWaitHandle.WaitAll(new[] { done1, done2 });

            f1.Dispose();
            f2.Dispose();
        }
Exemplo n.º 3
0
        public void NoExceptionHandling()
        {
            var repo = new MockRepository();
            var action = repo.CreateMock<Action>();
            var failure = new Exception();
            action();
            LastCall.Throw(failure);

            repo.ReplayAll();

            var queue = new DefaultQueue();
            queue.Enqueue(action);

            try
            {
                queue.ExecuteNextBatch();
                Assert.Fail("Should throw Exception");
            }
            catch (Exception commFailure)
            {
                Assert.AreSame(failure, commFailure);
            }
            repo.VerifyAll();
        }