public void testGrowPool() throws Exception {
TaskQueueManager.setMaximumThreadCount(QUEUE_NAME,1);
//Allow some time to bring the thread count back down
stopWatch.block(500);
BaseTask task1 = new MeanwhileTest.TimerTask(500L);
BaseTask task2 = new MeanwhileTest.TimerTask(500L);
List<Task> taskList = new ArrayList<Task>();
taskList.add(task1);
taskList.add(task2);
TaskQueueManager.submit(QUEUE_NAME,taskList);
stopWatch.block(100);
assertEquals("TaskManger active size = 1",1,TaskQueueManager.getActiveCount(QUEUE_NAME));
// Block long enough for first task to complete and second task to begin
stopWatch.block(600);
stopWatch.block(100);
assertEquals("TaskManger active size = 1",1,TaskQueueManager.getActiveCount(QUEUE_NAME));
assertEquals("Task 1 SUCCESS with 1 thread",TaskStatus.SUCCESS,task1.getStatus());
assertEquals("Task 2 WORKING with 1 thread",TaskStatus.WORKING,task2.getStatus());
assertEquals("TaskManger pool size = 1",1,TaskQueueManager.getMaximumPoolSize(QUEUE_NAME));
//Wait until the second task completes
stopWatch.block(400);
//Set thread count to 2
TaskQueueManager.setMaximumThreadCount(QUEUE_NAME,2);
task1 = new MeanwhileTest.TimerTask(500L);
task2 = new MeanwhileTest.TimerTask(500L);
BaseTask task3 = new MeanwhileTest.TimerTask(500L);
taskList = new ArrayList<Task>();
taskList.add(task1);
taskList.add(task2);
taskList.add(task3);
TaskQueueManager.submit(QUEUE_NAME,taskList);
stopWatch.block(100);
assertEquals("TaskManger active size = 2",2,TaskQueueManager.getActiveCount(QUEUE_NAME));
// Block long enough for first two tasks to complete and third task to begin
stopWatch.block(800);
assertEquals("TaskManger active size = 1",1,TaskQueueManager.getActiveCount(QUEUE_NAME));
assertEquals("Task 1 SUCCESS with 2 threads",TaskStatus.SUCCESS,task1.getStatus());
assertEquals("Task 2 SUCCESS with 2 threads",TaskStatus.SUCCESS,task2.getStatus());
assertEquals("Task 3 WORKING with 2 threads",TaskStatus.WORKING,task3.getStatus());
assertEquals("TaskManger pool size = 2",2,TaskQueueManager.getMaximumPoolSize(QUEUE_NAME));
}