Beispiel #1
0
        public void TestReenteringJobMixedWithOrdinaryJobs()
        {
            _jobCount = 0;
            AsyncProcessor processor = new AsyncProcessor(false);

            using ( processor )
            {
                const int total = 10;
                processor.QueueJob(JobPriority.AboveNormal, new SleepJob(0));
                processor.QueueJob(JobPriority.AboveNormal, new SleepJob(0));
                processor.QueueJob(JobPriority.AboveNormal, new SleepJob(0));
                processor.QueueJob(JobPriority.AboveNormal, new SleepJob(0));
                processor.QueueJob(new GroupJob(total, total));
                processor.QueueJob(new SleepJob(300));
                processor.QueueJob(new SleepJob(0));
                processor.QueueJob(new SleepJob(0));
                processor.QueueJob(JobPriority.Immediate, new SleepJob(0));
                processor.StartThread();
                Thread.Sleep(200);
                if (_jobCount != total + 7)
                {
                    throw new Exception("TestReenteringJobMixedWithOrdinaryJobs() failed (first check). _jobCount = " + _jobCount);
                }
                Thread.Sleep(150);
                if (_jobCount != total + 11)
                {
                    throw new Exception("TestReenteringJobMixedWithOrdinaryJobs() failed (second check). _jobCount = " + _jobCount);
                }
            }
        }
Beispiel #2
0
        public void TestMultipleAsyncProcessors()
        {
            const int      count          = 300000;
            AsyncProcessor lockProcessor1 = new AsyncProcessor(false);
            AsyncProcessor lockProcessor2 = new AsyncProcessor(false);
            AsyncProcessor lockProcessor3 = new AsyncProcessor(false);
            AsyncProcessor lockProcessor4 = new AsyncProcessor(false);
            ArrayList      lockJobs       = new ArrayList(count);

            for (int i = 0; i < count; ++i)
            {
                lockJobs.Add(new LockJob());
            }

            for (int i = 0; i < count; ++i)
            {
                lockProcessor1.QueueJob((AbstractJob)lockJobs[i]);
                lockProcessor2.QueueJob((AbstractJob)lockJobs[i]);
                lockProcessor3.QueueJob((AbstractJob)lockJobs[i]);
                lockProcessor4.QueueJob((AbstractJob)lockJobs[i]);
            }
            lockProcessor1.QueueEndOfWork();
            lockProcessor2.QueueEndOfWork();
            lockProcessor3.QueueEndOfWork();
            lockProcessor4.QueueEndOfWork();
            lockProcessor1.StartThread();
            lockProcessor2.StartThread();
            lockProcessor3.StartThread();
            lockProcessor4.StartThread();
            lockProcessor1.WaitUntilFinished();
            lockProcessor2.WaitUntilFinished();
            lockProcessor3.WaitUntilFinished();
            lockProcessor4.WaitUntilFinished();
        }
Beispiel #3
0
        public void TestIdleRepeated()
        {
            Console.Out.WriteLine("Starting TestIdleRepetable()");
            AsyncProcessor processor = new AsyncProcessor(false);

            _jobCount = 0;
            using ( processor )
            {
                processor.IdlePeriod = 500;
                processor.StartThread();
                processor.QueueIdleJob(new IdleRepeatedJob(processor));
                Thread.Sleep(1500);
            }
            if (_jobCount != 4)
            {
                throw new Exception("TestIdle() failed. _jobCount = " + _jobCount);
            }
        }
Beispiel #4
0
        public void TestSpinWaitLock()
        {
            SpinWaitLock   aLock = new SpinWaitLock();
            AsyncProcessor proc1 = new AsyncProcessor(false);
            AsyncProcessor proc2 = new AsyncProcessor(false);

            using ( proc1 )
            {
                using ( proc2 )
                {
                    for (int i = 0; i < 100000; ++i)
                    {
                        proc1.QueueJob(new SpinWaitLockJob(aLock));
                        proc2.QueueJob(new SpinWaitLockJob(aLock));
                    }
                    proc1.StartThread();
                    proc2.StartThread();
                    proc1.QueueEndOfWork();
                    proc2.QueueEndOfWork();
                    proc1.WaitUntilFinished();
                    proc2.WaitUntilFinished();
                }
            }
        }