194 |
|
final CountDownLatch quittingTime = new CountDownLatch(1); |
195 |
|
final Callable<Void> awaiter = new CheckedCallable<Void>() { |
196 |
|
public Void realCall() throws InterruptedException { |
197 |
< |
quittingTime.await(); |
197 |
> |
assertTrue(quittingTime.await(2*LONG_DELAY_MS, MILLISECONDS)); |
198 |
|
return null; |
199 |
|
}}; |
200 |
|
final ExecutorService p |
201 |
|
= new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, |
202 |
|
new ArrayBlockingQueue<Runnable>(10)); |
203 |
< |
try (PoolCleaner cleaner = cleaner(p)) { |
204 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
203 |
> |
try (PoolCleaner cleaner = cleaner(p, quittingTime)) { |
204 |
> |
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
205 |
|
public void realRun() throws Exception { |
206 |
|
Future<Void> future = p.submit(awaiter); |
207 |
|
submitted.countDown(); |
208 |
|
future.get(); |
209 |
|
}}); |
210 |
< |
t.start(); |
211 |
< |
submitted.await(); |
210 |
> |
|
211 |
> |
await(submitted); |
212 |
|
t.interrupt(); |
213 |
< |
t.join(); |
214 |
< |
quittingTime.countDown(); |
213 |
> |
awaitTermination(t); |
214 |
|
} |
215 |
|
} |
216 |
|
|
449 |
|
public void testTimedInvokeAny4() throws Exception { |
450 |
|
final ExecutorService e = new DirectExecutorService(); |
451 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
452 |
+ |
long startTime = System.nanoTime(); |
453 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
454 |
|
l.add(new NPETask()); |
455 |
|
try { |
456 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
456 |
> |
e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); |
457 |
|
shouldThrow(); |
458 |
|
} catch (ExecutionException success) { |
459 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
460 |
|
} |
461 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
462 |
|
} |
463 |
|
} |
464 |
|
|
468 |
|
public void testTimedInvokeAny5() throws Exception { |
469 |
|
final ExecutorService e = new DirectExecutorService(); |
470 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
471 |
+ |
long startTime = System.nanoTime(); |
472 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
473 |
|
l.add(new StringTask()); |
474 |
|
l.add(new StringTask()); |
475 |
< |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
475 |
> |
String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); |
476 |
|
assertSame(TEST_STRING, result); |
477 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
478 |
|
} |
479 |
|
} |
480 |
|
|
542 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
543 |
|
l.add(new NPETask()); |
544 |
|
List<Future<String>> futures = |
545 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
545 |
> |
e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS); |
546 |
|
assertEquals(1, futures.size()); |
547 |
|
try { |
548 |
|
futures.get(0).get(); |