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.1 by dl, Fri Jul 31 23:02:49 2009 UTC vs.
Revision 1.24 by jsr166, Mon Sep 13 15:34:42 2010 UTC

# Line 4 | Line 4
4   * http://creativecommons.org/licenses/publicdomain
5   */
6  
7
7   import junit.framework.*;
8   import java.util.*;
9 < import java.util.concurrent.*;
10 < import java.util.concurrent.locks.*;
11 < import java.security.*;
9 > import java.util.concurrent.Executors;
10 > import java.util.concurrent.ExecutorService;
11 > import java.util.concurrent.AbstractExecutorService;
12 > import java.util.concurrent.CountDownLatch;
13 > import java.util.concurrent.Callable;
14 > import java.util.concurrent.Future;
15 > import java.util.concurrent.ExecutionException;
16 > import java.util.concurrent.CancellationException;
17 > import java.util.concurrent.RejectedExecutionException;
18 > import java.util.concurrent.ForkJoinPool;
19 > import java.util.concurrent.ForkJoinTask;
20 > import java.util.concurrent.ForkJoinWorkerThread;
21 > import java.util.concurrent.RecursiveTask;
22 > import java.util.concurrent.TimeUnit;
23 > import java.util.concurrent.locks.ReentrantLock;
24 > import java.security.AccessControlException;
25 > import java.security.Policy;
26 > import java.security.PrivilegedAction;
27 > import java.security.PrivilegedExceptionAction;
28  
29 < public class ForkJoinPoolTest extends JSR166TestCase{
29 > public class ForkJoinPoolTest extends JSR166TestCase {
30      public static void main(String[] args) {
31 <        junit.textui.TestRunner.run (suite());
31 >        junit.textui.TestRunner.run(suite());
32      }
33 +
34      public static Test suite() {
35          return new TestSuite(ForkJoinPoolTest.class);
36      }
# Line 25 | Line 41 | public class ForkJoinPoolTest extends JS
41       * 1. shutdown and related methods are tested via super.joinPool.
42       *
43       * 2. newTaskFor and adapters are tested in submit/invoke tests
44 <     *
44 >     *
45       * 3. We cannot portably test monitoring methods such as
46       * getStealCount() since they rely ultimately on random task
47       * stealing that may cause tasks not to be stolen/propagated
48       * across threads, especially on uniprocessors.
49 <     *
49 >     *
50       * 4. There are no independently testable ForkJoinWorkerThread
51       * methods, but they are covered here and in task tests.
52       */
# Line 38 | Line 54 | public class ForkJoinPoolTest extends JS
54      // Some classes to test extension and factory methods
55  
56      static class MyHandler implements Thread.UncaughtExceptionHandler {
57 <        int catches = 0;
57 >        volatile int catches = 0;
58          public void uncaughtException(Thread t, Throwable e) {
59              ++catches;
60          }
# Line 47 | Line 63 | public class ForkJoinPoolTest extends JS
63      // to test handlers
64      static class FailingFJWSubclass extends ForkJoinWorkerThread {
65          public FailingFJWSubclass(ForkJoinPool p) { super(p) ; }
66 <        protected void onStart() { throw new Error(); }
66 >        protected void onStart() { super.onStart(); throw new Error(); }
67      }
68  
69 <    static class FailingThreadFactory implements ForkJoinPool.ForkJoinWorkerThreadFactory {
70 <        int calls = 0;
71 <        public ForkJoinWorkerThread newThread(ForkJoinPool p){
69 >    static class FailingThreadFactory
70 >            implements ForkJoinPool.ForkJoinWorkerThreadFactory {
71 >        volatile int calls = 0;
72 >        public ForkJoinWorkerThread newThread(ForkJoinPool p) {
73              if (++calls > 1) return null;
74              return new FailingFJWSubclass(p);
75 <        }  
75 >        }
76      }
77  
78 <    static class SubFJP extends ForkJoinPool { // to expose protected
78 >    static class SubFJP extends ForkJoinPool { // to expose protected
79          SubFJP() { super(1); }
80          public int drainTasksTo(Collection<? super ForkJoinTask<?>> c) {
81              return super.drainTasksTo(c);
# Line 83 | Line 100 | public class ForkJoinPoolTest extends JS
100      }
101  
102      // A simple recursive task for testing
103 <    static final class FibTask extends RecursiveTask<Integer> {
103 >    static final class FibTask extends RecursiveTask<Integer> {
104          final int number;
105          FibTask(int n) { number = n; }
106          public Integer compute() {
# Line 97 | Line 114 | public class ForkJoinPoolTest extends JS
114      }
115  
116      // A failing task for testing
117 <    static final class FailingTask extends ForkJoinTask<Void> {
117 >    static final class FailingTask extends ForkJoinTask<Void> {
118          public final Void getRawResult() { return null; }
119          protected final void setRawResult(Void mustBeNull) { }
120          protected final boolean exec() { throw new Error(); }
# Line 105 | Line 122 | public class ForkJoinPoolTest extends JS
122      }
123  
124      // Fib needlessly using locking to test ManagedBlockers
125 <    static final class LockingFibTask extends RecursiveTask<Integer> {
125 >    static final class LockingFibTask extends RecursiveTask<Integer> {
126          final int number;
127          final ManagedLocker locker;
128          final ReentrantLock lock;
129 <        LockingFibTask(int n, ManagedLocker locker, ReentrantLock lock) {
130 <            number = n;
129 >        LockingFibTask(int n, ManagedLocker locker, ReentrantLock lock) {
130 >            number = n;
131              this.locker = locker;
132              this.lock = lock;
133          }
# Line 119 | Line 136 | public class ForkJoinPoolTest extends JS
136              LockingFibTask f1 = null;
137              LockingFibTask f2 = null;
138              locker.block();
139 <            n = number;
139 >            n = number;
140              if (n > 1) {
141                  f1 = new LockingFibTask(n - 1, locker, lock);
142                  f2 = new LockingFibTask(n - 2, locker, lock);
# Line 134 | Line 151 | public class ForkJoinPoolTest extends JS
151          }
152      }
153  
154 <    /**
155 <     * Succesfully constructed pool reports default factory,
154 >    /**
155 >     * Successfully constructed pool reports default factory,
156       * parallelism and async mode policies, no active threads or
157       * tasks, and quiescent running state.
158       */
159      public void testDefaultInitialState() {
160 <        ForkJoinPool p = null;
160 >        ForkJoinPool p = new ForkJoinPool(1);
161          try {
162 <            p = new ForkJoinPool(1);
163 <            assertTrue(p.getFactory() == ForkJoinPool.defaultForkJoinWorkerThreadFactory);
162 >            assertTrue(p.getFactory() ==
163 >                       ForkJoinPool.defaultForkJoinWorkerThreadFactory);
164              assertTrue(p.isQuiescent());
148            assertTrue(p.getMaintainsParallelism());
165              assertFalse(p.getAsyncMode());
166              assertTrue(p.getActiveThreadCount() == 0);
167              assertTrue(p.getStealCount() == 0);
# Line 160 | Line 176 | public class ForkJoinPoolTest extends JS
176          }
177      }
178  
179 <    /**
180 <     * Constructor throws if size argument is less than zero
179 >    /**
180 >     * Constructor throws if size argument is less than zero
181       */
182      public void testConstructor1() {
183          try {
184              new ForkJoinPool(-1);
185              shouldThrow();
186 <        }
171 <        catch (IllegalArgumentException success){}
186 >        } catch (IllegalArgumentException success) {}
187      }
188  
189 <    /**
190 <     * Constructor throws if factory argument is null
189 >    /**
190 >     * Constructor throws if factory argument is null
191       */
192      public void testConstructor2() {
193          try {
194 <            new ForkJoinPool(1, null);
194 >            new ForkJoinPool(1, null, null, false);
195              shouldThrow();
196 <        }
182 <        catch (NullPointerException success){}  
196 >        } catch (NullPointerException success) {}
197      }
198  
199  
200 <    /**
201 <     * getParallelism returns size set in constructor
200 >    /**
201 >     * getParallelism returns size set in constructor
202       */
203      public void testGetParallelism() {
204 <        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;
204 >        ForkJoinPool p = new ForkJoinPool(1);
205          try {
220            p = new ForkJoinPool(1);
206              assertTrue(p.getParallelism() == 1);
222            p.setParallelism(-2);
223            shouldThrow();
224        }catch (IllegalArgumentException success){
207          } finally {
208              joinPool(p);
209          }
210      }
211  
212 <    /**
212 >    /**
213       * getPoolSize returns number of started workers.
214       */
215      public void testGetPoolSize() {
216 <        ForkJoinPool p = null;
216 >        ForkJoinPool p = new ForkJoinPool(1);
217          try {
218 <            p = new ForkJoinPool(1);
237 <            assertTrue(p.getPoolSize() == 0);
218 >            assertTrue(p.getActiveThreadCount() == 0);
219              Future<String> future = p.submit(new StringTask());
220              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());
221          } finally {
222              joinPool(p);
223          }
224      }
225  
226 <    /**
226 >    /**
227       * setUncaughtExceptionHandler changes handler for uncaught exceptions.
228       *
229       * Additionally tests: Overriding ForkJoinWorkerThread.onStart
230       * performs its defined action
231       */
232 <    public void testSetUncaughtExceptionHandler() {
233 <        ForkJoinPool p = null;
232 >    public void testSetUncaughtExceptionHandler() throws InterruptedException {
233 >        MyHandler eh = new MyHandler();
234 >        ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(), eh, false);
235          try {
236 <            p = new ForkJoinPool(1, new FailingThreadFactory());
315 <            MyHandler eh = new MyHandler();
316 <            p.setUncaughtExceptionHandler(eh);
317 <            assertEquals(eh, p.getUncaughtExceptionHandler());
236 >            assert(eh == p.getUncaughtExceptionHandler());
237              p.execute(new FailingTask());
238              Thread.sleep(MEDIUM_DELAY_MS);
239              assertTrue(eh.catches > 0);
321        } catch(InterruptedException e){
322            unexpectedException();
240          } finally {
241 +            p.shutdownNow();
242              joinPool(p);
243          }
244      }
245  
246 <    /**
329 <     * setUncaughtExceptionHandler of null removes handler
330 <     */
331 <    public void testSetUncaughtExceptionHandler2() {
332 <        ForkJoinPool p = null;
333 <        try {
334 <            p = new ForkJoinPool(1);
335 <            p.setUncaughtExceptionHandler(null);
336 <            assertNull(p.getUncaughtExceptionHandler());
337 <        } finally {
338 <            joinPool(p);
339 <        }
340 <    }
341 <
342 <
343 <    /**
246 >    /**
247       * After invoking a single task, isQuiescent is true,
248       * queues are empty, threads are not active, and
249       * construction parameters continue to hold
250       */
251 <    public void testisQuiescent() {
252 <        ForkJoinPool p = null;
251 >    public void testisQuiescent() throws InterruptedException {
252 >        ForkJoinPool p = new ForkJoinPool(2);
253          try {
351            p = new ForkJoinPool(2);
254              p.invoke(new FibTask(20));
255 <            assertTrue(p.getFactory() == ForkJoinPool.defaultForkJoinWorkerThreadFactory);
255 >            assertTrue(p.getFactory() ==
256 >                       ForkJoinPool.defaultForkJoinWorkerThreadFactory);
257              Thread.sleep(MEDIUM_DELAY_MS);
258              assertTrue(p.isQuiescent());
356            assertTrue(p.getMaintainsParallelism());
259              assertFalse(p.getAsyncMode());
260              assertTrue(p.getActiveThreadCount() == 0);
261              assertTrue(p.getQueuedTaskCount() == 0);
# Line 362 | Line 264 | public class ForkJoinPoolTest extends JS
264              assertFalse(p.isShutdown());
265              assertFalse(p.isTerminating());
266              assertFalse(p.isTerminated());
365        } catch(InterruptedException e){
366            unexpectedException();
267          } finally {
268              joinPool(p);
269          }
# Line 372 | Line 272 | public class ForkJoinPoolTest extends JS
272      /**
273       * Completed submit(ForkJoinTask) returns result
274       */
275 <    public void testSubmitForkJoinTask() {
276 <        ForkJoinPool p = null;
275 >    public void testSubmitForkJoinTask() throws Throwable {
276 >        ForkJoinPool p = new ForkJoinPool(1);
277          try {
378            p = new ForkJoinPool(1);
278              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
279              int r = f.get();
280              assertTrue(r == 21);
382        } catch (ExecutionException ex) {
383            unexpectedException();
384        } catch (InterruptedException ex) {
385            unexpectedException();
281          } finally {
282              joinPool(p);
283          }
# Line 392 | Line 287 | public class ForkJoinPoolTest extends JS
287       * A task submitted after shutdown is rejected
288       */
289      public void testSubmitAfterShutdown() {
290 <        ForkJoinPool p = null;
290 >        ForkJoinPool p = new ForkJoinPool(1);
291          try {
397            p = new ForkJoinPool(1);
292              p.shutdown();
293              assertTrue(p.isShutdown());
294              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
# Line 408 | Line 302 | public class ForkJoinPoolTest extends JS
302      /**
303       * Pool maintains parallelism when using ManagedBlocker
304       */
305 <    public void testBlockingForkJoinTask() {
306 <        ForkJoinPool p = null;
305 >    public void testBlockingForkJoinTask() throws Throwable {
306 >        ForkJoinPool p = new ForkJoinPool(4);
307          try {
414            p = new ForkJoinPool(4);
308              ReentrantLock lock = new ReentrantLock();
309              ManagedLocker locker = new ManagedLocker(lock);
310              ForkJoinTask<Integer> f = new LockingFibTask(30, locker, lock);
311              p.execute(f);
419            assertTrue(p.getPoolSize() >= 4);
312              int r = f.get();
313 <            assertTrue(r ==  832040);
422 <        } catch (ExecutionException ex) {
423 <            unexpectedException();
424 <        } catch (InterruptedException ex) {
425 <            unexpectedException();
313 >            assertTrue(r == 832040);
314          } finally {
315 <            joinPool(p);
315 >            p.shutdownNow(); // don't wait out shutdown
316          }
317      }
318  
# Line 432 | Line 320 | public class ForkJoinPoolTest extends JS
320       * pollSubmission returns unexecuted submitted task, if present
321       */
322      public void testPollSubmission() {
323 <        SubFJP p = null;
323 >        SubFJP p = new SubFJP();
324          try {
437            p = new SubFJP();
325              ForkJoinTask a = p.submit(new MediumRunnable());
326              ForkJoinTask b = p.submit(new MediumRunnable());
327              ForkJoinTask c = p.submit(new MediumRunnable());
# Line 450 | Line 337 | public class ForkJoinPoolTest extends JS
337       * drainTasksTo transfers unexecuted submitted tasks, if present
338       */
339      public void testDrainTasksTo() {
340 <        SubFJP p = null;
340 >        SubFJP p = new SubFJP();
341          try {
455            p = new SubFJP();
342              ForkJoinTask a = p.submit(new MediumRunnable());
343              ForkJoinTask b = p.submit(new MediumRunnable());
344              ForkJoinTask c = p.submit(new MediumRunnable());
# Line 468 | Line 354 | public class ForkJoinPoolTest extends JS
354          }
355      }
356  
357 <    
357 >
358      // FJ Versions of AbstractExecutorService tests
359  
360      /**
361       * execute(runnable) runs it to completion
362       */
363 <    public void testExecuteRunnable() {
363 >    public void testExecuteRunnable() throws Throwable {
364 >        ExecutorService e = new ForkJoinPool(1);
365          try {
479            ExecutorService e = new ForkJoinPool(1);
366              TrackedShortRunnable task = new TrackedShortRunnable();
367              assertFalse(task.done);
368              Future<?> future = e.submit(task);
369              future.get();
370              assertTrue(task.done);
371 <        }
372 <        catch (ExecutionException ex) {
487 <            unexpectedException();
488 <        }
489 <        catch (InterruptedException ex) {
490 <            unexpectedException();
371 >        } finally {
372 >            joinPool(e);
373          }
374      }
375  
# Line 495 | Line 377 | public class ForkJoinPoolTest extends JS
377      /**
378       * Completed submit(callable) returns result
379       */
380 <    public void testSubmitCallable() {
380 >    public void testSubmitCallable() throws Throwable {
381 >        ExecutorService e = new ForkJoinPool(1);
382          try {
500            ExecutorService e = new ForkJoinPool(1);
383              Future<String> future = e.submit(new StringTask());
384              String result = future.get();
385              assertSame(TEST_STRING, result);
386 <        }
387 <        catch (ExecutionException ex) {
506 <            unexpectedException();
507 <        }
508 <        catch (InterruptedException ex) {
509 <            unexpectedException();
386 >        } finally {
387 >            joinPool(e);
388          }
389      }
390  
391      /**
392       * Completed submit(runnable) returns successfully
393       */
394 <    public void testSubmitRunnable() {
394 >    public void testSubmitRunnable() throws Throwable {
395 >        ExecutorService e = new ForkJoinPool(1);
396          try {
518            ExecutorService e = new ForkJoinPool(1);
397              Future<?> future = e.submit(new NoOpRunnable());
398              future.get();
399              assertTrue(future.isDone());
400 <        }
401 <        catch (ExecutionException ex) {
524 <            unexpectedException();
525 <        }
526 <        catch (InterruptedException ex) {
527 <            unexpectedException();
400 >        } finally {
401 >            joinPool(e);
402          }
403      }
404  
405      /**
406       * Completed submit(runnable, result) returns result
407       */
408 <    public void testSubmitRunnable2() {
408 >    public void testSubmitRunnable2() throws Throwable {
409 >        ExecutorService e = new ForkJoinPool(1);
410          try {
536            ExecutorService e = new ForkJoinPool(1);
411              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
412              String result = future.get();
413              assertSame(TEST_STRING, result);
414 <        }
415 <        catch (ExecutionException ex) {
542 <            unexpectedException();
543 <        }
544 <        catch (InterruptedException ex) {
545 <            unexpectedException();
414 >        } finally {
415 >            joinPool(e);
416          }
417      }
418  
# Line 550 | Line 420 | public class ForkJoinPoolTest extends JS
420      /**
421       * A submitted privileged action to completion
422       */
423 <    public void testSubmitPrivilegedAction() {
423 >    public void testSubmitPrivilegedAction() throws Throwable {
424          Policy savedPolicy = null;
425          try {
426              savedPolicy = Policy.getPolicy();
# Line 558 | Line 428 | public class ForkJoinPoolTest extends JS
428              policy.addPermission(new RuntimePermission("getContextClassLoader"));
429              policy.addPermission(new RuntimePermission("setContextClassLoader"));
430              Policy.setPolicy(policy);
431 <        } catch(AccessControlException ok) {
431 >        } catch (AccessControlException ok) {
432              return;
433          }
434 +
435          try {
436              ExecutorService e = new ForkJoinPool(1);
437 <            Future future = e.submit(Executors.callable(new PrivilegedAction() {
437 >            try {
438 >                Future future = e.submit(Executors.callable(new PrivilegedAction() {
439                      public Object run() {
440                          return TEST_STRING;
441                      }}));
442  
443 <            Object result = future.get();
444 <            assertSame(TEST_STRING, result);
445 <        }
446 <        catch (ExecutionException ex) {
575 <            unexpectedException();
576 <        }
577 <        catch (InterruptedException ex) {
578 <            unexpectedException();
579 <        }
580 <        finally {
581 <            try {
582 <                Policy.setPolicy(savedPolicy);
583 <            } catch(AccessControlException ok) {
584 <                return;
443 >                Object result = future.get();
444 >                assertSame(TEST_STRING, result);
445 >            } finally {
446 >                joinPool(e);
447              }
448 +        } finally {
449 +            Policy.setPolicy(savedPolicy);
450          }
451      }
452  
453      /**
454       * A submitted a privileged exception action runs to completion
455       */
456 <    public void testSubmitPrivilegedExceptionAction() {
456 >    public void testSubmitPrivilegedExceptionAction() throws Throwable {
457          Policy savedPolicy = null;
458          try {
459              savedPolicy = Policy.getPolicy();
# Line 597 | Line 461 | public class ForkJoinPoolTest extends JS
461              policy.addPermission(new RuntimePermission("getContextClassLoader"));
462              policy.addPermission(new RuntimePermission("setContextClassLoader"));
463              Policy.setPolicy(policy);
464 <        } catch(AccessControlException ok) {
464 >        } catch (AccessControlException ok) {
465              return;
466          }
467  
468          try {
469              ExecutorService e = new ForkJoinPool(1);
470 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
470 >            try {
471 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
472                      public Object run() {
473                          return TEST_STRING;
474                      }}));
475  
476 <            Object result = future.get();
477 <            assertSame(TEST_STRING, result);
478 <        }
479 <        catch (ExecutionException ex) {
480 <            unexpectedException();
481 <        }
617 <        catch (InterruptedException ex) {
618 <            unexpectedException();
619 <        }
620 <        finally {
476 >                Object result = future.get();
477 >                assertSame(TEST_STRING, result);
478 >            } finally {
479 >                joinPool(e);
480 >            }
481 >        } finally {
482              Policy.setPolicy(savedPolicy);
483          }
484      }
# Line 625 | Line 486 | public class ForkJoinPoolTest extends JS
486      /**
487       * A submitted failed privileged exception action reports exception
488       */
489 <    public void testSubmitFailedPrivilegedExceptionAction() {
489 >    public void testSubmitFailedPrivilegedExceptionAction() throws Throwable {
490          Policy savedPolicy = null;
491          try {
492              savedPolicy = Policy.getPolicy();
# Line 633 | Line 494 | public class ForkJoinPoolTest extends JS
494              policy.addPermission(new RuntimePermission("getContextClassLoader"));
495              policy.addPermission(new RuntimePermission("setContextClassLoader"));
496              Policy.setPolicy(policy);
497 <        } catch(AccessControlException ok) {
497 >        } catch (AccessControlException ok) {
498              return;
499          }
500  
640
501          try {
502              ExecutorService e = new ForkJoinPool(1);
503 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
503 >            try {
504 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
505                      public Object run() throws Exception {
506                          throw new IndexOutOfBoundsException();
507                      }}));
508  
509 <            Object result = future.get();
510 <            shouldThrow();
511 <        }
512 <        catch (ExecutionException success) {
513 <        } catch (CancellationException success) {
514 <        } catch (InterruptedException ex) {
515 <            unexpectedException();
516 <        }
656 <        finally {
509 >                Object result = future.get();
510 >                shouldThrow();
511 >            } catch (ExecutionException success) {
512 >                assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
513 >            } finally {
514 >                joinPool(e);
515 >            }
516 >        } finally {
517              Policy.setPolicy(savedPolicy);
518          }
519      }
520  
521      /**
522 <     * execute(null runnable) throws NPE
522 >     * execute(null runnable) throws NullPointerException
523       */
524      public void testExecuteNullRunnable() {
525 +        ExecutorService e = new ForkJoinPool(1);
526          try {
666            ExecutorService e = new ForkJoinPool(1);
527              TrackedShortRunnable task = null;
528              Future<?> future = e.submit(task);
529              shouldThrow();
530 <        }
531 <        catch (NullPointerException success) {
532 <        }
673 <        catch (Exception ex) {
674 <            unexpectedException();
530 >        } catch (NullPointerException success) {
531 >        } finally {
532 >            joinPool(e);
533          }
534      }
535  
536  
537      /**
538 <     * submit(null callable) throws NPE
538 >     * submit(null callable) throws NullPointerException
539       */
540      public void testSubmitNullCallable() {
541 +        ExecutorService e = new ForkJoinPool(1);
542          try {
684            ExecutorService e = new ForkJoinPool(1);
543              StringTask t = null;
544              Future<String> future = e.submit(t);
545              shouldThrow();
546 <        }
547 <        catch (NullPointerException success) {
548 <        }
691 <        catch (Exception ex) {
692 <            unexpectedException();
546 >        } catch (NullPointerException success) {
547 >        } finally {
548 >            joinPool(e);
549          }
550      }
551  
552  
553      /**
554 <     *  Blocking on submit(callable) throws InterruptedException if
555 <     *  caller interrupted.
554 >     * Blocking on submit(callable) throws InterruptedException if
555 >     * caller interrupted.
556       */
557 <    public void testInterruptedSubmit() {
557 >    public void testInterruptedSubmit() throws InterruptedException {
558          final ForkJoinPool p = new ForkJoinPool(1);
559 <        Thread t = new Thread(new Runnable() {
560 <                public void run() {
561 <                    try {
562 <                        p.submit(new Callable<Object>() {
563 <                                public Object call() {
564 <                                    try {
565 <                                        Thread.sleep(MEDIUM_DELAY_MS);
566 <                                        shouldThrow();
567 <                                    } catch(InterruptedException e){
568 <                                    }
569 <                                    return null;
570 <                                }
571 <                            }).get();
572 <                    } catch(InterruptedException success){
573 <                    } catch(Exception e) {
574 <                        unexpectedException();
575 <                    }
576 <
721 <                }
722 <            });
723 <        try {
724 <            t.start();
725 <            Thread.sleep(SHORT_DELAY_MS);
726 <            t.interrupt();
727 <        } catch(Exception e){
728 <            unexpectedException();
729 <        }
559 >
560 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
561 >            public void realRun() throws Throwable {
562 >                p.submit(new CheckedCallable<Object>() {
563 >                    public Object realCall() throws Throwable {
564 >                        try {
565 >                            Thread.sleep(MEDIUM_DELAY_MS);
566 >                        } catch (InterruptedException ok) {
567 >                        }
568 >                        return null;
569 >                    }}).get();
570 >            }});
571 >
572 >        t.start();
573 >        Thread.sleep(SHORT_DELAY_MS);
574 >        t.interrupt();
575 >        t.join();
576 >        p.shutdownNow();
577          joinPool(p);
578      }
579  
580      /**
581 <     *  get of submit(callable) throws ExecutionException if callable
582 <     *  throws exception
581 >     * get of submit(callable) throws ExecutionException if callable
582 >     * throws exception
583       */
584 <    public void testSubmitEE() {
584 >    public void testSubmitEE() throws Throwable {
585          ForkJoinPool p = new ForkJoinPool(1);
739
586          try {
587 <            Callable c = new Callable() {
588 <                    public Object call() {
589 <                        int i = 5/0;
590 <                        return Boolean.TRUE;
591 <                    }
746 <                };
747 <
748 <            for(int i =0; i < 5; i++){
749 <                p.submit(c).get();
750 <            }
751 <
587 >            p.submit(new Callable() {
588 >                public Object call() {
589 >                    int i = 5/0;
590 >                    return Boolean.TRUE;
591 >                }}).get();
592              shouldThrow();
593 +        } catch (ExecutionException success) {
594 +            assertTrue(success.getCause() instanceof ArithmeticException);
595 +        } finally {
596 +            joinPool(p);
597          }
754        catch(ExecutionException success){
755        } catch (CancellationException success) {
756        } catch(Exception e) {
757            unexpectedException();
758        }
759        joinPool(p);
598      }
599  
600      /**
601 <     * invokeAny(null) throws NPE
601 >     * invokeAny(null) throws NullPointerException
602       */
603 <    public void testInvokeAny1() {
603 >    public void testInvokeAny1() throws Throwable {
604          ExecutorService e = new ForkJoinPool(1);
605          try {
606              e.invokeAny(null);
607 +            shouldThrow();
608          } catch (NullPointerException success) {
770        } catch(Exception ex) {
771            unexpectedException();
609          } finally {
610              joinPool(e);
611          }
612      }
613  
614      /**
615 <     * invokeAny(empty collection) throws IAE
615 >     * invokeAny(empty collection) throws IllegalArgumentException
616       */
617 <    public void testInvokeAny2() {
617 >    public void testInvokeAny2() throws Throwable {
618          ExecutorService e = new ForkJoinPool(1);
619          try {
620              e.invokeAny(new ArrayList<Callable<String>>());
621 +            shouldThrow();
622          } catch (IllegalArgumentException success) {
785        } catch(Exception ex) {
786            unexpectedException();
623          } finally {
624              joinPool(e);
625          }
626      }
627  
628      /**
629 <     * invokeAny(c) throws NPE if c has null elements
629 >     * invokeAny(c) throws NullPointerException if c has a single null element
630       */
631 <    public void testInvokeAny3() {
631 >    public void testInvokeAny3() throws Throwable {
632          ExecutorService e = new ForkJoinPool(1);
633 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
634 +        l.add(null);
635          try {
798            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
799            l.add(new StringTask());
800            l.add(null);
636              e.invokeAny(l);
637 +            shouldThrow();
638          } catch (NullPointerException success) {
803        } catch(Exception ex) {
804            ex.printStackTrace();
805            unexpectedException();
639          } finally {
640              joinPool(e);
641          }
642      }
643  
644      /**
645 +     * invokeAny(c) throws NullPointerException if c has null elements
646 +     */
647 +    public void testInvokeAny4() throws Throwable {
648 +        CountDownLatch latch = new CountDownLatch(1);
649 +        ExecutorService e = new ForkJoinPool(1);
650 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
651 +        l.add(latchAwaitingStringTask(latch));
652 +        l.add(null);
653 +        try {
654 +            e.invokeAny(l);
655 +            shouldThrow();
656 +        } catch (NullPointerException success) {
657 +        } finally {
658 +            latch.countDown();
659 +            joinPool(e);
660 +        }
661 +    }
662 +
663 +    /**
664       * invokeAny(c) throws ExecutionException if no task in c completes
665       */
666 <    public void testInvokeAny4() {
666 >    public void testInvokeAny5() throws Throwable {
667          ExecutorService e = new ForkJoinPool(1);
668 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
669 +        l.add(new NPETask());
670          try {
817            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
818            l.add(new NPETask());
671              e.invokeAny(l);
672 <        } catch(ExecutionException success) {
673 <        } catch (CancellationException success) {
674 <        } catch(Exception ex) {
823 <            unexpectedException();
672 >            shouldThrow();
673 >        } catch (ExecutionException success) {
674 >            assertTrue(success.getCause() instanceof NullPointerException);
675          } finally {
676              joinPool(e);
677          }
# Line 829 | Line 680 | public class ForkJoinPoolTest extends JS
680      /**
681       * invokeAny(c) returns result of some task in c if at least one completes
682       */
683 <    public void testInvokeAny5() {
683 >    public void testInvokeAny6() throws Throwable {
684          ExecutorService e = new ForkJoinPool(1);
685          try {
686 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
686 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
687              l.add(new StringTask());
688              l.add(new StringTask());
689              String result = e.invokeAny(l);
690              assertSame(TEST_STRING, result);
840        } catch (ExecutionException success) {
841        } catch (CancellationException success) {
842        } catch(Exception ex) {
843            unexpectedException();
691          } finally {
692              joinPool(e);
693          }
694      }
695  
696      /**
697 <     * invokeAll(null) throws NPE
697 >     * invokeAll(null) throws NullPointerException
698       */
699 <    public void testInvokeAll1() {
699 >    public void testInvokeAll1() throws Throwable {
700          ExecutorService e = new ForkJoinPool(1);
701          try {
702              e.invokeAll(null);
703 +            shouldThrow();
704          } catch (NullPointerException success) {
857        } catch(Exception ex) {
858            unexpectedException();
705          } finally {
706              joinPool(e);
707          }
# Line 864 | Line 710 | public class ForkJoinPoolTest extends JS
710      /**
711       * invokeAll(empty collection) returns empty collection
712       */
713 <    public void testInvokeAll2() {
713 >    public void testInvokeAll2() throws InterruptedException {
714          ExecutorService e = new ForkJoinPool(1);
715          try {
716 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
716 >            List<Future<String>> r
717 >                = e.invokeAll(new ArrayList<Callable<String>>());
718              assertTrue(r.isEmpty());
872        } catch(Exception ex) {
873            unexpectedException();
719          } finally {
720              joinPool(e);
721          }
722      }
723  
724      /**
725 <     * invokeAll(c) throws NPE if c has null elements
725 >     * invokeAll(c) throws NullPointerException if c has null elements
726       */
727 <    public void testInvokeAll3() {
727 >    public void testInvokeAll3() throws InterruptedException {
728          ExecutorService e = new ForkJoinPool(1);
729 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
730 +        l.add(new StringTask());
731 +        l.add(null);
732          try {
885            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
886            l.add(new StringTask());
887            l.add(null);
733              e.invokeAll(l);
734 +            shouldThrow();
735          } catch (NullPointerException success) {
890        } catch(Exception ex) {
891            unexpectedException();
736          } finally {
737              joinPool(e);
738          }
739      }
740  
741      /**
742 <     * get of returned element of invokeAll(c) throws exception on failed task
742 >     * get of returned element of invokeAll(c) throws
743 >     * ExecutionException on failed task
744       */
745 <    public void testInvokeAll4() {
745 >    public void testInvokeAll4() throws Throwable {
746          ExecutorService e = new ForkJoinPool(1);
747 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
748 +        l.add(new NPETask());
749 +        List<Future<String>> futures = e.invokeAll(l);
750 +        assertEquals(1, futures.size());
751          try {
752 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
753 <            l.add(new NPETask());
754 <            List<Future<String>> result = e.invokeAll(l);
755 <            assertEquals(1, result.size());
907 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
908 <                it.next().get();
909 <        } catch(ExecutionException success) {
910 <        } catch (CancellationException success) {
911 <        } catch(Exception ex) {
912 <            ex.printStackTrace();
913 <            unexpectedException();
752 >            futures.get(0).get();
753 >            shouldThrow();
754 >        } catch (ExecutionException success) {
755 >            assertTrue(success.getCause() instanceof NullPointerException);
756          } finally {
757              joinPool(e);
758          }
# Line 919 | Line 761 | public class ForkJoinPoolTest extends JS
761      /**
762       * invokeAll(c) returns results of all completed tasks in c
763       */
764 <    public void testInvokeAll5() {
764 >    public void testInvokeAll5() throws Throwable {
765          ExecutorService e = new ForkJoinPool(1);
766          try {
767 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
767 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
768              l.add(new StringTask());
769              l.add(new StringTask());
770 <            List<Future<String>> result = e.invokeAll(l);
771 <            assertEquals(2, result.size());
772 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
773 <                assertSame(TEST_STRING, it.next().get());
932 <        } catch (ExecutionException success) {
933 <        } catch (CancellationException success) {
934 <        } catch(Exception ex) {
935 <            ex.printStackTrace();
936 <            unexpectedException();
770 >            List<Future<String>> futures = e.invokeAll(l);
771 >            assertEquals(2, futures.size());
772 >            for (Future<String> future : futures)
773 >                assertSame(TEST_STRING, future.get());
774          } finally {
775              joinPool(e);
776          }
# Line 941 | Line 778 | public class ForkJoinPoolTest extends JS
778  
779  
780      /**
781 <     * timed invokeAny(null) throws NPE
781 >     * timed invokeAny(null) throws NullPointerException
782       */
783 <    public void testTimedInvokeAny1() {
783 >    public void testTimedInvokeAny1() throws Throwable {
784          ExecutorService e = new ForkJoinPool(1);
785          try {
786              e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
787 +            shouldThrow();
788          } catch (NullPointerException success) {
951        } catch(Exception ex) {
952            ex.printStackTrace();
953            unexpectedException();
789          } finally {
790              joinPool(e);
791          }
792      }
793  
794      /**
795 <     * timed invokeAny(null time unit) throws NPE
795 >     * timed invokeAny(null time unit) throws NullPointerException
796       */
797 <    public void testTimedInvokeAnyNullTimeUnit() {
797 >    public void testTimedInvokeAnyNullTimeUnit() throws Throwable {
798          ExecutorService e = new ForkJoinPool(1);
799 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
800 +        l.add(new StringTask());
801          try {
965            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
966            l.add(new StringTask());
802              e.invokeAny(l, MEDIUM_DELAY_MS, null);
803 +            shouldThrow();
804          } catch (NullPointerException success) {
969        } catch(Exception ex) {
970            ex.printStackTrace();
971            unexpectedException();
805          } finally {
806              joinPool(e);
807          }
808      }
809  
810      /**
811 <     * timed invokeAny(empty collection) throws IAE
811 >     * timed invokeAny(empty collection) throws IllegalArgumentException
812       */
813 <    public void testTimedInvokeAny2() {
813 >    public void testTimedInvokeAny2() throws Throwable {
814          ExecutorService e = new ForkJoinPool(1);
815          try {
816 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
816 >            e.invokeAny(new ArrayList<Callable<String>>(),
817 >                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
818 >            shouldThrow();
819          } catch (IllegalArgumentException success) {
985        } catch(Exception ex) {
986            ex.printStackTrace();
987            unexpectedException();
820          } finally {
821              joinPool(e);
822          }
823      }
824  
825      /**
826 <     * timed invokeAny(c) throws NPE if c has null elements
826 >     * timed invokeAny(c) throws NullPointerException if c has null elements
827       */
828 <    public void testTimedInvokeAny3() {
828 >    public void testTimedInvokeAny3() throws Throwable {
829 >        CountDownLatch latch = new CountDownLatch(1);
830          ExecutorService e = new ForkJoinPool(1);
831 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
832 +        l.add(latchAwaitingStringTask(latch));
833 +        l.add(null);
834          try {
999            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1000            l.add(new StringTask());
1001            l.add(null);
835              e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
836 +            shouldThrow();
837          } catch (NullPointerException success) {
1004        } catch(Exception ex) {
1005            ex.printStackTrace();
1006            unexpectedException();
838          } finally {
839 +            latch.countDown();
840              joinPool(e);
841          }
842      }
# Line 1012 | Line 844 | public class ForkJoinPoolTest extends JS
844      /**
845       * timed invokeAny(c) throws ExecutionException if no task completes
846       */
847 <    public void testTimedInvokeAny4() {
847 >    public void testTimedInvokeAny4() throws Throwable {
848          ExecutorService e = new ForkJoinPool(1);
849 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
850 +        l.add(new NPETask());
851          try {
1018            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1019            l.add(new NPETask());
852              e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
853 <        } catch(ExecutionException success) {
854 <        } catch (CancellationException success) {
855 <        } catch(Exception ex) {
1024 <            ex.printStackTrace();
1025 <            unexpectedException();
853 >            shouldThrow();
854 >        } catch (ExecutionException success) {
855 >            assertTrue(success.getCause() instanceof NullPointerException);
856          } finally {
857              joinPool(e);
858          }
# Line 1031 | Line 861 | public class ForkJoinPoolTest extends JS
861      /**
862       * timed invokeAny(c) returns result of some task in c
863       */
864 <    public void testTimedInvokeAny5() {
864 >    public void testTimedInvokeAny5() throws Throwable {
865          ExecutorService e = new ForkJoinPool(1);
866          try {
867 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
867 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
868              l.add(new StringTask());
869              l.add(new StringTask());
870              String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
871              assertSame(TEST_STRING, result);
1042        } catch (ExecutionException success) {
1043        } catch (CancellationException success) {
1044        } catch(Exception ex) {
1045            ex.printStackTrace();
1046            unexpectedException();
872          } finally {
873              joinPool(e);
874          }
875      }
876  
877      /**
878 <     * timed invokeAll(null) throws NPE
878 >     * timed invokeAll(null) throws NullPointerException
879       */
880 <    public void testTimedInvokeAll1() {
880 >    public void testTimedInvokeAll1() throws Throwable {
881          ExecutorService e = new ForkJoinPool(1);
882          try {
883              e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
884 +            shouldThrow();
885          } catch (NullPointerException success) {
1060        } catch(Exception ex) {
1061            ex.printStackTrace();
1062            unexpectedException();
886          } finally {
887              joinPool(e);
888          }
889      }
890  
891      /**
892 <     * timed invokeAll(null time unit) throws NPE
892 >     * timed invokeAll(null time unit) throws NullPointerException
893       */
894 <    public void testTimedInvokeAllNullTimeUnit() {
894 >    public void testTimedInvokeAllNullTimeUnit() throws Throwable {
895          ExecutorService e = new ForkJoinPool(1);
896 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
897 +        l.add(new StringTask());
898          try {
1074            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1075            l.add(new StringTask());
899              e.invokeAll(l, MEDIUM_DELAY_MS, null);
900 +            shouldThrow();
901          } catch (NullPointerException success) {
1078        } catch(Exception ex) {
1079            ex.printStackTrace();
1080            unexpectedException();
902          } finally {
903              joinPool(e);
904          }
# Line 1086 | Line 907 | public class ForkJoinPoolTest extends JS
907      /**
908       * timed invokeAll(empty collection) returns empty collection
909       */
910 <    public void testTimedInvokeAll2() {
910 >    public void testTimedInvokeAll2() throws InterruptedException {
911          ExecutorService e = new ForkJoinPool(1);
912          try {
913 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
913 >            List<Future<String>> r
914 >                = e.invokeAll(new ArrayList<Callable<String>>(),
915 >                              MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
916              assertTrue(r.isEmpty());
1094        } catch(Exception ex) {
1095            ex.printStackTrace();
1096            unexpectedException();
917          } finally {
918              joinPool(e);
919          }
920      }
921  
922      /**
923 <     * timed invokeAll(c) throws NPE if c has null elements
923 >     * timed invokeAll(c) throws NullPointerException if c has null elements
924       */
925 <    public void testTimedInvokeAll3() {
925 >    public void testTimedInvokeAll3() throws InterruptedException {
926          ExecutorService e = new ForkJoinPool(1);
927 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
928 +        l.add(new StringTask());
929 +        l.add(null);
930          try {
1108            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1109            l.add(new StringTask());
1110            l.add(null);
931              e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
932 +            shouldThrow();
933          } catch (NullPointerException success) {
1113        } catch(Exception ex) {
1114            ex.printStackTrace();
1115            unexpectedException();
934          } finally {
935              joinPool(e);
936          }
# Line 1121 | Line 939 | public class ForkJoinPoolTest extends JS
939      /**
940       * get of returned element of invokeAll(c) throws exception on failed task
941       */
942 <    public void testTimedInvokeAll4() {
942 >    public void testTimedInvokeAll4() throws Throwable {
943          ExecutorService e = new ForkJoinPool(1);
944 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
945 +        l.add(new NPETask());
946 +        List<Future<String>> futures
947 +            = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
948 +        assertEquals(1, futures.size());
949          try {
950 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
951 <            l.add(new NPETask());
952 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
953 <            assertEquals(1, result.size());
1131 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1132 <                it.next().get();
1133 <        } catch(ExecutionException success) {
1134 <        } catch (CancellationException success) {
1135 <        } catch(Exception ex) {
1136 <            ex.printStackTrace();
1137 <            unexpectedException();
950 >            futures.get(0).get();
951 >            shouldThrow();
952 >        } catch (ExecutionException success) {
953 >            assertTrue(success.getCause() instanceof NullPointerException);
954          } finally {
955              joinPool(e);
956          }
# Line 1143 | Line 959 | public class ForkJoinPoolTest extends JS
959      /**
960       * timed invokeAll(c) returns results of all completed tasks in c
961       */
962 <    public void testTimedInvokeAll5() {
962 >    public void testTimedInvokeAll5() throws Throwable {
963          ExecutorService e = new ForkJoinPool(1);
964          try {
965 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
965 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
966              l.add(new StringTask());
967              l.add(new StringTask());
968 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
969 <            assertEquals(2, result.size());
970 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
971 <                assertSame(TEST_STRING, it.next().get());
972 <        } catch (ExecutionException success) {
1157 <        } catch (CancellationException success) {
1158 <        } catch(Exception ex) {
1159 <            ex.printStackTrace();
1160 <            unexpectedException();
968 >            List<Future<String>> futures
969 >                = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
970 >            assertEquals(2, futures.size());
971 >            for (Future<String> future : futures)
972 >                assertSame(TEST_STRING, future.get());
973          } finally {
974              joinPool(e);
975          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines