1097 |
|
public void testTimedInvokeAny4() throws Exception { |
1098 |
|
final ExecutorService e = new CustomExecutor(2); |
1099 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1100 |
+ |
long startTime = System.nanoTime(); |
1101 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1102 |
|
l.add(new NPETask()); |
1103 |
|
try { |
1104 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1104 |
> |
e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); |
1105 |
|
shouldThrow(); |
1106 |
|
} catch (ExecutionException success) { |
1107 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
1108 |
|
} |
1109 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1110 |
|
} |
1111 |
|
} |
1112 |
|
|
1220 |
|
* timed invokeAll(c) cancels tasks not completed by timeout |
1221 |
|
*/ |
1222 |
|
public void testTimedInvokeAll6() throws Exception { |
1223 |
< |
final ExecutorService e = new CustomExecutor(2); |
1224 |
< |
try (PoolCleaner cleaner = cleaner(e)) { |
1225 |
< |
for (long timeout = timeoutMillis();;) { |
1223 |
> |
for (long timeout = timeoutMillis();;) { |
1224 |
> |
final CountDownLatch done = new CountDownLatch(1); |
1225 |
> |
final Callable<String> waiter = new CheckedCallable<String>() { |
1226 |
> |
public String realCall() { |
1227 |
> |
try { done.await(LONG_DELAY_MS, MILLISECONDS); } |
1228 |
> |
catch (InterruptedException ok) {} |
1229 |
> |
return "1"; }}; |
1230 |
> |
final ExecutorService p = new CustomExecutor(2); |
1231 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
1232 |
|
List<Callable<String>> tasks = new ArrayList<>(); |
1233 |
|
tasks.add(new StringTask("0")); |
1234 |
< |
tasks.add(Executors.callable(new LongPossiblyInterruptedRunnable(), TEST_STRING)); |
1234 |
> |
tasks.add(waiter); |
1235 |
|
tasks.add(new StringTask("2")); |
1236 |
|
long startTime = System.nanoTime(); |
1237 |
|
List<Future<String>> futures = |
1238 |
< |
e.invokeAll(tasks, timeout, MILLISECONDS); |
1238 |
> |
p.invokeAll(tasks, timeout, MILLISECONDS); |
1239 |
|
assertEquals(tasks.size(), futures.size()); |
1240 |
|
assertTrue(millisElapsedSince(startTime) >= timeout); |
1241 |
|
for (Future future : futures) |