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.9 by jsr166, Wed Aug 5 00:49:40 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 170 | Line 183 | public class ForkJoinPoolTest extends JS
183          try {
184              new ForkJoinPool(-1);
185              shouldThrow();
186 <        }
174 <        catch (IllegalArgumentException success) {}
186 >        } catch (IllegalArgumentException success) {}
187      }
188  
189      /**
# Line 179 | 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) {
185 <        }
196 >        } catch (NullPointerException success) {}
197      }
198  
199  
# Line 190 | Line 201 | public class ForkJoinPoolTest extends JS
201       * getParallelism returns size set in constructor
202       */
203      public void testGetParallelism() {
204 <        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;
204 >        ForkJoinPool p = new ForkJoinPool(1);
205          try {
223            p = new ForkJoinPool(1);
206              assertTrue(p.getParallelism() == 1);
225            p.setParallelism(-2);
226            shouldThrow();
227        } catch (IllegalArgumentException success) {
207          } finally {
208              joinPool(p);
209          }
# Line 234 | 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);
240 <            assertTrue(p.getPoolSize() == 0);
218 >            assertTrue(p.getActiveThreadCount() == 0);
219              Future<String> future = p.submit(new StringTask());
220              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());
221          } finally {
222              joinPool(p);
223          }
# Line 312 | 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());
318 <            MyHandler eh = new MyHandler();
319 <            p.setUncaughtExceptionHandler(eh);
320 <            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      /**
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    /**
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 {
352            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());
358            assertTrue(p.getMaintainsParallelism());
259              assertFalse(p.getAsyncMode());
260              assertTrue(p.getActiveThreadCount() == 0);
261              assertTrue(p.getQueuedTaskCount() == 0);
# Line 373 | 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 {
378            p = new ForkJoinPool(1);
278              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
279              int r = f.get();
280              assertTrue(r == 21);
# Line 388 | 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 {
393            p = new ForkJoinPool(1);
292              p.shutdown();
293              assertTrue(p.isShutdown());
294              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
# Line 405 | 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 {
410            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);
415            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 424 | 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 {
429            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 442 | 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 {
447            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 468 | 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 481 | 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 491 | 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 501 | 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 521 | 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 553 | 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 581 | Line 498 | public class ForkJoinPoolTest extends JS
498              return;
499          }
500  
584
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) {
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 601 | 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 {
605            ExecutorService e = new ForkJoinPool(1);
527              TrackedShortRunnable task = null;
528              Future<?> future = e.submit(task);
529              shouldThrow();
530          } catch (NullPointerException success) {
531 +        } finally {
532 +            joinPool(e);
533          }
534      }
535  
# Line 615 | 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 {
619            ExecutorService e = new ForkJoinPool(1);
543              StringTask t = null;
544              Future<String> future = e.submit(t);
545              shouldThrow();
546          } catch (NullPointerException success) {
547 +        } finally {
548 +            joinPool(e);
549          }
550      }
551  
# Line 633 | Line 558 | public class ForkJoinPoolTest extends JS
558          final ForkJoinPool p = new ForkJoinPool(1);
559  
560          Thread t = new Thread(new CheckedInterruptedRunnable() {
561 <            void realRun() throws Throwable {
561 >            public void realRun() throws Throwable {
562                  p.submit(new CheckedCallable<Object>() {
563                      public Object realCall() throws Throwable {
564                          try {
# Line 666 | Line 591 | public class ForkJoinPoolTest extends JS
591                  }}).get();
592              shouldThrow();
593          } catch (ExecutionException success) {
594 +            assertTrue(success.getCause() instanceof ArithmeticException);
595 +        } finally {
596 +            joinPool(p);
597          }
670        joinPool(p);
598      }
599  
600      /**
# Line 703 | 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 {
707            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
708            l.add(null);
636              e.invokeAny(l);
637              shouldThrow();
638          } catch (NullPointerException success) {
# Line 718 | 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 {
723            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
724            l.add(new Callable<String>() {
725                public String call() {
726                    // The delay gives the pool a chance to notice
727                    // the null element.
728                    sleepTillInterrupted(SMALL_DELAY_MS);
729                    return "foo";
730                }});
731            l.add(null);
654              e.invokeAny(l);
655              shouldThrow();
656          } catch (NullPointerException success) {
657          } finally {
658 +            latch.countDown();
659              joinPool(e);
660          }
661      }
# Line 742 | 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 {
746            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
747            l.add(new NPETask());
671              e.invokeAny(l);
672              shouldThrow();
673          } catch (ExecutionException success) {
674 +            assertTrue(success.getCause() instanceof NullPointerException);
675          } finally {
676              joinPool(e);
677          }
# 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);
756          } finally {
757              joinPool(e);
758          }
# Line 840 | 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 859 | 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 872 | 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 {
876            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
877            l.add(new StringTask());
802              e.invokeAny(l, MEDIUM_DELAY_MS, null);
803              shouldThrow();
804          } catch (NullPointerException success) {
# Line 890 | 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 902 | 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>>();
908 <            l.add(new StringTask());
909 <            l.add(null);
910 <            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 920 | 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>>();
925 <            l.add(new NPETask());
926 <            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);
856          } finally {
857              joinPool(e);
858          }
# Line 937 | 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 953 | 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 966 | 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 {
970            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
971            l.add(new StringTask());
899              e.invokeAll(l, MEDIUM_DELAY_MS, null);
900              shouldThrow();
901          } catch (NullPointerException success) {
# Line 985 | 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 997 | 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>>();
1002 <            l.add(new StringTask());
1003 <            l.add(null);
1004 <            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 1014 | 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>>();
1019 <            l.add(new NPETask());
1020 <            List<Future<String>> result
1021 <                = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1022 <            assertEquals(1, result.size());
1023 <            for (Future<String> future : result)
1024 <                future.get();
950 >            futures.get(0).get();
951              shouldThrow();
952          } catch (ExecutionException success) {
953 +            assertTrue(success.getCause() instanceof NullPointerException);
954          } finally {
955              joinPool(e);
956          }
# Line 1035 | 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