예제 #1
0
 protected override void Execute()
 {
     if (++_jobCount < 5)
     {
         _proc2.RunJob(new RunJobInProcessor(_proc1, this));
     }
 }
예제 #2
0
 protected override void Execute()
 {
     if (_jobCount < _maxJobs)
     {
         ++_jobCount;
         _proc1.RunJob(new CrossRunJob(_proc2, _proc1));
     }
 }
예제 #3
0
        public void TestRunJob()
        {
            _jobCount = 0;
            AsyncProcessor processor = new AsyncProcessor();

            using ( processor )
            {
                SleepJob job   = new SleepJob(400);
                DateTime start = DateTime.Now;
                // sleep for 2 secodns in processor's thread
                processor.RunJob(job);
                processor.RunJob(job);
                if (start.AddSeconds(0.79) >= DateTime.Now)
                {
                    throw new Exception("TestRunJob() failed.");
                }
            }
        }
예제 #4
0
 [SetUp] public void SetUp()
 {
     _core       = new TestCore();
     _resourceAP = new AsyncProcessor(true);
     _core.SetResourceAP(_resourceAP);
     _storage = _core.ResourceStore;
     _storage = _storage;
     MyPalStorage.Storage.OwnerThread = _resourceAP.Thread;
     _manager = new ProtocolHandlerManager();
     _core.SetProtocolHandlerManager(_manager);
     _plugin = new MockPlugin();
     _resourceAP.RunJob(new MethodInvoker(RegisterResources));
 }
예제 #5
0
        public void TestNullHandleAfterFinish()
        {
            AsyncProcessor processor = new AsyncProcessor();

            using ( processor )
            {
                SleepJob job = new SleepJob(0);
                processor.RunJob(job);
                if (job.NextWaitHandle != null)
                {
                    throw new Exception("TestNullHandleAfterFinish() failed.");
                }
            }
        }
예제 #6
0
        [Test] public void RegisterFromAnotherThread()
        {
            AsyncProcessor processor = new AsyncProcessor(true);

            using ( processor )
            {
                RegisterProtocolHandler handler = new RegisterProtocolHandler(_manager, _plugin);
                processor.RunJob(handler);
                if (handler.Exception != null)
                {
                    throw handler.Exception;
                }
            }
        }
예제 #7
0
        public void TestRunReenteringGroup()
        {
            AsyncProcessor processor = new AsyncProcessor();

            using ( processor )
            {
                const int total = 5;
                _jobCount = 0;
                GroupJob job = new GroupJob(total, 1);
                processor.RunJob(job);
                if (_jobCount != total + 3)
                {
                    throw new Exception("TestRunReenteringGroup(): GroupJob( total, 1 ) failed. _jobCount = " + _jobCount);
                }
                _jobCount = 0;
                job       = new GroupJob(total, 3);
                processor.RunJob(job);
                if (_jobCount != total + 3)
                {
                    throw new Exception("TestRunReenteringGroup(): GroupJob( total, 3 ) failed. _jobCount = " + _jobCount);
                }
                _jobCount = 0;
                job       = new GroupJob(total, 5);
                processor.RunJob(job);
                if (_jobCount != total + 3)
                {
                    throw new Exception("TestRunReenteringGroup(): GroupJob( total, 5 ) failed. _jobCount = " + _jobCount);
                }
                _jobCount = 0;
                job       = new GroupJob(total, 11);
                processor.RunJob(job);
                if (_jobCount != total + 3)
                {
                    throw new Exception("TestRunReenteringGroup(): GroupJob( total, 11 ) failed. _jobCount = " + _jobCount);
                }
            }
        }
예제 #8
0
        public void TestRunMultipleStepJob()
        {
            MultipleStepJob job       = new MultipleStepJob();
            AsyncProcessor  processor = new AsyncProcessor();

            using ( processor )
            {
                processor.RunJob(job);
            }

            if (job.counter != 5)
            {
                throw new Exception("TestRunMultipleStepJob(): multiple step async processing. " + job.counter);
            }
        }
예제 #9
0
        public FullTextIndexer.QueryResult QueryList(string query)
        {
            FullTextIndexer.QueryResult qr;
            ThreadPriority priority = _textProcessor.ThreadPriority;

            _textProcessor.ThreadPriority = ThreadPriority.Normal;
            try
            {
                qr = (FullTextIndexer.QueryResult)_textProcessor.RunJob("Searching for " + query,
                                                                        new QueryRequest(_textIndexer.ProcessQuery), query, Interlocked.Increment(ref _dummyCounter));
            }
            finally
            {
                _textProcessor.ThreadPriority = priority;
            }
            return(qr);
        }
예제 #10
0
        public void TestRunNonUniqieJobs()
        {
            SleepJob       job   = new SleepJob(200);
            AsyncProcessor proc  = new AsyncProcessor();
            AsyncProcessor proc1 = new AsyncProcessor();

            using ( proc )
            {
                using ( proc1 )
                {
                    proc.QueueJob(JobPriority.Immediate, job);
                    Thread.Sleep(50);
                    proc1.QueueJob(new JobRunner(job, proc));
                    Thread.Sleep(50);
                    proc.RunJob(job);   // this should throw the exception
                }
            }
        }
예제 #11
0
        public void TestRecurringRunEqualJobs()
        {
            _jobCount = 0;
            AsyncProcessor  proc1 = new AsyncProcessor();
            AsyncProcessor  proc2 = new AsyncProcessor();
            RecurringRunJob job   = new RecurringRunJob(proc1, proc2);

            using ( proc2 )
            {
                using ( proc1 )
                {
                    proc1.RunJob(job);
                }
            }
            if (_jobCount != 5)
            {
                throw new Exception("TestRecurringRunEqualJobs() failed. _jobCount = " + _jobCount);
            }
        }
예제 #12
0
        public void TestCrossRunJob()
        {
            _jobCount            = 0;
            CrossRunJob._maxJobs = AsyncProcessor._maxWaitableHandles * 2 - 2;
            AsyncProcessor proc1 = new AsyncProcessor();
            AsyncProcessor proc2 = new AsyncProcessor();
            CrossRunJob    job   = new CrossRunJob(proc1, proc2);

            using ( proc2 )
            {
                using ( proc1 )
                {
                    proc2.RunJob(job);
                }
            }
            if (_jobCount != CrossRunJob._maxJobs)
            {
                throw new Exception("TestCrossRunJob() failed. _jobCount = " + _jobCount);
            }
        }
예제 #13
0
        public void TestNonBlockingRun()
        {
            _jobCount = 0;
            AsyncProcessor proc1 = new AsyncProcessor();
            AsyncProcessor proc2 = new AsyncProcessor();

            using ( proc1 )
            {
                using ( proc2 )
                {
                    proc1.QueueJob(JobPriority.Immediate, new NonBlockingRunJob(proc2));
                    proc1.RunJob(new SleepJob(0));
                    Thread.Sleep(100);
                    if (_jobCount != 2)
                    {
                        throw new Exception("TestNonBlockingRun() failed. _jobCount = " + _jobCount);
                    }
                }
            }
        }
예제 #14
0
        public void TestRunReenteringEnumerator()
        {
            _jobCount = 0;
            AsyncProcessor processor = new AsyncProcessor();

            using ( processor )
            {
                const int     total = 5;
                EnumeratorJob job   = new EnumeratorJob(total, 100);
                DateTime      start = DateTime.Now;
                processor.RunJob(job);
                if (start.AddMilliseconds(total * 99) > DateTime.Now)
                {
                    throw new Exception("TestRunReenteringEnumerator() finished too early. _jobCount = " + _jobCount);
                }
                if (_jobCount != total + 1)
                {
                    throw new Exception("TestRunReenteringEnumerator() failed. _jobCount = " + _jobCount);
                }
            }
        }
예제 #15
0
 protected override void Execute()
 {
     _proc.RunJob(_job);
 }
예제 #16
0
 protected override void Execute()
 {
     _proc.RunJob(new NamedJob());
 }
예제 #17
0
 protected override void Execute()
 {
     _pairProc.RunJob(new SleepJob(1000));
 }