ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ForkJoinPoolTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ForkJoinPoolTest.java (file contents):
Revision 1.1 by dl, Fri Jul 31 23:02:49 2009 UTC vs.
Revision 1.9 by jsr166, Wed Aug 5 00:49:40 2009 UTC

# Line 8 | Line 8
8   import junit.framework.*;
9   import java.util.*;
10   import java.util.concurrent.*;
11 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
12   import java.util.concurrent.locks.*;
13   import java.security.*;
14  
15 < public class ForkJoinPoolTest extends JSR166TestCase{
15 > public class ForkJoinPoolTest extends JSR166TestCase {
16      public static void main(String[] args) {
17          junit.textui.TestRunner.run (suite());
18      }
# Line 25 | Line 26 | public class ForkJoinPoolTest extends JS
26       * 1. shutdown and related methods are tested via super.joinPool.
27       *
28       * 2. newTaskFor and adapters are tested in submit/invoke tests
29 <     *
29 >     *
30       * 3. We cannot portably test monitoring methods such as
31       * getStealCount() since they rely ultimately on random task
32       * stealing that may cause tasks not to be stolen/propagated
33       * across threads, especially on uniprocessors.
34 <     *
34 >     *
35       * 4. There are no independently testable ForkJoinWorkerThread
36       * methods, but they are covered here and in task tests.
37       */
# Line 50 | Line 51 | public class ForkJoinPoolTest extends JS
51          protected void onStart() { throw new Error(); }
52      }
53  
54 <    static class FailingThreadFactory implements ForkJoinPool.ForkJoinWorkerThreadFactory {
54 >    static class FailingThreadFactory
55 >            implements ForkJoinPool.ForkJoinWorkerThreadFactory {
56          int calls = 0;
57 <        public ForkJoinWorkerThread newThread(ForkJoinPool p){
57 >        public ForkJoinWorkerThread newThread(ForkJoinPool p) {
58              if (++calls > 1) return null;
59              return new FailingFJWSubclass(p);
60 <        }  
60 >        }
61      }
62  
63 <    static class SubFJP extends ForkJoinPool { // to expose protected
63 >    static class SubFJP extends ForkJoinPool { // to expose protected
64          SubFJP() { super(1); }
65          public int drainTasksTo(Collection<? super ForkJoinTask<?>> c) {
66              return super.drainTasksTo(c);
# Line 83 | Line 85 | public class ForkJoinPoolTest extends JS
85      }
86  
87      // A simple recursive task for testing
88 <    static final class FibTask extends RecursiveTask<Integer> {
88 >    static final class FibTask extends RecursiveTask<Integer> {
89          final int number;
90          FibTask(int n) { number = n; }
91          public Integer compute() {
# Line 97 | Line 99 | public class ForkJoinPoolTest extends JS
99      }
100  
101      // A failing task for testing
102 <    static final class FailingTask extends ForkJoinTask<Void> {
102 >    static final class FailingTask extends ForkJoinTask<Void> {
103          public final Void getRawResult() { return null; }
104          protected final void setRawResult(Void mustBeNull) { }
105          protected final boolean exec() { throw new Error(); }
# Line 105 | Line 107 | public class ForkJoinPoolTest extends JS
107      }
108  
109      // Fib needlessly using locking to test ManagedBlockers
110 <    static final class LockingFibTask extends RecursiveTask<Integer> {
110 >    static final class LockingFibTask extends RecursiveTask<Integer> {
111          final int number;
112          final ManagedLocker locker;
113          final ReentrantLock lock;
114 <        LockingFibTask(int n, ManagedLocker locker, ReentrantLock lock) {
115 <            number = n;
114 >        LockingFibTask(int n, ManagedLocker locker, ReentrantLock lock) {
115 >            number = n;
116              this.locker = locker;
117              this.lock = lock;
118          }
# Line 119 | Line 121 | public class ForkJoinPoolTest extends JS
121              LockingFibTask f1 = null;
122              LockingFibTask f2 = null;
123              locker.block();
124 <            n = number;
124 >            n = number;
125              if (n > 1) {
126                  f1 = new LockingFibTask(n - 1, locker, lock);
127                  f2 = new LockingFibTask(n - 2, locker, lock);
# Line 134 | Line 136 | public class ForkJoinPoolTest extends JS
136          }
137      }
138  
139 <    /**
140 <     * Succesfully constructed pool reports default factory,
139 >    /**
140 >     * Successfully constructed pool reports default factory,
141       * parallelism and async mode policies, no active threads or
142       * tasks, and quiescent running state.
143       */
# Line 143 | Line 145 | public class ForkJoinPoolTest extends JS
145          ForkJoinPool p = null;
146          try {
147              p = new ForkJoinPool(1);
148 <            assertTrue(p.getFactory() == ForkJoinPool.defaultForkJoinWorkerThreadFactory);
148 >            assertTrue(p.getFactory() ==
149 >                       ForkJoinPool.defaultForkJoinWorkerThreadFactory);
150              assertTrue(p.isQuiescent());
151              assertTrue(p.getMaintainsParallelism());
152              assertFalse(p.getAsyncMode());
# Line 160 | Line 163 | public class ForkJoinPoolTest extends JS
163          }
164      }
165  
166 <    /**
167 <     * Constructor throws if size argument is less than zero
166 >    /**
167 >     * Constructor throws if size argument is less than zero
168       */
169      public void testConstructor1() {
170          try {
171              new ForkJoinPool(-1);
172              shouldThrow();
173          }
174 <        catch (IllegalArgumentException success){}
174 >        catch (IllegalArgumentException success) {}
175      }
176  
177 <    /**
178 <     * Constructor throws if factory argument is null
177 >    /**
178 >     * Constructor throws if factory argument is null
179       */
180      public void testConstructor2() {
181          try {
182              new ForkJoinPool(1, null);
183              shouldThrow();
184 +        } catch (NullPointerException success) {
185          }
182        catch (NullPointerException success){}  
186      }
187  
188  
189 <    /**
190 <     * getParallelism returns size set in constructor
189 >    /**
190 >     * getParallelism returns size set in constructor
191       */
192      public void testGetParallelism() {
193          ForkJoinPool p = null;
# Line 196 | Line 199 | public class ForkJoinPoolTest extends JS
199          }
200      }
201  
202 <    /**
202 >    /**
203       * setParallelism changes reported parallelism level.
204       */
205      public void testSetParallelism() {
# Line 211 | Line 214 | public class ForkJoinPoolTest extends JS
214          }
215      }
216  
217 <    /**
217 >    /**
218       * setParallelism with argument <= 0 throws exception
219       */
220      public void testSetParallelism2() {
# Line 221 | Line 224 | public class ForkJoinPoolTest extends JS
224              assertTrue(p.getParallelism() == 1);
225              p.setParallelism(-2);
226              shouldThrow();
227 <        }catch (IllegalArgumentException success){
227 >        } catch (IllegalArgumentException success) {
228          } finally {
229              joinPool(p);
230          }
231      }
232  
233 <    /**
233 >    /**
234       * getPoolSize returns number of started workers.
235       */
236      public void testGetPoolSize() {
# Line 243 | Line 246 | public class ForkJoinPoolTest extends JS
246          }
247      }
248  
249 <    /**
249 >    /**
250       * setMaximumPoolSize changes size reported by getMaximumPoolSize.
251       */
252      public void testSetMaximumPoolSize() {
# Line 257 | Line 260 | public class ForkJoinPoolTest extends JS
260          }
261      }
262  
263 <    /**
263 >    /**
264       * setMaximumPoolSize with argument <= 0 throws exception
265       */
266      public void testSetMaximumPoolSize2() {
# Line 266 | Line 269 | public class ForkJoinPoolTest extends JS
269              p = new ForkJoinPool(1);
270              p.setMaximumPoolSize(-2);
271              shouldThrow();
272 <        }catch (IllegalArgumentException success){
272 >        } catch (IllegalArgumentException success) {
273          } finally {
274              joinPool(p);
275          }
276      }
277  
278 <    /**
278 >    /**
279       * setMaintainsParallelism changes policy reported by
280       * getMaintainsParallelism.
281       */
# Line 286 | Line 289 | public class ForkJoinPoolTest extends JS
289              joinPool(p);
290          }
291      }
292 <    
293 <    /**
292 >
293 >    /**
294       * setAsyncMode changes policy reported by
295       * getAsyncMode.
296       */
# Line 302 | Line 305 | public class ForkJoinPoolTest extends JS
305          }
306      }
307  
308 <    /**
308 >    /**
309       * setUncaughtExceptionHandler changes handler for uncaught exceptions.
310       *
311       * Additionally tests: Overriding ForkJoinWorkerThread.onStart
312       * performs its defined action
313       */
314 <    public void testSetUncaughtExceptionHandler() {
314 >    public void testSetUncaughtExceptionHandler() throws InterruptedException {
315          ForkJoinPool p = null;
316          try {
317              p = new ForkJoinPool(1, new FailingThreadFactory());
# Line 318 | Line 321 | public class ForkJoinPoolTest extends JS
321              p.execute(new FailingTask());
322              Thread.sleep(MEDIUM_DELAY_MS);
323              assertTrue(eh.catches > 0);
321        } catch(InterruptedException e){
322            unexpectedException();
324          } finally {
325              joinPool(p);
326          }
327      }
328  
329 <    /**
329 >    /**
330       * setUncaughtExceptionHandler of null removes handler
331       */
332      public void testSetUncaughtExceptionHandler2() {
# Line 340 | Line 341 | public class ForkJoinPoolTest extends JS
341      }
342  
343  
344 <    /**
344 >    /**
345       * After invoking a single task, isQuiescent is true,
346       * queues are empty, threads are not active, and
347       * construction parameters continue to hold
348       */
349 <    public void testisQuiescent() {
349 >    public void testisQuiescent() throws InterruptedException {
350          ForkJoinPool p = null;
351          try {
352              p = new ForkJoinPool(2);
353              p.invoke(new FibTask(20));
354 <            assertTrue(p.getFactory() == ForkJoinPool.defaultForkJoinWorkerThreadFactory);
354 >            assertTrue(p.getFactory() ==
355 >                       ForkJoinPool.defaultForkJoinWorkerThreadFactory);
356              Thread.sleep(MEDIUM_DELAY_MS);
357              assertTrue(p.isQuiescent());
358              assertTrue(p.getMaintainsParallelism());
# Line 362 | Line 364 | public class ForkJoinPoolTest extends JS
364              assertFalse(p.isShutdown());
365              assertFalse(p.isTerminating());
366              assertFalse(p.isTerminated());
365        } catch(InterruptedException e){
366            unexpectedException();
367          } finally {
368              joinPool(p);
369          }
# Line 372 | Line 372 | public class ForkJoinPoolTest extends JS
372      /**
373       * Completed submit(ForkJoinTask) returns result
374       */
375 <    public void testSubmitForkJoinTask() {
375 >    public void testSubmitForkJoinTask() throws Throwable {
376          ForkJoinPool p = null;
377          try {
378              p = new ForkJoinPool(1);
379              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
380              int r = f.get();
381              assertTrue(r == 21);
382        } catch (ExecutionException ex) {
383            unexpectedException();
384        } catch (InterruptedException ex) {
385            unexpectedException();
382          } finally {
383              joinPool(p);
384          }
# Line 408 | Line 404 | public class ForkJoinPoolTest extends JS
404      /**
405       * Pool maintains parallelism when using ManagedBlocker
406       */
407 <    public void testBlockingForkJoinTask() {
407 >    public void testBlockingForkJoinTask() throws Throwable {
408          ForkJoinPool p = null;
409          try {
410              p = new ForkJoinPool(4);
# Line 419 | Line 415 | public class ForkJoinPoolTest extends JS
415              assertTrue(p.getPoolSize() >= 4);
416              int r = f.get();
417              assertTrue(r ==  832040);
422        } catch (ExecutionException ex) {
423            unexpectedException();
424        } catch (InterruptedException ex) {
425            unexpectedException();
418          } finally {
419 <            joinPool(p);
419 >            p.shutdownNow(); // don't wait out shutdown
420          }
421      }
422  
# Line 468 | Line 460 | public class ForkJoinPoolTest extends JS
460          }
461      }
462  
463 <    
463 >
464      // FJ Versions of AbstractExecutorService tests
465  
466      /**
467       * execute(runnable) runs it to completion
468       */
469 <    public void testExecuteRunnable() {
470 <        try {
471 <            ExecutorService e = new ForkJoinPool(1);
472 <            TrackedShortRunnable task = new TrackedShortRunnable();
473 <            assertFalse(task.done);
474 <            Future<?> future = e.submit(task);
475 <            future.get();
484 <            assertTrue(task.done);
485 <        }
486 <        catch (ExecutionException ex) {
487 <            unexpectedException();
488 <        }
489 <        catch (InterruptedException ex) {
490 <            unexpectedException();
491 <        }
469 >    public void testExecuteRunnable() throws Throwable {
470 >        ExecutorService e = new ForkJoinPool(1);
471 >        TrackedShortRunnable task = new TrackedShortRunnable();
472 >        assertFalse(task.done);
473 >        Future<?> future = e.submit(task);
474 >        future.get();
475 >        assertTrue(task.done);
476      }
477  
478  
479      /**
480       * Completed submit(callable) returns result
481       */
482 <    public void testSubmitCallable() {
483 <        try {
484 <            ExecutorService e = new ForkJoinPool(1);
485 <            Future<String> future = e.submit(new StringTask());
486 <            String result = future.get();
503 <            assertSame(TEST_STRING, result);
504 <        }
505 <        catch (ExecutionException ex) {
506 <            unexpectedException();
507 <        }
508 <        catch (InterruptedException ex) {
509 <            unexpectedException();
510 <        }
482 >    public void testSubmitCallable() throws Throwable {
483 >        ExecutorService e = new ForkJoinPool(1);
484 >        Future<String> future = e.submit(new StringTask());
485 >        String result = future.get();
486 >        assertSame(TEST_STRING, result);
487      }
488  
489      /**
490       * Completed submit(runnable) returns successfully
491       */
492 <    public void testSubmitRunnable() {
493 <        try {
494 <            ExecutorService e = new ForkJoinPool(1);
495 <            Future<?> future = e.submit(new NoOpRunnable());
496 <            future.get();
521 <            assertTrue(future.isDone());
522 <        }
523 <        catch (ExecutionException ex) {
524 <            unexpectedException();
525 <        }
526 <        catch (InterruptedException ex) {
527 <            unexpectedException();
528 <        }
492 >    public void testSubmitRunnable() throws Throwable {
493 >        ExecutorService e = new ForkJoinPool(1);
494 >        Future<?> future = e.submit(new NoOpRunnable());
495 >        future.get();
496 >        assertTrue(future.isDone());
497      }
498  
499      /**
500       * Completed submit(runnable, result) returns result
501       */
502 <    public void testSubmitRunnable2() {
503 <        try {
504 <            ExecutorService e = new ForkJoinPool(1);
505 <            Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
506 <            String result = future.get();
539 <            assertSame(TEST_STRING, result);
540 <        }
541 <        catch (ExecutionException ex) {
542 <            unexpectedException();
543 <        }
544 <        catch (InterruptedException ex) {
545 <            unexpectedException();
546 <        }
502 >    public void testSubmitRunnable2() throws Throwable {
503 >        ExecutorService e = new ForkJoinPool(1);
504 >        Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
505 >        String result = future.get();
506 >        assertSame(TEST_STRING, result);
507      }
508  
509  
510      /**
511       * A submitted privileged action to completion
512       */
513 <    public void testSubmitPrivilegedAction() {
513 >    public void testSubmitPrivilegedAction() throws Throwable {
514          Policy savedPolicy = null;
515          try {
516              savedPolicy = Policy.getPolicy();
# Line 558 | Line 518 | public class ForkJoinPoolTest extends JS
518              policy.addPermission(new RuntimePermission("getContextClassLoader"));
519              policy.addPermission(new RuntimePermission("setContextClassLoader"));
520              Policy.setPolicy(policy);
521 <        } catch(AccessControlException ok) {
521 >        } catch (AccessControlException ok) {
522              return;
523          }
524          try {
# Line 571 | Line 531 | public class ForkJoinPoolTest extends JS
531              Object result = future.get();
532              assertSame(TEST_STRING, result);
533          }
574        catch (ExecutionException ex) {
575            unexpectedException();
576        }
577        catch (InterruptedException ex) {
578            unexpectedException();
579        }
534          finally {
535 <            try {
582 <                Policy.setPolicy(savedPolicy);
583 <            } catch(AccessControlException ok) {
584 <                return;
585 <            }
535 >            Policy.setPolicy(savedPolicy);
536          }
537      }
538  
539      /**
540       * A submitted a privileged exception action runs to completion
541       */
542 <    public void testSubmitPrivilegedExceptionAction() {
542 >    public void testSubmitPrivilegedExceptionAction() throws Throwable {
543          Policy savedPolicy = null;
544          try {
545              savedPolicy = Policy.getPolicy();
# Line 597 | Line 547 | public class ForkJoinPoolTest extends JS
547              policy.addPermission(new RuntimePermission("getContextClassLoader"));
548              policy.addPermission(new RuntimePermission("setContextClassLoader"));
549              Policy.setPolicy(policy);
550 <        } catch(AccessControlException ok) {
550 >        } catch (AccessControlException ok) {
551              return;
552          }
553  
# Line 611 | Line 561 | public class ForkJoinPoolTest extends JS
561              Object result = future.get();
562              assertSame(TEST_STRING, result);
563          }
614        catch (ExecutionException ex) {
615            unexpectedException();
616        }
617        catch (InterruptedException ex) {
618            unexpectedException();
619        }
564          finally {
565              Policy.setPolicy(savedPolicy);
566          }
# Line 625 | Line 569 | public class ForkJoinPoolTest extends JS
569      /**
570       * A submitted failed privileged exception action reports exception
571       */
572 <    public void testSubmitFailedPrivilegedExceptionAction() {
572 >    public void testSubmitFailedPrivilegedExceptionAction() throws Throwable {
573          Policy savedPolicy = null;
574          try {
575              savedPolicy = Policy.getPolicy();
# Line 633 | Line 577 | public class ForkJoinPoolTest extends JS
577              policy.addPermission(new RuntimePermission("getContextClassLoader"));
578              policy.addPermission(new RuntimePermission("setContextClassLoader"));
579              Policy.setPolicy(policy);
580 <        } catch(AccessControlException ok) {
580 >        } catch (AccessControlException ok) {
581              return;
582          }
583  
# Line 647 | Line 591 | public class ForkJoinPoolTest extends JS
591  
592              Object result = future.get();
593              shouldThrow();
594 <        }
595 <        catch (ExecutionException success) {
652 <        } catch (CancellationException success) {
653 <        } catch (InterruptedException ex) {
654 <            unexpectedException();
655 <        }
656 <        finally {
594 >        } catch (ExecutionException success) {
595 >        } finally {
596              Policy.setPolicy(savedPolicy);
597          }
598      }
599  
600      /**
601 <     * execute(null runnable) throws NPE
601 >     * execute(null runnable) throws NullPointerException
602       */
603      public void testExecuteNullRunnable() {
604          try {
# Line 667 | Line 606 | public class ForkJoinPoolTest extends JS
606              TrackedShortRunnable task = null;
607              Future<?> future = e.submit(task);
608              shouldThrow();
609 <        }
671 <        catch (NullPointerException success) {
672 <        }
673 <        catch (Exception ex) {
674 <            unexpectedException();
609 >        } catch (NullPointerException success) {
610          }
611      }
612  
613  
614      /**
615 <     * submit(null callable) throws NPE
615 >     * submit(null callable) throws NullPointerException
616       */
617      public void testSubmitNullCallable() {
618          try {
# Line 685 | Line 620 | public class ForkJoinPoolTest extends JS
620              StringTask t = null;
621              Future<String> future = e.submit(t);
622              shouldThrow();
623 <        }
689 <        catch (NullPointerException success) {
690 <        }
691 <        catch (Exception ex) {
692 <            unexpectedException();
623 >        } catch (NullPointerException success) {
624          }
625      }
626  
627  
628      /**
629 <     *  Blocking on submit(callable) throws InterruptedException if
630 <     *  caller interrupted.
629 >     * Blocking on submit(callable) throws InterruptedException if
630 >     * caller interrupted.
631       */
632 <    public void testInterruptedSubmit() {
632 >    public void testInterruptedSubmit() throws InterruptedException {
633          final ForkJoinPool p = new ForkJoinPool(1);
634 <        Thread t = new Thread(new Runnable() {
635 <                public void run() {
636 <                    try {
637 <                        p.submit(new Callable<Object>() {
638 <                                public Object call() {
639 <                                    try {
640 <                                        Thread.sleep(MEDIUM_DELAY_MS);
641 <                                        shouldThrow();
642 <                                    } catch(InterruptedException e){
643 <                                    }
644 <                                    return null;
645 <                                }
646 <                            }).get();
647 <                    } catch(InterruptedException success){
648 <                    } catch(Exception e) {
649 <                        unexpectedException();
650 <                    }
651 <
721 <                }
722 <            });
723 <        try {
724 <            t.start();
725 <            Thread.sleep(SHORT_DELAY_MS);
726 <            t.interrupt();
727 <        } catch(Exception e){
728 <            unexpectedException();
729 <        }
634 >
635 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
636 >            void realRun() throws Throwable {
637 >                p.submit(new CheckedCallable<Object>() {
638 >                    public Object realCall() throws Throwable {
639 >                        try {
640 >                            Thread.sleep(MEDIUM_DELAY_MS);
641 >                        } catch (InterruptedException ok) {
642 >                        }
643 >                        return null;
644 >                    }}).get();
645 >            }});
646 >
647 >        t.start();
648 >        Thread.sleep(SHORT_DELAY_MS);
649 >        t.interrupt();
650 >        t.join();
651 >        p.shutdownNow();
652          joinPool(p);
653      }
654  
655      /**
656 <     *  get of submit(callable) throws ExecutionException if callable
657 <     *  throws exception
656 >     * get of submit(callable) throws ExecutionException if callable
657 >     * throws exception
658       */
659 <    public void testSubmitEE() {
659 >    public void testSubmitEE() throws Throwable {
660          ForkJoinPool p = new ForkJoinPool(1);
739
661          try {
662 <            Callable c = new Callable() {
663 <                    public Object call() {
664 <                        int i = 5/0;
665 <                        return Boolean.TRUE;
666 <                    }
746 <                };
747 <
748 <            for(int i =0; i < 5; i++){
749 <                p.submit(c).get();
750 <            }
751 <
662 >            p.submit(new Callable() {
663 >                public Object call() {
664 >                    int i = 5/0;
665 >                    return Boolean.TRUE;
666 >                }}).get();
667              shouldThrow();
668 <        }
754 <        catch(ExecutionException success){
755 <        } catch (CancellationException success) {
756 <        } catch(Exception e) {
757 <            unexpectedException();
668 >        } catch (ExecutionException success) {
669          }
670          joinPool(p);
671      }
672  
673      /**
674 <     * invokeAny(null) throws NPE
674 >     * invokeAny(null) throws NullPointerException
675       */
676 <    public void testInvokeAny1() {
676 >    public void testInvokeAny1() throws Throwable {
677          ExecutorService e = new ForkJoinPool(1);
678          try {
679              e.invokeAny(null);
680 +            shouldThrow();
681          } catch (NullPointerException success) {
770        } catch(Exception ex) {
771            unexpectedException();
682          } finally {
683              joinPool(e);
684          }
685      }
686  
687      /**
688 <     * invokeAny(empty collection) throws IAE
688 >     * invokeAny(empty collection) throws IllegalArgumentException
689       */
690 <    public void testInvokeAny2() {
690 >    public void testInvokeAny2() throws Throwable {
691          ExecutorService e = new ForkJoinPool(1);
692          try {
693              e.invokeAny(new ArrayList<Callable<String>>());
694 +            shouldThrow();
695          } catch (IllegalArgumentException success) {
785        } catch(Exception ex) {
786            unexpectedException();
696          } finally {
697              joinPool(e);
698          }
699      }
700  
701      /**
702 <     * invokeAny(c) throws NPE if c has null elements
702 >     * invokeAny(c) throws NullPointerException if c has a single null element
703       */
704 <    public void testInvokeAny3() {
704 >    public void testInvokeAny3() throws Throwable {
705          ExecutorService e = new ForkJoinPool(1);
706          try {
707              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
799            l.add(new StringTask());
708              l.add(null);
709              e.invokeAny(l);
710 +            shouldThrow();
711 +        } catch (NullPointerException success) {
712 +        } finally {
713 +            joinPool(e);
714 +        }
715 +    }
716 +
717 +    /**
718 +     * invokeAny(c) throws NullPointerException if c has null elements
719 +     */
720 +    public void testInvokeAny4() throws Throwable {
721 +        ExecutorService e = new ForkJoinPool(1);
722 +        try {
723 +            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
724 +            l.add(new Callable<String>() {
725 +                public String call() {
726 +                    // The delay gives the pool a chance to notice
727 +                    // the null element.
728 +                    sleepTillInterrupted(SMALL_DELAY_MS);
729 +                    return "foo";
730 +                }});
731 +            l.add(null);
732 +            e.invokeAny(l);
733 +            shouldThrow();
734          } catch (NullPointerException success) {
803        } catch(Exception ex) {
804            ex.printStackTrace();
805            unexpectedException();
735          } finally {
736              joinPool(e);
737          }
# Line 811 | Line 740 | public class ForkJoinPoolTest extends JS
740      /**
741       * invokeAny(c) throws ExecutionException if no task in c completes
742       */
743 <    public void testInvokeAny4() {
743 >    public void testInvokeAny5() throws Throwable {
744          ExecutorService e = new ForkJoinPool(1);
745          try {
746              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
747              l.add(new NPETask());
748              e.invokeAny(l);
749 <        } catch(ExecutionException success) {
750 <        } catch (CancellationException success) {
822 <        } catch(Exception ex) {
823 <            unexpectedException();
749 >            shouldThrow();
750 >        } catch (ExecutionException success) {
751          } finally {
752              joinPool(e);
753          }
# Line 829 | Line 756 | public class ForkJoinPoolTest extends JS
756      /**
757       * invokeAny(c) returns result of some task in c if at least one completes
758       */
759 <    public void testInvokeAny5() {
759 >    public void testInvokeAny6() throws Throwable {
760          ExecutorService e = new ForkJoinPool(1);
761          try {
762              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 837 | Line 764 | public class ForkJoinPoolTest extends JS
764              l.add(new StringTask());
765              String result = e.invokeAny(l);
766              assertSame(TEST_STRING, result);
840        } catch (ExecutionException success) {
841        } catch (CancellationException success) {
842        } catch(Exception ex) {
843            unexpectedException();
767          } finally {
768              joinPool(e);
769          }
770      }
771  
772      /**
773 <     * invokeAll(null) throws NPE
773 >     * invokeAll(null) throws NullPointerException
774       */
775 <    public void testInvokeAll1() {
775 >    public void testInvokeAll1() throws Throwable {
776          ExecutorService e = new ForkJoinPool(1);
777          try {
778              e.invokeAll(null);
779 +            shouldThrow();
780          } catch (NullPointerException success) {
857        } catch(Exception ex) {
858            unexpectedException();
781          } finally {
782              joinPool(e);
783          }
# Line 864 | Line 786 | public class ForkJoinPoolTest extends JS
786      /**
787       * invokeAll(empty collection) returns empty collection
788       */
789 <    public void testInvokeAll2() {
789 >    public void testInvokeAll2() throws InterruptedException {
790          ExecutorService e = new ForkJoinPool(1);
791          try {
792 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
792 >            List<Future<String>> r
793 >                = e.invokeAll(new ArrayList<Callable<String>>());
794              assertTrue(r.isEmpty());
872        } catch(Exception ex) {
873            unexpectedException();
795          } finally {
796              joinPool(e);
797          }
798      }
799  
800      /**
801 <     * invokeAll(c) throws NPE if c has null elements
801 >     * invokeAll(c) throws NullPointerException if c has null elements
802       */
803 <    public void testInvokeAll3() {
803 >    public void testInvokeAll3() throws InterruptedException {
804          ExecutorService e = new ForkJoinPool(1);
805          try {
806              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
807              l.add(new StringTask());
808              l.add(null);
809              e.invokeAll(l);
810 +            shouldThrow();
811          } catch (NullPointerException success) {
890        } catch(Exception ex) {
891            unexpectedException();
812          } finally {
813              joinPool(e);
814          }
815      }
816  
817      /**
818 <     * get of returned element of invokeAll(c) throws exception on failed task
818 >     * get of returned element of invokeAll(c) throws
819 >     * ExecutionException on failed task
820       */
821 <    public void testInvokeAll4() {
821 >    public void testInvokeAll4() throws Throwable {
822          ExecutorService e = new ForkJoinPool(1);
823          try {
824              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
825              l.add(new NPETask());
826              List<Future<String>> result = e.invokeAll(l);
827              assertEquals(1, result.size());
828 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
829 <                it.next().get();
830 <        } catch(ExecutionException success) {
831 <        } catch (CancellationException success) {
911 <        } catch(Exception ex) {
912 <            ex.printStackTrace();
913 <            unexpectedException();
828 >            for (Future<String> future : result)
829 >                future.get();
830 >            shouldThrow();
831 >        } catch (ExecutionException success) {
832          } finally {
833              joinPool(e);
834          }
# Line 919 | Line 837 | public class ForkJoinPoolTest extends JS
837      /**
838       * invokeAll(c) returns results of all completed tasks in c
839       */
840 <    public void testInvokeAll5() {
840 >    public void testInvokeAll5() throws Throwable {
841          ExecutorService e = new ForkJoinPool(1);
842          try {
843              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 927 | Line 845 | public class ForkJoinPoolTest extends JS
845              l.add(new StringTask());
846              List<Future<String>> result = e.invokeAll(l);
847              assertEquals(2, result.size());
848 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
849 <                assertSame(TEST_STRING, it.next().get());
932 <        } catch (ExecutionException success) {
933 <        } catch (CancellationException success) {
934 <        } catch(Exception ex) {
935 <            ex.printStackTrace();
936 <            unexpectedException();
848 >            for (Future<String> future : result)
849 >                assertSame(TEST_STRING, future.get());
850          } finally {
851              joinPool(e);
852          }
# Line 941 | Line 854 | public class ForkJoinPoolTest extends JS
854  
855  
856      /**
857 <     * timed invokeAny(null) throws NPE
857 >     * timed invokeAny(null) throws NullPointerException
858       */
859 <    public void testTimedInvokeAny1() {
859 >    public void testTimedInvokeAny1() throws Throwable {
860          ExecutorService e = new ForkJoinPool(1);
861          try {
862 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
862 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
863 >            shouldThrow();
864          } catch (NullPointerException success) {
951        } catch(Exception ex) {
952            ex.printStackTrace();
953            unexpectedException();
865          } finally {
866              joinPool(e);
867          }
868      }
869  
870      /**
871 <     * timed invokeAny(null time unit) throws NPE
871 >     * timed invokeAny(null time unit) throws NullPointerException
872       */
873 <    public void testTimedInvokeAnyNullTimeUnit() {
873 >    public void testTimedInvokeAnyNullTimeUnit() throws Throwable {
874          ExecutorService e = new ForkJoinPool(1);
875          try {
876              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
877              l.add(new StringTask());
878              e.invokeAny(l, MEDIUM_DELAY_MS, null);
879 +            shouldThrow();
880          } catch (NullPointerException success) {
969        } catch(Exception ex) {
970            ex.printStackTrace();
971            unexpectedException();
881          } finally {
882              joinPool(e);
883          }
884      }
885  
886      /**
887 <     * timed invokeAny(empty collection) throws IAE
887 >     * timed invokeAny(empty collection) throws IllegalArgumentException
888       */
889 <    public void testTimedInvokeAny2() {
889 >    public void testTimedInvokeAny2() throws Throwable {
890          ExecutorService e = new ForkJoinPool(1);
891          try {
892 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
892 >            e.invokeAny(new ArrayList<Callable<String>>(),
893 >                        MEDIUM_DELAY_MS, MILLISECONDS);
894 >            shouldThrow();
895          } catch (IllegalArgumentException success) {
985        } catch(Exception ex) {
986            ex.printStackTrace();
987            unexpectedException();
896          } finally {
897              joinPool(e);
898          }
899      }
900  
901      /**
902 <     * timed invokeAny(c) throws NPE if c has null elements
902 >     * timed invokeAny(c) throws NullPointerException if c has null elements
903       */
904 <    public void testTimedInvokeAny3() {
904 >    public void testTimedInvokeAny3() throws Throwable {
905          ExecutorService e = new ForkJoinPool(1);
906          try {
907              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
908              l.add(new StringTask());
909              l.add(null);
910 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
910 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
911 >            shouldThrow();
912          } catch (NullPointerException success) {
1004        } catch(Exception ex) {
1005            ex.printStackTrace();
1006            unexpectedException();
913          } finally {
914              joinPool(e);
915          }
# Line 1012 | Line 918 | public class ForkJoinPoolTest extends JS
918      /**
919       * timed invokeAny(c) throws ExecutionException if no task completes
920       */
921 <    public void testTimedInvokeAny4() {
921 >    public void testTimedInvokeAny4() throws Throwable {
922          ExecutorService e = new ForkJoinPool(1);
923          try {
924              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
925              l.add(new NPETask());
926 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
927 <        } catch(ExecutionException success) {
928 <        } catch (CancellationException success) {
1023 <        } catch(Exception ex) {
1024 <            ex.printStackTrace();
1025 <            unexpectedException();
926 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
927 >            shouldThrow();
928 >        } catch (ExecutionException success) {
929          } finally {
930              joinPool(e);
931          }
# Line 1031 | Line 934 | public class ForkJoinPoolTest extends JS
934      /**
935       * timed invokeAny(c) returns result of some task in c
936       */
937 <    public void testTimedInvokeAny5() {
937 >    public void testTimedInvokeAny5() throws Throwable {
938          ExecutorService e = new ForkJoinPool(1);
939          try {
940              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
941              l.add(new StringTask());
942              l.add(new StringTask());
943 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
943 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
944              assertSame(TEST_STRING, result);
1042        } catch (ExecutionException success) {
1043        } catch (CancellationException success) {
1044        } catch(Exception ex) {
1045            ex.printStackTrace();
1046            unexpectedException();
945          } finally {
946              joinPool(e);
947          }
948      }
949  
950      /**
951 <     * timed invokeAll(null) throws NPE
951 >     * timed invokeAll(null) throws NullPointerException
952       */
953 <    public void testTimedInvokeAll1() {
953 >    public void testTimedInvokeAll1() throws Throwable {
954          ExecutorService e = new ForkJoinPool(1);
955          try {
956 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
956 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
957 >            shouldThrow();
958          } catch (NullPointerException success) {
1060        } catch(Exception ex) {
1061            ex.printStackTrace();
1062            unexpectedException();
959          } finally {
960              joinPool(e);
961          }
962      }
963  
964      /**
965 <     * timed invokeAll(null time unit) throws NPE
965 >     * timed invokeAll(null time unit) throws NullPointerException
966       */
967 <    public void testTimedInvokeAllNullTimeUnit() {
967 >    public void testTimedInvokeAllNullTimeUnit() throws Throwable {
968          ExecutorService e = new ForkJoinPool(1);
969          try {
970              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
971              l.add(new StringTask());
972              e.invokeAll(l, MEDIUM_DELAY_MS, null);
973 +            shouldThrow();
974          } catch (NullPointerException success) {
1078        } catch(Exception ex) {
1079            ex.printStackTrace();
1080            unexpectedException();
975          } finally {
976              joinPool(e);
977          }
# Line 1086 | Line 980 | public class ForkJoinPoolTest extends JS
980      /**
981       * timed invokeAll(empty collection) returns empty collection
982       */
983 <    public void testTimedInvokeAll2() {
983 >    public void testTimedInvokeAll2() throws InterruptedException {
984          ExecutorService e = new ForkJoinPool(1);
985          try {
986 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
986 >            List<Future<String>> r
987 >                = e.invokeAll(new ArrayList<Callable<String>>(),
988 >                              MEDIUM_DELAY_MS, MILLISECONDS);
989              assertTrue(r.isEmpty());
1094        } catch(Exception ex) {
1095            ex.printStackTrace();
1096            unexpectedException();
990          } finally {
991              joinPool(e);
992          }
993      }
994  
995      /**
996 <     * timed invokeAll(c) throws NPE if c has null elements
996 >     * timed invokeAll(c) throws NullPointerException if c has null elements
997       */
998 <    public void testTimedInvokeAll3() {
998 >    public void testTimedInvokeAll3() throws InterruptedException {
999          ExecutorService e = new ForkJoinPool(1);
1000          try {
1001              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1002              l.add(new StringTask());
1003              l.add(null);
1004 <            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1004 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1005 >            shouldThrow();
1006          } catch (NullPointerException success) {
1113        } catch(Exception ex) {
1114            ex.printStackTrace();
1115            unexpectedException();
1007          } finally {
1008              joinPool(e);
1009          }
# Line 1121 | Line 1012 | public class ForkJoinPoolTest extends JS
1012      /**
1013       * get of returned element of invokeAll(c) throws exception on failed task
1014       */
1015 <    public void testTimedInvokeAll4() {
1015 >    public void testTimedInvokeAll4() throws Throwable {
1016          ExecutorService e = new ForkJoinPool(1);
1017          try {
1018              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1019              l.add(new NPETask());
1020 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1020 >            List<Future<String>> result
1021 >                = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1022              assertEquals(1, result.size());
1023 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1024 <                it.next().get();
1025 <        } catch(ExecutionException success) {
1026 <        } catch (CancellationException success) {
1135 <        } catch(Exception ex) {
1136 <            ex.printStackTrace();
1137 <            unexpectedException();
1023 >            for (Future<String> future : result)
1024 >                future.get();
1025 >            shouldThrow();
1026 >        } catch (ExecutionException success) {
1027          } finally {
1028              joinPool(e);
1029          }
# Line 1143 | Line 1032 | public class ForkJoinPoolTest extends JS
1032      /**
1033       * timed invokeAll(c) returns results of all completed tasks in c
1034       */
1035 <    public void testTimedInvokeAll5() {
1035 >    public void testTimedInvokeAll5() throws Throwable {
1036          ExecutorService e = new ForkJoinPool(1);
1037          try {
1038              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1039              l.add(new StringTask());
1040              l.add(new StringTask());
1041 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1041 >            List<Future<String>> result
1042 >                = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1043              assertEquals(2, result.size());
1044 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1045 <                assertSame(TEST_STRING, it.next().get());
1156 <        } catch (ExecutionException success) {
1157 <        } catch (CancellationException success) {
1158 <        } catch(Exception ex) {
1159 <            ex.printStackTrace();
1160 <            unexpectedException();
1044 >            for (Future<String> future : result)
1045 >                assertSame(TEST_STRING, future.get());
1046          } finally {
1047              joinPool(e);
1048          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines