manager.setMaximumThreadCount(1);
//Allow some time to bring the thread count back down
stopWatch.block(500);
//Cancel by Task
BaseChain task1 = new TimerTask(500L);
BaseChain task2 = new TimerTask(500L);
BaseChain task3 = new TimerTask(500L);
task2.chain(task3);
List<BaseChain> taskList = new ArrayList<BaseChain>();
taskList.add(task1);
taskList.add(task2);
List<ClaimCheck> claims = manager.execute(taskList);
boolean canceled = manager.cancel(claims.get(1));
assertTrue("task2 report canceled true - Claim Check",canceled);
assertEquals(TaskStatus.CANCELED,task2.getStatus());
assertEquals(TaskStatus.CANCELED,task3.getStatus());
stopWatch.block(500);
//Cancel by UUID
task1 = new TimerTask(500L);
task2 = new TimerTask(500L);
task3 = new TimerTask(500L);
task2.chain(task3);
taskList = new ArrayList<BaseChain>();
taskList.add(task1);
taskList.add(task2);
claims = manager.execute(taskList);
canceled = manager.cancel(UUID.fromString(claims.get(1).toString()));
assertTrue("task2 report canceled true - UUID",canceled);
assertEquals(TaskStatus.CANCELED,task2.getStatus());
assertEquals(TaskStatus.CANCELED,task3.getStatus());
stopWatch.block(500);
//Cancel by UUID String
task1 = new TimerTask(500L);
task2 = new TimerTask(500L);
task3 = new TimerTask(500L);
task2.chain(task3);
taskList = new ArrayList<BaseChain>();
taskList.add(task1);
taskList.add(task2);
claims = manager.execute(taskList);
canceled = manager.cancel(claims.get(1).toString());
assertTrue("task2 report canceled true - UUID String",canceled);
assertEquals(TaskStatus.CANCELED,task2.getStatus());
assertEquals(TaskStatus.CANCELED,task3.getStatus());
stopWatch.block(500);
//Cancel by and do not queue
task1 = new TimerTask(500L);
task2 = new TimerTask(500L);
task3 = new TimerTask(500L);
task2.chain(task3);
taskList = new ArrayList<BaseChain>();
taskList.add(task1);
taskList.add(task2);
claims = manager.execute(taskList);
stopWatch.block(700);
canceled = manager.cancel(claims.get(1));
assertTrue("task3 report canceled true",canceled);
assertEquals(TaskStatus.WORKING,task2.getStatus());
assertEquals(TaskStatus.DEQUEUED,task3.getStatus());
stopWatch.block(1000);
assertEquals(TaskStatus.SUCCESS,task2.getStatus());
assertEquals(TaskStatus.CANCELED,task3.getStatus());
//Does not cancel in-flight tasks
task1 = new TimerTask(500L);
task2 = new TimerTask(500L);