20 |
|
return new TestSuite(ScheduledExecutorTest.class); |
21 |
|
} |
22 |
|
|
23 |
– |
|
23 |
|
/** |
24 |
|
* execute successfully executes a runnable |
25 |
|
*/ |
38 |
|
} |
39 |
|
} |
40 |
|
|
42 |
– |
|
41 |
|
/** |
42 |
|
* delayed schedule of callable successfully executes after delay |
43 |
|
*/ |
174 |
|
joinPool(p); |
175 |
|
} |
176 |
|
|
179 |
– |
|
177 |
|
/** |
178 |
|
* execute(null) throws NPE |
179 |
|
*/ |
456 |
|
} |
457 |
|
|
458 |
|
/** |
459 |
< |
* isShutDown is false before shutdown, true after |
459 |
> |
* isShutdown is false before shutdown, true after |
460 |
|
*/ |
461 |
|
public void testIsShutdown() { |
462 |
|
|
470 |
|
assertTrue(p.isShutdown()); |
471 |
|
} |
472 |
|
|
476 |
– |
|
473 |
|
/** |
474 |
|
* isTerminated is false before termination, true after |
475 |
|
*/ |
613 |
|
} |
614 |
|
|
615 |
|
/** |
616 |
< |
* shutDownNow returns a list containing tasks that were not run |
616 |
> |
* shutdownNow returns a list containing tasks that were not run |
617 |
|
*/ |
618 |
|
public void testShutdownNow() { |
619 |
|
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
635 |
|
* In default setting, shutdown cancels periodic but not delayed |
636 |
|
* tasks at shutdown |
637 |
|
*/ |
638 |
< |
public void testShutDown1() throws InterruptedException { |
638 |
> |
public void testShutdown1() throws InterruptedException { |
639 |
|
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
640 |
|
assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy()); |
641 |
|
assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy()); |
660 |
|
} |
661 |
|
} |
662 |
|
|
667 |
– |
|
663 |
|
/** |
664 |
|
* If setExecuteExistingDelayedTasksAfterShutdownPolicy is false, |
665 |
|
* delayed tasks are cancelled at shutdown |
666 |
|
*/ |
667 |
< |
public void testShutDown2() throws InterruptedException { |
667 |
> |
public void testShutdown2() throws InterruptedException { |
668 |
|
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
669 |
|
p.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); |
670 |
|
assertFalse(p.getExecuteExistingDelayedTasksAfterShutdownPolicy()); |
690 |
|
* If setContinueExistingPeriodicTasksAfterShutdownPolicy is set false, |
691 |
|
* periodic tasks are cancelled at shutdown |
692 |
|
*/ |
693 |
< |
public void testShutDown3() throws InterruptedException { |
693 |
> |
public void testShutdown3() throws InterruptedException { |
694 |
|
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
695 |
|
assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy()); |
696 |
|
assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy()); |
697 |
|
p.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); |
698 |
|
assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy()); |
699 |
|
assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy()); |
700 |
+ |
long initialDelay = LONG_DELAY_MS; |
701 |
|
ScheduledFuture task = |
702 |
< |
p.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, MILLISECONDS); |
702 |
> |
p.scheduleAtFixedRate(new NoOpRunnable(), initialDelay, |
703 |
> |
5, MILLISECONDS); |
704 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
705 |
|
assertTrue(p.isShutdown()); |
709 |
– |
BlockingQueue q = p.getQueue(); |
706 |
|
assertTrue(p.getQueue().isEmpty()); |
707 |
|
assertTrue(task.isDone()); |
708 |
|
assertTrue(task.isCancelled()); |
709 |
< |
assertTrue(p.awaitTermination(SMALL_DELAY_MS, MILLISECONDS)); |
714 |
< |
assertTrue(p.isTerminated()); |
709 |
> |
joinPool(p); |
710 |
|
} |
711 |
|
|
712 |
|
/** |
713 |
|
* if setContinueExistingPeriodicTasksAfterShutdownPolicy is true, |
714 |
|
* periodic tasks are not cancelled at shutdown |
715 |
|
*/ |
716 |
< |
public void testShutDown4() throws InterruptedException { |
716 |
> |
public void testShutdown4() throws InterruptedException { |
717 |
|
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
718 |
|
final CountDownLatch counter = new CountDownLatch(2); |
719 |
|
try { |
1170 |
|
} |
1171 |
|
} |
1172 |
|
|
1178 |
– |
|
1173 |
|
} |