220 |
|
normalizedTime <= cycles) |
221 |
|
return; |
222 |
|
} |
223 |
< |
throw new AssertionError("unexpected execution rate"); |
223 |
> |
fail("unexpected execution rate"); |
224 |
|
} |
225 |
|
} |
226 |
|
|
246 |
|
normalizedTime <= cycles) |
247 |
|
return; |
248 |
|
} |
249 |
< |
throw new AssertionError("unexpected execution rate"); |
249 |
> |
fail("unexpected execution rate"); |
250 |
|
} |
251 |
|
} |
252 |
|
|
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 |
|
|
1116 |
|
public void testTimedInvokeAny5() throws Exception { |
1117 |
|
final ExecutorService e = new CustomExecutor(2); |
1118 |
|
try (PoolCleaner cleaner = cleaner(e)) { |
1119 |
+ |
long startTime = System.nanoTime(); |
1120 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1121 |
|
l.add(new StringTask()); |
1122 |
|
l.add(new StringTask()); |
1123 |
< |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1123 |
> |
String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS); |
1124 |
|
assertSame(TEST_STRING, result); |
1125 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1126 |
|
} |
1127 |
|
} |
1128 |
|
|
1222 |
|
* timed invokeAll(c) cancels tasks not completed by timeout |
1223 |
|
*/ |
1224 |
|
public void testTimedInvokeAll6() throws Exception { |
1225 |
< |
final ExecutorService e = new CustomExecutor(2); |
1226 |
< |
try (PoolCleaner cleaner = cleaner(e)) { |
1227 |
< |
for (long timeout = timeoutMillis();;) { |
1225 |
> |
for (long timeout = timeoutMillis();;) { |
1226 |
> |
final CountDownLatch done = new CountDownLatch(1); |
1227 |
> |
final Callable<String> waiter = new CheckedCallable<String>() { |
1228 |
> |
public String realCall() { |
1229 |
> |
try { done.await(LONG_DELAY_MS, MILLISECONDS); } |
1230 |
> |
catch (InterruptedException ok) {} |
1231 |
> |
return "1"; }}; |
1232 |
> |
final ExecutorService p = new CustomExecutor(2); |
1233 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
1234 |
|
List<Callable<String>> tasks = new ArrayList<>(); |
1235 |
|
tasks.add(new StringTask("0")); |
1236 |
< |
tasks.add(Executors.callable(new LongPossiblyInterruptedRunnable(), TEST_STRING)); |
1236 |
> |
tasks.add(waiter); |
1237 |
|
tasks.add(new StringTask("2")); |
1238 |
|
long startTime = System.nanoTime(); |
1239 |
|
List<Future<String>> futures = |
1240 |
< |
e.invokeAll(tasks, timeout, MILLISECONDS); |
1240 |
> |
p.invokeAll(tasks, timeout, MILLISECONDS); |
1241 |
|
assertEquals(tasks.size(), futures.size()); |
1242 |
|
assertTrue(millisElapsedSince(startTime) >= timeout); |
1243 |
|
for (Future future : futures) |