public void DoesNotRunRunnableWithShutdownExecutorService()
        {
            _threadPoolExecutor.ShutdownNow();
            _callerRunsPolicy.RejectedExecution(_runnable, _threadPoolExecutor);

            _runnable.AssertWasNotCalled(r => r.Run());
        }
Exemplo n.º 2
0
        [Test] public void ForEachLimitsParallismToThreadPoolExecutorCoreSize(
            [Values(Parallelism - 2, Parallelism + 2)] int coreSize)
        {
            var tf       = new ManagedThreadFactory(ThreadManager);
            var executor = new ThreadPoolExecutor(coreSize, Parallelism + 2,
                                                  TimeSpan.MaxValue, new LinkedBlockingQueue <IRunnable>(1), tf);

            try
            {
                T[] sources = TestData <T> .MakeTestArray(_sampleSize);

                List <T> results  = new List <T>(_sampleSize);
                var      parallel = new ParallelCompletion <T, int>(executor,
                                                                    _localInit,
                                                                    (t, s, l) =>
                {
                    Thread.Sleep(10); lock (results) results.Add(t);
                    return(0);
                },
                                                                    _localFinally);
                parallel.ForEach(sources, Parallelism);
                Assert.That(results, Is.EquivalentTo(sources));
                Assert.That(parallel.ActualDegreeOfParallelism, Is.EqualTo(Math.Min(Parallelism, coreSize)));
            }
            finally
            {
                executor.ShutdownNow();
            }

            ThreadManager.JoinAndVerify();
        }
Exemplo n.º 3
0
        [Test] public void DoesNotRunRunnableWithShutdownExecutorService()
        {
            _threadPoolExecutor.ShutdownNow();
            _discardOldestPolicy.RejectedExecution(_runnable, _threadPoolExecutor);

            _runnable.AssertWasNotCalled(r => r.Run());
            _threadPoolExecutor.AssertWasNotCalled(e => e.Execute(Arg <Action> .Is.Anything));
            _threadPoolExecutor.AssertWasNotCalled(e => e.Execute(Arg <IRunnable> .Is.Anything));
        }
 /// <summary>
 /// Perform a shutdown on the ThreadPoolExecutor.
 /// </summary>
 public void Shutdown()
 {
     if (logger.IsInfoEnabled)
     {
         logger.Info("Shutting down ThreadPoolExecutor" + (_objectName != null ? " '" + _objectName + "'" : ""));
     }
     if (_waitForTasksToCompleteOnShutdown)
     {
         _threadPoolExecutor.Shutdown();
     }
     else
     {
         _threadPoolExecutor.ShutdownNow();
     }
 }
Exemplo n.º 5
0
 /// <exception cref="System.Exception"/>
 protected override void ServiceStop()
 {
     if (stopped.GetAndSet(true))
     {
         // return if already stopped
         return;
     }
     // shutdown any containers that might be left running
     ShutdownAllContainers();
     if (eventHandlingThread != null)
     {
         eventHandlingThread.Interrupt();
     }
     if (launcherPool != null)
     {
         launcherPool.ShutdownNow();
     }
     base.ServiceStop();
 }
Exemplo n.º 6
0
 /// <summary>Cleanly shutdown</summary>
 public virtual void Shutdown()
 {
     executor.ShutdownNow();
 }