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.13 by jsr166, Thu Nov 26 15:42:15 2009 UTC vs.
Revision 1.24 by jsr166, Mon Sep 13 15:34:42 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;
11 < import java.util.concurrent.locks.*;
12 < import java.security.*;
9 > import java.util.concurrent.Executors;
10 > import java.util.concurrent.ExecutorService;
11 > import java.util.concurrent.AbstractExecutorService;
12 > import java.util.concurrent.CountDownLatch;
13 > import java.util.concurrent.Callable;
14 > import java.util.concurrent.Future;
15 > import java.util.concurrent.ExecutionException;
16 > import java.util.concurrent.CancellationException;
17 > import java.util.concurrent.RejectedExecutionException;
18 > import java.util.concurrent.ForkJoinPool;
19 > import java.util.concurrent.ForkJoinTask;
20 > import java.util.concurrent.ForkJoinWorkerThread;
21 > import java.util.concurrent.RecursiveTask;
22 > import java.util.concurrent.TimeUnit;
23 > import java.util.concurrent.locks.ReentrantLock;
24 > import java.security.AccessControlException;
25 > import java.security.Policy;
26 > import java.security.PrivilegedAction;
27 > import java.security.PrivilegedExceptionAction;
28  
29   public class ForkJoinPoolTest extends JSR166TestCase {
30      public static void main(String[] args) {
31 <        junit.textui.TestRunner.run (suite());
31 >        junit.textui.TestRunner.run(suite());
32      }
33 +
34      public static Test suite() {
35          return new TestSuite(ForkJoinPoolTest.class);
36      }
# Line 39 | Line 54 | public class ForkJoinPoolTest extends JS
54      // Some classes to test extension and factory methods
55  
56      static class MyHandler implements Thread.UncaughtExceptionHandler {
57 <        int catches = 0;
57 >        volatile int catches = 0;
58          public void uncaughtException(Thread t, Throwable e) {
59              ++catches;
60          }
# Line 48 | Line 63 | public class ForkJoinPoolTest extends JS
63      // to test handlers
64      static class FailingFJWSubclass extends ForkJoinWorkerThread {
65          public FailingFJWSubclass(ForkJoinPool p) { super(p) ; }
66 <        protected void onStart() { throw new Error(); }
66 >        protected void onStart() { super.onStart(); throw new Error(); }
67      }
68  
69      static class FailingThreadFactory
70              implements ForkJoinPool.ForkJoinWorkerThreadFactory {
71 <        int calls = 0;
71 >        volatile int calls = 0;
72          public ForkJoinWorkerThread newThread(ForkJoinPool p) {
73              if (++calls > 1) return null;
74              return new FailingFJWSubclass(p);
# Line 142 | Line 157 | public class ForkJoinPoolTest extends JS
157       * tasks, and quiescent running state.
158       */
159      public void testDefaultInitialState() {
160 <        ForkJoinPool p = null;
160 >        ForkJoinPool p = new ForkJoinPool(1);
161          try {
147            p = new ForkJoinPool(1);
162              assertTrue(p.getFactory() ==
163                         ForkJoinPool.defaultForkJoinWorkerThreadFactory);
164              assertTrue(p.isQuiescent());
151            assertTrue(p.getMaintainsParallelism());
165              assertFalse(p.getAsyncMode());
166              assertTrue(p.getActiveThreadCount() == 0);
167              assertTrue(p.getStealCount() == 0);
# Line 178 | Line 191 | public class ForkJoinPoolTest extends JS
191       */
192      public void testConstructor2() {
193          try {
194 <            new ForkJoinPool(1, null);
194 >            new ForkJoinPool(1, null, null, false);
195              shouldThrow();
196          } catch (NullPointerException success) {}
197      }
# Line 188 | Line 201 | public class ForkJoinPoolTest extends JS
201       * getParallelism returns size set in constructor
202       */
203      public void testGetParallelism() {
204 <        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;
204 >        ForkJoinPool p = new ForkJoinPool(1);
205          try {
221            p = new ForkJoinPool(1);
206              assertTrue(p.getParallelism() == 1);
223            p.setParallelism(-2);
224            shouldThrow();
225        } catch (IllegalArgumentException success) {
207          } finally {
208              joinPool(p);
209          }
# Line 232 | Line 213 | public class ForkJoinPoolTest extends JS
213       * getPoolSize returns number of started workers.
214       */
215      public void testGetPoolSize() {
216 <        ForkJoinPool p = null;
216 >        ForkJoinPool p = new ForkJoinPool(1);
217          try {
218 <            p = new ForkJoinPool(1);
238 <            assertTrue(p.getPoolSize() == 0);
218 >            assertTrue(p.getActiveThreadCount() == 0);
219              Future<String> future = p.submit(new StringTask());
220              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());
221          } finally {
222              joinPool(p);
223          }
# Line 310 | Line 230 | public class ForkJoinPoolTest extends JS
230       * performs its defined action
231       */
232      public void testSetUncaughtExceptionHandler() throws InterruptedException {
233 <        ForkJoinPool p = null;
233 >        MyHandler eh = new MyHandler();
234 >        ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(), eh, false);
235          try {
236 <            p = new ForkJoinPool(1, new FailingThreadFactory());
316 <            MyHandler eh = new MyHandler();
317 <            p.setUncaughtExceptionHandler(eh);
318 <            assertEquals(eh, p.getUncaughtExceptionHandler());
236 >            assert(eh == p.getUncaughtExceptionHandler());
237              p.execute(new FailingTask());
238              Thread.sleep(MEDIUM_DELAY_MS);
239              assertTrue(eh.catches > 0);
240          } finally {
241 +            p.shutdownNow();
242              joinPool(p);
243          }
244      }
245  
246      /**
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    /**
247       * After invoking a single task, isQuiescent is true,
248       * queues are empty, threads are not active, and
249       * construction parameters continue to hold
250       */
251      public void testisQuiescent() throws InterruptedException {
252 <        ForkJoinPool p = null;
252 >        ForkJoinPool p = new ForkJoinPool(2);
253          try {
350            p = new ForkJoinPool(2);
254              p.invoke(new FibTask(20));
255              assertTrue(p.getFactory() ==
256                         ForkJoinPool.defaultForkJoinWorkerThreadFactory);
257              Thread.sleep(MEDIUM_DELAY_MS);
258              assertTrue(p.isQuiescent());
356            assertTrue(p.getMaintainsParallelism());
259              assertFalse(p.getAsyncMode());
260              assertTrue(p.getActiveThreadCount() == 0);
261              assertTrue(p.getQueuedTaskCount() == 0);
# Line 371 | Line 273 | public class ForkJoinPoolTest extends JS
273       * Completed submit(ForkJoinTask) returns result
274       */
275      public void testSubmitForkJoinTask() throws Throwable {
276 <        ForkJoinPool p = null;
276 >        ForkJoinPool p = new ForkJoinPool(1);
277          try {
376            p = new ForkJoinPool(1);
278              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
279              int r = f.get();
280              assertTrue(r == 21);
# Line 386 | Line 287 | public class ForkJoinPoolTest extends JS
287       * A task submitted after shutdown is rejected
288       */
289      public void testSubmitAfterShutdown() {
290 <        ForkJoinPool p = null;
290 >        ForkJoinPool p = new ForkJoinPool(1);
291          try {
391            p = new ForkJoinPool(1);
292              p.shutdown();
293              assertTrue(p.isShutdown());
294              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
# Line 403 | Line 303 | public class ForkJoinPoolTest extends JS
303       * Pool maintains parallelism when using ManagedBlocker
304       */
305      public void testBlockingForkJoinTask() throws Throwable {
306 <        ForkJoinPool p = null;
306 >        ForkJoinPool p = new ForkJoinPool(4);
307          try {
408            p = new ForkJoinPool(4);
308              ReentrantLock lock = new ReentrantLock();
309              ManagedLocker locker = new ManagedLocker(lock);
310              ForkJoinTask<Integer> f = new LockingFibTask(30, locker, lock);
311              p.execute(f);
413            assertTrue(p.getPoolSize() >= 4);
312              int r = f.get();
313 <            assertTrue(r ==  832040);
313 >            assertTrue(r == 832040);
314          } finally {
315              p.shutdownNow(); // don't wait out shutdown
316          }
# Line 422 | Line 320 | public class ForkJoinPoolTest extends JS
320       * pollSubmission returns unexecuted submitted task, if present
321       */
322      public void testPollSubmission() {
323 <        SubFJP p = null;
323 >        SubFJP p = new SubFJP();
324          try {
427            p = new SubFJP();
325              ForkJoinTask a = p.submit(new MediumRunnable());
326              ForkJoinTask b = p.submit(new MediumRunnable());
327              ForkJoinTask c = p.submit(new MediumRunnable());
# Line 440 | Line 337 | public class ForkJoinPoolTest extends JS
337       * drainTasksTo transfers unexecuted submitted tasks, if present
338       */
339      public void testDrainTasksTo() {
340 <        SubFJP p = null;
340 >        SubFJP p = new SubFJP();
341          try {
445            p = new SubFJP();
342              ForkJoinTask a = p.submit(new MediumRunnable());
343              ForkJoinTask b = p.submit(new MediumRunnable());
344              ForkJoinTask c = p.submit(new MediumRunnable());
# Line 466 | Line 362 | public class ForkJoinPoolTest extends JS
362       */
363      public void testExecuteRunnable() throws Throwable {
364          ExecutorService e = new ForkJoinPool(1);
365 <        TrackedShortRunnable task = new TrackedShortRunnable();
366 <        assertFalse(task.done);
367 <        Future<?> future = e.submit(task);
368 <        future.get();
369 <        assertTrue(task.done);
365 >        try {
366 >            TrackedShortRunnable task = new TrackedShortRunnable();
367 >            assertFalse(task.done);
368 >            Future<?> future = e.submit(task);
369 >            future.get();
370 >            assertTrue(task.done);
371 >        } finally {
372 >            joinPool(e);
373 >        }
374      }
375  
376  
# Line 479 | Line 379 | public class ForkJoinPoolTest extends JS
379       */
380      public void testSubmitCallable() throws Throwable {
381          ExecutorService e = new ForkJoinPool(1);
382 <        Future<String> future = e.submit(new StringTask());
383 <        String result = future.get();
384 <        assertSame(TEST_STRING, result);
382 >        try {
383 >            Future<String> future = e.submit(new StringTask());
384 >            String result = future.get();
385 >            assertSame(TEST_STRING, result);
386 >        } finally {
387 >            joinPool(e);
388 >        }
389      }
390  
391      /**
# Line 489 | Line 393 | public class ForkJoinPoolTest extends JS
393       */
394      public void testSubmitRunnable() throws Throwable {
395          ExecutorService e = new ForkJoinPool(1);
396 <        Future<?> future = e.submit(new NoOpRunnable());
397 <        future.get();
398 <        assertTrue(future.isDone());
396 >        try {
397 >            Future<?> future = e.submit(new NoOpRunnable());
398 >            future.get();
399 >            assertTrue(future.isDone());
400 >        } finally {
401 >            joinPool(e);
402 >        }
403      }
404  
405      /**
# Line 499 | Line 407 | public class ForkJoinPoolTest extends JS
407       */
408      public void testSubmitRunnable2() throws Throwable {
409          ExecutorService e = new ForkJoinPool(1);
410 <        Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
411 <        String result = future.get();
412 <        assertSame(TEST_STRING, result);
410 >        try {
411 >            Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
412 >            String result = future.get();
413 >            assertSame(TEST_STRING, result);
414 >        } finally {
415 >            joinPool(e);
416 >        }
417      }
418  
419  
# Line 519 | Line 431 | public class ForkJoinPoolTest extends JS
431          } catch (AccessControlException ok) {
432              return;
433          }
434 +
435          try {
436              ExecutorService e = new ForkJoinPool(1);
437 <            Future future = e.submit(Executors.callable(new PrivilegedAction() {
437 >            try {
438 >                Future future = e.submit(Executors.callable(new PrivilegedAction() {
439                      public Object run() {
440                          return TEST_STRING;
441                      }}));
442  
443 <            Object result = future.get();
444 <            assertSame(TEST_STRING, result);
445 <        }
446 <        finally {
443 >                Object result = future.get();
444 >                assertSame(TEST_STRING, result);
445 >            } finally {
446 >                joinPool(e);
447 >            }
448 >        } finally {
449              Policy.setPolicy(savedPolicy);
450          }
451      }
# Line 551 | Line 467 | public class ForkJoinPoolTest extends JS
467  
468          try {
469              ExecutorService e = new ForkJoinPool(1);
470 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
470 >            try {
471 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
472                      public Object run() {
473                          return TEST_STRING;
474                      }}));
475  
476 <            Object result = future.get();
477 <            assertSame(TEST_STRING, result);
478 <        }
479 <        finally {
476 >                Object result = future.get();
477 >                assertSame(TEST_STRING, result);
478 >            } finally {
479 >                joinPool(e);
480 >            }
481 >        } finally {
482              Policy.setPolicy(savedPolicy);
483          }
484      }
# Line 579 | Line 498 | public class ForkJoinPoolTest extends JS
498              return;
499          }
500  
582
501          try {
502              ExecutorService e = new ForkJoinPool(1);
503 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
503 >            try {
504 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
505                      public Object run() throws Exception {
506                          throw new IndexOutOfBoundsException();
507                      }}));
508  
509 <            Object result = future.get();
510 <            shouldThrow();
511 <        } catch (ExecutionException success) {
512 <            assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
509 >                Object result = future.get();
510 >                shouldThrow();
511 >            } catch (ExecutionException success) {
512 >                assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
513 >            } finally {
514 >                joinPool(e);
515 >            }
516          } finally {
517              Policy.setPolicy(savedPolicy);
518          }
# Line 600 | Line 522 | public class ForkJoinPoolTest extends JS
522       * execute(null runnable) throws NullPointerException
523       */
524      public void testExecuteNullRunnable() {
525 +        ExecutorService e = new ForkJoinPool(1);
526          try {
604            ExecutorService e = new ForkJoinPool(1);
527              TrackedShortRunnable task = null;
528              Future<?> future = e.submit(task);
529              shouldThrow();
530 <        } catch (NullPointerException success) {}
530 >        } catch (NullPointerException success) {
531 >        } finally {
532 >            joinPool(e);
533 >        }
534      }
535  
536  
# Line 613 | Line 538 | public class ForkJoinPoolTest extends JS
538       * submit(null callable) throws NullPointerException
539       */
540      public void testSubmitNullCallable() {
541 +        ExecutorService e = new ForkJoinPool(1);
542          try {
617            ExecutorService e = new ForkJoinPool(1);
543              StringTask t = null;
544              Future<String> future = e.submit(t);
545              shouldThrow();
546 <        } catch (NullPointerException success) {}
546 >        } catch (NullPointerException success) {
547 >        } finally {
548 >            joinPool(e);
549 >        }
550      }
551  
552  
# Line 664 | Line 592 | public class ForkJoinPoolTest extends JS
592              shouldThrow();
593          } catch (ExecutionException success) {
594              assertTrue(success.getCause() instanceof ArithmeticException);
595 +        } finally {
596 +            joinPool(p);
597          }
668
669        joinPool(p);
598      }
599  
600      /**
# Line 702 | Line 630 | public class ForkJoinPoolTest extends JS
630       */
631      public void testInvokeAny3() throws Throwable {
632          ExecutorService e = new ForkJoinPool(1);
633 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
634 +        l.add(null);
635          try {
706            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
707            l.add(null);
636              e.invokeAny(l);
637              shouldThrow();
638          } catch (NullPointerException success) {
# Line 717 | Line 645 | public class ForkJoinPoolTest extends JS
645       * invokeAny(c) throws NullPointerException if c has null elements
646       */
647      public void testInvokeAny4() throws Throwable {
648 +        CountDownLatch latch = new CountDownLatch(1);
649          ExecutorService e = new ForkJoinPool(1);
650 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
651 +        l.add(latchAwaitingStringTask(latch));
652 +        l.add(null);
653          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);
654              e.invokeAny(l);
655              shouldThrow();
656          } catch (NullPointerException success) {
657          } finally {
658 +            latch.countDown();
659              joinPool(e);
660          }
661      }
# Line 741 | Line 665 | public class ForkJoinPoolTest extends JS
665       */
666      public void testInvokeAny5() throws Throwable {
667          ExecutorService e = new ForkJoinPool(1);
668 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
669 +        l.add(new NPETask());
670          try {
745            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
746            l.add(new NPETask());
671              e.invokeAny(l);
672              shouldThrow();
673          } catch (ExecutionException success) {
# Line 759 | Line 683 | public class ForkJoinPoolTest extends JS
683      public void testInvokeAny6() throws Throwable {
684          ExecutorService e = new ForkJoinPool(1);
685          try {
686 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
686 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
687              l.add(new StringTask());
688              l.add(new StringTask());
689              String result = e.invokeAny(l);
# Line 802 | Line 726 | public class ForkJoinPoolTest extends JS
726       */
727      public void testInvokeAll3() throws InterruptedException {
728          ExecutorService e = new ForkJoinPool(1);
729 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
730 +        l.add(new StringTask());
731 +        l.add(null);
732          try {
806            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
807            l.add(new StringTask());
808            l.add(null);
733              e.invokeAll(l);
734              shouldThrow();
735          } catch (NullPointerException success) {
# Line 820 | Line 744 | public class ForkJoinPoolTest extends JS
744       */
745      public void testInvokeAll4() throws Throwable {
746          ExecutorService e = new ForkJoinPool(1);
747 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
748 +        l.add(new NPETask());
749 +        List<Future<String>> futures = e.invokeAll(l);
750 +        assertEquals(1, futures.size());
751          try {
752 <            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();
752 >            futures.get(0).get();
753              shouldThrow();
754          } catch (ExecutionException success) {
755              assertTrue(success.getCause() instanceof NullPointerException);
# Line 841 | Line 764 | public class ForkJoinPoolTest extends JS
764      public void testInvokeAll5() throws Throwable {
765          ExecutorService e = new ForkJoinPool(1);
766          try {
767 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
767 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
768              l.add(new StringTask());
769              l.add(new StringTask());
770 <            List<Future<String>> result = e.invokeAll(l);
771 <            assertEquals(2, result.size());
772 <            for (Future<String> future : result)
770 >            List<Future<String>> futures = e.invokeAll(l);
771 >            assertEquals(2, futures.size());
772 >            for (Future<String> future : futures)
773                  assertSame(TEST_STRING, future.get());
774          } finally {
775              joinPool(e);
# Line 860 | Line 783 | public class ForkJoinPoolTest extends JS
783      public void testTimedInvokeAny1() throws Throwable {
784          ExecutorService e = new ForkJoinPool(1);
785          try {
786 <            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
786 >            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
787              shouldThrow();
788          } catch (NullPointerException success) {
789          } finally {
# Line 873 | Line 796 | public class ForkJoinPoolTest extends JS
796       */
797      public void testTimedInvokeAnyNullTimeUnit() throws Throwable {
798          ExecutorService e = new ForkJoinPool(1);
799 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
800 +        l.add(new StringTask());
801          try {
877            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
878            l.add(new StringTask());
802              e.invokeAny(l, MEDIUM_DELAY_MS, null);
803              shouldThrow();
804          } catch (NullPointerException success) {
# Line 891 | Line 814 | public class ForkJoinPoolTest extends JS
814          ExecutorService e = new ForkJoinPool(1);
815          try {
816              e.invokeAny(new ArrayList<Callable<String>>(),
817 <                        MEDIUM_DELAY_MS, MILLISECONDS);
817 >                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
818              shouldThrow();
819          } catch (IllegalArgumentException success) {
820          } finally {
# Line 903 | Line 826 | public class ForkJoinPoolTest extends JS
826       * timed invokeAny(c) throws NullPointerException if c has null elements
827       */
828      public void testTimedInvokeAny3() throws Throwable {
829 +        CountDownLatch latch = new CountDownLatch(1);
830          ExecutorService e = new ForkJoinPool(1);
831 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
832 +        l.add(latchAwaitingStringTask(latch));
833 +        l.add(null);
834          try {
835 <            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);
835 >            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
836              shouldThrow();
837          } catch (NullPointerException success) {
838          } finally {
839 +            latch.countDown();
840              joinPool(e);
841          }
842      }
# Line 921 | Line 846 | public class ForkJoinPoolTest extends JS
846       */
847      public void testTimedInvokeAny4() throws Throwable {
848          ExecutorService e = new ForkJoinPool(1);
849 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
850 +        l.add(new NPETask());
851          try {
852 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
926 <            l.add(new NPETask());
927 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
852 >            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
853              shouldThrow();
854          } catch (ExecutionException success) {
855              assertTrue(success.getCause() instanceof NullPointerException);
# Line 939 | Line 864 | public class ForkJoinPoolTest extends JS
864      public void testTimedInvokeAny5() throws Throwable {
865          ExecutorService e = new ForkJoinPool(1);
866          try {
867 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
867 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
868              l.add(new StringTask());
869              l.add(new StringTask());
870 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
870 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
871              assertSame(TEST_STRING, result);
872          } finally {
873              joinPool(e);
# Line 955 | Line 880 | public class ForkJoinPoolTest extends JS
880      public void testTimedInvokeAll1() throws Throwable {
881          ExecutorService e = new ForkJoinPool(1);
882          try {
883 <            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
883 >            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
884              shouldThrow();
885          } catch (NullPointerException success) {
886          } finally {
# Line 968 | Line 893 | public class ForkJoinPoolTest extends JS
893       */
894      public void testTimedInvokeAllNullTimeUnit() throws Throwable {
895          ExecutorService e = new ForkJoinPool(1);
896 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
897 +        l.add(new StringTask());
898          try {
972            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
973            l.add(new StringTask());
899              e.invokeAll(l, MEDIUM_DELAY_MS, null);
900              shouldThrow();
901          } catch (NullPointerException success) {
# Line 987 | Line 912 | public class ForkJoinPoolTest extends JS
912          try {
913              List<Future<String>> r
914                  = e.invokeAll(new ArrayList<Callable<String>>(),
915 <                              MEDIUM_DELAY_MS, MILLISECONDS);
915 >                              MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
916              assertTrue(r.isEmpty());
917          } finally {
918              joinPool(e);
# Line 999 | Line 924 | public class ForkJoinPoolTest extends JS
924       */
925      public void testTimedInvokeAll3() throws InterruptedException {
926          ExecutorService e = new ForkJoinPool(1);
927 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
928 +        l.add(new StringTask());
929 +        l.add(null);
930          try {
931 <            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);
931 >            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
932              shouldThrow();
933          } catch (NullPointerException success) {
934          } finally {
# Line 1016 | Line 941 | public class ForkJoinPoolTest extends JS
941       */
942      public void testTimedInvokeAll4() throws Throwable {
943          ExecutorService e = new ForkJoinPool(1);
944 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
945 +        l.add(new NPETask());
946 +        List<Future<String>> futures
947 +            = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
948 +        assertEquals(1, futures.size());
949          try {
950 <            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();
950 >            futures.get(0).get();
951              shouldThrow();
952          } catch (ExecutionException success) {
953              assertTrue(success.getCause() instanceof NullPointerException);
# Line 1038 | Line 962 | public class ForkJoinPoolTest extends JS
962      public void testTimedInvokeAll5() throws Throwable {
963          ExecutorService e = new ForkJoinPool(1);
964          try {
965 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
965 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
966              l.add(new StringTask());
967              l.add(new StringTask());
968 <            List<Future<String>> result
969 <                = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
970 <            assertEquals(2, result.size());
971 <            for (Future<String> future : result)
968 >            List<Future<String>> futures
969 >                = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
970 >            assertEquals(2, futures.size());
971 >            for (Future<String> future : futures)
972                  assertSame(TEST_STRING, future.get());
973          } finally {
974              joinPool(e);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines