Beispiel #1
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 #2
0
        public void TestAsyncProcessorEvents()
        {
            _jobCount = 0;
            AsyncProcessor proc = new AsyncProcessor(false);

            using ( proc )
            {
                proc.ThreadStarted     += new EventHandler(proc_ThreadStarted);
                proc.ThreadStarted     += new EventHandler(proc_ThreadStarted1);
                proc.ThreadStarted     += new EventHandler(proc_ThreadStarted2);
                proc.ThreadFinished    += new EventHandler(proc_ThreadStarted);
                proc.ThreadFinished    += new EventHandler(proc_ThreadStarted1);
                proc.FillingEmptyQueue += new EventHandler(proc_FillingEmptyQueue);
                proc.QueueGotEmpty     += new EventHandler(proc_QueueGotEmpty);
                proc.QueueGotEmpty     += new EventHandler(proc_QueueGotEmpty1);
                proc.JobStarting       += new EventHandler(proc_JobStarting);
                proc.JobFinished       += new EventHandler(proc_JobFinished);
                proc.JobQueued         += new JetBrains.Omea.AsyncProcessing.AsyncProcessor.JobDelegate(proc_JobQueued);
                proc.QueueJob(new SleepJob(0));
                proc.QueueJob(new SleepJob(0));
                proc.QueueJob(new SleepJob(0));
                proc.QueueJob(new SleepJob(0));
                proc.QueueEndOfWork();
                proc.EmployCurrentThread();
            }
            if (_jobCount != 0)
            {
                throw new Exception("TestAsyncProcessorEvents() failed. _jobCount = " + _jobCount);
            }
        }
Beispiel #3
0
        public void TestEmployCurrentThread()
        {
            _jobCount = 0;
            AsyncProcessor proc = new AsyncProcessor(false);

            using ( proc )
            {
                proc.QueueJob(new SleepJob(0));
                proc.QueueJob(new SleepJob(0));
                proc.QueueJob(new SleepJob(0));
                proc.QueueEndOfWork();
                proc.EmployCurrentThread();
            }
            if (_jobCount != 3)
            {
                throw new Exception("TestEmployCurrentThread() failed. _jobCount = " + _jobCount);
            }
        }
Beispiel #4
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 #5
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();
                }
            }
        }