473 |
|
* submitted |
474 |
|
*/ |
475 |
|
public void testGetTaskCount() throws InterruptedException { |
476 |
+ |
final int TASKS = 3; |
477 |
+ |
final CountDownLatch done = new CountDownLatch(1); |
478 |
|
final ThreadPoolExecutor p = new CustomExecutor(1); |
479 |
< |
try (PoolCleaner cleaner = cleaner(p)) { |
479 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
480 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
479 |
– |
final CountDownLatch done = new CountDownLatch(1); |
480 |
– |
final int TASKS = 5; |
481 |
|
assertEquals(0, p.getTaskCount()); |
482 |
< |
for (int i = 0; i < TASKS; i++) |
482 |
> |
assertEquals(0, p.getCompletedTaskCount()); |
483 |
> |
p.execute(new CheckedRunnable() { |
484 |
> |
public void realRun() throws InterruptedException { |
485 |
> |
threadStarted.countDown(); |
486 |
> |
done.await(); |
487 |
> |
}}); |
488 |
> |
assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); |
489 |
> |
assertEquals(1, p.getTaskCount()); |
490 |
> |
assertEquals(0, p.getCompletedTaskCount()); |
491 |
> |
for (int i = 0; i < TASKS; i++) { |
492 |
> |
assertEquals(1 + i, p.getTaskCount()); |
493 |
|
p.execute(new CheckedRunnable() { |
494 |
|
public void realRun() throws InterruptedException { |
495 |
|
threadStarted.countDown(); |
496 |
+ |
assertEquals(1 + TASKS, p.getTaskCount()); |
497 |
|
done.await(); |
498 |
|
}}); |
499 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
500 |
< |
assertEquals(TASKS, p.getTaskCount()); |
501 |
< |
done.countDown(); |
499 |
> |
} |
500 |
> |
assertEquals(1 + TASKS, p.getTaskCount()); |
501 |
> |
assertEquals(0, p.getCompletedTaskCount()); |
502 |
|
} |
503 |
+ |
assertEquals(1 + TASKS, p.getTaskCount()); |
504 |
+ |
assertEquals(1 + TASKS, p.getCompletedTaskCount()); |
505 |
|
} |
506 |
|
|
507 |
|
/** |