[SetUp] public void SetUp()
 {
     _queue              = MockRepository.GenerateStub <IBlockingQueue <IRunnable> >();
     _runnable           = MockRepository.GenerateMock <IRunnable>();
     _callerRunsPolicy   = new ThreadPoolExecutor.CallerRunsPolicy();
     _threadPoolExecutor = new ThreadPoolExecutor(1, 1, TimeSpan.FromSeconds(1), _queue);
 }
 public void SetUp()
 {
     _queue = MockRepository.GenerateStub<IBlockingQueue<IRunnable>>();
     _runnable = MockRepository.GenerateMock<IRunnable>();
     _callerRunsPolicy = new ThreadPoolExecutor.CallerRunsPolicy();
     _threadPoolExecutor = new ThreadPoolExecutor(1, 1, TimeSpan.FromSeconds(1), _queue);
 }
Esempio n. 3
0
        public void ExecuteDropsTaskOnShutdownWithCallerRunsPolicy()
        {
            IRejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();

            ExecutorService = new ThreadPoolExecutor(1, 1, Delays.Long, new ArrayBlockingQueue <IRunnable>(1), h);
            AssertExecutorDropsTaskOnShutdown(ExecutorService);
        }
Esempio n. 4
0
        public void ExecuteRunsTaskInCurrentThreadWhenSaturatedWithCallerRunsPolicy()
        {
            IRejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
            var es = new ThreadPoolExecutor(1, 1, Delays.Long, new ArrayBlockingQueue <IRunnable>(1), h);

            ExecutorService = es;
            IRunnable[] tasks  = new IRunnable[_size];
            var         caller = Thread.CurrentThread;

            for (int i = 0; i < _size; ++i)
            {
                tasks[i] = MockRepository.GenerateStub <IRunnable>();
                tasks[i].Stub(r => r.Run()).Do(
                    ThreadManager.GetManagedAction(
                        () => Assert.That(Thread.CurrentThread, Is.EqualTo(caller))));
            }

            es.Execute(_mediumInterruptableAction);
            for (int i = 0; i < _size; ++i)
            {
                es.Execute(tasks[i]);
            }

            for (int i = 1; i < _size; ++i)
            {
                tasks[i].AssertWasCalled(r => r.Run());
            }
            InterruptAndJoinPool(es);
            ThreadManager.JoinAndVerify();
        }
Esempio n. 5
0
        private static ExecutorService BuildExecutorService(JobScheduler scheduler)
        {
            BlockingQueue <ThreadStart> workQueue       = new LinkedBlockingQueue <ThreadStart>(_ioParallelism * 4);
            RejectedExecutionHandler    rejectionPolicy = new ThreadPoolExecutor.CallerRunsPolicy();
            ThreadFactory threadFactory = scheduler.ThreadFactory(Group.FILE_IO_HELPER);

            return(new ThreadPoolExecutor(0, _ioParallelism, 10, TimeUnit.SECONDS, workQueue, threadFactory, rejectionPolicy));
        }
        private ExecutorService CreateThreadPool()
        {
            int threads = NumberOfPopulationWorkers;
            BlockingQueue <ThreadStart> workQueue             = new LinkedBlockingQueue <ThreadStart>(_taskQueueSize);
            ThreadFactory            threadFactory            = daemon(FLUSH_THREAD_NAME_PREFIX);
            RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();

            return(new ThreadPoolExecutor(threads, threads, 0L, TimeUnit.MILLISECONDS, workQueue, threadFactory, rejectedExecutionHandler));
        }