@Test
  public void testLessThanMaxPoolSizeThreadsLaunched() throws InterruptedException {
    int CORE_POOL_SIZE = 2;
    int MAX_POOL_SIZE = 10;
    int TASKS_COUNT = 8;
    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(CORE_POOL_SIZE);
    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, 30000, TimeUnit.MILLISECONDS, queue);
    BufferedThreadPoolExecutorCompletionService<Runnable> service = new BufferedThreadPoolExecutorCompletionService<>(threadPoolExecutor);
    for (int tc = 0; tc < TASKS_COUNT; tc++) {
      service.submit(new Runnable() {
        @Override
        public void run() {
          try {
            longOp();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }, null);
    }

    // While waiting for tasks completion, check how many threads are being used
    Thread.sleep(500);
    Assert.assertEquals(TASKS_COUNT - CORE_POOL_SIZE, threadPoolExecutor.getActiveCount());
    for (int tc = 0; tc < TASKS_COUNT; tc++) {
      Future<Runnable> take = service.take();
      Assert.assertTrue(take.isDone());
      Assert.assertTrue("No more than TASKS_COUNT threads should be launched", threadPoolExecutor.getActiveCount() <= TASKS_COUNT);
    }
    threadPoolExecutor.shutdown();
  }
Tests that when load is more than core-pool-size and less than
max-pool-size, the number of threads scales up.

@throws InterruptedException
ambari-server/src/test/java/org/apache/ambari/server/controller/test/BufferedThreadPoolExecutorCompletionServiceTest.java