1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
22 |
|
import java.util.concurrent.ForkJoinWorkerThread; |
23 |
|
import java.util.concurrent.RecursiveTask; |
24 |
|
import java.util.concurrent.TimeUnit; |
25 |
+ |
import java.util.concurrent.atomic.AtomicBoolean; |
26 |
|
import java.util.concurrent.locks.ReentrantLock; |
27 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
28 |
+ |
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
29 |
|
import java.security.AccessControlException; |
30 |
|
import java.security.Policy; |
31 |
|
import java.security.PrivilegedAction; |
40 |
|
return new TestSuite(ForkJoinPoolTest.class); |
41 |
|
} |
42 |
|
|
43 |
< |
/** |
43 |
> |
/* |
44 |
|
* Testing coverage notes: |
45 |
|
* |
46 |
|
* 1. shutdown and related methods are tested via super.joinPool. |
166 |
|
try { |
167 |
|
assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory, |
168 |
|
p.getFactory()); |
166 |
– |
assertTrue(p.isQuiescent()); |
169 |
|
assertFalse(p.getAsyncMode()); |
170 |
|
assertEquals(0, p.getActiveThreadCount()); |
171 |
|
assertEquals(0, p.getStealCount()); |
200 |
|
} catch (NullPointerException success) {} |
201 |
|
} |
202 |
|
|
201 |
– |
|
203 |
|
/** |
204 |
|
* getParallelism returns size set in constructor |
205 |
|
*/ |
227 |
|
} |
228 |
|
|
229 |
|
/** |
230 |
+ |
* awaitTermination on a non-shutdown pool times out |
231 |
+ |
*/ |
232 |
+ |
public void testAwaitTermination_timesOut() throws InterruptedException { |
233 |
+ |
ForkJoinPool p = new ForkJoinPool(1); |
234 |
+ |
assertFalse(p.isTerminated()); |
235 |
+ |
assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS)); |
236 |
+ |
assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS)); |
237 |
+ |
assertFalse(p.awaitTermination(-1L, NANOSECONDS)); |
238 |
+ |
assertFalse(p.awaitTermination(-1L, MILLISECONDS)); |
239 |
+ |
assertFalse(p.awaitTermination(0L, NANOSECONDS)); |
240 |
+ |
assertFalse(p.awaitTermination(0L, MILLISECONDS)); |
241 |
+ |
long timeoutNanos = 999999L; |
242 |
+ |
long startTime = System.nanoTime(); |
243 |
+ |
assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS)); |
244 |
+ |
assertTrue(System.nanoTime() - startTime >= timeoutNanos); |
245 |
+ |
assertFalse(p.isTerminated()); |
246 |
+ |
startTime = System.nanoTime(); |
247 |
+ |
long timeoutMillis = timeoutMillis(); |
248 |
+ |
assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS)); |
249 |
+ |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
250 |
+ |
assertFalse(p.isTerminated()); |
251 |
+ |
p.shutdown(); |
252 |
+ |
assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
253 |
+ |
assertTrue(p.isTerminated()); |
254 |
+ |
} |
255 |
+ |
|
256 |
+ |
/** |
257 |
|
* setUncaughtExceptionHandler changes handler for uncaught exceptions. |
258 |
|
* |
259 |
|
* Additionally tests: Overriding ForkJoinWorkerThread.onStart |
260 |
|
* performs its defined action |
261 |
|
*/ |
262 |
|
public void testSetUncaughtExceptionHandler() throws InterruptedException { |
263 |
< |
MyHandler eh = new MyHandler(); |
263 |
> |
final CountDownLatch uehInvoked = new CountDownLatch(1); |
264 |
> |
final Thread.UncaughtExceptionHandler eh = |
265 |
> |
new Thread.UncaughtExceptionHandler() { |
266 |
> |
public void uncaughtException(Thread t, Throwable e) { |
267 |
> |
uehInvoked.countDown(); |
268 |
> |
}}; |
269 |
|
ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(), |
270 |
|
eh, false); |
271 |
|
try { |
272 |
|
assertSame(eh, p.getUncaughtExceptionHandler()); |
273 |
< |
p.execute(new FailingTask()); |
274 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
275 |
< |
assertTrue(eh.catches > 0); |
273 |
> |
try { |
274 |
> |
p.execute(new FibTask(8)); |
275 |
> |
assertTrue(uehInvoked.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
276 |
> |
} catch (RejectedExecutionException ok) { |
277 |
> |
} |
278 |
|
} finally { |
279 |
< |
p.shutdownNow(); |
279 |
> |
p.shutdownNow(); // failure might have prevented processing task |
280 |
|
joinPool(p); |
281 |
|
} |
282 |
|
} |
283 |
|
|
284 |
|
/** |
285 |
< |
* After invoking a single task, isQuiescent is true, |
286 |
< |
* queues are empty, threads are not active, and |
287 |
< |
* construction parameters continue to hold |
285 |
> |
* After invoking a single task, isQuiescent eventually becomes |
286 |
> |
* true, at which time queues are empty, threads are not active, |
287 |
> |
* the task has completed successfully, and construction |
288 |
> |
* parameters continue to hold |
289 |
|
*/ |
290 |
< |
public void testisQuiescent() throws InterruptedException { |
290 |
> |
public void testIsQuiescent() throws Exception { |
291 |
|
ForkJoinPool p = new ForkJoinPool(2); |
292 |
|
try { |
293 |
< |
p.invoke(new FibTask(20)); |
293 |
> |
assertTrue(p.isQuiescent()); |
294 |
> |
long startTime = System.nanoTime(); |
295 |
> |
FibTask f = new FibTask(20); |
296 |
> |
p.invoke(f); |
297 |
|
assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory, |
298 |
|
p.getFactory()); |
299 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
299 |
> |
while (! p.isQuiescent()) { |
300 |
> |
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
301 |
> |
throw new AssertionFailedError("timed out"); |
302 |
> |
assertFalse(p.getAsyncMode()); |
303 |
> |
assertFalse(p.isShutdown()); |
304 |
> |
assertFalse(p.isTerminating()); |
305 |
> |
assertFalse(p.isTerminated()); |
306 |
> |
Thread.yield(); |
307 |
> |
} |
308 |
> |
|
309 |
|
assertTrue(p.isQuiescent()); |
310 |
|
assertFalse(p.getAsyncMode()); |
311 |
|
assertEquals(0, p.getActiveThreadCount()); |
315 |
|
assertFalse(p.isShutdown()); |
316 |
|
assertFalse(p.isTerminating()); |
317 |
|
assertFalse(p.isTerminated()); |
318 |
+ |
assertTrue(f.isDone()); |
319 |
+ |
assertEquals(6765, (int) f.get()); |
320 |
|
} finally { |
321 |
|
joinPool(p); |
322 |
|
} |
360 |
|
try { |
361 |
|
ReentrantLock lock = new ReentrantLock(); |
362 |
|
ManagedLocker locker = new ManagedLocker(lock); |
363 |
< |
ForkJoinTask<Integer> f = new LockingFibTask(30, locker, lock); |
363 |
> |
ForkJoinTask<Integer> f = new LockingFibTask(20, locker, lock); |
364 |
|
p.execute(f); |
365 |
< |
assertEquals(832040, (int) f.get()); |
365 |
> |
assertEquals(6765, (int) f.get()); |
366 |
|
} finally { |
367 |
|
p.shutdownNow(); // don't wait out shutdown |
368 |
|
} |
372 |
|
* pollSubmission returns unexecuted submitted task, if present |
373 |
|
*/ |
374 |
|
public void testPollSubmission() { |
375 |
+ |
final CountDownLatch done = new CountDownLatch(1); |
376 |
|
SubFJP p = new SubFJP(); |
377 |
|
try { |
378 |
< |
ForkJoinTask a = p.submit(new MediumRunnable()); |
379 |
< |
ForkJoinTask b = p.submit(new MediumRunnable()); |
380 |
< |
ForkJoinTask c = p.submit(new MediumRunnable()); |
378 |
> |
ForkJoinTask a = p.submit(awaiter(done)); |
379 |
> |
ForkJoinTask b = p.submit(awaiter(done)); |
380 |
> |
ForkJoinTask c = p.submit(awaiter(done)); |
381 |
|
ForkJoinTask r = p.pollSubmission(); |
382 |
|
assertTrue(r == a || r == b || r == c); |
383 |
|
assertFalse(r.isDone()); |
384 |
|
} finally { |
385 |
+ |
done.countDown(); |
386 |
|
joinPool(p); |
387 |
|
} |
388 |
|
} |
391 |
|
* drainTasksTo transfers unexecuted submitted tasks, if present |
392 |
|
*/ |
393 |
|
public void testDrainTasksTo() { |
394 |
+ |
final CountDownLatch done = new CountDownLatch(1); |
395 |
|
SubFJP p = new SubFJP(); |
396 |
|
try { |
397 |
< |
ForkJoinTask a = p.submit(new MediumRunnable()); |
398 |
< |
ForkJoinTask b = p.submit(new MediumRunnable()); |
399 |
< |
ForkJoinTask c = p.submit(new MediumRunnable()); |
397 |
> |
ForkJoinTask a = p.submit(awaiter(done)); |
398 |
> |
ForkJoinTask b = p.submit(awaiter(done)); |
399 |
> |
ForkJoinTask c = p.submit(awaiter(done)); |
400 |
|
ArrayList<ForkJoinTask> al = new ArrayList(); |
401 |
|
p.drainTasksTo(al); |
402 |
|
assertTrue(al.size() > 0); |
405 |
|
assertFalse(r.isDone()); |
406 |
|
} |
407 |
|
} finally { |
408 |
+ |
done.countDown(); |
409 |
|
joinPool(p); |
410 |
|
} |
411 |
|
} |
412 |
|
|
359 |
– |
|
413 |
|
// FJ Versions of AbstractExecutorService tests |
414 |
|
|
415 |
|
/** |
418 |
|
public void testExecuteRunnable() throws Throwable { |
419 |
|
ExecutorService e = new ForkJoinPool(1); |
420 |
|
try { |
421 |
< |
TrackedShortRunnable task = new TrackedShortRunnable(); |
422 |
< |
assertFalse(task.done); |
421 |
> |
final AtomicBoolean done = new AtomicBoolean(false); |
422 |
> |
CheckedRunnable task = new CheckedRunnable() { |
423 |
> |
public void realRun() { |
424 |
> |
done.set(true); |
425 |
> |
}}; |
426 |
|
Future<?> future = e.submit(task); |
427 |
< |
future.get(); |
428 |
< |
assertTrue(task.done); |
427 |
> |
assertNull(future.get()); |
428 |
> |
assertNull(future.get(0, MILLISECONDS)); |
429 |
> |
assertTrue(done.get()); |
430 |
> |
assertTrue(future.isDone()); |
431 |
> |
assertFalse(future.isCancelled()); |
432 |
|
} finally { |
433 |
|
joinPool(e); |
434 |
|
} |
435 |
|
} |
436 |
|
|
378 |
– |
|
437 |
|
/** |
438 |
|
* Completed submit(callable) returns result |
439 |
|
*/ |
441 |
|
ExecutorService e = new ForkJoinPool(1); |
442 |
|
try { |
443 |
|
Future<String> future = e.submit(new StringTask()); |
444 |
< |
String result = future.get(); |
445 |
< |
assertSame(TEST_STRING, result); |
444 |
> |
assertSame(TEST_STRING, future.get()); |
445 |
> |
assertTrue(future.isDone()); |
446 |
> |
assertFalse(future.isCancelled()); |
447 |
|
} finally { |
448 |
|
joinPool(e); |
449 |
|
} |
456 |
|
ExecutorService e = new ForkJoinPool(1); |
457 |
|
try { |
458 |
|
Future<?> future = e.submit(new NoOpRunnable()); |
459 |
< |
future.get(); |
459 |
> |
assertNull(future.get()); |
460 |
|
assertTrue(future.isDone()); |
461 |
+ |
assertFalse(future.isCancelled()); |
462 |
|
} finally { |
463 |
|
joinPool(e); |
464 |
|
} |
471 |
|
ExecutorService e = new ForkJoinPool(1); |
472 |
|
try { |
473 |
|
Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING); |
474 |
< |
String result = future.get(); |
475 |
< |
assertSame(TEST_STRING, result); |
474 |
> |
assertSame(TEST_STRING, future.get()); |
475 |
> |
assertTrue(future.isDone()); |
476 |
> |
assertFalse(future.isCancelled()); |
477 |
|
} finally { |
478 |
|
joinPool(e); |
479 |
|
} |
480 |
|
} |
481 |
|
|
421 |
– |
|
482 |
|
/** |
483 |
< |
* A submitted privileged action to completion |
483 |
> |
* A submitted privileged action runs to completion |
484 |
|
*/ |
485 |
< |
public void testSubmitPrivilegedAction() throws Throwable { |
486 |
< |
Policy savedPolicy = null; |
487 |
< |
try { |
488 |
< |
savedPolicy = Policy.getPolicy(); |
489 |
< |
AdjustablePolicy policy = new AdjustablePolicy(); |
430 |
< |
policy.addPermission(new RuntimePermission("getContextClassLoader")); |
431 |
< |
policy.addPermission(new RuntimePermission("setContextClassLoader")); |
432 |
< |
Policy.setPolicy(policy); |
433 |
< |
} catch (AccessControlException ok) { |
434 |
< |
return; |
435 |
< |
} |
436 |
< |
|
437 |
< |
try { |
485 |
> |
public void testSubmitPrivilegedAction() throws Exception { |
486 |
> |
final Callable callable = Executors.callable(new PrivilegedAction() { |
487 |
> |
public Object run() { return TEST_STRING; }}); |
488 |
> |
Runnable r = new CheckedRunnable() { |
489 |
> |
public void realRun() throws Exception { |
490 |
|
ExecutorService e = new ForkJoinPool(1); |
491 |
|
try { |
492 |
< |
Future future = e.submit(Executors.callable(new PrivilegedAction() { |
493 |
< |
public Object run() { |
442 |
< |
return TEST_STRING; |
443 |
< |
}})); |
444 |
< |
|
445 |
< |
Object result = future.get(); |
446 |
< |
assertSame(TEST_STRING, result); |
492 |
> |
Future future = e.submit(callable); |
493 |
> |
assertSame(TEST_STRING, future.get()); |
494 |
|
} finally { |
495 |
|
joinPool(e); |
496 |
|
} |
497 |
< |
} finally { |
498 |
< |
Policy.setPolicy(savedPolicy); |
499 |
< |
} |
497 |
> |
}}; |
498 |
> |
|
499 |
> |
runWithPermissions(r, new RuntimePermission("modifyThread")); |
500 |
|
} |
501 |
|
|
502 |
|
/** |
503 |
< |
* A submitted a privileged exception action runs to completion |
503 |
> |
* A submitted privileged exception action runs to completion |
504 |
|
*/ |
505 |
< |
public void testSubmitPrivilegedExceptionAction() throws Throwable { |
506 |
< |
Policy savedPolicy = null; |
507 |
< |
try { |
508 |
< |
savedPolicy = Policy.getPolicy(); |
509 |
< |
AdjustablePolicy policy = new AdjustablePolicy(); |
510 |
< |
policy.addPermission(new RuntimePermission("getContextClassLoader")); |
464 |
< |
policy.addPermission(new RuntimePermission("setContextClassLoader")); |
465 |
< |
Policy.setPolicy(policy); |
466 |
< |
} catch (AccessControlException ok) { |
467 |
< |
return; |
468 |
< |
} |
469 |
< |
|
470 |
< |
try { |
505 |
> |
public void testSubmitPrivilegedExceptionAction() throws Exception { |
506 |
> |
final Callable callable = |
507 |
> |
Executors.callable(new PrivilegedExceptionAction() { |
508 |
> |
public Object run() { return TEST_STRING; }}); |
509 |
> |
Runnable r = new CheckedRunnable() { |
510 |
> |
public void realRun() throws Exception { |
511 |
|
ExecutorService e = new ForkJoinPool(1); |
512 |
|
try { |
513 |
< |
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
514 |
< |
public Object run() { |
475 |
< |
return TEST_STRING; |
476 |
< |
}})); |
477 |
< |
|
478 |
< |
Object result = future.get(); |
479 |
< |
assertSame(TEST_STRING, result); |
513 |
> |
Future future = e.submit(callable); |
514 |
> |
assertSame(TEST_STRING, future.get()); |
515 |
|
} finally { |
516 |
|
joinPool(e); |
517 |
|
} |
518 |
< |
} finally { |
519 |
< |
Policy.setPolicy(savedPolicy); |
520 |
< |
} |
518 |
> |
}}; |
519 |
> |
|
520 |
> |
runWithPermissions(r, new RuntimePermission("modifyThread")); |
521 |
|
} |
522 |
|
|
523 |
|
/** |
524 |
|
* A submitted failed privileged exception action reports exception |
525 |
|
*/ |
526 |
< |
public void testSubmitFailedPrivilegedExceptionAction() throws Throwable { |
527 |
< |
Policy savedPolicy = null; |
528 |
< |
try { |
529 |
< |
savedPolicy = Policy.getPolicy(); |
530 |
< |
AdjustablePolicy policy = new AdjustablePolicy(); |
531 |
< |
policy.addPermission(new RuntimePermission("getContextClassLoader")); |
497 |
< |
policy.addPermission(new RuntimePermission("setContextClassLoader")); |
498 |
< |
Policy.setPolicy(policy); |
499 |
< |
} catch (AccessControlException ok) { |
500 |
< |
return; |
501 |
< |
} |
502 |
< |
|
503 |
< |
try { |
526 |
> |
public void testSubmitFailedPrivilegedExceptionAction() throws Exception { |
527 |
> |
final Callable callable = |
528 |
> |
Executors.callable(new PrivilegedExceptionAction() { |
529 |
> |
public Object run() { throw new IndexOutOfBoundsException(); }}); |
530 |
> |
Runnable r = new CheckedRunnable() { |
531 |
> |
public void realRun() throws Exception { |
532 |
|
ExecutorService e = new ForkJoinPool(1); |
533 |
|
try { |
534 |
< |
Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { |
535 |
< |
public Object run() throws Exception { |
536 |
< |
throw new IndexOutOfBoundsException(); |
537 |
< |
}})); |
538 |
< |
|
539 |
< |
Object result = future.get(); |
540 |
< |
shouldThrow(); |
513 |
< |
} catch (ExecutionException success) { |
514 |
< |
assertTrue(success.getCause() instanceof IndexOutOfBoundsException); |
534 |
> |
Future future = e.submit(callable); |
535 |
> |
try { |
536 |
> |
future.get(); |
537 |
> |
shouldThrow(); |
538 |
> |
} catch (ExecutionException success) { |
539 |
> |
assertTrue(success.getCause() instanceof IndexOutOfBoundsException); |
540 |
> |
} |
541 |
|
} finally { |
542 |
|
joinPool(e); |
543 |
|
} |
544 |
< |
} finally { |
545 |
< |
Policy.setPolicy(savedPolicy); |
546 |
< |
} |
544 |
> |
}}; |
545 |
> |
|
546 |
> |
runWithPermissions(r, new RuntimePermission("modifyThread")); |
547 |
|
} |
548 |
|
|
549 |
|
/** |
551 |
|
*/ |
552 |
|
public void testExecuteNullRunnable() { |
553 |
|
ExecutorService e = new ForkJoinPool(1); |
528 |
– |
TrackedShortRunnable task = null; |
554 |
|
try { |
555 |
< |
Future<?> future = e.submit(task); |
555 |
> |
Future<?> future = e.submit((Runnable) null); |
556 |
|
shouldThrow(); |
557 |
|
} catch (NullPointerException success) { |
558 |
|
} finally { |
560 |
|
} |
561 |
|
} |
562 |
|
|
538 |
– |
|
563 |
|
/** |
564 |
|
* submit(null callable) throws NullPointerException |
565 |
|
*/ |
566 |
|
public void testSubmitNullCallable() { |
567 |
|
ExecutorService e = new ForkJoinPool(1); |
544 |
– |
StringTask t = null; |
568 |
|
try { |
569 |
< |
Future<String> future = e.submit(t); |
569 |
> |
Future<String> future = e.submit((Callable) null); |
570 |
|
shouldThrow(); |
571 |
|
} catch (NullPointerException success) { |
572 |
|
} finally { |
574 |
|
} |
575 |
|
} |
576 |
|
|
554 |
– |
|
577 |
|
/** |
578 |
< |
* Blocking on submit(callable) throws InterruptedException if |
557 |
< |
* caller interrupted. |
578 |
> |
* submit(callable).get() throws InterruptedException if interrupted |
579 |
|
*/ |
580 |
|
public void testInterruptedSubmit() throws InterruptedException { |
581 |
< |
final ForkJoinPool p = new ForkJoinPool(1); |
582 |
< |
|
583 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
584 |
< |
public void realRun() throws Throwable { |
585 |
< |
p.submit(new CheckedCallable<Object>() { |
586 |
< |
public Object realCall() throws Throwable { |
587 |
< |
try { |
588 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
589 |
< |
} catch (InterruptedException ok) { |
590 |
< |
} |
591 |
< |
return null; |
592 |
< |
}}).get(); |
593 |
< |
}}); |
594 |
< |
|
595 |
< |
t.start(); |
596 |
< |
Thread.sleep(SHORT_DELAY_MS); |
597 |
< |
t.interrupt(); |
598 |
< |
t.join(); |
599 |
< |
p.shutdownNow(); |
600 |
< |
joinPool(p); |
581 |
> |
final CountDownLatch submitted = new CountDownLatch(1); |
582 |
> |
final CountDownLatch quittingTime = new CountDownLatch(1); |
583 |
> |
final ExecutorService p = new ForkJoinPool(1); |
584 |
> |
final Callable<Void> awaiter = new CheckedCallable<Void>() { |
585 |
> |
public Void realCall() throws InterruptedException { |
586 |
> |
assertTrue(quittingTime.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
587 |
> |
return null; |
588 |
> |
}}; |
589 |
> |
try { |
590 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
591 |
> |
public void realRun() throws Exception { |
592 |
> |
Future<Void> future = p.submit(awaiter); |
593 |
> |
submitted.countDown(); |
594 |
> |
future.get(); |
595 |
> |
}}); |
596 |
> |
t.start(); |
597 |
> |
assertTrue(submitted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
598 |
> |
t.interrupt(); |
599 |
> |
t.join(); |
600 |
> |
} finally { |
601 |
> |
quittingTime.countDown(); |
602 |
> |
joinPool(p); |
603 |
> |
} |
604 |
|
} |
605 |
|
|
606 |
|
/** |
611 |
|
ForkJoinPool p = new ForkJoinPool(1); |
612 |
|
try { |
613 |
|
p.submit(new Callable() { |
614 |
< |
public Object call() { |
615 |
< |
int i = 5/0; |
592 |
< |
return Boolean.TRUE; |
593 |
< |
}}).get(); |
614 |
> |
public Object call() { throw new ArithmeticException(); }}) |
615 |
> |
.get(); |
616 |
|
shouldThrow(); |
617 |
|
} catch (ExecutionException success) { |
618 |
|
assertTrue(success.getCause() instanceof ArithmeticException); |
800 |
|
} |
801 |
|
} |
802 |
|
|
781 |
– |
|
803 |
|
/** |
804 |
|
* timed invokeAny(null) throws NullPointerException |
805 |
|
*/ |
806 |
|
public void testTimedInvokeAny1() throws Throwable { |
807 |
|
ExecutorService e = new ForkJoinPool(1); |
808 |
|
try { |
809 |
< |
e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
809 |
> |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); |
810 |
|
shouldThrow(); |
811 |
|
} catch (NullPointerException success) { |
812 |
|
} finally { |
837 |
|
ExecutorService e = new ForkJoinPool(1); |
838 |
|
try { |
839 |
|
e.invokeAny(new ArrayList<Callable<String>>(), |
840 |
< |
MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
840 |
> |
MEDIUM_DELAY_MS, MILLISECONDS); |
841 |
|
shouldThrow(); |
842 |
|
} catch (IllegalArgumentException success) { |
843 |
|
} finally { |
855 |
|
l.add(latchAwaitingStringTask(latch)); |
856 |
|
l.add(null); |
857 |
|
try { |
858 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
858 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
859 |
|
shouldThrow(); |
860 |
|
} catch (NullPointerException success) { |
861 |
|
} finally { |
872 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
873 |
|
l.add(new NPETask()); |
874 |
|
try { |
875 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
875 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
876 |
|
shouldThrow(); |
877 |
|
} catch (ExecutionException success) { |
878 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
890 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
891 |
|
l.add(new StringTask()); |
892 |
|
l.add(new StringTask()); |
893 |
< |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
893 |
> |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
894 |
|
assertSame(TEST_STRING, result); |
895 |
|
} finally { |
896 |
|
joinPool(e); |
903 |
|
public void testTimedInvokeAll1() throws Throwable { |
904 |
|
ExecutorService e = new ForkJoinPool(1); |
905 |
|
try { |
906 |
< |
e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
906 |
> |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); |
907 |
|
shouldThrow(); |
908 |
|
} catch (NullPointerException success) { |
909 |
|
} finally { |
935 |
|
try { |
936 |
|
List<Future<String>> r |
937 |
|
= e.invokeAll(new ArrayList<Callable<String>>(), |
938 |
< |
MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
938 |
> |
MEDIUM_DELAY_MS, MILLISECONDS); |
939 |
|
assertTrue(r.isEmpty()); |
940 |
|
} finally { |
941 |
|
joinPool(e); |
951 |
|
l.add(new StringTask()); |
952 |
|
l.add(null); |
953 |
|
try { |
954 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
954 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
955 |
|
shouldThrow(); |
956 |
|
} catch (NullPointerException success) { |
957 |
|
} finally { |
967 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
968 |
|
l.add(new NPETask()); |
969 |
|
List<Future<String>> futures |
970 |
< |
= e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
970 |
> |
= e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
971 |
|
assertEquals(1, futures.size()); |
972 |
|
try { |
973 |
|
futures.get(0).get(); |
989 |
|
l.add(new StringTask()); |
990 |
|
l.add(new StringTask()); |
991 |
|
List<Future<String>> futures |
992 |
< |
= e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
992 |
> |
= e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
993 |
|
assertEquals(2, futures.size()); |
994 |
|
for (Future<String> future : futures) |
995 |
|
assertSame(TEST_STRING, future.get()); |