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.12 by jsr166, Sat Nov 21 20:10:48 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 178 | 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) {}
196      }
# Line 188 | Line 200 | public class ForkJoinPoolTest extends JS
200       * getParallelism returns size set in constructor
201       */
202      public void testGetParallelism() {
203 <        ForkJoinPool p = null;
192 <        try {
193 <            p = new ForkJoinPool(1);
194 <            assertTrue(p.getParallelism() == 1);
195 <        } finally {
196 <            joinPool(p);
197 <        }
198 <    }
199 <
200 <    /**
201 <     * setParallelism changes reported parallelism level.
202 <     */
203 <    public void testSetParallelism() {
204 <        ForkJoinPool p = null;
205 <        try {
206 <            p = new ForkJoinPool(1);
207 <            assertTrue(p.getParallelism() == 1);
208 <            p.setParallelism(2);
209 <            assertTrue(p.getParallelism() == 2);
210 <        } finally {
211 <            joinPool(p);
212 <        }
213 <    }
214 <
215 <    /**
216 <     * setParallelism with argument <= 0 throws exception
217 <     */
218 <    public void testSetParallelism2() {
219 <        ForkJoinPool p = null;
203 >        ForkJoinPool p = new ForkJoinPool(1);
204          try {
221            p = new ForkJoinPool(1);
205              assertTrue(p.getParallelism() == 1);
223            p.setParallelism(-2);
224            shouldThrow();
225        } catch (IllegalArgumentException success) {
206          } finally {
207              joinPool(p);
208          }
# Line 232 | 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);
238 <            assertTrue(p.getPoolSize() == 0);
217 >            assertTrue(p.getActiveThreadCount() == 0);
218              Future<String> future = p.submit(new StringTask());
219              assertTrue(p.getPoolSize() == 1);
241
242        } finally {
243            joinPool(p);
244        }
245    }
246
247    /**
248     * setMaximumPoolSize changes size reported by getMaximumPoolSize.
249     */
250    public void testSetMaximumPoolSize() {
251        ForkJoinPool p = null;
252        try {
253            p = new ForkJoinPool(1);
254            p.setMaximumPoolSize(2);
255            assertTrue(p.getMaximumPoolSize() == 2);
256        } finally {
257            joinPool(p);
258        }
259    }
260
261    /**
262     * setMaximumPoolSize with argument <= 0 throws exception
263     */
264    public void testSetMaximumPoolSize2() {
265        ForkJoinPool p = null;
266        try {
267            p = new ForkJoinPool(1);
268            p.setMaximumPoolSize(-2);
269            shouldThrow();
270        } catch (IllegalArgumentException success) {
271        } finally {
272            joinPool(p);
273        }
274    }
275
276    /**
277     * setMaintainsParallelism changes policy reported by
278     * getMaintainsParallelism.
279     */
280    public void testSetMaintainsParallelism() {
281        ForkJoinPool p = null;
282        try {
283            p = new ForkJoinPool(1);
284            p.setMaintainsParallelism(false);
285            assertFalse(p.getMaintainsParallelism());
286        } finally {
287            joinPool(p);
288        }
289    }
290
291    /**
292     * setAsyncMode changes policy reported by
293     * getAsyncMode.
294     */
295    public void testSetAsyncMode() {
296        ForkJoinPool p = null;
297        try {
298            p = new ForkJoinPool(1);
299            p.setAsyncMode(true);
300            assertTrue(p.getAsyncMode());
220          } finally {
221              joinPool(p);
222          }
# Line 310 | 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());
316 <            MyHandler eh = new MyHandler();
317 <            p.setUncaughtExceptionHandler(eh);
318 <            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      /**
328     * setUncaughtExceptionHandler of null removes handler
329     */
330    public void testSetUncaughtExceptionHandler2() {
331        ForkJoinPool p = null;
332        try {
333            p = new ForkJoinPool(1);
334            p.setUncaughtExceptionHandler(null);
335            assertNull(p.getUncaughtExceptionHandler());
336        } finally {
337            joinPool(p);
338        }
339    }
340
341
342    /**
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 {
350            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());
356            assertTrue(p.getMaintainsParallelism());
258              assertFalse(p.getAsyncMode());
259              assertTrue(p.getActiveThreadCount() == 0);
260              assertTrue(p.getQueuedTaskCount() == 0);
# Line 371 | 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 {
376            p = new ForkJoinPool(1);
277              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
278              int r = f.get();
279              assertTrue(r == 21);
# Line 386 | 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 {
391            p = new ForkJoinPool(1);
291              p.shutdown();
292              assertTrue(p.isShutdown());
293              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
# Line 403 | 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 {
408            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);
413            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 422 | 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 {
427            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 440 | 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 {
445            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 466 | 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 479 | 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 489 | 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 499 | 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 519 | 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 551 | 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 579 | Line 497 | public class ForkJoinPoolTest extends JS
497              return;
498          }
499  
582
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) {
511 <            assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
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 600 | 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 {
604            ExecutorService e = new ForkJoinPool(1);
526              TrackedShortRunnable task = null;
527              Future<?> future = e.submit(task);
528              shouldThrow();
529 <        } catch (NullPointerException success) {}
529 >        } catch (NullPointerException success) {
530 >        } finally {
531 >            joinPool(e);
532 >        }
533      }
534  
535  
# Line 613 | 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 {
617            ExecutorService e = new ForkJoinPool(1);
542              StringTask t = null;
543              Future<String> future = e.submit(t);
544              shouldThrow();
545 <        } catch (NullPointerException success) {}
545 >        } catch (NullPointerException success) {
546 >        } finally {
547 >            joinPool(e);
548 >        }
549      }
550  
551  
# Line 630 | 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                          try {
# Line 664 | Line 591 | public class ForkJoinPoolTest extends JS
591              shouldThrow();
592          } catch (ExecutionException success) {
593              assertTrue(success.getCause() instanceof ArithmeticException);
594 +        } finally {
595 +            joinPool(p);
596          }
668
669        joinPool(p);
597      }
598  
599      /**
# Line 702 | Line 629 | public class ForkJoinPoolTest extends JS
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 {
706            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
707            l.add(null);
635              e.invokeAny(l);
636              shouldThrow();
637          } catch (NullPointerException success) {
# Line 717 | Line 644 | public class ForkJoinPoolTest extends JS
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 {
722            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
723            l.add(new Callable<String>() {
724                public String call() {
725                    // The delay gives the pool a chance to notice
726                    // the null element.
727                    sleepTillInterrupted(SMALL_DELAY_MS);
728                    return "foo";
729                }});
730            l.add(null);
653              e.invokeAny(l);
654              shouldThrow();
655          } catch (NullPointerException success) {
656          } finally {
657 +            latch.countDown();
658              joinPool(e);
659          }
660      }
# Line 741 | Line 664 | public class ForkJoinPoolTest extends JS
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 {
745            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
746            l.add(new NPETask());
670              e.invokeAny(l);
671              shouldThrow();
672          } catch (ExecutionException success) {
# Line 759 | Line 682 | public class ForkJoinPoolTest extends JS
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 802 | 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 {
806            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
807            l.add(new StringTask());
808            l.add(null);
732              e.invokeAll(l);
733              shouldThrow();
734          } catch (NullPointerException success) {
# Line 820 | 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>>();
825 <            l.add(new NPETask());
826 <            List<Future<String>> result = e.invokeAll(l);
827 <            assertEquals(1, result.size());
828 <            for (Future<String> future : result)
829 <                future.get();
751 >            futures.get(0).get();
752              shouldThrow();
753          } catch (ExecutionException success) {
754              assertTrue(success.getCause() instanceof NullPointerException);
# Line 841 | 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 860 | 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 873 | 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 {
877            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
878            l.add(new StringTask());
801              e.invokeAny(l, MEDIUM_DELAY_MS, null);
802              shouldThrow();
803          } catch (NullPointerException success) {
# Line 891 | 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 903 | 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>>();
909 <            l.add(new StringTask());
910 <            l.add(null);
911 <            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 921 | 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>>();
926 <            l.add(new NPETask());
927 <            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);
# Line 939 | 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 955 | 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 968 | 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 {
972            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
973            l.add(new StringTask());
898              e.invokeAll(l, MEDIUM_DELAY_MS, null);
899              shouldThrow();
900          } catch (NullPointerException success) {
# Line 987 | 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 999 | 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>>();
1004 <            l.add(new StringTask());
1005 <            l.add(null);
1006 <            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 1016 | 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>>();
1021 <            l.add(new NPETask());
1022 <            List<Future<String>> result
1023 <                = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1024 <            assertEquals(1, result.size());
1025 <            for (Future<String> future : result)
1026 <                future.get();
949 >            futures.get(0).get();
950              shouldThrow();
951          } catch (ExecutionException success) {
952              assertTrue(success.getCause() instanceof NullPointerException);
# Line 1038 | 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