Beispiel #1
0
        public void TestTimedMergedJob()
        {
            AsyncProcessor processor = new AsyncProcessor();

            _jobCount = 0;
            using ( processor )
            {
                processor.QueueJobAt(DateTime.Now.AddSeconds(1), new TimedMergedJob());
                processor.QueueJobAt(DateTime.Now.AddSeconds(2), new TimedMergedJob());
                processor.QueueJobAt(DateTime.Now.AddSeconds(3), new TimedMergedJob());
                processor.QueueJobAt(DateTime.Now.AddSeconds(4), new TimedMergedJob());
                Thread.Sleep(4200);
            }
            if (_jobCount != 1)
            {
                throw new Exception("TestTimedMergedJob(): Timed merged job failed. _jobCount = " + _jobCount);
            }
        }
Beispiel #2
0
        public void TestCancellation()
        {
            _jobCount = 0;
            AsyncProcessor processor = new AsyncProcessor();

            using ( processor )
            {
                TimedJob job = new TimedJob();
                processor.QueueJobAt(DateTime.Now.AddSeconds(4), job);
                processor.QueueJobAt(DateTime.Now.AddSeconds(4.01), job);
                processor.CancelTimedJobs(job);
                processor.QueueEndOfWork();
                processor.WaitUntilFinished();
                if (_jobCount != -2)
                {
                    throw new Exception("TestCancellation() failed. _jobCount = " + _jobCount);
                }
            }
        }
Beispiel #3
0
        public void TestAbortAsyncProThread()
        {
            AsyncProcessor processor = new AsyncProcessor();

            _jobCount = 0;
            using ( processor )
            {
                processor.QueueJobAt(DateTime.Now.AddSeconds(-1), new TimedJob());
                processor.QueueJobAt(DateTime.Now.AddSeconds(2), new TimedJob());
                Thread.Sleep(500);
                processor.Thread.Abort();
                // after thread was aborted async processor should restart its own thread
                // and remain able to process units of work
                processor.QueueJob(new TimedJob());
                Thread.Sleep(2000);
            }
            if (_jobCount != 3)
            {
                throw new Exception("TestAbortAsyncProThread() failed. _jobCount = " + _jobCount);
            }
        }
Beispiel #4
0
        public void TestTimedJobs()
        {
            AsyncProcessor processor = new AsyncProcessor();

            _jobCount = 0;
            using ( processor )
            {
                processor.QueueJobAt(DateTime.Now.AddSeconds(-1), new TimedJob());
                processor.QueueJobAt(DateTime.Now.AddSeconds(1), new TimedJob());
                processor.QueueJobAt(DateTime.Now.AddSeconds(2), new TimedJob());
                processor.QueueJobAt(DateTime.Now.AddSeconds(2), new TimedJob());
                processor.QueueJobAt(DateTime.Now.AddSeconds(2), new TimedJob());
                processor.QueueJobAt(DateTime.Now.AddSeconds(3), new TimedJob());
                processor.QueueJobAt(DateTime.Now.AddSeconds(4), new TimedJob());
                Thread.Sleep(200);
                if (_jobCount != 1)
                {
                    throw new Exception("First timed job failed. _jobCount = " + _jobCount);
                }
                Thread.Sleep(1000);
                if (_jobCount != 2)
                {
                    throw new Exception("Second timed job failed. _jobCount = " + _jobCount);
                }
                Thread.Sleep(1000);
                if (_jobCount != 5)
                {
                    throw new Exception("Third-to-fifth  timed jobs failed. _jobCount = " + _jobCount);
                }
                Thread.Sleep(1000);
                if (_jobCount != 6)
                {
                    throw new Exception("Sixth timed job failed. _jobCount = " + _jobCount);
                }
                Thread.Sleep(1000);
            }
            if (_jobCount != 7)
            {
                throw new Exception("Seventh timed job failed. _jobCount = " + _jobCount);
            }
        }