510 |
|
} |
511 |
|
|
512 |
|
/** |
513 |
< |
* isShutDown is false before shutdown, true after |
513 |
> |
* isShutdown is false before shutdown, true after |
514 |
|
*/ |
515 |
|
public void testIsShutdown() { |
516 |
|
CustomExecutor p = new CustomExecutor(1); |
667 |
|
} |
668 |
|
|
669 |
|
/** |
670 |
< |
* shutDownNow returns a list containing tasks that were not run |
670 |
> |
* shutdownNow returns a list containing tasks that were not run |
671 |
|
*/ |
672 |
< |
public void testShutDownNow() { |
672 |
> |
public void testShutdownNow() { |
673 |
|
CustomExecutor p = new CustomExecutor(1); |
674 |
|
for (int i = 0; i < 5; i++) |
675 |
|
p.schedule(new SmallPossiblyInterruptedRunnable(), |
689 |
|
* In default setting, shutdown cancels periodic but not delayed |
690 |
|
* tasks at shutdown |
691 |
|
*/ |
692 |
< |
public void testShutDown1() throws InterruptedException { |
692 |
> |
public void testShutdown1() throws InterruptedException { |
693 |
|
CustomExecutor p = new CustomExecutor(1); |
694 |
|
assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy()); |
695 |
|
assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy()); |
719 |
|
* If setExecuteExistingDelayedTasksAfterShutdownPolicy is false, |
720 |
|
* delayed tasks are cancelled at shutdown |
721 |
|
*/ |
722 |
< |
public void testShutDown2() throws InterruptedException { |
722 |
> |
public void testShutdown2() throws InterruptedException { |
723 |
|
CustomExecutor p = new CustomExecutor(1); |
724 |
|
p.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); |
725 |
|
assertFalse(p.getExecuteExistingDelayedTasksAfterShutdownPolicy()); |
746 |
|
* If setContinueExistingPeriodicTasksAfterShutdownPolicy is set false, |
747 |
|
* periodic tasks are cancelled at shutdown |
748 |
|
*/ |
749 |
< |
public void testShutDown3() throws InterruptedException { |
749 |
> |
public void testShutdown3() throws InterruptedException { |
750 |
|
CustomExecutor p = new CustomExecutor(1); |
751 |
|
assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy()); |
752 |
|
assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy()); |
753 |
|
p.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); |
754 |
|
assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy()); |
755 |
|
assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy()); |
756 |
+ |
long initialDelay = LONG_DELAY_MS; |
757 |
|
ScheduledFuture task = |
758 |
< |
p.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, MILLISECONDS); |
758 |
> |
p.scheduleAtFixedRate(new NoOpRunnable(), initialDelay, |
759 |
> |
5, MILLISECONDS); |
760 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
761 |
|
assertTrue(p.isShutdown()); |
760 |
– |
BlockingQueue q = p.getQueue(); |
762 |
|
assertTrue(p.getQueue().isEmpty()); |
763 |
|
assertTrue(task.isDone()); |
764 |
|
assertTrue(task.isCancelled()); |
765 |
< |
assertTrue(p.awaitTermination(SMALL_DELAY_MS, MILLISECONDS)); |
765 |
< |
assertTrue(p.isTerminated()); |
765 |
> |
joinPool(p); |
766 |
|
} |
767 |
|
|
768 |
|
/** |
769 |
|
* if setContinueExistingPeriodicTasksAfterShutdownPolicy is true, |
770 |
|
* periodic tasks are not cancelled at shutdown |
771 |
|
*/ |
772 |
< |
public void testShutDown4() throws InterruptedException { |
772 |
> |
public void testShutdown4() throws InterruptedException { |
773 |
|
CustomExecutor p = new CustomExecutor(1); |
774 |
|
final CountDownLatch counter = new CountDownLatch(2); |
775 |
|
try { |