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.4 by jsr166, Sat Aug 1 21:56:02 2009 UTC vs.
Revision 1.45 by dl, Tue Jan 10 14:03:17 2012 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7
7   import junit.framework.*;
8 < import java.util.*;
9 < import java.util.concurrent.*;
10 < import java.util.concurrent.locks.*;
11 < import java.security.*;
8 > import java.util.ArrayList;
9 > import java.util.Collection;
10 > import java.util.List;
11 > import java.util.concurrent.Executors;
12 > import java.util.concurrent.ExecutorService;
13 > import java.util.concurrent.AbstractExecutorService;
14 > import java.util.concurrent.CountDownLatch;
15 > import java.util.concurrent.Callable;
16 > import java.util.concurrent.Future;
17 > import java.util.concurrent.ExecutionException;
18 > import java.util.concurrent.CancellationException;
19 > import java.util.concurrent.RejectedExecutionException;
20 > import java.util.concurrent.ForkJoinPool;
21 > import java.util.concurrent.ForkJoinTask;
22 > import java.util.concurrent.ForkJoinWorkerThread;
23 > import java.util.concurrent.RecursiveTask;
24 > import java.util.concurrent.TimeUnit;
25 > import java.util.concurrent.atomic.AtomicBoolean;
26 > import java.util.concurrent.locks.ReentrantLock;
27 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
28 > import java.security.AccessControlException;
29 > import java.security.Policy;
30 > import java.security.PrivilegedAction;
31 > import java.security.PrivilegedExceptionAction;
32  
33   public class ForkJoinPoolTest extends JSR166TestCase {
34      public static void main(String[] args) {
35 <        junit.textui.TestRunner.run (suite());
35 >        junit.textui.TestRunner.run(suite());
36      }
37 +
38      public static Test suite() {
39          return new TestSuite(ForkJoinPoolTest.class);
40      }
# Line 38 | Line 58 | public class ForkJoinPoolTest extends JS
58      // Some classes to test extension and factory methods
59  
60      static class MyHandler implements Thread.UncaughtExceptionHandler {
61 <        int catches = 0;
61 >        volatile int catches = 0;
62          public void uncaughtException(Thread t, Throwable e) {
63              ++catches;
64          }
# Line 47 | Line 67 | public class ForkJoinPoolTest extends JS
67      // to test handlers
68      static class FailingFJWSubclass extends ForkJoinWorkerThread {
69          public FailingFJWSubclass(ForkJoinPool p) { super(p) ; }
70 <        protected void onStart() { throw new Error(); }
70 >        protected void onStart() { super.onStart(); throw new Error(); }
71      }
72  
73 <    static class FailingThreadFactory implements ForkJoinPool.ForkJoinWorkerThreadFactory {
74 <        int calls = 0;
73 >    static class FailingThreadFactory
74 >            implements ForkJoinPool.ForkJoinWorkerThreadFactory {
75 >        volatile int calls = 0;
76          public ForkJoinWorkerThread newThread(ForkJoinPool p) {
77              if (++calls > 1) return null;
78              return new FailingFJWSubclass(p);
# Line 135 | Line 156 | public class ForkJoinPoolTest extends JS
156      }
157  
158      /**
159 <     * Succesfully constructed pool reports default factory,
159 >     * Successfully constructed pool reports default factory,
160       * parallelism and async mode policies, no active threads or
161       * tasks, and quiescent running state.
162       */
163      public void testDefaultInitialState() {
164 <        ForkJoinPool p = null;
164 >        ForkJoinPool p = new ForkJoinPool(1);
165          try {
166 <            p = new ForkJoinPool(1);
167 <            assertTrue(p.getFactory() == ForkJoinPool.defaultForkJoinWorkerThreadFactory);
147 <            assertTrue(p.isQuiescent());
148 <            assertTrue(p.getMaintainsParallelism());
166 >            assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory,
167 >                       p.getFactory());
168              assertFalse(p.getAsyncMode());
169 <            assertTrue(p.getActiveThreadCount() == 0);
170 <            assertTrue(p.getStealCount() == 0);
171 <            assertTrue(p.getQueuedTaskCount() == 0);
172 <            assertTrue(p.getQueuedSubmissionCount() == 0);
169 >            assertEquals(0, p.getActiveThreadCount());
170 >            assertEquals(0, p.getStealCount());
171 >            assertEquals(0, p.getQueuedTaskCount());
172 >            assertEquals(0, p.getQueuedSubmissionCount());
173              assertFalse(p.hasQueuedSubmissions());
174              assertFalse(p.isShutdown());
175              assertFalse(p.isTerminating());
# Line 167 | Line 186 | public class ForkJoinPoolTest extends JS
186          try {
187              new ForkJoinPool(-1);
188              shouldThrow();
189 <        }
171 <        catch (IllegalArgumentException success) {}
189 >        } catch (IllegalArgumentException success) {}
190      }
191  
192      /**
# Line 176 | Line 194 | public class ForkJoinPoolTest extends JS
194       */
195      public void testConstructor2() {
196          try {
197 <            new ForkJoinPool(1, null);
197 >            new ForkJoinPool(1, null, null, false);
198              shouldThrow();
199 <        }
182 <        catch (NullPointerException success) {}
199 >        } catch (NullPointerException success) {}
200      }
201  
185
202      /**
203       * getParallelism returns size set in constructor
204       */
205      public void testGetParallelism() {
206 <        ForkJoinPool p = null;
191 <        try {
192 <            p = new ForkJoinPool(1);
193 <            assertTrue(p.getParallelism() == 1);
194 <        } finally {
195 <            joinPool(p);
196 <        }
197 <    }
198 <
199 <    /**
200 <     * setParallelism changes reported parallelism level.
201 <     */
202 <    public void testSetParallelism() {
203 <        ForkJoinPool p = null;
204 <        try {
205 <            p = new ForkJoinPool(1);
206 <            assertTrue(p.getParallelism() == 1);
207 <            p.setParallelism(2);
208 <            assertTrue(p.getParallelism() == 2);
209 <        } finally {
210 <            joinPool(p);
211 <        }
212 <    }
213 <
214 <    /**
215 <     * setParallelism with argument <= 0 throws exception
216 <     */
217 <    public void testSetParallelism2() {
218 <        ForkJoinPool p = null;
206 >        ForkJoinPool p = new ForkJoinPool(1);
207          try {
208 <            p = new ForkJoinPool(1);
221 <            assertTrue(p.getParallelism() == 1);
222 <            p.setParallelism(-2);
223 <            shouldThrow();
224 <        } catch (IllegalArgumentException success) {
208 >            assertEquals(1, p.getParallelism());
209          } finally {
210              joinPool(p);
211          }
# Line 231 | Line 215 | public class ForkJoinPoolTest extends JS
215       * getPoolSize returns number of started workers.
216       */
217      public void testGetPoolSize() {
218 <        ForkJoinPool p = null;
218 >        ForkJoinPool p = new ForkJoinPool(1);
219          try {
220 <            p = new ForkJoinPool(1);
237 <            assertTrue(p.getPoolSize() == 0);
220 >            assertEquals(0, p.getActiveThreadCount());
221              Future<String> future = p.submit(new StringTask());
222 <            assertTrue(p.getPoolSize() == 1);
240 <
241 <        } finally {
242 <            joinPool(p);
243 <        }
244 <    }
245 <
246 <    /**
247 <     * setMaximumPoolSize changes size reported by getMaximumPoolSize.
248 <     */
249 <    public void testSetMaximumPoolSize() {
250 <        ForkJoinPool p = null;
251 <        try {
252 <            p = new ForkJoinPool(1);
253 <            p.setMaximumPoolSize(2);
254 <            assertTrue(p.getMaximumPoolSize() == 2);
255 <        } finally {
256 <            joinPool(p);
257 <        }
258 <    }
259 <
260 <    /**
261 <     * setMaximumPoolSize with argument <= 0 throws exception
262 <     */
263 <    public void testSetMaximumPoolSize2() {
264 <        ForkJoinPool p = null;
265 <        try {
266 <            p = new ForkJoinPool(1);
267 <            p.setMaximumPoolSize(-2);
268 <            shouldThrow();
269 <        } catch (IllegalArgumentException success) {
270 <        } finally {
271 <            joinPool(p);
272 <        }
273 <    }
274 <
275 <    /**
276 <     * setMaintainsParallelism changes policy reported by
277 <     * getMaintainsParallelism.
278 <     */
279 <    public void testSetMaintainsParallelism() {
280 <        ForkJoinPool p = null;
281 <        try {
282 <            p = new ForkJoinPool(1);
283 <            p.setMaintainsParallelism(false);
284 <            assertFalse(p.getMaintainsParallelism());
285 <        } finally {
286 <            joinPool(p);
287 <        }
288 <    }
289 <
290 <    /**
291 <     * setAsyncMode changes policy reported by
292 <     * getAsyncMode.
293 <     */
294 <    public void testSetAsyncMode() {
295 <        ForkJoinPool p = null;
296 <        try {
297 <            p = new ForkJoinPool(1);
298 <            p.setAsyncMode(true);
299 <            assertTrue(p.getAsyncMode());
222 >            assertEquals(1, p.getPoolSize());
223          } finally {
224              joinPool(p);
225          }
# Line 308 | Line 231 | public class ForkJoinPoolTest extends JS
231       * Additionally tests: Overriding ForkJoinWorkerThread.onStart
232       * performs its defined action
233       */
234 <    public void testSetUncaughtExceptionHandler() {
235 <        ForkJoinPool p = null;
234 >    public void testSetUncaughtExceptionHandler() throws InterruptedException {
235 >        final CountDownLatch uehInvoked = new CountDownLatch(1);
236 >        final Thread.UncaughtExceptionHandler eh =
237 >            new Thread.UncaughtExceptionHandler() {
238 >                public void uncaughtException(Thread t, Throwable e) {
239 >                    uehInvoked.countDown();
240 >                }};
241 >        ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(),
242 >                                          eh, false);
243          try {
244 <            p = new ForkJoinPool(1, new FailingThreadFactory());
245 <            MyHandler eh = new MyHandler();
246 <            p.setUncaughtExceptionHandler(eh);
247 <            assertEquals(eh, p.getUncaughtExceptionHandler());
248 <            p.execute(new FailingTask());
249 <            Thread.sleep(MEDIUM_DELAY_MS);
320 <            assertTrue(eh.catches > 0);
321 <        } catch (InterruptedException e) {
322 <            unexpectedException();
244 >            assertSame(eh, p.getUncaughtExceptionHandler());
245 >            try {
246 >                p.execute(new FibTask(8));
247 >                assertTrue(uehInvoked.await(MEDIUM_DELAY_MS, MILLISECONDS));
248 >            } catch(RejectedExecutionException ok) {
249 >            }
250          } finally {
251 +            p.shutdownNow(); // failure might have prevented processing task
252              joinPool(p);
253          }
254      }
255  
256      /**
257 <     * setUncaughtExceptionHandler of null removes handler
257 >     * After invoking a single task, isQuiescent eventually becomes
258 >     * true, at which time queues are empty, threads are not active,
259 >     * the task has completed successfully, and construction
260 >     * parameters continue to hold
261       */
262 <    public void testSetUncaughtExceptionHandler2() {
263 <        ForkJoinPool p = null;
262 >    public void testIsQuiescent() throws Exception {
263 >        ForkJoinPool p = new ForkJoinPool(2);
264          try {
265 <            p = new ForkJoinPool(1);
266 <            p.setUncaughtExceptionHandler(null);
267 <            assertNull(p.getUncaughtExceptionHandler());
268 <        } finally {
269 <            joinPool(p);
270 <        }
271 <    }
272 <
265 >            assertTrue(p.isQuiescent());
266 >            long startTime = System.nanoTime();
267 >            FibTask f = new FibTask(20);
268 >            p.invoke(f);
269 >            assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory,
270 >                       p.getFactory());
271 >            while (! p.isQuiescent()) {
272 >                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
273 >                    throw new AssertionFailedError("timed out");
274 >                assertFalse(p.getAsyncMode());
275 >                assertFalse(p.isShutdown());
276 >                assertFalse(p.isTerminating());
277 >                assertFalse(p.isTerminated());
278 >                Thread.yield();
279 >            }
280  
343    /**
344     * After invoking a single task, isQuiescent is true,
345     * queues are empty, threads are not active, and
346     * construction parameters continue to hold
347     */
348    public void testisQuiescent() {
349        ForkJoinPool p = null;
350        try {
351            p = new ForkJoinPool(2);
352            p.invoke(new FibTask(20));
353            assertTrue(p.getFactory() == ForkJoinPool.defaultForkJoinWorkerThreadFactory);
354            Thread.sleep(MEDIUM_DELAY_MS);
281              assertTrue(p.isQuiescent());
356            assertTrue(p.getMaintainsParallelism());
282              assertFalse(p.getAsyncMode());
283 <            assertTrue(p.getActiveThreadCount() == 0);
284 <            assertTrue(p.getQueuedTaskCount() == 0);
285 <            assertTrue(p.getQueuedSubmissionCount() == 0);
283 >            assertEquals(0, p.getActiveThreadCount());
284 >            assertEquals(0, p.getQueuedTaskCount());
285 >            assertEquals(0, p.getQueuedSubmissionCount());
286              assertFalse(p.hasQueuedSubmissions());
287              assertFalse(p.isShutdown());
288              assertFalse(p.isTerminating());
289              assertFalse(p.isTerminated());
290 <        } catch (InterruptedException e) {
291 <            unexpectedException();
290 >            assertTrue(f.isDone());
291 >            assertEquals(6765, (int) f.get());
292          } finally {
293              joinPool(p);
294          }
# Line 372 | Line 297 | public class ForkJoinPoolTest extends JS
297      /**
298       * Completed submit(ForkJoinTask) returns result
299       */
300 <    public void testSubmitForkJoinTask() {
301 <        ForkJoinPool p = null;
300 >    public void testSubmitForkJoinTask() throws Throwable {
301 >        ForkJoinPool p = new ForkJoinPool(1);
302          try {
378            p = new ForkJoinPool(1);
303              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
304 <            int r = f.get();
381 <            assertTrue(r == 21);
382 <        } catch (ExecutionException ex) {
383 <            unexpectedException();
384 <        } catch (InterruptedException ex) {
385 <            unexpectedException();
304 >            assertEquals(21, (int) f.get());
305          } finally {
306              joinPool(p);
307          }
# Line 392 | Line 311 | public class ForkJoinPoolTest extends JS
311       * A task submitted after shutdown is rejected
312       */
313      public void testSubmitAfterShutdown() {
314 <        ForkJoinPool p = null;
314 >        ForkJoinPool p = new ForkJoinPool(1);
315          try {
397            p = new ForkJoinPool(1);
316              p.shutdown();
317              assertTrue(p.isShutdown());
318 <            ForkJoinTask<Integer> f = p.submit(new FibTask(8));
319 <            shouldThrow();
320 <        } catch (RejectedExecutionException success) {
318 >            try {
319 >                ForkJoinTask<Integer> f = p.submit(new FibTask(8));
320 >                shouldThrow();
321 >            } catch (RejectedExecutionException success) {}
322          } finally {
323              joinPool(p);
324          }
# Line 408 | Line 327 | public class ForkJoinPoolTest extends JS
327      /**
328       * Pool maintains parallelism when using ManagedBlocker
329       */
330 <    public void testBlockingForkJoinTask() {
331 <        ForkJoinPool p = null;
330 >    public void testBlockingForkJoinTask() throws Throwable {
331 >        ForkJoinPool p = new ForkJoinPool(4);
332          try {
414            p = new ForkJoinPool(4);
333              ReentrantLock lock = new ReentrantLock();
334              ManagedLocker locker = new ManagedLocker(lock);
335 <            ForkJoinTask<Integer> f = new LockingFibTask(30, locker, lock);
335 >            ForkJoinTask<Integer> f = new LockingFibTask(20, locker, lock);
336              p.execute(f);
337 <            assertTrue(p.getPoolSize() >= 4);
420 <            int r = f.get();
421 <            assertTrue(r ==  832040);
422 <        } catch (ExecutionException ex) {
423 <            unexpectedException();
424 <        } catch (InterruptedException ex) {
425 <            unexpectedException();
337 >            assertEquals(6765, (int) f.get());
338          } finally {
339 <            joinPool(p);
339 >            p.shutdownNow(); // don't wait out shutdown
340          }
341      }
342  
# Line 432 | Line 344 | public class ForkJoinPoolTest extends JS
344       * pollSubmission returns unexecuted submitted task, if present
345       */
346      public void testPollSubmission() {
347 <        SubFJP p = null;
347 >        final CountDownLatch done = new CountDownLatch(1);
348 >        SubFJP p = new SubFJP();
349          try {
350 <            p = new SubFJP();
351 <            ForkJoinTask a = p.submit(new MediumRunnable());
352 <            ForkJoinTask b = p.submit(new MediumRunnable());
440 <            ForkJoinTask c = p.submit(new MediumRunnable());
350 >            ForkJoinTask a = p.submit(awaiter(done));
351 >            ForkJoinTask b = p.submit(awaiter(done));
352 >            ForkJoinTask c = p.submit(awaiter(done));
353              ForkJoinTask r = p.pollSubmission();
354              assertTrue(r == a || r == b || r == c);
355              assertFalse(r.isDone());
356          } finally {
357 +            done.countDown();
358              joinPool(p);
359          }
360      }
# Line 450 | Line 363 | public class ForkJoinPoolTest extends JS
363       * drainTasksTo transfers unexecuted submitted tasks, if present
364       */
365      public void testDrainTasksTo() {
366 <        SubFJP p = null;
366 >        final CountDownLatch done = new CountDownLatch(1);
367 >        SubFJP p = new SubFJP();
368          try {
369 <            p = new SubFJP();
370 <            ForkJoinTask a = p.submit(new MediumRunnable());
371 <            ForkJoinTask b = p.submit(new MediumRunnable());
458 <            ForkJoinTask c = p.submit(new MediumRunnable());
369 >            ForkJoinTask a = p.submit(awaiter(done));
370 >            ForkJoinTask b = p.submit(awaiter(done));
371 >            ForkJoinTask c = p.submit(awaiter(done));
372              ArrayList<ForkJoinTask> al = new ArrayList();
373              p.drainTasksTo(al);
374              assertTrue(al.size() > 0);
# Line 464 | Line 377 | public class ForkJoinPoolTest extends JS
377                  assertFalse(r.isDone());
378              }
379          } finally {
380 +            done.countDown();
381              joinPool(p);
382          }
383      }
384  
471
385      // FJ Versions of AbstractExecutorService tests
386  
387      /**
388       * execute(runnable) runs it to completion
389       */
390 <    public void testExecuteRunnable() {
390 >    public void testExecuteRunnable() throws Throwable {
391 >        ExecutorService e = new ForkJoinPool(1);
392          try {
393 <            ExecutorService e = new ForkJoinPool(1);
394 <            TrackedShortRunnable task = new TrackedShortRunnable();
395 <            assertFalse(task.done);
393 >            final AtomicBoolean done = new AtomicBoolean(false);
394 >            CheckedRunnable task = new CheckedRunnable() {
395 >                public void realRun() {
396 >                    done.set(true);
397 >                }};
398              Future<?> future = e.submit(task);
399 <            future.get();
400 <            assertTrue(task.done);
401 <        }
402 <        catch (ExecutionException ex) {
403 <            unexpectedException();
404 <        }
405 <        catch (InterruptedException ex) {
490 <            unexpectedException();
399 >            assertNull(future.get());
400 >            assertNull(future.get(0, MILLISECONDS));
401 >            assertTrue(done.get());
402 >            assertTrue(future.isDone());
403 >            assertFalse(future.isCancelled());
404 >        } finally {
405 >            joinPool(e);
406          }
407      }
408  
494
409      /**
410       * Completed submit(callable) returns result
411       */
412 <    public void testSubmitCallable() {
412 >    public void testSubmitCallable() throws Throwable {
413 >        ExecutorService e = new ForkJoinPool(1);
414          try {
500            ExecutorService e = new ForkJoinPool(1);
415              Future<String> future = e.submit(new StringTask());
416 <            String result = future.get();
417 <            assertSame(TEST_STRING, result);
418 <        }
419 <        catch (ExecutionException ex) {
420 <            unexpectedException();
507 <        }
508 <        catch (InterruptedException ex) {
509 <            unexpectedException();
416 >            assertSame(TEST_STRING, future.get());
417 >            assertTrue(future.isDone());
418 >            assertFalse(future.isCancelled());
419 >        } finally {
420 >            joinPool(e);
421          }
422      }
423  
424      /**
425       * Completed submit(runnable) returns successfully
426       */
427 <    public void testSubmitRunnable() {
427 >    public void testSubmitRunnable() throws Throwable {
428 >        ExecutorService e = new ForkJoinPool(1);
429          try {
518            ExecutorService e = new ForkJoinPool(1);
430              Future<?> future = e.submit(new NoOpRunnable());
431 <            future.get();
431 >            assertNull(future.get());
432              assertTrue(future.isDone());
433 <        }
434 <        catch (ExecutionException ex) {
435 <            unexpectedException();
525 <        }
526 <        catch (InterruptedException ex) {
527 <            unexpectedException();
433 >            assertFalse(future.isCancelled());
434 >        } finally {
435 >            joinPool(e);
436          }
437      }
438  
439      /**
440       * Completed submit(runnable, result) returns result
441       */
442 <    public void testSubmitRunnable2() {
442 >    public void testSubmitRunnable2() throws Throwable {
443 >        ExecutorService e = new ForkJoinPool(1);
444          try {
536            ExecutorService e = new ForkJoinPool(1);
445              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
446 <            String result = future.get();
447 <            assertSame(TEST_STRING, result);
448 <        }
449 <        catch (ExecutionException ex) {
450 <            unexpectedException();
543 <        }
544 <        catch (InterruptedException ex) {
545 <            unexpectedException();
446 >            assertSame(TEST_STRING, future.get());
447 >            assertTrue(future.isDone());
448 >            assertFalse(future.isCancelled());
449 >        } finally {
450 >            joinPool(e);
451          }
452      }
453  
549
454      /**
455 <     * A submitted privileged action to completion
455 >     * A submitted privileged action runs to completion
456       */
457 <    public void testSubmitPrivilegedAction() {
458 <        Policy savedPolicy = null;
459 <        try {
460 <            savedPolicy = Policy.getPolicy();
461 <            AdjustablePolicy policy = new AdjustablePolicy();
558 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
559 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
560 <            Policy.setPolicy(policy);
561 <        } catch (AccessControlException ok) {
562 <            return;
563 <        }
564 <        try {
565 <            ExecutorService e = new ForkJoinPool(1);
566 <            Future future = e.submit(Executors.callable(new PrivilegedAction() {
457 >    public void testSubmitPrivilegedAction() throws Exception {
458 >        Runnable r = new CheckedRunnable() {
459 >            public void realRun() throws Exception {
460 >                ExecutorService e = new ForkJoinPool(1);
461 >                Future future = e.submit(Executors.callable(new PrivilegedAction() {
462                      public Object run() {
463                          return TEST_STRING;
464                      }}));
465  
466 <            Object result = future.get();
467 <            assertSame(TEST_STRING, result);
468 <        }
469 <        catch (ExecutionException ex) {
470 <            unexpectedException();
576 <        }
577 <        catch (InterruptedException ex) {
578 <            unexpectedException();
579 <        }
580 <        finally {
581 <            try {
582 <                Policy.setPolicy(savedPolicy);
583 <            } catch (AccessControlException ok) {
584 <                return;
585 <            }
586 <        }
466 >                assertSame(TEST_STRING, future.get());
467 >            }};
468 >
469 >        runWithPermissions(r,
470 >                           new RuntimePermission("modifyThread"));
471      }
472  
473      /**
474 <     * A submitted a privileged exception action runs to completion
474 >     * A submitted privileged exception action runs to completion
475       */
476 <    public void testSubmitPrivilegedExceptionAction() {
477 <        Policy savedPolicy = null;
478 <        try {
479 <            savedPolicy = Policy.getPolicy();
480 <            AdjustablePolicy policy = new AdjustablePolicy();
597 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
598 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
599 <            Policy.setPolicy(policy);
600 <        } catch (AccessControlException ok) {
601 <            return;
602 <        }
603 <
604 <        try {
605 <            ExecutorService e = new ForkJoinPool(1);
606 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
476 >    public void testSubmitPrivilegedExceptionAction() throws Exception {
477 >        Runnable r = new CheckedRunnable() {
478 >            public void realRun() throws Exception {
479 >                ExecutorService e = new ForkJoinPool(1);
480 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
481                      public Object run() {
482                          return TEST_STRING;
483                      }}));
484  
485 <            Object result = future.get();
486 <            assertSame(TEST_STRING, result);
487 <        }
488 <        catch (ExecutionException ex) {
615 <            unexpectedException();
616 <        }
617 <        catch (InterruptedException ex) {
618 <            unexpectedException();
619 <        }
620 <        finally {
621 <            Policy.setPolicy(savedPolicy);
622 <        }
485 >                assertSame(TEST_STRING, future.get());
486 >            }};
487 >
488 >        runWithPermissions(r, new RuntimePermission("modifyThread"));
489      }
490  
491      /**
492       * A submitted failed privileged exception action reports exception
493       */
494 <    public void testSubmitFailedPrivilegedExceptionAction() {
495 <        Policy savedPolicy = null;
496 <        try {
497 <            savedPolicy = Policy.getPolicy();
498 <            AdjustablePolicy policy = new AdjustablePolicy();
633 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
634 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
635 <            Policy.setPolicy(policy);
636 <        } catch (AccessControlException ok) {
637 <            return;
638 <        }
639 <
640 <
641 <        try {
642 <            ExecutorService e = new ForkJoinPool(1);
643 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
494 >    public void testSubmitFailedPrivilegedExceptionAction() throws Exception {
495 >        Runnable r = new CheckedRunnable() {
496 >            public void realRun() throws Exception {
497 >                ExecutorService e = new ForkJoinPool(1);
498 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
499                      public Object run() throws Exception {
500                          throw new IndexOutOfBoundsException();
501                      }}));
502  
503 <            Object result = future.get();
504 <            shouldThrow();
505 <        }
506 <        catch (ExecutionException success) {
507 <        } catch (CancellationException success) {
508 <        } catch (InterruptedException ex) {
509 <            unexpectedException();
510 <        }
656 <        finally {
657 <            Policy.setPolicy(savedPolicy);
658 <        }
503 >                try {
504 >                    future.get();
505 >                    shouldThrow();
506 >                } catch (ExecutionException success) {
507 >                    assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
508 >                }}};
509 >
510 >        runWithPermissions(r, new RuntimePermission("modifyThread"));
511      }
512  
513      /**
514 <     * execute(null runnable) throws NPE
514 >     * execute(null runnable) throws NullPointerException
515       */
516      public void testExecuteNullRunnable() {
517 +        ExecutorService e = new ForkJoinPool(1);
518          try {
519 <            ExecutorService e = new ForkJoinPool(1);
667 <            TrackedShortRunnable task = null;
668 <            Future<?> future = e.submit(task);
519 >            Future<?> future = e.submit((Runnable) null);
520              shouldThrow();
521 <        }
522 <        catch (NullPointerException success) {
523 <        }
673 <        catch (Exception ex) {
674 <            unexpectedException();
521 >        } catch (NullPointerException success) {
522 >        } finally {
523 >            joinPool(e);
524          }
525      }
526  
678
527      /**
528 <     * submit(null callable) throws NPE
528 >     * submit(null callable) throws NullPointerException
529       */
530      public void testSubmitNullCallable() {
531 +        ExecutorService e = new ForkJoinPool(1);
532          try {
533 <            ExecutorService e = new ForkJoinPool(1);
685 <            StringTask t = null;
686 <            Future<String> future = e.submit(t);
533 >            Future<String> future = e.submit((Callable) null);
534              shouldThrow();
535 <        }
536 <        catch (NullPointerException success) {
537 <        }
691 <        catch (Exception ex) {
692 <            unexpectedException();
535 >        } catch (NullPointerException success) {
536 >        } finally {
537 >            joinPool(e);
538          }
539      }
540  
696
541      /**
542 <     * Blocking on submit(callable) throws InterruptedException if
699 <     * caller interrupted.
542 >     * submit(callable).get() throws InterruptedException if interrupted
543       */
544 <    public void testInterruptedSubmit() {
545 <        final ForkJoinPool p = new ForkJoinPool(1);
546 <        Thread t = new Thread(new Runnable() {
547 <                public void run() {
548 <                    try {
549 <                        p.submit(new Callable<Object>() {
550 <                                public Object call() {
551 <                                    try {
552 <                                        Thread.sleep(MEDIUM_DELAY_MS);
553 <                                        shouldThrow();
554 <                                    } catch (InterruptedException e) {
555 <                                    }
556 <                                    return null;
557 <                                }
558 <                            }).get();
559 <                    } catch (InterruptedException success) {
717 <                    } catch (Exception e) {
718 <                        unexpectedException();
719 <                    }
720 <
721 <                }
722 <            });
723 <        try {
544 >    public void testInterruptedSubmit() throws InterruptedException {
545 >        final CountDownLatch submitted    = new CountDownLatch(1);
546 >        final CountDownLatch quittingTime = new CountDownLatch(1);
547 >        final ExecutorService p = new ForkJoinPool(1);
548 >        final Callable<Void> awaiter = new CheckedCallable<Void>() {
549 >            public Void realCall() throws InterruptedException {
550 >                assertTrue(quittingTime.await(MEDIUM_DELAY_MS, MILLISECONDS));
551 >                return null;
552 >            }};
553 >        try {
554 >            Thread t = new Thread(new CheckedInterruptedRunnable() {
555 >                public void realRun() throws Exception {
556 >                    Future<Void> future = p.submit(awaiter);
557 >                    submitted.countDown();
558 >                    future.get();
559 >                }});
560              t.start();
561 <            Thread.sleep(SHORT_DELAY_MS);
561 >            assertTrue(submitted.await(MEDIUM_DELAY_MS, MILLISECONDS));
562              t.interrupt();
563 <        } catch (Exception e) {
564 <            unexpectedException();
563 >            t.join();
564 >        } finally {
565 >            quittingTime.countDown();
566 >            joinPool(p);
567          }
730        joinPool(p);
568      }
569  
570      /**
571       * get of submit(callable) throws ExecutionException if callable
572       * throws exception
573       */
574 <    public void testSubmitEE() {
574 >    public void testSubmitEE() throws Throwable {
575          ForkJoinPool p = new ForkJoinPool(1);
739
576          try {
577 <            Callable c = new Callable() {
578 <                    public Object call() {
579 <                        int i = 5/0;
580 <                        return Boolean.TRUE;
581 <                    }
746 <                };
747 <
748 <            for (int i = 0; i < 5; i++) {
749 <                p.submit(c).get();
750 <            }
751 <
577 >            p.submit(new Callable() {
578 >                public Object call() {
579 >                    int i = 5/0;
580 >                    return Boolean.TRUE;
581 >                }}).get();
582              shouldThrow();
583          } catch (ExecutionException success) {
584 <        } catch (CancellationException success) {
585 <        } catch (Exception e) {
586 <            unexpectedException();
584 >            assertTrue(success.getCause() instanceof ArithmeticException);
585 >        } finally {
586 >            joinPool(p);
587          }
758        joinPool(p);
588      }
589  
590      /**
591 <     * invokeAny(null) throws NPE
591 >     * invokeAny(null) throws NullPointerException
592       */
593 <    public void testInvokeAny1() {
593 >    public void testInvokeAny1() throws Throwable {
594          ExecutorService e = new ForkJoinPool(1);
595          try {
596              e.invokeAny(null);
597 +            shouldThrow();
598          } catch (NullPointerException success) {
769        } catch (Exception ex) {
770            unexpectedException();
599          } finally {
600              joinPool(e);
601          }
602      }
603  
604      /**
605 <     * invokeAny(empty collection) throws IAE
605 >     * invokeAny(empty collection) throws IllegalArgumentException
606       */
607 <    public void testInvokeAny2() {
607 >    public void testInvokeAny2() throws Throwable {
608          ExecutorService e = new ForkJoinPool(1);
609          try {
610              e.invokeAny(new ArrayList<Callable<String>>());
611 +            shouldThrow();
612          } catch (IllegalArgumentException success) {
784        } catch (Exception ex) {
785            unexpectedException();
613          } finally {
614              joinPool(e);
615          }
616      }
617  
618      /**
619 <     * invokeAny(c) throws NPE if c has null elements
619 >     * invokeAny(c) throws NullPointerException if c has a single null element
620       */
621 <    public void testInvokeAny3() {
621 >    public void testInvokeAny3() throws Throwable {
622          ExecutorService e = new ForkJoinPool(1);
623 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
624 +        l.add(null);
625 +        try {
626 +            e.invokeAny(l);
627 +            shouldThrow();
628 +        } catch (NullPointerException success) {
629 +        } finally {
630 +            joinPool(e);
631 +        }
632 +    }
633 +
634 +    /**
635 +     * invokeAny(c) throws NullPointerException if c has null elements
636 +     */
637 +    public void testInvokeAny4() throws Throwable {
638 +        CountDownLatch latch = new CountDownLatch(1);
639 +        ExecutorService e = new ForkJoinPool(1);
640 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
641 +        l.add(latchAwaitingStringTask(latch));
642 +        l.add(null);
643          try {
797            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
798            l.add(new StringTask());
799            l.add(null);
644              e.invokeAny(l);
645 +            shouldThrow();
646          } catch (NullPointerException success) {
802        } catch (Exception ex) {
803            ex.printStackTrace();
804            unexpectedException();
647          } finally {
648 +            latch.countDown();
649              joinPool(e);
650          }
651      }
# Line 810 | Line 653 | public class ForkJoinPoolTest extends JS
653      /**
654       * invokeAny(c) throws ExecutionException if no task in c completes
655       */
656 <    public void testInvokeAny4() {
656 >    public void testInvokeAny5() throws Throwable {
657          ExecutorService e = new ForkJoinPool(1);
658 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
659 +        l.add(new NPETask());
660          try {
816            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
817            l.add(new NPETask());
661              e.invokeAny(l);
662 +            shouldThrow();
663          } catch (ExecutionException success) {
664 <        } catch (CancellationException success) {
821 <        } catch (Exception ex) {
822 <            unexpectedException();
664 >            assertTrue(success.getCause() instanceof NullPointerException);
665          } finally {
666              joinPool(e);
667          }
# Line 828 | Line 670 | public class ForkJoinPoolTest extends JS
670      /**
671       * invokeAny(c) returns result of some task in c if at least one completes
672       */
673 <    public void testInvokeAny5() {
673 >    public void testInvokeAny6() throws Throwable {
674          ExecutorService e = new ForkJoinPool(1);
675          try {
676 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
676 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
677              l.add(new StringTask());
678              l.add(new StringTask());
679              String result = e.invokeAny(l);
680              assertSame(TEST_STRING, result);
839        } catch (ExecutionException success) {
840        } catch (CancellationException success) {
841        } catch (Exception ex) {
842            unexpectedException();
681          } finally {
682              joinPool(e);
683          }
684      }
685  
686      /**
687 <     * invokeAll(null) throws NPE
687 >     * invokeAll(null) throws NullPointerException
688       */
689 <    public void testInvokeAll1() {
689 >    public void testInvokeAll1() throws Throwable {
690          ExecutorService e = new ForkJoinPool(1);
691          try {
692              e.invokeAll(null);
693 +            shouldThrow();
694          } catch (NullPointerException success) {
856        } catch (Exception ex) {
857            unexpectedException();
695          } finally {
696              joinPool(e);
697          }
# Line 863 | Line 700 | public class ForkJoinPoolTest extends JS
700      /**
701       * invokeAll(empty collection) returns empty collection
702       */
703 <    public void testInvokeAll2() {
703 >    public void testInvokeAll2() throws InterruptedException {
704          ExecutorService e = new ForkJoinPool(1);
705          try {
706 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
706 >            List<Future<String>> r
707 >                = e.invokeAll(new ArrayList<Callable<String>>());
708              assertTrue(r.isEmpty());
871        } catch (Exception ex) {
872            unexpectedException();
709          } finally {
710              joinPool(e);
711          }
712      }
713  
714      /**
715 <     * invokeAll(c) throws NPE if c has null elements
715 >     * invokeAll(c) throws NullPointerException if c has null elements
716       */
717 <    public void testInvokeAll3() {
717 >    public void testInvokeAll3() throws InterruptedException {
718          ExecutorService e = new ForkJoinPool(1);
719 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
720 +        l.add(new StringTask());
721 +        l.add(null);
722          try {
884            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
885            l.add(new StringTask());
886            l.add(null);
723              e.invokeAll(l);
724 +            shouldThrow();
725          } catch (NullPointerException success) {
889        } catch (Exception ex) {
890            unexpectedException();
726          } finally {
727              joinPool(e);
728          }
729      }
730  
731      /**
732 <     * get of returned element of invokeAll(c) throws exception on failed task
732 >     * get of returned element of invokeAll(c) throws
733 >     * ExecutionException on failed task
734       */
735 <    public void testInvokeAll4() {
735 >    public void testInvokeAll4() throws Throwable {
736          ExecutorService e = new ForkJoinPool(1);
737 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
738 +        l.add(new NPETask());
739 +        List<Future<String>> futures = e.invokeAll(l);
740 +        assertEquals(1, futures.size());
741          try {
742 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
743 <            l.add(new NPETask());
904 <            List<Future<String>> result = e.invokeAll(l);
905 <            assertEquals(1, result.size());
906 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
907 <                it.next().get();
742 >            futures.get(0).get();
743 >            shouldThrow();
744          } catch (ExecutionException success) {
745 <        } catch (CancellationException success) {
910 <        } catch (Exception ex) {
911 <            ex.printStackTrace();
912 <            unexpectedException();
745 >            assertTrue(success.getCause() instanceof NullPointerException);
746          } finally {
747              joinPool(e);
748          }
# Line 918 | Line 751 | public class ForkJoinPoolTest extends JS
751      /**
752       * invokeAll(c) returns results of all completed tasks in c
753       */
754 <    public void testInvokeAll5() {
754 >    public void testInvokeAll5() throws Throwable {
755          ExecutorService e = new ForkJoinPool(1);
756          try {
757 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
757 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
758              l.add(new StringTask());
759              l.add(new StringTask());
760 <            List<Future<String>> result = e.invokeAll(l);
761 <            assertEquals(2, result.size());
762 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
763 <                assertSame(TEST_STRING, it.next().get());
931 <        } catch (ExecutionException success) {
932 <        } catch (CancellationException success) {
933 <        } catch (Exception ex) {
934 <            ex.printStackTrace();
935 <            unexpectedException();
760 >            List<Future<String>> futures = e.invokeAll(l);
761 >            assertEquals(2, futures.size());
762 >            for (Future<String> future : futures)
763 >                assertSame(TEST_STRING, future.get());
764          } finally {
765              joinPool(e);
766          }
767      }
768  
941
769      /**
770 <     * timed invokeAny(null) throws NPE
770 >     * timed invokeAny(null) throws NullPointerException
771       */
772 <    public void testTimedInvokeAny1() {
772 >    public void testTimedInvokeAny1() throws Throwable {
773          ExecutorService e = new ForkJoinPool(1);
774          try {
775 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
775 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
776 >            shouldThrow();
777          } catch (NullPointerException success) {
950        } catch (Exception ex) {
951            ex.printStackTrace();
952            unexpectedException();
778          } finally {
779              joinPool(e);
780          }
781      }
782  
783      /**
784 <     * timed invokeAny(null time unit) throws NPE
784 >     * timed invokeAny(null time unit) throws NullPointerException
785       */
786 <    public void testTimedInvokeAnyNullTimeUnit() {
786 >    public void testTimedInvokeAnyNullTimeUnit() throws Throwable {
787          ExecutorService e = new ForkJoinPool(1);
788 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
789 +        l.add(new StringTask());
790          try {
964            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
965            l.add(new StringTask());
791              e.invokeAny(l, MEDIUM_DELAY_MS, null);
792 +            shouldThrow();
793          } catch (NullPointerException success) {
968        } catch (Exception ex) {
969            ex.printStackTrace();
970            unexpectedException();
794          } finally {
795              joinPool(e);
796          }
797      }
798  
799      /**
800 <     * timed invokeAny(empty collection) throws IAE
800 >     * timed invokeAny(empty collection) throws IllegalArgumentException
801       */
802 <    public void testTimedInvokeAny2() {
802 >    public void testTimedInvokeAny2() throws Throwable {
803          ExecutorService e = new ForkJoinPool(1);
804          try {
805 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
805 >            e.invokeAny(new ArrayList<Callable<String>>(),
806 >                        MEDIUM_DELAY_MS, MILLISECONDS);
807 >            shouldThrow();
808          } catch (IllegalArgumentException success) {
984        } catch (Exception ex) {
985            ex.printStackTrace();
986            unexpectedException();
809          } finally {
810              joinPool(e);
811          }
812      }
813  
814      /**
815 <     * timed invokeAny(c) throws NPE if c has null elements
815 >     * timed invokeAny(c) throws NullPointerException if c has null elements
816       */
817 <    public void testTimedInvokeAny3() {
817 >    public void testTimedInvokeAny3() throws Throwable {
818 >        CountDownLatch latch = new CountDownLatch(1);
819          ExecutorService e = new ForkJoinPool(1);
820 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
821 +        l.add(latchAwaitingStringTask(latch));
822 +        l.add(null);
823          try {
824 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
825 <            l.add(new StringTask());
1000 <            l.add(null);
1001 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
824 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
825 >            shouldThrow();
826          } catch (NullPointerException success) {
1003        } catch (Exception ex) {
1004            ex.printStackTrace();
1005            unexpectedException();
827          } finally {
828 +            latch.countDown();
829              joinPool(e);
830          }
831      }
# Line 1011 | Line 833 | public class ForkJoinPoolTest extends JS
833      /**
834       * timed invokeAny(c) throws ExecutionException if no task completes
835       */
836 <    public void testTimedInvokeAny4() {
836 >    public void testTimedInvokeAny4() throws Throwable {
837          ExecutorService e = new ForkJoinPool(1);
838 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
839 +        l.add(new NPETask());
840          try {
841 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
842 <            l.add(new NPETask());
1019 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
841 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
842 >            shouldThrow();
843          } catch (ExecutionException success) {
844 <        } catch (CancellationException success) {
1022 <        } catch (Exception ex) {
1023 <            ex.printStackTrace();
1024 <            unexpectedException();
844 >            assertTrue(success.getCause() instanceof NullPointerException);
845          } finally {
846              joinPool(e);
847          }
# Line 1030 | Line 850 | public class ForkJoinPoolTest extends JS
850      /**
851       * timed invokeAny(c) returns result of some task in c
852       */
853 <    public void testTimedInvokeAny5() {
853 >    public void testTimedInvokeAny5() throws Throwable {
854          ExecutorService e = new ForkJoinPool(1);
855          try {
856 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
856 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
857              l.add(new StringTask());
858              l.add(new StringTask());
859 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
859 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
860              assertSame(TEST_STRING, result);
1041        } catch (ExecutionException success) {
1042        } catch (CancellationException success) {
1043        } catch (Exception ex) {
1044            ex.printStackTrace();
1045            unexpectedException();
861          } finally {
862              joinPool(e);
863          }
864      }
865  
866      /**
867 <     * timed invokeAll(null) throws NPE
867 >     * timed invokeAll(null) throws NullPointerException
868       */
869 <    public void testTimedInvokeAll1() {
869 >    public void testTimedInvokeAll1() throws Throwable {
870          ExecutorService e = new ForkJoinPool(1);
871          try {
872 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
872 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
873 >            shouldThrow();
874          } catch (NullPointerException success) {
1059        } catch (Exception ex) {
1060            ex.printStackTrace();
1061            unexpectedException();
875          } finally {
876              joinPool(e);
877          }
878      }
879  
880      /**
881 <     * timed invokeAll(null time unit) throws NPE
881 >     * timed invokeAll(null time unit) throws NullPointerException
882       */
883 <    public void testTimedInvokeAllNullTimeUnit() {
883 >    public void testTimedInvokeAllNullTimeUnit() throws Throwable {
884          ExecutorService e = new ForkJoinPool(1);
885 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
886 +        l.add(new StringTask());
887          try {
1073            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1074            l.add(new StringTask());
888              e.invokeAll(l, MEDIUM_DELAY_MS, null);
889 +            shouldThrow();
890          } catch (NullPointerException success) {
1077        } catch (Exception ex) {
1078            ex.printStackTrace();
1079            unexpectedException();
891          } finally {
892              joinPool(e);
893          }
# Line 1085 | Line 896 | public class ForkJoinPoolTest extends JS
896      /**
897       * timed invokeAll(empty collection) returns empty collection
898       */
899 <    public void testTimedInvokeAll2() {
899 >    public void testTimedInvokeAll2() throws InterruptedException {
900          ExecutorService e = new ForkJoinPool(1);
901          try {
902 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
902 >            List<Future<String>> r
903 >                = e.invokeAll(new ArrayList<Callable<String>>(),
904 >                              MEDIUM_DELAY_MS, MILLISECONDS);
905              assertTrue(r.isEmpty());
1093        } catch (Exception ex) {
1094            ex.printStackTrace();
1095            unexpectedException();
906          } finally {
907              joinPool(e);
908          }
909      }
910  
911      /**
912 <     * timed invokeAll(c) throws NPE if c has null elements
912 >     * timed invokeAll(c) throws NullPointerException if c has null elements
913       */
914 <    public void testTimedInvokeAll3() {
914 >    public void testTimedInvokeAll3() throws InterruptedException {
915          ExecutorService e = new ForkJoinPool(1);
916 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
917 +        l.add(new StringTask());
918 +        l.add(null);
919          try {
920 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
921 <            l.add(new StringTask());
1109 <            l.add(null);
1110 <            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
920 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
921 >            shouldThrow();
922          } catch (NullPointerException success) {
1112        } catch (Exception ex) {
1113            ex.printStackTrace();
1114            unexpectedException();
923          } finally {
924              joinPool(e);
925          }
# Line 1120 | Line 928 | public class ForkJoinPoolTest extends JS
928      /**
929       * get of returned element of invokeAll(c) throws exception on failed task
930       */
931 <    public void testTimedInvokeAll4() {
931 >    public void testTimedInvokeAll4() throws Throwable {
932          ExecutorService e = new ForkJoinPool(1);
933 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
934 +        l.add(new NPETask());
935 +        List<Future<String>> futures
936 +            = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
937 +        assertEquals(1, futures.size());
938          try {
939 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
940 <            l.add(new NPETask());
1128 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1129 <            assertEquals(1, result.size());
1130 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1131 <                it.next().get();
939 >            futures.get(0).get();
940 >            shouldThrow();
941          } catch (ExecutionException success) {
942 <        } catch (CancellationException success) {
1134 <        } catch (Exception ex) {
1135 <            ex.printStackTrace();
1136 <            unexpectedException();
942 >            assertTrue(success.getCause() instanceof NullPointerException);
943          } finally {
944              joinPool(e);
945          }
# Line 1142 | Line 948 | public class ForkJoinPoolTest extends JS
948      /**
949       * timed invokeAll(c) returns results of all completed tasks in c
950       */
951 <    public void testTimedInvokeAll5() {
951 >    public void testTimedInvokeAll5() throws Throwable {
952          ExecutorService e = new ForkJoinPool(1);
953          try {
954 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
954 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
955              l.add(new StringTask());
956              l.add(new StringTask());
957 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
958 <            assertEquals(2, result.size());
959 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
960 <                assertSame(TEST_STRING, it.next().get());
961 <        } catch (ExecutionException success) {
1156 <        } catch (CancellationException success) {
1157 <        } catch (Exception ex) {
1158 <            ex.printStackTrace();
1159 <            unexpectedException();
957 >            List<Future<String>> futures
958 >                = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
959 >            assertEquals(2, futures.size());
960 >            for (Future<String> future : futures)
961 >                assertSame(TEST_STRING, future.get());
962          } finally {
963              joinPool(e);
964          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines