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.7 by dl, Tue Aug 4 00:23:18 2009 UTC vs.
Revision 1.23 by jsr166, Sat Sep 11 19:04:12 2010 UTC

# Line 4 | Line 4
4   * http://creativecommons.org/licenses/publicdomain
5   */
6  
7
7   import junit.framework.*;
8   import java.util.*;
9 < import java.util.concurrent.*;
10 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
9 > import java.util.concurrent.Executor;
10 > import java.util.concurrent.Executors;
11 > import java.util.concurrent.ExecutorService;
12 > import java.util.concurrent.AbstractExecutorService;
13 > import java.util.concurrent.CountDownLatch;
14 > import java.util.concurrent.Callable;
15 > import java.util.concurrent.Future;
16 > import java.util.concurrent.ExecutionException;
17 > import java.util.concurrent.CancellationException;
18 > import java.util.concurrent.RejectedExecutionException;
19 > import java.util.concurrent.ForkJoinPool;
20 > import java.util.concurrent.ForkJoinTask;
21 > import java.util.concurrent.ForkJoinWorkerThread;
22 > import java.util.concurrent.RecursiveAction;
23 > import java.util.concurrent.RecursiveTask;
24 > import java.util.concurrent.TimeUnit;
25   import java.util.concurrent.locks.*;
26   import java.security.*;
27  
28   public class ForkJoinPoolTest extends JSR166TestCase {
29      public static void main(String[] args) {
30 <        junit.textui.TestRunner.run (suite());
30 >        junit.textui.TestRunner.run(suite());
31      }
32 +
33      public static Test suite() {
34          return new TestSuite(ForkJoinPoolTest.class);
35      }
# Line 39 | Line 53 | public class ForkJoinPoolTest extends JS
53      // Some classes to test extension and factory methods
54  
55      static class MyHandler implements Thread.UncaughtExceptionHandler {
56 <        int catches = 0;
56 >        volatile int catches = 0;
57          public void uncaughtException(Thread t, Throwable e) {
58              ++catches;
59          }
# Line 48 | Line 62 | public class ForkJoinPoolTest extends JS
62      // to test handlers
63      static class FailingFJWSubclass extends ForkJoinWorkerThread {
64          public FailingFJWSubclass(ForkJoinPool p) { super(p) ; }
65 <        protected void onStart() { throw new Error(); }
65 >        protected void onStart() { super.onStart(); throw new Error(); }
66      }
67  
68      static class FailingThreadFactory
69              implements ForkJoinPool.ForkJoinWorkerThreadFactory {
70 <        int calls = 0;
70 >        volatile int calls = 0;
71          public ForkJoinWorkerThread newThread(ForkJoinPool p) {
72              if (++calls > 1) return null;
73              return new FailingFJWSubclass(p);
# Line 142 | Line 156 | public class ForkJoinPoolTest extends JS
156       * tasks, and quiescent running state.
157       */
158      public void testDefaultInitialState() {
159 <        ForkJoinPool p = null;
159 >        ForkJoinPool p = new ForkJoinPool(1);
160          try {
147            p = new ForkJoinPool(1);
161              assertTrue(p.getFactory() ==
162                         ForkJoinPool.defaultForkJoinWorkerThreadFactory);
163              assertTrue(p.isQuiescent());
151            assertTrue(p.getMaintainsParallelism());
164              assertFalse(p.getAsyncMode());
165              assertTrue(p.getActiveThreadCount() == 0);
166              assertTrue(p.getStealCount() == 0);
# Line 170 | Line 182 | public class ForkJoinPoolTest extends JS
182          try {
183              new ForkJoinPool(-1);
184              shouldThrow();
185 <        }
174 <        catch (IllegalArgumentException success) {}
185 >        } catch (IllegalArgumentException success) {}
186      }
187  
188      /**
# Line 179 | Line 190 | public class ForkJoinPoolTest extends JS
190       */
191      public void testConstructor2() {
192          try {
193 <            new ForkJoinPool(1, null);
193 >            new ForkJoinPool(1, null, null, false);
194              shouldThrow();
195 <        } catch (NullPointerException success) {
185 <        }
195 >        } catch (NullPointerException success) {}
196      }
197  
198  
# Line 190 | Line 200 | public class ForkJoinPoolTest extends JS
200       * getParallelism returns size set in constructor
201       */
202      public void testGetParallelism() {
203 <        ForkJoinPool p = null;
194 <        try {
195 <            p = new ForkJoinPool(1);
196 <            assertTrue(p.getParallelism() == 1);
197 <        } finally {
198 <            joinPool(p);
199 <        }
200 <    }
201 <
202 <    /**
203 <     * setParallelism changes reported parallelism level.
204 <     */
205 <    public void testSetParallelism() {
206 <        ForkJoinPool p = null;
207 <        try {
208 <            p = new ForkJoinPool(1);
209 <            assertTrue(p.getParallelism() == 1);
210 <            p.setParallelism(2);
211 <            assertTrue(p.getParallelism() == 2);
212 <        } finally {
213 <            joinPool(p);
214 <        }
215 <    }
216 <
217 <    /**
218 <     * setParallelism with argument <= 0 throws exception
219 <     */
220 <    public void testSetParallelism2() {
221 <        ForkJoinPool p = null;
203 >        ForkJoinPool p = new ForkJoinPool(1);
204          try {
223            p = new ForkJoinPool(1);
205              assertTrue(p.getParallelism() == 1);
225            p.setParallelism(-2);
226            shouldThrow();
227        } catch (IllegalArgumentException success) {
206          } finally {
207              joinPool(p);
208          }
# Line 234 | Line 212 | public class ForkJoinPoolTest extends JS
212       * getPoolSize returns number of started workers.
213       */
214      public void testGetPoolSize() {
215 <        ForkJoinPool p = null;
215 >        ForkJoinPool p = new ForkJoinPool(1);
216          try {
217 <            p = new ForkJoinPool(1);
240 <            assertTrue(p.getPoolSize() == 0);
217 >            assertTrue(p.getActiveThreadCount() == 0);
218              Future<String> future = p.submit(new StringTask());
219              assertTrue(p.getPoolSize() == 1);
243
244        } finally {
245            joinPool(p);
246        }
247    }
248
249    /**
250     * setMaximumPoolSize changes size reported by getMaximumPoolSize.
251     */
252    public void testSetMaximumPoolSize() {
253        ForkJoinPool p = null;
254        try {
255            p = new ForkJoinPool(1);
256            p.setMaximumPoolSize(2);
257            assertTrue(p.getMaximumPoolSize() == 2);
258        } finally {
259            joinPool(p);
260        }
261    }
262
263    /**
264     * setMaximumPoolSize with argument <= 0 throws exception
265     */
266    public void testSetMaximumPoolSize2() {
267        ForkJoinPool p = null;
268        try {
269            p = new ForkJoinPool(1);
270            p.setMaximumPoolSize(-2);
271            shouldThrow();
272        } catch (IllegalArgumentException success) {
273        } finally {
274            joinPool(p);
275        }
276    }
277
278    /**
279     * setMaintainsParallelism changes policy reported by
280     * getMaintainsParallelism.
281     */
282    public void testSetMaintainsParallelism() {
283        ForkJoinPool p = null;
284        try {
285            p = new ForkJoinPool(1);
286            p.setMaintainsParallelism(false);
287            assertFalse(p.getMaintainsParallelism());
288        } finally {
289            joinPool(p);
290        }
291    }
292
293    /**
294     * setAsyncMode changes policy reported by
295     * getAsyncMode.
296     */
297    public void testSetAsyncMode() {
298        ForkJoinPool p = null;
299        try {
300            p = new ForkJoinPool(1);
301            p.setAsyncMode(true);
302            assertTrue(p.getAsyncMode());
220          } finally {
221              joinPool(p);
222          }
# Line 312 | Line 229 | public class ForkJoinPoolTest extends JS
229       * performs its defined action
230       */
231      public void testSetUncaughtExceptionHandler() throws InterruptedException {
232 <        ForkJoinPool p = null;
232 >        MyHandler eh = new MyHandler();
233 >        ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(), eh, false);
234          try {
235 <            p = new ForkJoinPool(1, new FailingThreadFactory());
318 <            MyHandler eh = new MyHandler();
319 <            p.setUncaughtExceptionHandler(eh);
320 <            assertEquals(eh, p.getUncaughtExceptionHandler());
235 >            assert(eh == p.getUncaughtExceptionHandler());
236              p.execute(new FailingTask());
237              Thread.sleep(MEDIUM_DELAY_MS);
238              assertTrue(eh.catches > 0);
239          } finally {
240 +            p.shutdownNow();
241              joinPool(p);
242          }
243      }
244  
245      /**
330     * setUncaughtExceptionHandler of null removes handler
331     */
332    public void testSetUncaughtExceptionHandler2() {
333        ForkJoinPool p = null;
334        try {
335            p = new ForkJoinPool(1);
336            p.setUncaughtExceptionHandler(null);
337            assertNull(p.getUncaughtExceptionHandler());
338        } finally {
339            joinPool(p);
340        }
341    }
342
343
344    /**
246       * After invoking a single task, isQuiescent is true,
247       * queues are empty, threads are not active, and
248       * construction parameters continue to hold
249       */
250      public void testisQuiescent() throws InterruptedException {
251 <        ForkJoinPool p = null;
251 >        ForkJoinPool p = new ForkJoinPool(2);
252          try {
352            p = new ForkJoinPool(2);
253              p.invoke(new FibTask(20));
254              assertTrue(p.getFactory() ==
255                         ForkJoinPool.defaultForkJoinWorkerThreadFactory);
256              Thread.sleep(MEDIUM_DELAY_MS);
257              assertTrue(p.isQuiescent());
358            assertTrue(p.getMaintainsParallelism());
258              assertFalse(p.getAsyncMode());
259              assertTrue(p.getActiveThreadCount() == 0);
260              assertTrue(p.getQueuedTaskCount() == 0);
# Line 373 | Line 272 | public class ForkJoinPoolTest extends JS
272       * Completed submit(ForkJoinTask) returns result
273       */
274      public void testSubmitForkJoinTask() throws Throwable {
275 <        ForkJoinPool p = null;
275 >        ForkJoinPool p = new ForkJoinPool(1);
276          try {
378            p = new ForkJoinPool(1);
277              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
278              int r = f.get();
279              assertTrue(r == 21);
# Line 388 | Line 286 | public class ForkJoinPoolTest extends JS
286       * A task submitted after shutdown is rejected
287       */
288      public void testSubmitAfterShutdown() {
289 <        ForkJoinPool p = null;
289 >        ForkJoinPool p = new ForkJoinPool(1);
290          try {
393            p = new ForkJoinPool(1);
291              p.shutdown();
292              assertTrue(p.isShutdown());
293              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
# Line 405 | Line 302 | public class ForkJoinPoolTest extends JS
302       * Pool maintains parallelism when using ManagedBlocker
303       */
304      public void testBlockingForkJoinTask() throws Throwable {
305 <        ForkJoinPool p = null;
305 >        ForkJoinPool p = new ForkJoinPool(4);
306          try {
410            p = new ForkJoinPool(4);
307              ReentrantLock lock = new ReentrantLock();
308              ManagedLocker locker = new ManagedLocker(lock);
309              ForkJoinTask<Integer> f = new LockingFibTask(30, locker, lock);
310              p.execute(f);
415            assertTrue(p.getPoolSize() >= 4);
311              int r = f.get();
312 <            assertTrue(r ==  832040);
312 >            assertTrue(r == 832040);
313          } finally {
314              p.shutdownNow(); // don't wait out shutdown
315          }
# Line 424 | Line 319 | public class ForkJoinPoolTest extends JS
319       * pollSubmission returns unexecuted submitted task, if present
320       */
321      public void testPollSubmission() {
322 <        SubFJP p = null;
322 >        SubFJP p = new SubFJP();
323          try {
429            p = new SubFJP();
324              ForkJoinTask a = p.submit(new MediumRunnable());
325              ForkJoinTask b = p.submit(new MediumRunnable());
326              ForkJoinTask c = p.submit(new MediumRunnable());
# Line 442 | Line 336 | public class ForkJoinPoolTest extends JS
336       * drainTasksTo transfers unexecuted submitted tasks, if present
337       */
338      public void testDrainTasksTo() {
339 <        SubFJP p = null;
339 >        SubFJP p = new SubFJP();
340          try {
447            p = new SubFJP();
341              ForkJoinTask a = p.submit(new MediumRunnable());
342              ForkJoinTask b = p.submit(new MediumRunnable());
343              ForkJoinTask c = p.submit(new MediumRunnable());
# Line 468 | Line 361 | public class ForkJoinPoolTest extends JS
361       */
362      public void testExecuteRunnable() throws Throwable {
363          ExecutorService e = new ForkJoinPool(1);
364 <        TrackedShortRunnable task = new TrackedShortRunnable();
365 <        assertFalse(task.done);
366 <        Future<?> future = e.submit(task);
367 <        future.get();
368 <        assertTrue(task.done);
364 >        try {
365 >            TrackedShortRunnable task = new TrackedShortRunnable();
366 >            assertFalse(task.done);
367 >            Future<?> future = e.submit(task);
368 >            future.get();
369 >            assertTrue(task.done);
370 >        } finally {
371 >            joinPool(e);
372 >        }
373      }
374  
375  
# Line 481 | Line 378 | public class ForkJoinPoolTest extends JS
378       */
379      public void testSubmitCallable() throws Throwable {
380          ExecutorService e = new ForkJoinPool(1);
381 <        Future<String> future = e.submit(new StringTask());
382 <        String result = future.get();
383 <        assertSame(TEST_STRING, result);
381 >        try {
382 >            Future<String> future = e.submit(new StringTask());
383 >            String result = future.get();
384 >            assertSame(TEST_STRING, result);
385 >        } finally {
386 >            joinPool(e);
387 >        }
388      }
389  
390      /**
# Line 491 | Line 392 | public class ForkJoinPoolTest extends JS
392       */
393      public void testSubmitRunnable() throws Throwable {
394          ExecutorService e = new ForkJoinPool(1);
395 <        Future<?> future = e.submit(new NoOpRunnable());
396 <        future.get();
397 <        assertTrue(future.isDone());
395 >        try {
396 >            Future<?> future = e.submit(new NoOpRunnable());
397 >            future.get();
398 >            assertTrue(future.isDone());
399 >        } finally {
400 >            joinPool(e);
401 >        }
402      }
403  
404      /**
# Line 501 | Line 406 | public class ForkJoinPoolTest extends JS
406       */
407      public void testSubmitRunnable2() throws Throwable {
408          ExecutorService e = new ForkJoinPool(1);
409 <        Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
410 <        String result = future.get();
411 <        assertSame(TEST_STRING, result);
409 >        try {
410 >            Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
411 >            String result = future.get();
412 >            assertSame(TEST_STRING, result);
413 >        } finally {
414 >            joinPool(e);
415 >        }
416      }
417  
418  
# Line 521 | Line 430 | public class ForkJoinPoolTest extends JS
430          } catch (AccessControlException ok) {
431              return;
432          }
433 +
434          try {
435              ExecutorService e = new ForkJoinPool(1);
436 <            Future future = e.submit(Executors.callable(new PrivilegedAction() {
436 >            try {
437 >                Future future = e.submit(Executors.callable(new PrivilegedAction() {
438                      public Object run() {
439                          return TEST_STRING;
440                      }}));
441  
442 <            Object result = future.get();
443 <            assertSame(TEST_STRING, result);
444 <        }
445 <        finally {
442 >                Object result = future.get();
443 >                assertSame(TEST_STRING, result);
444 >            } finally {
445 >                joinPool(e);
446 >            }
447 >        } finally {
448              Policy.setPolicy(savedPolicy);
449          }
450      }
# Line 553 | Line 466 | public class ForkJoinPoolTest extends JS
466  
467          try {
468              ExecutorService e = new ForkJoinPool(1);
469 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
469 >            try {
470 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
471                      public Object run() {
472                          return TEST_STRING;
473                      }}));
474  
475 <            Object result = future.get();
476 <            assertSame(TEST_STRING, result);
477 <        }
478 <        finally {
475 >                Object result = future.get();
476 >                assertSame(TEST_STRING, result);
477 >            } finally {
478 >                joinPool(e);
479 >            }
480 >        } finally {
481              Policy.setPolicy(savedPolicy);
482          }
483      }
# Line 581 | Line 497 | public class ForkJoinPoolTest extends JS
497              return;
498          }
499  
584
500          try {
501              ExecutorService e = new ForkJoinPool(1);
502 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
502 >            try {
503 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
504                      public Object run() throws Exception {
505                          throw new IndexOutOfBoundsException();
506                      }}));
507  
508 <            Object result = future.get();
509 <            shouldThrow();
510 <        } catch (ExecutionException success) {
508 >                Object result = future.get();
509 >                shouldThrow();
510 >            } catch (ExecutionException success) {
511 >                assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
512 >            } finally {
513 >                joinPool(e);
514 >            }
515          } finally {
516              Policy.setPolicy(savedPolicy);
517          }
# Line 601 | Line 521 | public class ForkJoinPoolTest extends JS
521       * execute(null runnable) throws NullPointerException
522       */
523      public void testExecuteNullRunnable() {
524 +        ExecutorService e = new ForkJoinPool(1);
525          try {
605            ExecutorService e = new ForkJoinPool(1);
526              TrackedShortRunnable task = null;
527              Future<?> future = e.submit(task);
528              shouldThrow();
529          } catch (NullPointerException success) {
530 +        } finally {
531 +            joinPool(e);
532          }
533      }
534  
# Line 615 | Line 537 | public class ForkJoinPoolTest extends JS
537       * submit(null callable) throws NullPointerException
538       */
539      public void testSubmitNullCallable() {
540 +        ExecutorService e = new ForkJoinPool(1);
541          try {
619            ExecutorService e = new ForkJoinPool(1);
542              StringTask t = null;
543              Future<String> future = e.submit(t);
544              shouldThrow();
545          } catch (NullPointerException success) {
546 +        } finally {
547 +            joinPool(e);
548          }
549      }
550  
# Line 633 | Line 557 | public class ForkJoinPoolTest extends JS
557          final ForkJoinPool p = new ForkJoinPool(1);
558  
559          Thread t = new Thread(new CheckedInterruptedRunnable() {
560 <            void realRun() throws Throwable {
560 >            public void realRun() throws Throwable {
561                  p.submit(new CheckedCallable<Object>() {
562                      public Object realCall() throws Throwable {
563 <                        Thread.sleep(MEDIUM_DELAY_MS);
563 >                        try {
564 >                            Thread.sleep(MEDIUM_DELAY_MS);
565 >                        } catch (InterruptedException ok) {
566 >                        }
567                          return null;
568                      }}).get();
569              }});
570  
571          t.start();
572 +        Thread.sleep(SHORT_DELAY_MS);
573          t.interrupt();
574 +        t.join();
575          p.shutdownNow();
576 +        joinPool(p);
577      }
578  
579      /**
# Line 652 | Line 582 | public class ForkJoinPoolTest extends JS
582       */
583      public void testSubmitEE() throws Throwable {
584          ForkJoinPool p = new ForkJoinPool(1);
655
585          try {
586 <            Callable c = new Callable() {
587 <                    public Object call() {
588 <                        int i = 5/0;
589 <                        return Boolean.TRUE;
590 <                    }
662 <                };
663 <
664 <            for (int i = 0; i < 5; i++) {
665 <                p.submit(c).get();
666 <            }
586 >            p.submit(new Callable() {
587 >                public Object call() {
588 >                    int i = 5/0;
589 >                    return Boolean.TRUE;
590 >                }}).get();
591              shouldThrow();
592          } catch (ExecutionException success) {
593 +            assertTrue(success.getCause() instanceof ArithmeticException);
594 +        } finally {
595 +            joinPool(p);
596          }
670        joinPool(p);
597      }
598  
599      /**
# Line 699 | Line 625 | public class ForkJoinPoolTest extends JS
625      }
626  
627      /**
628 <     * invokeAny(c) throws NullPointerException if c has null elements
628 >     * invokeAny(c) throws NullPointerException if c has a single null element
629       */
630      public void testInvokeAny3() throws Throwable {
631          ExecutorService e = new ForkJoinPool(1);
632 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
633 +        l.add(null);
634          try {
707            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
708            l.add(new StringTask());
709            l.add(null);
635              e.invokeAny(l);
636              shouldThrow();
637          } catch (NullPointerException success) {
# Line 716 | Line 641 | public class ForkJoinPoolTest extends JS
641      }
642  
643      /**
644 <     * invokeAny(c) throws ExecutionException if no task in c completes
644 >     * invokeAny(c) throws NullPointerException if c has null elements
645       */
646      public void testInvokeAny4() throws Throwable {
647 +        CountDownLatch latch = new CountDownLatch(1);
648 +        ExecutorService e = new ForkJoinPool(1);
649 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
650 +        l.add(latchAwaitingStringTask(latch));
651 +        l.add(null);
652 +        try {
653 +            e.invokeAny(l);
654 +            shouldThrow();
655 +        } catch (NullPointerException success) {
656 +        } finally {
657 +            latch.countDown();
658 +            joinPool(e);
659 +        }
660 +    }
661 +
662 +    /**
663 +     * invokeAny(c) throws ExecutionException if no task in c completes
664 +     */
665 +    public void testInvokeAny5() throws Throwable {
666          ExecutorService e = new ForkJoinPool(1);
667 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
668 +        l.add(new NPETask());
669          try {
724            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
725            l.add(new NPETask());
670              e.invokeAny(l);
671              shouldThrow();
672          } catch (ExecutionException success) {
673 +            assertTrue(success.getCause() instanceof NullPointerException);
674          } finally {
675              joinPool(e);
676          }
# Line 734 | Line 679 | public class ForkJoinPoolTest extends JS
679      /**
680       * invokeAny(c) returns result of some task in c if at least one completes
681       */
682 <    public void testInvokeAny5() throws Throwable {
682 >    public void testInvokeAny6() throws Throwable {
683          ExecutorService e = new ForkJoinPool(1);
684          try {
685 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
685 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
686              l.add(new StringTask());
687              l.add(new StringTask());
688              String result = e.invokeAny(l);
# Line 780 | Line 725 | public class ForkJoinPoolTest extends JS
725       */
726      public void testInvokeAll3() throws InterruptedException {
727          ExecutorService e = new ForkJoinPool(1);
728 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
729 +        l.add(new StringTask());
730 +        l.add(null);
731          try {
784            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
785            l.add(new StringTask());
786            l.add(null);
732              e.invokeAll(l);
733              shouldThrow();
734          } catch (NullPointerException success) {
# Line 798 | Line 743 | public class ForkJoinPoolTest extends JS
743       */
744      public void testInvokeAll4() throws Throwable {
745          ExecutorService e = new ForkJoinPool(1);
746 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
747 +        l.add(new NPETask());
748 +        List<Future<String>> futures = e.invokeAll(l);
749 +        assertEquals(1, futures.size());
750          try {
751 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
803 <            l.add(new NPETask());
804 <            List<Future<String>> result = e.invokeAll(l);
805 <            assertEquals(1, result.size());
806 <            for (Future<String> future : result)
807 <                future.get();
751 >            futures.get(0).get();
752              shouldThrow();
753          } catch (ExecutionException success) {
754 +            assertTrue(success.getCause() instanceof NullPointerException);
755          } finally {
756              joinPool(e);
757          }
# Line 818 | Line 763 | public class ForkJoinPoolTest extends JS
763      public void testInvokeAll5() throws Throwable {
764          ExecutorService e = new ForkJoinPool(1);
765          try {
766 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
766 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
767              l.add(new StringTask());
768              l.add(new StringTask());
769 <            List<Future<String>> result = e.invokeAll(l);
770 <            assertEquals(2, result.size());
771 <            for (Future<String> future : result)
769 >            List<Future<String>> futures = e.invokeAll(l);
770 >            assertEquals(2, futures.size());
771 >            for (Future<String> future : futures)
772                  assertSame(TEST_STRING, future.get());
773          } finally {
774              joinPool(e);
# Line 837 | Line 782 | public class ForkJoinPoolTest extends JS
782      public void testTimedInvokeAny1() throws Throwable {
783          ExecutorService e = new ForkJoinPool(1);
784          try {
785 <            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
785 >            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
786              shouldThrow();
787          } catch (NullPointerException success) {
788          } finally {
# Line 850 | Line 795 | public class ForkJoinPoolTest extends JS
795       */
796      public void testTimedInvokeAnyNullTimeUnit() throws Throwable {
797          ExecutorService e = new ForkJoinPool(1);
798 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
799 +        l.add(new StringTask());
800          try {
854            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
855            l.add(new StringTask());
801              e.invokeAny(l, MEDIUM_DELAY_MS, null);
802              shouldThrow();
803          } catch (NullPointerException success) {
# Line 868 | Line 813 | public class ForkJoinPoolTest extends JS
813          ExecutorService e = new ForkJoinPool(1);
814          try {
815              e.invokeAny(new ArrayList<Callable<String>>(),
816 <                        MEDIUM_DELAY_MS, MILLISECONDS);
816 >                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
817              shouldThrow();
818          } catch (IllegalArgumentException success) {
819          } finally {
# Line 880 | Line 825 | public class ForkJoinPoolTest extends JS
825       * timed invokeAny(c) throws NullPointerException if c has null elements
826       */
827      public void testTimedInvokeAny3() throws Throwable {
828 +        CountDownLatch latch = new CountDownLatch(1);
829          ExecutorService e = new ForkJoinPool(1);
830 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
831 +        l.add(latchAwaitingStringTask(latch));
832 +        l.add(null);
833          try {
834 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
886 <            l.add(new StringTask());
887 <            l.add(null);
888 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
834 >            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
835              shouldThrow();
836          } catch (NullPointerException success) {
837          } finally {
838 +            latch.countDown();
839              joinPool(e);
840          }
841      }
# Line 898 | Line 845 | public class ForkJoinPoolTest extends JS
845       */
846      public void testTimedInvokeAny4() throws Throwable {
847          ExecutorService e = new ForkJoinPool(1);
848 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
849 +        l.add(new NPETask());
850          try {
851 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
903 <            l.add(new NPETask());
904 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
851 >            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
852              shouldThrow();
853          } catch (ExecutionException success) {
854 +            assertTrue(success.getCause() instanceof NullPointerException);
855          } finally {
856              joinPool(e);
857          }
# Line 915 | Line 863 | public class ForkJoinPoolTest extends JS
863      public void testTimedInvokeAny5() throws Throwable {
864          ExecutorService e = new ForkJoinPool(1);
865          try {
866 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
866 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
867              l.add(new StringTask());
868              l.add(new StringTask());
869 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
869 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
870              assertSame(TEST_STRING, result);
871          } finally {
872              joinPool(e);
# Line 931 | Line 879 | public class ForkJoinPoolTest extends JS
879      public void testTimedInvokeAll1() throws Throwable {
880          ExecutorService e = new ForkJoinPool(1);
881          try {
882 <            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
882 >            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
883              shouldThrow();
884          } catch (NullPointerException success) {
885          } finally {
# Line 944 | Line 892 | public class ForkJoinPoolTest extends JS
892       */
893      public void testTimedInvokeAllNullTimeUnit() throws Throwable {
894          ExecutorService e = new ForkJoinPool(1);
895 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
896 +        l.add(new StringTask());
897          try {
948            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
949            l.add(new StringTask());
898              e.invokeAll(l, MEDIUM_DELAY_MS, null);
899              shouldThrow();
900          } catch (NullPointerException success) {
# Line 963 | Line 911 | public class ForkJoinPoolTest extends JS
911          try {
912              List<Future<String>> r
913                  = e.invokeAll(new ArrayList<Callable<String>>(),
914 <                              MEDIUM_DELAY_MS, MILLISECONDS);
914 >                              MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
915              assertTrue(r.isEmpty());
916          } finally {
917              joinPool(e);
# Line 975 | Line 923 | public class ForkJoinPoolTest extends JS
923       */
924      public void testTimedInvokeAll3() throws InterruptedException {
925          ExecutorService e = new ForkJoinPool(1);
926 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
927 +        l.add(new StringTask());
928 +        l.add(null);
929          try {
930 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
980 <            l.add(new StringTask());
981 <            l.add(null);
982 <            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
930 >            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
931              shouldThrow();
932          } catch (NullPointerException success) {
933          } finally {
# Line 992 | Line 940 | public class ForkJoinPoolTest extends JS
940       */
941      public void testTimedInvokeAll4() throws Throwable {
942          ExecutorService e = new ForkJoinPool(1);
943 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
944 +        l.add(new NPETask());
945 +        List<Future<String>> futures
946 +            = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
947 +        assertEquals(1, futures.size());
948          try {
949 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
997 <            l.add(new NPETask());
998 <            List<Future<String>> result
999 <                = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1000 <            assertEquals(1, result.size());
1001 <            for (Future<String> future : result)
1002 <                future.get();
949 >            futures.get(0).get();
950              shouldThrow();
951          } catch (ExecutionException success) {
952 +            assertTrue(success.getCause() instanceof NullPointerException);
953          } finally {
954              joinPool(e);
955          }
# Line 1013 | Line 961 | public class ForkJoinPoolTest extends JS
961      public void testTimedInvokeAll5() throws Throwable {
962          ExecutorService e = new ForkJoinPool(1);
963          try {
964 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
964 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
965              l.add(new StringTask());
966              l.add(new StringTask());
967 <            List<Future<String>> result
968 <                = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
969 <            assertEquals(2, result.size());
970 <            for (Future<String> future : result)
967 >            List<Future<String>> futures
968 >                = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
969 >            assertEquals(2, futures.size());
970 >            for (Future<String> future : futures)
971                  assertSame(TEST_STRING, future.get());
972          } finally {
973              joinPool(e);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines