Exemple #1
0
        public void ItDoesWorkInOrder()
        {
            var complete1 = false;
            var complete2 = false;
            var complete3 = false;
            var queue = new WorkQueue();

            queue.Add(new WorkQueueItem(() => complete1 = true, 1));
            queue.Add(new WorkQueueItem(() => complete2 = true, 1));
            queue.Add(new WorkQueueItem(() => complete3 = true, 1));

            queue.DoUnitOfWork();
            Assert.That(complete1, Is.True);
            Assert.That(complete2, Is.False);
            Assert.That(complete3, Is.False);

            queue.DoUnitOfWork();
            Assert.That(complete1, Is.True);
            Assert.That(complete2, Is.True);
            Assert.That(complete3, Is.False);

            queue.DoUnitOfWork();
            Assert.That(complete1, Is.True);
            Assert.That(complete2, Is.True);
            Assert.That(complete3, Is.True);
        }
Exemple #2
0
 public ParallelWorkQueue()
 {
     _thread = new Thread(Run);
     _workQueue = new WorkQueue();
     _event = new AutoResetEvent(false);
     _thread.Start();
 }
Exemple #3
0
        public void ItKnowsWhenItHasWork()
        {
            var complete = false;
            var queue = new WorkQueue();

            queue.Add(new WorkQueueItem(() => complete = true, 1));

            Assert.That(queue.HasWork, Is.True);
        }
Exemple #4
0
        public void ItDoesWork()
        {
            var complete = false;
            var queue = new WorkQueue();

            queue.Add(new WorkQueueItem(() => complete = true, 1));

            queue.DoUnitOfWork();

            Assert.That(complete, Is.True);
        }
Exemple #5
0
        public void ItGivesUpOnWork()
        {
            var queue = new WorkQueue();

            queue.Add(new WorkQueueItem(() =>
            {
                throw new Exception();
            }, 2));

            queue.DoUnitOfWork();

            Assert.That(queue.HasWork, Is.False);
        }
Exemple #6
0
        public void ItRetriesWork()
        {
            var complete = false;
            var queue = new WorkQueue();

            queue.Add(new WorkQueueItem(() =>
            {
                complete = true;
                throw new Exception();
            }, 2, new[] { typeof(Exception) }));

            queue.DoUnitOfWork();

            Assert.That(complete, Is.True);

            complete = false;
            queue.DoUnitOfWork();

            Assert.That(complete, Is.True);
        }
Exemple #7
0
        public void ItKnowsWhenItDoesNotHaveWork()
        {
            var queue = new WorkQueue();

            Assert.That(queue.HasWork, Is.False);
        }
Exemple #8
0
        public void ItWaitsToDoWork()
        {
            var complete = false;
            var queue = new WorkQueue();

            queue.Add(new WorkQueueItem(() => complete = true, 1));

            Assert.That(complete, Is.False);
        }