public void testCloseableScheduleWithFixedDelayAndAdditionalTasks()
        {
            AtomicInteger outerCounter = new AtomicInteger(0);
            IRunnable command = RunnableUtils.FromFunc(() => { Console.WriteLine("--");
                                                                 outerCounter.IncrementAndGet();
            });
            executorService.scheduleWithFixedDelay(command, DELAY_MS, DELAY_MS);
            CloseableScheduledExecutorService service = new CloseableScheduledExecutorService(executorService);
            AtomicInteger innerCounter = new AtomicInteger(0);
            service.scheduleWithFixedDelay(RunnableUtils.FromFunc(() => { Console.WriteLine("!!"); innerCounter.IncrementAndGet(); }),
                                            DELAY_MS,
                                            DELAY_MS);

            Thread.Sleep(DELAY_MS * 4);

            service.Dispose();
            Thread.Sleep(DELAY_MS * 2);
            Assert.AreEqual(0, service.size());
            int innerValue = innerCounter.Get();
            Assert.True(innerValue > 0);

            int value = outerCounter.Get();
            Thread.Sleep(DELAY_MS* 2);
            int newValue = outerCounter.Get();
            Assert.True(newValue > value);
            Assert.AreEqual(innerValue, innerCounter.Get());

            value = newValue;
            Thread.Sleep(DELAY_MS* 2);
            newValue = outerCounter.Get();
            Assert.True(newValue > value);
            Assert.AreEqual(innerValue, innerCounter.Get());
        }
 public void Setup(int maxTasksInPool, int tasksToFork)
 {
     AtomicInteger atomicVal = new AtomicInteger();
     IExecutorService execService = new LimitedTaskExecutorService(maxTasksInPool);
     ICollection<IFuture<int>> futures = new List<IFuture<int>>(tasksToFork);
     for (int i = 0; i < tasksToFork; i++)
     {
         var task = new FutureTask<int>(CallableUtils.FromFunc(() =>
         {
             Thread.Yield();
             Thread.Sleep(7);
             int value = atomicVal.IncrementAndGet();
             Thread.Yield();
             return value;
         }));
         IFuture<int> future = execService.submit(task);
         futures.Add(future);
     }
     var results = new List<int>();
     foreach (IFuture<int> future in futures)
     {
         int value = future.get();
         results.Add(value);
     }
     results.Sort();
     int prevValue = results[0];
     Console.WriteLine(prevValue);
     for (int i = 1; i < results.Count; i++)
     {
         Console.WriteLine(results[i]);
         Assert.AreEqual(prevValue + 1, results[i]);
         prevValue = results[i];
     }
     Assert.AreEqual(atomicVal.Get(), tasksToFork);
 }