42 |
|
* execute successfully executes a runnable |
43 |
|
*/ |
44 |
|
public void testExecute() throws InterruptedException { |
45 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
45 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
46 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
47 |
|
final CountDownLatch done = new CountDownLatch(1); |
48 |
|
final Runnable task = new CheckedRunnable() { |
49 |
|
public void realRun() { done.countDown(); }}; |
50 |
|
p.execute(task); |
51 |
< |
assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS)); |
51 |
> |
assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS)); |
52 |
|
} |
53 |
|
} |
54 |
|
|
56 |
|
* delayed schedule of callable successfully executes after delay |
57 |
|
*/ |
58 |
|
public void testSchedule1() throws Exception { |
59 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
59 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
60 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
61 |
|
final long startTime = System.nanoTime(); |
62 |
|
final CountDownLatch done = new CountDownLatch(1); |
77 |
|
* delayed schedule of runnable successfully executes after delay |
78 |
|
*/ |
79 |
|
public void testSchedule3() throws Exception { |
80 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
80 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
81 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
82 |
|
final long startTime = System.nanoTime(); |
83 |
|
final CountDownLatch done = new CountDownLatch(1); |
97 |
|
* scheduleAtFixedRate executes runnable after given initial delay |
98 |
|
*/ |
99 |
|
public void testSchedule4() throws Exception { |
100 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
100 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
101 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
102 |
|
final long startTime = System.nanoTime(); |
103 |
|
final CountDownLatch done = new CountDownLatch(1); |
119 |
|
* scheduleWithFixedDelay executes runnable after given initial delay |
120 |
|
*/ |
121 |
|
public void testSchedule5() throws Exception { |
122 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
122 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
123 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
124 |
|
final long startTime = System.nanoTime(); |
125 |
|
final CountDownLatch done = new CountDownLatch(1); |
146 |
|
* scheduleAtFixedRate executes series of tasks at given rate |
147 |
|
*/ |
148 |
|
public void testFixedRateSequence() throws InterruptedException { |
149 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
149 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
150 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
151 |
|
for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) { |
152 |
|
long startTime = System.nanoTime(); |
156 |
|
public void realRun() { done.countDown(); }}; |
157 |
|
ScheduledFuture h = |
158 |
|
p.scheduleAtFixedRate(task, 0, delay, MILLISECONDS); |
159 |
< |
done.await(); |
159 |
> |
await(done); |
160 |
|
h.cancel(true); |
161 |
|
double normalizedTime = |
162 |
|
(double) millisElapsedSince(startTime) / delay; |
172 |
|
* scheduleWithFixedDelay executes series of tasks with given period |
173 |
|
*/ |
174 |
|
public void testFixedDelaySequence() throws InterruptedException { |
175 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
175 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
176 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
177 |
|
for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) { |
178 |
|
long startTime = System.nanoTime(); |
182 |
|
public void realRun() { done.countDown(); }}; |
183 |
|
ScheduledFuture h = |
184 |
|
p.scheduleWithFixedDelay(task, 0, delay, MILLISECONDS); |
185 |
< |
done.await(); |
185 |
> |
await(done); |
186 |
|
h.cancel(true); |
187 |
|
double normalizedTime = |
188 |
|
(double) millisElapsedSince(startTime) / delay; |
198 |
|
* execute(null) throws NPE |
199 |
|
*/ |
200 |
|
public void testExecuteNull() throws InterruptedException { |
201 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
201 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
202 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
203 |
|
try { |
204 |
|
p.execute(null); |
225 |
|
* execute throws RejectedExecutionException if shutdown |
226 |
|
*/ |
227 |
|
public void testSchedule1_RejectedExecutionException() throws InterruptedException { |
228 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
228 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
229 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
230 |
|
try { |
231 |
|
p.shutdown(); |
241 |
|
* schedule throws RejectedExecutionException if shutdown |
242 |
|
*/ |
243 |
|
public void testSchedule2_RejectedExecutionException() throws InterruptedException { |
244 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
244 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
245 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
246 |
|
try { |
247 |
|
p.shutdown(); |
257 |
|
* schedule callable throws RejectedExecutionException if shutdown |
258 |
|
*/ |
259 |
|
public void testSchedule3_RejectedExecutionException() throws InterruptedException { |
260 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
260 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
261 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
262 |
|
try { |
263 |
|
p.shutdown(); |
273 |
|
* scheduleAtFixedRate throws RejectedExecutionException if shutdown |
274 |
|
*/ |
275 |
|
public void testScheduleAtFixedRate1_RejectedExecutionException() throws InterruptedException { |
276 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
276 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
277 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
278 |
|
try { |
279 |
|
p.shutdown(); |
289 |
|
* scheduleWithFixedDelay throws RejectedExecutionException if shutdown |
290 |
|
*/ |
291 |
|
public void testScheduleWithFixedDelay1_RejectedExecutionException() throws InterruptedException { |
292 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
292 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
293 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
294 |
|
try { |
295 |
|
p.shutdown(); |
306 |
|
* thread becomes active |
307 |
|
*/ |
308 |
|
public void testGetActiveCount() throws InterruptedException { |
309 |
+ |
final CountDownLatch done = new CountDownLatch(1); |
310 |
|
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(2); |
311 |
< |
try (PoolCleaner cleaner = cleaner(p)) { |
311 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
312 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
312 |
– |
final CountDownLatch done = new CountDownLatch(1); |
313 |
|
assertEquals(0, p.getActiveCount()); |
314 |
|
p.execute(new CheckedRunnable() { |
315 |
|
public void realRun() throws InterruptedException { |
316 |
|
threadStarted.countDown(); |
317 |
|
assertEquals(1, p.getActiveCount()); |
318 |
< |
done.await(); |
318 |
> |
await(done); |
319 |
|
}}); |
320 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
320 |
> |
await(threadStarted); |
321 |
|
assertEquals(1, p.getActiveCount()); |
322 |
– |
done.countDown(); |
322 |
|
} |
323 |
|
} |
324 |
|
|
372 |
|
final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(THREADS); |
373 |
|
final CountDownLatch threadsStarted = new CountDownLatch(THREADS); |
374 |
|
final CountDownLatch done = new CountDownLatch(1); |
375 |
< |
try (PoolCleaner cleaner = cleaner(p)) { |
375 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
376 |
|
assertEquals(0, p.getLargestPoolSize()); |
377 |
|
for (int i = 0; i < THREADS; i++) |
378 |
|
p.execute(new CheckedRunnable() { |
379 |
|
public void realRun() throws InterruptedException { |
380 |
|
threadsStarted.countDown(); |
381 |
< |
done.await(); |
381 |
> |
await(done); |
382 |
|
assertEquals(THREADS, p.getLargestPoolSize()); |
383 |
|
}}); |
384 |
< |
assertTrue(threadsStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
384 |
> |
await(threadsStarted); |
385 |
|
assertEquals(THREADS, p.getLargestPoolSize()); |
387 |
– |
done.countDown(); |
386 |
|
} |
387 |
|
assertEquals(THREADS, p.getLargestPoolSize()); |
388 |
|
} |
395 |
|
final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
396 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
397 |
|
final CountDownLatch done = new CountDownLatch(1); |
398 |
< |
try (PoolCleaner cleaner = cleaner(p)) { |
398 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
399 |
|
assertEquals(0, p.getPoolSize()); |
400 |
|
p.execute(new CheckedRunnable() { |
401 |
|
public void realRun() throws InterruptedException { |
402 |
|
threadStarted.countDown(); |
403 |
|
assertEquals(1, p.getPoolSize()); |
404 |
< |
done.await(); |
404 |
> |
await(done); |
405 |
|
}}); |
406 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
406 |
> |
await(threadStarted); |
407 |
|
assertEquals(1, p.getPoolSize()); |
410 |
– |
done.countDown(); |
408 |
|
} |
409 |
|
} |
410 |
|
|
423 |
|
p.execute(new CheckedRunnable() { |
424 |
|
public void realRun() throws InterruptedException { |
425 |
|
threadStarted.countDown(); |
426 |
< |
done.await(); |
426 |
> |
await(done); |
427 |
|
}}); |
428 |
< |
assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); |
428 |
> |
await(threadStarted); |
429 |
|
assertEquals(1, p.getTaskCount()); |
430 |
|
assertEquals(0, p.getCompletedTaskCount()); |
431 |
|
for (int i = 0; i < TASKS; i++) { |
434 |
|
public void realRun() throws InterruptedException { |
435 |
|
threadStarted.countDown(); |
436 |
|
assertEquals(1 + TASKS, p.getTaskCount()); |
437 |
< |
done.await(); |
437 |
> |
await(done); |
438 |
|
}}); |
439 |
|
} |
440 |
|
assertEquals(1 + TASKS, p.getTaskCount()); |
461 |
|
*/ |
462 |
|
public void testSetThreadFactory() throws InterruptedException { |
463 |
|
ThreadFactory threadFactory = new SimpleThreadFactory(); |
464 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
464 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
465 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
466 |
|
p.setThreadFactory(threadFactory); |
467 |
|
assertSame(threadFactory, p.getThreadFactory()); |
472 |
|
* setThreadFactory(null) throws NPE |
473 |
|
*/ |
474 |
|
public void testSetThreadFactoryNull() throws InterruptedException { |
475 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
475 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
476 |
|
try (PoolCleaner cleaner = cleaner(p)) { |
477 |
|
try { |
478 |
|
p.setThreadFactory(null); |
486 |
|
*/ |
487 |
|
public void testIsShutdown() { |
488 |
|
|
489 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
489 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
490 |
|
try { |
491 |
|
assertFalse(p.isShutdown()); |
492 |
|
} |
509 |
|
public void realRun() throws InterruptedException { |
510 |
|
assertFalse(p.isTerminated()); |
511 |
|
threadStarted.countDown(); |
512 |
< |
done.await(); |
512 |
> |
await(done); |
513 |
|
}}); |
514 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
514 |
> |
await(threadStarted); |
515 |
|
assertFalse(p.isTerminating()); |
516 |
|
done.countDown(); |
517 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
533 |
|
public void realRun() throws InterruptedException { |
534 |
|
assertFalse(p.isTerminating()); |
535 |
|
threadStarted.countDown(); |
536 |
< |
done.await(); |
536 |
> |
await(done); |
537 |
|
}}); |
538 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
538 |
> |
await(threadStarted); |
539 |
|
assertFalse(p.isTerminating()); |
540 |
|
done.countDown(); |
541 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
549 |
|
* getQueue returns the work queue, which contains queued tasks |
550 |
|
*/ |
551 |
|
public void testGetQueue() throws InterruptedException { |
552 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
553 |
< |
try (PoolCleaner cleaner = cleaner(p)) { |
552 |
> |
final CountDownLatch done = new CountDownLatch(1); |
553 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
554 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
555 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
558 |
– |
final CountDownLatch done = new CountDownLatch(1); |
556 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
557 |
|
for (int i = 0; i < tasks.length; i++) { |
558 |
|
Runnable r = new CheckedRunnable() { |
559 |
|
public void realRun() throws InterruptedException { |
560 |
|
threadStarted.countDown(); |
561 |
< |
done.await(); |
561 |
> |
await(done); |
562 |
|
}}; |
563 |
|
tasks[i] = p.schedule(r, 1, MILLISECONDS); |
564 |
|
} |
565 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
565 |
> |
await(threadStarted); |
566 |
|
BlockingQueue<Runnable> q = p.getQueue(); |
567 |
|
assertTrue(q.contains(tasks[tasks.length - 1])); |
568 |
|
assertFalse(q.contains(tasks[0])); |
572 |
– |
done.countDown(); |
569 |
|
} |
570 |
|
} |
571 |
|
|
573 |
|
* remove(task) removes queued task, and fails to remove active task |
574 |
|
*/ |
575 |
|
public void testRemove() throws InterruptedException { |
576 |
+ |
final CountDownLatch done = new CountDownLatch(1); |
577 |
|
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
578 |
< |
try (PoolCleaner cleaner = cleaner(p)) { |
578 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
579 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
580 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
584 |
– |
final CountDownLatch done = new CountDownLatch(1); |
581 |
|
for (int i = 0; i < tasks.length; i++) { |
582 |
|
Runnable r = new CheckedRunnable() { |
583 |
|
public void realRun() throws InterruptedException { |
584 |
|
threadStarted.countDown(); |
585 |
< |
done.await(); |
585 |
> |
await(done); |
586 |
|
}}; |
587 |
|
tasks[i] = p.schedule(r, 1, MILLISECONDS); |
588 |
|
} |
589 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
589 |
> |
await(threadStarted); |
590 |
|
BlockingQueue<Runnable> q = p.getQueue(); |
591 |
|
assertFalse(p.remove((Runnable)tasks[0])); |
592 |
|
assertTrue(q.contains((Runnable)tasks[4])); |
597 |
|
assertTrue(q.contains((Runnable)tasks[3])); |
598 |
|
assertTrue(p.remove((Runnable)tasks[3])); |
599 |
|
assertFalse(q.contains((Runnable)tasks[3])); |
604 |
– |
done.countDown(); |
600 |
|
} |
601 |
|
} |
602 |
|
|
604 |
|
* purge eventually removes cancelled tasks from the queue |
605 |
|
*/ |
606 |
|
public void testPurge() throws InterruptedException { |
607 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
608 |
< |
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
609 |
< |
for (int i = 0; i < tasks.length; i++) |
610 |
< |
tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(), |
611 |
< |
LONG_DELAY_MS, MILLISECONDS); |
612 |
< |
try { |
607 |
> |
final ScheduledFuture[] tasks = new ScheduledFuture[5]; |
608 |
> |
final Runnable releaser = new Runnable() { public void run() { |
609 |
> |
for (ScheduledFuture task : tasks) |
610 |
> |
if (task != null) task.cancel(true); }}; |
611 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
612 |
> |
try (PoolCleaner cleaner = cleaner(p, releaser)) { |
613 |
> |
for (int i = 0; i < tasks.length; i++) |
614 |
> |
tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(), |
615 |
> |
LONG_DELAY_MS, MILLISECONDS); |
616 |
|
int max = tasks.length; |
617 |
|
if (tasks[4].cancel(true)) --max; |
618 |
|
if (tasks[3].cancel(true)) --max; |
624 |
|
long count = p.getTaskCount(); |
625 |
|
if (count == max) |
626 |
|
return; |
627 |
< |
} while (millisElapsedSince(startTime) < MEDIUM_DELAY_MS); |
627 |
> |
} while (millisElapsedSince(startTime) < LONG_DELAY_MS); |
628 |
|
fail("Purge failed to remove cancelled tasks"); |
631 |
– |
} finally { |
632 |
– |
for (ScheduledFuture task : tasks) |
633 |
– |
task.cancel(true); |
634 |
– |
joinPool(p); |
629 |
|
} |
630 |
|
} |
631 |
|
|
649 |
|
}}; |
650 |
|
for (int i = 0; i < count; i++) |
651 |
|
p.execute(waiter); |
652 |
< |
assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS)); |
652 |
> |
await(threadsStarted); |
653 |
|
assertEquals(poolSize, p.getActiveCount()); |
654 |
|
assertEquals(0, p.getCompletedTaskCount()); |
655 |
|
final List<Runnable> queuedTasks; |
672 |
|
* and those tasks are drained from the queue |
673 |
|
*/ |
674 |
|
public void testShutdownNow_delayedTasks() throws InterruptedException { |
675 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
675 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
676 |
|
List<ScheduledFuture> tasks = new ArrayList<>(); |
677 |
|
for (int i = 0; i < 3; i++) { |
678 |
|
Runnable r = new NoOpRunnable(); |
1046 |
|
public void testTimedInvokeAny4() throws Exception { |
1047 |
|
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
1048 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1049 |
+ |
long startTime = System.nanoTime(); |
1050 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1051 |
|
l.add(new NPETask()); |
1052 |
|
try { |
1053 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1053 |
> |
e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); |
1054 |
|
shouldThrow(); |
1055 |
|
} catch (ExecutionException success) { |
1056 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
1057 |
|
} |
1058 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1059 |
|
} |
1060 |
|
} |
1061 |
|
|
1138 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1139 |
|
l.add(new NPETask()); |
1140 |
|
List<Future<String>> futures = |
1141 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1141 |
> |
e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS); |
1142 |
|
assertEquals(1, futures.size()); |
1143 |
|
try { |
1144 |
|
futures.get(0).get(); |
1170 |
|
* timed invokeAll(c) cancels tasks not completed by timeout |
1171 |
|
*/ |
1172 |
|
public void testTimedInvokeAll6() throws Exception { |
1173 |
< |
final ExecutorService e = new ScheduledThreadPoolExecutor(2); |
1174 |
< |
try (PoolCleaner cleaner = cleaner(e)) { |
1175 |
< |
for (long timeout = timeoutMillis();;) { |
1173 |
> |
for (long timeout = timeoutMillis();;) { |
1174 |
> |
final CountDownLatch done = new CountDownLatch(1); |
1175 |
> |
final Callable<String> waiter = new CheckedCallable<String>() { |
1176 |
> |
public String realCall() { |
1177 |
> |
try { done.await(LONG_DELAY_MS, MILLISECONDS); } |
1178 |
> |
catch (InterruptedException ok) {} |
1179 |
> |
return "1"; }}; |
1180 |
> |
final ExecutorService p = new ScheduledThreadPoolExecutor(2); |
1181 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
1182 |
|
List<Callable<String>> tasks = new ArrayList<>(); |
1183 |
|
tasks.add(new StringTask("0")); |
1184 |
< |
tasks.add(Executors.callable(new LongPossiblyInterruptedRunnable(), TEST_STRING)); |
1184 |
> |
tasks.add(waiter); |
1185 |
|
tasks.add(new StringTask("2")); |
1186 |
|
long startTime = System.nanoTime(); |
1187 |
|
List<Future<String>> futures = |
1188 |
< |
e.invokeAll(tasks, timeout, MILLISECONDS); |
1188 |
> |
p.invokeAll(tasks, timeout, MILLISECONDS); |
1189 |
|
assertEquals(tasks.size(), futures.size()); |
1190 |
|
assertTrue(millisElapsedSince(startTime) >= timeout); |
1191 |
|
for (Future future : futures) |