416 |
|
* submitted |
417 |
|
*/ |
418 |
|
public void testGetTaskCount() throws InterruptedException { |
419 |
+ |
final int TASKS = 3; |
420 |
+ |
final CountDownLatch done = new CountDownLatch(1); |
421 |
|
final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
422 |
< |
try (PoolCleaner cleaner = cleaner(p)) { |
422 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
423 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
422 |
– |
final CountDownLatch done = new CountDownLatch(1); |
423 |
– |
final int TASKS = 5; |
424 |
|
assertEquals(0, p.getTaskCount()); |
425 |
< |
for (int i = 0; i < TASKS; i++) |
425 |
> |
assertEquals(0, p.getCompletedTaskCount()); |
426 |
> |
p.execute(new CheckedRunnable() { |
427 |
> |
public void realRun() throws InterruptedException { |
428 |
> |
threadStarted.countDown(); |
429 |
> |
done.await(); |
430 |
> |
}}); |
431 |
> |
assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); |
432 |
> |
assertEquals(1, p.getTaskCount()); |
433 |
> |
assertEquals(0, p.getCompletedTaskCount()); |
434 |
> |
for (int i = 0; i < TASKS; i++) { |
435 |
> |
assertEquals(1 + i, p.getTaskCount()); |
436 |
|
p.execute(new CheckedRunnable() { |
437 |
|
public void realRun() throws InterruptedException { |
438 |
|
threadStarted.countDown(); |
439 |
+ |
assertEquals(1 + TASKS, p.getTaskCount()); |
440 |
|
done.await(); |
441 |
|
}}); |
442 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
443 |
< |
assertEquals(TASKS, p.getTaskCount()); |
444 |
< |
done.countDown(); |
442 |
> |
} |
443 |
> |
assertEquals(1 + TASKS, p.getTaskCount()); |
444 |
> |
assertEquals(0, p.getCompletedTaskCount()); |
445 |
|
} |
446 |
+ |
assertEquals(1 + TASKS, p.getTaskCount()); |
447 |
+ |
assertEquals(1 + TASKS, p.getCompletedTaskCount()); |
448 |
|
} |
449 |
|
|
450 |
|
/** |
451 |
|
* getThreadFactory returns factory in constructor if not set |
452 |
|
*/ |
453 |
|
public void testGetThreadFactory() throws InterruptedException { |
454 |
< |
ThreadFactory threadFactory = new SimpleThreadFactory(); |
455 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, threadFactory); |
456 |
< |
assertSame(threadFactory, p.getThreadFactory()); |
457 |
< |
joinPool(p); |
454 |
> |
final ThreadFactory threadFactory = new SimpleThreadFactory(); |
455 |
> |
final ScheduledThreadPoolExecutor p = |
456 |
> |
new ScheduledThreadPoolExecutor(1, threadFactory); |
457 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
458 |
> |
assertSame(threadFactory, p.getThreadFactory()); |
459 |
> |
} |
460 |
|
} |
461 |
|
|
462 |
|
/** |
645 |
|
final AtomicInteger ran = new AtomicInteger(0); |
646 |
|
final ScheduledThreadPoolExecutor p = |
647 |
|
new ScheduledThreadPoolExecutor(poolSize); |
648 |
< |
CountDownLatch threadsStarted = new CountDownLatch(poolSize); |
648 |
> |
final CountDownLatch threadsStarted = new CountDownLatch(poolSize); |
649 |
|
Runnable waiter = new CheckedRunnable() { public void realRun() { |
650 |
|
threadsStarted.countDown(); |
651 |
|
try { |