예제 #1
0
        public void TestThreadCount()
        {
            Console.Out.WriteLine("----=<TestThreadCount>=----");
            ThreadPoolStartInfo tpsi = new ThreadPoolStartInfo();

            tpsi.MinimumThreads = 15;
            tpsi.DelayedInit    = false;
            _pool = new ThreadPool(tpsi);
            Assert.AreEqual(15, _pool.ThreadCount);
        }
예제 #2
0
 public void TestImmediateInit()
 {
   Console.Out.WriteLine("----=<TestImmediateInit>=----");
   ThreadPoolStartInfo tpsi = new ThreadPoolStartInfo();
   tpsi.MinimumThreads = 2;
   tpsi.MaximumThreads = 5;
   tpsi.ThreadIdleTimeout = 1000;
   tpsi.DelayedInit = false;
   _pool = new ThreadPool(tpsi);
   SetupLogging();
   Assert.AreEqual(2, _pool.ThreadCount, "Thread count not 2; pool immediate initialization not OK");
   _pool.Stop();
 }
예제 #3
0
        public void TestImmediateInit()
        {
            Console.Out.WriteLine("----=<TestImmediateInit>=----");
            ThreadPoolStartInfo tpsi = new ThreadPoolStartInfo();

            tpsi.MinimumThreads    = 2;
            tpsi.MaximumThreads    = 5;
            tpsi.ThreadIdleTimeout = 1000;
            tpsi.DelayedInit       = false;
            _pool = new ThreadPool(tpsi);
            SetupLogging();
            Assert.AreEqual(2, _pool.ThreadCount, "Thread count not 2; pool immediate initialization not OK");
            _pool.Stop();
        }
예제 #4
0
        public void TestIntervalWork()
        {
            ThreadPoolStartInfo tpsi = new ThreadPoolStartInfo(2, 10, 1000);

            _pool = new ThreadPool(tpsi);
            SetupLogging();
            IntervalWork iWork = new IntervalWork(new DoWorkHandler(delegate() { TestIntervalWorkRuns++; }),
                                                  new TimeSpan(0, 0, 1));

            iWork.Description = "TestIntervalWork";
            _pool.AddIntervalWork(iWork, true);
            while (TestIntervalWorkRuns < 2)
            {
                Thread.Sleep(100);
            }
            _pool.RemoveIntervalWork(iWork);
            Assert.AreEqual(2, _pool.WorkItemsProcessed);
        }
예제 #5
0
        public void TestDropBackToMinThreads()
        {
            Console.Out.WriteLine("----=<TestDropBackToMinThreads>=----");
            ThreadPoolStartInfo tpsi = new ThreadPoolStartInfo(2, 10, 100);

            _pool = new ThreadPool(tpsi);
            SetupLogging();
            for (int i = 0; i < 10; i++)
            {
                _pool.Add(new DoWorkHandler(delegate() { Thread.Sleep(300); }), "TestDropBackToMinThreads" + i);
                Thread.Sleep(10);
            }
            Thread.Sleep(600);
            Assert.AreEqual(0, _pool.BusyThreadCount);
            Assert.AreEqual(10, _pool.WorkItemsProcessed);
            Assert.AreEqual(2, _pool.ThreadCount, "Pool did not drop back down to 2 threads");
            _pool.Stop();
        }
예제 #6
0
        public void TestWorkQueueLengthBusyCountAndWorkCancellation()
        {
            DoWorkHandler workHandler = new DoWorkHandler(delegate() { Thread.Sleep(300); });

            Console.Out.WriteLine("----=<TestWorkItemsProcessed>=----");
            List <IWork>        workList = new List <IWork>();
            ThreadPoolStartInfo tpsi     = new ThreadPoolStartInfo(1, 1, 10);

            _pool = new ThreadPool(tpsi);
            SetupLogging();

            _pool.Add(workHandler);
            Thread.Sleep(10);
            Assert.AreEqual(1, _pool.BusyThreadCount);
            for (int i = 0; i < 10; i++)
            {
                workList.Add(_pool.Add(workHandler));
            }
            Assert.AreEqual(10, _pool.QueueLength);

            foreach (IWork work in workList)
            {
                work.State = WorkState.CANCELED;
            }
            _pool.MinimumThreads = _pool.MaximumThreads = 10;
            _pool.MinimumThreads = 0;

            while (_pool.BusyThreadCount > 0)
            {
                Thread.Sleep(100);
            }

            foreach (IWork work in workList)
            {
                Assert.AreEqual(WorkState.CANCELED, work.State);
            }
            Assert.AreEqual(0, _pool.QueueLength);
            Assert.AreEqual(0, _pool.BusyThreadCount);
        }
예제 #7
0
 public void Dispose()
 {
     Console.Out.WriteLine("----=<Stop>=----");
     _pool.Stop();
     _pool = null;
 }
예제 #8
0
 public void Init()
 {
     Console.Out.WriteLine("----=<Init>=----");
     _pool = new ThreadPool(2, 5);
     SetupLogging();
 }
예제 #9
0
 public void Dispose()
 {
   Console.Out.WriteLine("----=<Stop>=----");
   _pool.Stop();
   _pool = null;
 }
예제 #10
0
 public void Init()
 {
   Console.Out.WriteLine("----=<Init>=----");
   _pool = new ThreadPool(2, 5);
   SetupLogging();
 }
예제 #11
0
 public void TestIntervalWork()
 {
   ThreadPoolStartInfo tpsi = new ThreadPoolStartInfo(2, 10, 1000);
   _pool = new ThreadPool(tpsi);
   SetupLogging();
   IntervalWork iWork = new IntervalWork(new DoWorkHandler(delegate() { TestIntervalWorkRuns++; }),
                                         new TimeSpan(0, 0, 1));
   iWork.Description = "TestIntervalWork";
   _pool.AddIntervalWork(iWork, true);
   while (TestIntervalWorkRuns < 2)
   {
     Thread.Sleep(100);
   }
   _pool.RemoveIntervalWork(iWork);
   Assert.AreEqual(2, _pool.WorkItemsProcessed);
 }
예제 #12
0
    public void TestWorkQueueLengthBusyCountAndWorkCancellation()
    {
      DoWorkHandler workHandler = new DoWorkHandler(delegate() { Thread.Sleep(300); });
      Console.Out.WriteLine("----=<TestWorkItemsProcessed>=----");
      List<IWork> workList = new List<IWork>();
      ThreadPoolStartInfo tpsi = new ThreadPoolStartInfo(1, 1, 10);
      _pool = new ThreadPool(tpsi);
      SetupLogging();

      _pool.Add(workHandler);
      Thread.Sleep(10);
      Assert.AreEqual(1, _pool.BusyThreadCount);
      for (int i = 0; i < 10; i++)
      {
        workList.Add(_pool.Add(workHandler));
      }
      Assert.AreEqual(10, _pool.QueueLength);

      foreach (IWork work in workList)
      {
        work.State = WorkState.CANCELED;
      }
      _pool.MinimumThreads = _pool.MaximumThreads = 10;
      _pool.MinimumThreads = 0;

      while (_pool.BusyThreadCount > 0)
      {
        Thread.Sleep(100);
      }

      foreach (IWork work in workList)
      {
        Assert.AreEqual(WorkState.CANCELED, work.State);
      }
      Assert.AreEqual(0, _pool.QueueLength);
      Assert.AreEqual(0, _pool.BusyThreadCount);
    }
예제 #13
0
 public void TestThreadCount()
 {
   Console.Out.WriteLine("----=<TestThreadCount>=----");
   ThreadPoolStartInfo tpsi = new ThreadPoolStartInfo();
   tpsi.MinimumThreads = 15;
   tpsi.DelayedInit = false;
   _pool = new ThreadPool(tpsi);
   Assert.AreEqual(15, _pool.ThreadCount);
 }
예제 #14
0
 public void TestDropBackToMinThreads()
 {
   Console.Out.WriteLine("----=<TestDropBackToMinThreads>=----");
   ThreadPoolStartInfo tpsi = new ThreadPoolStartInfo(2, 10, 100);
   _pool = new ThreadPool(tpsi);
   SetupLogging();
   for (int i = 0; i < 10; i++)
   {
     _pool.Add(new DoWorkHandler(delegate() { Thread.Sleep(300); }), "TestDropBackToMinThreads" + i);
     Thread.Sleep(10);
   }
   Thread.Sleep(600);
   Assert.AreEqual(0, _pool.BusyThreadCount);
   Assert.AreEqual(10, _pool.WorkItemsProcessed);
   Assert.AreEqual(2, _pool.ThreadCount, "Pool did not drop back down to 2 threads");
   _pool.Stop();
 }