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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines