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.17 by jsr166, Tue Jan 5 02:08:37 2010 UTC vs.
Revision 1.65 by jsr166, Tue Oct 6 21:22:54 2015 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
8 import junit.framework.*;
9 import java.util.*;
10 import java.util.concurrent.*;
7   import static java.util.concurrent.TimeUnit.MILLISECONDS;
8 < import java.util.concurrent.locks.*;
9 < import java.security.*;
8 > import static java.util.concurrent.TimeUnit.NANOSECONDS;
9 >
10 > import java.security.PrivilegedAction;
11 > import java.security.PrivilegedExceptionAction;
12 > import java.util.ArrayList;
13 > import java.util.Collection;
14 > import java.util.List;
15 > import java.util.concurrent.Callable;
16 > import java.util.concurrent.CountDownLatch;
17 > import java.util.concurrent.ExecutionException;
18 > import java.util.concurrent.Executors;
19 > import java.util.concurrent.ExecutorService;
20 > import java.util.concurrent.ForkJoinPool;
21 > import java.util.concurrent.ForkJoinTask;
22 > import java.util.concurrent.ForkJoinWorkerThread;
23 > import java.util.concurrent.Future;
24 > import java.util.concurrent.RecursiveTask;
25 > import java.util.concurrent.RejectedExecutionException;
26 > import java.util.concurrent.atomic.AtomicBoolean;
27 > import java.util.concurrent.locks.ReentrantLock;
28 >
29 > import junit.framework.AssertionFailedError;
30 > import junit.framework.Test;
31 > import junit.framework.TestSuite;
32  
33   public class ForkJoinPoolTest extends JSR166TestCase {
34      public static void main(String[] args) {
35 <        junit.textui.TestRunner.run (suite());
35 >        main(suite(), args);
36      }
37 +
38      public static Test suite() {
39          return new TestSuite(ForkJoinPoolTest.class);
40      }
41  
42 <    /**
42 >    /*
43       * Testing coverage notes:
44       *
45       * 1. shutdown and related methods are tested via super.joinPool.
# Line 39 | Line 58 | public class ForkJoinPoolTest extends JS
58      // Some classes to test extension and factory methods
59  
60      static class MyHandler implements Thread.UncaughtExceptionHandler {
61 <        int catches = 0;
61 >        volatile int catches = 0;
62          public void uncaughtException(Thread t, Throwable e) {
63              ++catches;
64          }
# Line 48 | Line 67 | public class ForkJoinPoolTest extends JS
67      // to test handlers
68      static class FailingFJWSubclass extends ForkJoinWorkerThread {
69          public FailingFJWSubclass(ForkJoinPool p) { super(p) ; }
70 <        protected void onStart() { throw new Error(); }
70 >        protected void onStart() { super.onStart(); throw new Error(); }
71      }
72  
73      static class FailingThreadFactory
74              implements ForkJoinPool.ForkJoinWorkerThreadFactory {
75 <        int calls = 0;
75 >        volatile int calls = 0;
76          public ForkJoinWorkerThread newThread(ForkJoinPool p) {
77              if (++calls > 1) return null;
78              return new FailingFJWSubclass(p);
# Line 88 | Line 107 | public class ForkJoinPoolTest extends JS
107      static final class FibTask extends RecursiveTask<Integer> {
108          final int number;
109          FibTask(int n) { number = n; }
110 <        public Integer compute() {
110 >        protected Integer compute() {
111              int n = number;
112              if (n <= 1)
113                  return n;
# Line 116 | Line 135 | public class ForkJoinPoolTest extends JS
135              this.locker = locker;
136              this.lock = lock;
137          }
138 <        public Integer compute() {
138 >        protected Integer compute() {
139              int n;
140              LockingFibTask f1 = null;
141              LockingFibTask f2 = null;
# Line 142 | Line 161 | public class ForkJoinPoolTest extends JS
161       * tasks, and quiescent running state.
162       */
163      public void testDefaultInitialState() {
164 <        ForkJoinPool p = null;
165 <        try {
166 <            p = new ForkJoinPool(1);
167 <            assertTrue(p.getFactory() ==
149 <                       ForkJoinPool.defaultForkJoinWorkerThreadFactory);
150 <            assertTrue(p.isQuiescent());
151 <            assertTrue(p.getMaintainsParallelism());
164 >        ForkJoinPool p = new ForkJoinPool(1);
165 >        try (PoolCleaner cleaner = cleaner(p)) {
166 >            assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory,
167 >                       p.getFactory());
168              assertFalse(p.getAsyncMode());
169 <            assertTrue(p.getActiveThreadCount() == 0);
170 <            assertTrue(p.getStealCount() == 0);
171 <            assertTrue(p.getQueuedTaskCount() == 0);
172 <            assertTrue(p.getQueuedSubmissionCount() == 0);
169 >            assertEquals(0, p.getActiveThreadCount());
170 >            assertEquals(0, p.getStealCount());
171 >            assertEquals(0, p.getQueuedTaskCount());
172 >            assertEquals(0, p.getQueuedSubmissionCount());
173              assertFalse(p.hasQueuedSubmissions());
174              assertFalse(p.isShutdown());
175              assertFalse(p.isTerminating());
176              assertFalse(p.isTerminated());
161        } finally {
162            joinPool(p);
177          }
178      }
179  
# Line 178 | Line 192 | public class ForkJoinPoolTest extends JS
192       */
193      public void testConstructor2() {
194          try {
195 <            new ForkJoinPool(1, null);
195 >            new ForkJoinPool(1, null, null, false);
196              shouldThrow();
197          } catch (NullPointerException success) {}
198      }
199  
186
200      /**
201       * getParallelism returns size set in constructor
202       */
203      public void testGetParallelism() {
204 <        ForkJoinPool p = null;
205 <        try {
206 <            p = new ForkJoinPool(1);
194 <            assertTrue(p.getParallelism() == 1);
195 <        } finally {
196 <            joinPool(p);
197 <        }
198 <    }
199 <
200 <    /**
201 <     * setParallelism changes reported parallelism level.
202 <     */
203 <    public void testSetParallelism() {
204 <        ForkJoinPool p = null;
205 <        try {
206 <            p = new ForkJoinPool(1);
207 <            assertTrue(p.getParallelism() == 1);
208 <            p.setParallelism(2);
209 <            assertTrue(p.getParallelism() == 2);
210 <        } finally {
211 <            joinPool(p);
212 <        }
213 <    }
214 <
215 <    /**
216 <     * setParallelism with argument <= 0 throws exception
217 <     */
218 <    public void testSetParallelism2() {
219 <        ForkJoinPool p = null;
220 <        try {
221 <            p = new ForkJoinPool(1);
222 <            assertTrue(p.getParallelism() == 1);
223 <            p.setParallelism(-2);
224 <            shouldThrow();
225 <        } catch (IllegalArgumentException success) {
226 <        } finally {
227 <            joinPool(p);
204 >        ForkJoinPool p = new ForkJoinPool(1);
205 >        try (PoolCleaner cleaner = cleaner(p)) {
206 >            assertEquals(1, p.getParallelism());
207          }
208      }
209  
# Line 232 | Line 211 | public class ForkJoinPoolTest extends JS
211       * getPoolSize returns number of started workers.
212       */
213      public void testGetPoolSize() {
214 <        ForkJoinPool p = null;
215 <        try {
216 <            p = new ForkJoinPool(1);
238 <            assertTrue(p.getPoolSize() == 0);
214 >        ForkJoinPool p = new ForkJoinPool(1);
215 >        try (PoolCleaner cleaner = cleaner(p)) {
216 >            assertEquals(0, p.getActiveThreadCount());
217              Future<String> future = p.submit(new StringTask());
218 <            assertTrue(p.getPoolSize() == 1);
241 <
242 <        } finally {
243 <            joinPool(p);
244 <        }
245 <    }
246 <
247 <    /**
248 <     * setMaximumPoolSize changes size reported by getMaximumPoolSize.
249 <     */
250 <    public void testSetMaximumPoolSize() {
251 <        ForkJoinPool p = null;
252 <        try {
253 <            p = new ForkJoinPool(1);
254 <            p.setMaximumPoolSize(2);
255 <            assertTrue(p.getMaximumPoolSize() == 2);
256 <        } finally {
257 <            joinPool(p);
218 >            assertEquals(1, p.getPoolSize());
219          }
220      }
221  
222      /**
223 <     * setMaximumPoolSize with argument <= 0 throws exception
223 >     * awaitTermination on a non-shutdown pool times out
224       */
225 <    public void testSetMaximumPoolSize2() {
226 <        ForkJoinPool p = null;
227 <        try {
228 <            p = new ForkJoinPool(1);
229 <            p.setMaximumPoolSize(-2);
230 <            shouldThrow();
231 <        } catch (IllegalArgumentException success) {
232 <        } finally {
233 <            joinPool(p);
234 <        }
235 <    }
236 <
237 <    /**
238 <     * setMaintainsParallelism changes policy reported by
239 <     * getMaintainsParallelism.
240 <     */
241 <    public void testSetMaintainsParallelism() {
242 <        ForkJoinPool p = null;
243 <        try {
244 <            p = new ForkJoinPool(1);
245 <            p.setMaintainsParallelism(false);
246 <            assertFalse(p.getMaintainsParallelism());
247 <        } finally {
287 <            joinPool(p);
288 <        }
289 <    }
290 <
291 <    /**
292 <     * setAsyncMode changes policy reported by
293 <     * getAsyncMode.
294 <     */
295 <    public void testSetAsyncMode() {
296 <        ForkJoinPool p = null;
297 <        try {
298 <            p = new ForkJoinPool(1);
299 <            p.setAsyncMode(true);
300 <            assertTrue(p.getAsyncMode());
301 <        } finally {
302 <            joinPool(p);
225 >    public void testAwaitTermination_timesOut() throws InterruptedException {
226 >        ForkJoinPool p = new ForkJoinPool(1);
227 >        try (PoolCleaner cleaner = cleaner(p)) {
228 >            assertFalse(p.isTerminated());
229 >            assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS));
230 >            assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS));
231 >            assertFalse(p.awaitTermination(-1L, NANOSECONDS));
232 >            assertFalse(p.awaitTermination(-1L, MILLISECONDS));
233 >            assertFalse(p.awaitTermination(0L, NANOSECONDS));
234 >            assertFalse(p.awaitTermination(0L, MILLISECONDS));
235 >            long timeoutNanos = 999999L;
236 >            long startTime = System.nanoTime();
237 >            assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS));
238 >            assertTrue(System.nanoTime() - startTime >= timeoutNanos);
239 >            assertFalse(p.isTerminated());
240 >            startTime = System.nanoTime();
241 >            long timeoutMillis = timeoutMillis();
242 >            assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS));
243 >            assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
244 >            assertFalse(p.isTerminated());
245 >            p.shutdown();
246 >            assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
247 >            assertTrue(p.isTerminated());
248          }
249      }
250  
# Line 310 | Line 255 | public class ForkJoinPoolTest extends JS
255       * performs its defined action
256       */
257      public void testSetUncaughtExceptionHandler() throws InterruptedException {
258 <        ForkJoinPool p = null;
259 <        try {
260 <            p = new ForkJoinPool(1, new FailingThreadFactory());
261 <            MyHandler eh = new MyHandler();
262 <            p.setUncaughtExceptionHandler(eh);
263 <            assertEquals(eh, p.getUncaughtExceptionHandler());
264 <            p.execute(new FailingTask());
265 <            Thread.sleep(MEDIUM_DELAY_MS);
266 <            assertTrue(eh.catches > 0);
267 <        } finally {
268 <            joinPool(p);
258 >        final CountDownLatch uehInvoked = new CountDownLatch(1);
259 >        final Thread.UncaughtExceptionHandler ueh =
260 >            new Thread.UncaughtExceptionHandler() {
261 >                public void uncaughtException(Thread t, Throwable e) {
262 >                    uehInvoked.countDown();
263 >                }};
264 >        ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(),
265 >                                          ueh, false);
266 >        try (PoolCleaner cleaner = cleaner(p)) {
267 >            assertSame(ueh, p.getUncaughtExceptionHandler());
268 >            try {
269 >                try {
270 >                    p.execute(new FibTask(8));
271 >                    await(uehInvoked);
272 >                } catch (RejectedExecutionException ok) {}
273 >            } finally {
274 >                p.shutdownNow(); // failure might have prevented processing task
275 >            }
276          }
277      }
278  
279      /**
280 <     * setUncaughtExceptionHandler of null removes handler
281 <     */
282 <    public void testSetUncaughtExceptionHandler2() {
283 <        ForkJoinPool p = null;
284 <        try {
285 <            p = new ForkJoinPool(1);
286 <            p.setUncaughtExceptionHandler(null);
287 <            assertNull(p.getUncaughtExceptionHandler());
288 <        } finally {
289 <            joinPool(p);
290 <        }
291 <    }
292 <
280 >     * After invoking a single task, isQuiescent eventually becomes
281 >     * true, at which time queues are empty, threads are not active,
282 >     * the task has completed successfully, and construction
283 >     * parameters continue to hold
284 >     */
285 >    public void testIsQuiescent() throws Exception {
286 >        ForkJoinPool p = new ForkJoinPool(2);
287 >        try (PoolCleaner cleaner = cleaner(p)) {
288 >            assertTrue(p.isQuiescent());
289 >            long startTime = System.nanoTime();
290 >            FibTask f = new FibTask(20);
291 >            p.invoke(f);
292 >            assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory,
293 >                       p.getFactory());
294 >            while (! p.isQuiescent()) {
295 >                if (millisElapsedSince(startTime) > LONG_DELAY_MS)
296 >                    throw new AssertionFailedError("timed out");
297 >                assertFalse(p.getAsyncMode());
298 >                assertFalse(p.isShutdown());
299 >                assertFalse(p.isTerminating());
300 >                assertFalse(p.isTerminated());
301 >                Thread.yield();
302 >            }
303  
342    /**
343     * After invoking a single task, isQuiescent is true,
344     * queues are empty, threads are not active, and
345     * construction parameters continue to hold
346     */
347    public void testisQuiescent() throws InterruptedException {
348        ForkJoinPool p = null;
349        try {
350            p = new ForkJoinPool(2);
351            p.invoke(new FibTask(20));
352            assertTrue(p.getFactory() ==
353                       ForkJoinPool.defaultForkJoinWorkerThreadFactory);
354            Thread.sleep(MEDIUM_DELAY_MS);
304              assertTrue(p.isQuiescent());
356            assertTrue(p.getMaintainsParallelism());
305              assertFalse(p.getAsyncMode());
306 <            assertTrue(p.getActiveThreadCount() == 0);
307 <            assertTrue(p.getQueuedTaskCount() == 0);
308 <            assertTrue(p.getQueuedSubmissionCount() == 0);
306 >            assertEquals(0, p.getActiveThreadCount());
307 >            assertEquals(0, p.getQueuedTaskCount());
308 >            assertEquals(0, p.getQueuedSubmissionCount());
309              assertFalse(p.hasQueuedSubmissions());
310              assertFalse(p.isShutdown());
311              assertFalse(p.isTerminating());
312              assertFalse(p.isTerminated());
313 <        } finally {
314 <            joinPool(p);
313 >            assertTrue(f.isDone());
314 >            assertEquals(6765, (int) f.get());
315          }
316      }
317  
# Line 371 | Line 319 | public class ForkJoinPoolTest extends JS
319       * Completed submit(ForkJoinTask) returns result
320       */
321      public void testSubmitForkJoinTask() throws Throwable {
322 <        ForkJoinPool p = null;
323 <        try {
376 <            p = new ForkJoinPool(1);
322 >        ForkJoinPool p = new ForkJoinPool(1);
323 >        try (PoolCleaner cleaner = cleaner(p)) {
324              ForkJoinTask<Integer> f = p.submit(new FibTask(8));
325 <            int r = f.get();
379 <            assertTrue(r == 21);
380 <        } finally {
381 <            joinPool(p);
325 >            assertEquals(21, (int) f.get());
326          }
327      }
328  
# Line 386 | Line 330 | public class ForkJoinPoolTest extends JS
330       * A task submitted after shutdown is rejected
331       */
332      public void testSubmitAfterShutdown() {
333 <        ForkJoinPool p = null;
334 <        try {
391 <            p = new ForkJoinPool(1);
333 >        ForkJoinPool p = new ForkJoinPool(1);
334 >        try (PoolCleaner cleaner = cleaner(p)) {
335              p.shutdown();
336              assertTrue(p.isShutdown());
337 <            ForkJoinTask<Integer> f = p.submit(new FibTask(8));
338 <            shouldThrow();
339 <        } catch (RejectedExecutionException success) {
340 <        } finally {
398 <            joinPool(p);
337 >            try {
338 >                ForkJoinTask<Integer> f = p.submit(new FibTask(8));
339 >                shouldThrow();
340 >            } catch (RejectedExecutionException success) {}
341          }
342      }
343  
# Line 403 | Line 345 | public class ForkJoinPoolTest extends JS
345       * Pool maintains parallelism when using ManagedBlocker
346       */
347      public void testBlockingForkJoinTask() throws Throwable {
348 <        ForkJoinPool p = null;
348 >        ForkJoinPool p = new ForkJoinPool(4);
349          try {
408            p = new ForkJoinPool(4);
350              ReentrantLock lock = new ReentrantLock();
351              ManagedLocker locker = new ManagedLocker(lock);
352 <            ForkJoinTask<Integer> f = new LockingFibTask(30, locker, lock);
352 >            ForkJoinTask<Integer> f = new LockingFibTask(20, locker, lock);
353              p.execute(f);
354 <            assertTrue(p.getPoolSize() >= 4);
414 <            int r = f.get();
415 <            assertTrue(r == 832040);
354 >            assertEquals(6765, (int) f.get());
355          } finally {
356              p.shutdownNow(); // don't wait out shutdown
357          }
# Line 422 | Line 361 | public class ForkJoinPoolTest extends JS
361       * pollSubmission returns unexecuted submitted task, if present
362       */
363      public void testPollSubmission() {
364 <        SubFJP p = null;
365 <        try {
366 <            p = new SubFJP();
367 <            ForkJoinTask a = p.submit(new MediumRunnable());
368 <            ForkJoinTask b = p.submit(new MediumRunnable());
369 <            ForkJoinTask c = p.submit(new MediumRunnable());
364 >        final CountDownLatch done = new CountDownLatch(1);
365 >        SubFJP p = new SubFJP();
366 >        try (PoolCleaner cleaner = cleaner(p)) {
367 >            ForkJoinTask a = p.submit(awaiter(done));
368 >            ForkJoinTask b = p.submit(awaiter(done));
369 >            ForkJoinTask c = p.submit(awaiter(done));
370              ForkJoinTask r = p.pollSubmission();
371              assertTrue(r == a || r == b || r == c);
372              assertFalse(r.isDone());
373 <        } finally {
435 <            joinPool(p);
373 >            done.countDown();
374          }
375      }
376  
# Line 440 | Line 378 | public class ForkJoinPoolTest extends JS
378       * drainTasksTo transfers unexecuted submitted tasks, if present
379       */
380      public void testDrainTasksTo() {
381 <        SubFJP p = null;
382 <        try {
383 <            p = new SubFJP();
384 <            ForkJoinTask a = p.submit(new MediumRunnable());
385 <            ForkJoinTask b = p.submit(new MediumRunnable());
386 <            ForkJoinTask c = p.submit(new MediumRunnable());
381 >        final CountDownLatch done = new CountDownLatch(1);
382 >        SubFJP p = new SubFJP();
383 >        try (PoolCleaner cleaner = cleaner(p)) {
384 >            ForkJoinTask a = p.submit(awaiter(done));
385 >            ForkJoinTask b = p.submit(awaiter(done));
386 >            ForkJoinTask c = p.submit(awaiter(done));
387              ArrayList<ForkJoinTask> al = new ArrayList();
388              p.drainTasksTo(al);
389              assertTrue(al.size() > 0);
# Line 453 | Line 391 | public class ForkJoinPoolTest extends JS
391                  assertTrue(r == a || r == b || r == c);
392                  assertFalse(r.isDone());
393              }
394 <        } finally {
457 <            joinPool(p);
394 >            done.countDown();
395          }
396      }
397  
461
398      // FJ Versions of AbstractExecutorService tests
399  
400      /**
# Line 466 | Line 402 | public class ForkJoinPoolTest extends JS
402       */
403      public void testExecuteRunnable() throws Throwable {
404          ExecutorService e = new ForkJoinPool(1);
405 <        TrackedShortRunnable task = new TrackedShortRunnable();
406 <        assertFalse(task.done);
407 <        Future<?> future = e.submit(task);
408 <        future.get();
409 <        assertTrue(task.done);
405 >        try (PoolCleaner cleaner = cleaner(e)) {
406 >            final AtomicBoolean done = new AtomicBoolean(false);
407 >            Future<?> future = e.submit(new CheckedRunnable() {
408 >                public void realRun() {
409 >                    done.set(true);
410 >                }});
411 >            assertNull(future.get());
412 >            assertNull(future.get(0, MILLISECONDS));
413 >            assertTrue(done.get());
414 >            assertTrue(future.isDone());
415 >            assertFalse(future.isCancelled());
416 >        }
417      }
418  
476
419      /**
420       * Completed submit(callable) returns result
421       */
422      public void testSubmitCallable() throws Throwable {
423          ExecutorService e = new ForkJoinPool(1);
424 <        Future<String> future = e.submit(new StringTask());
425 <        String result = future.get();
426 <        assertSame(TEST_STRING, result);
424 >        try (PoolCleaner cleaner = cleaner(e)) {
425 >            Future<String> future = e.submit(new StringTask());
426 >            assertSame(TEST_STRING, future.get());
427 >            assertTrue(future.isDone());
428 >            assertFalse(future.isCancelled());
429 >        }
430      }
431  
432      /**
# Line 489 | Line 434 | public class ForkJoinPoolTest extends JS
434       */
435      public void testSubmitRunnable() throws Throwable {
436          ExecutorService e = new ForkJoinPool(1);
437 <        Future<?> future = e.submit(new NoOpRunnable());
438 <        future.get();
439 <        assertTrue(future.isDone());
437 >        try (PoolCleaner cleaner = cleaner(e)) {
438 >            Future<?> future = e.submit(new NoOpRunnable());
439 >            assertNull(future.get());
440 >            assertTrue(future.isDone());
441 >            assertFalse(future.isCancelled());
442 >        }
443      }
444  
445      /**
# Line 499 | Line 447 | public class ForkJoinPoolTest extends JS
447       */
448      public void testSubmitRunnable2() throws Throwable {
449          ExecutorService e = new ForkJoinPool(1);
450 <        Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
451 <        String result = future.get();
452 <        assertSame(TEST_STRING, result);
450 >        try (PoolCleaner cleaner = cleaner(e)) {
451 >            Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
452 >            assertSame(TEST_STRING, future.get());
453 >            assertTrue(future.isDone());
454 >            assertFalse(future.isCancelled());
455 >        }
456      }
457  
458      /**
459       * A submitted privileged action runs to completion
460       */
461 <    public void testSubmitPrivilegedAction() throws Throwable {
461 >    public void testSubmitPrivilegedAction() throws Exception {
462 >        final Callable callable = Executors.callable(new PrivilegedAction() {
463 >                public Object run() { return TEST_STRING; }});
464          Runnable r = new CheckedRunnable() {
465 <            public void realRun() throws Exception {
466 <                ExecutorService e = new ForkJoinPool(1);
467 <                Future future = e.submit(Executors.callable(new PrivilegedAction() {
468 <                    public Object run() {
469 <                        return TEST_STRING;
470 <                    }}));
471 <
519 <                Object result = future.get();
520 <                assertSame(TEST_STRING, result);
521 <            }};
465 >        public void realRun() throws Exception {
466 >            ExecutorService e = new ForkJoinPool(1);
467 >            try (PoolCleaner cleaner = cleaner(e)) {
468 >                Future future = e.submit(callable);
469 >                assertSame(TEST_STRING, future.get());
470 >            }
471 >        }};
472  
473          runWithPermissions(r, new RuntimePermission("modifyThread"));
474      }
# Line 526 | Line 476 | public class ForkJoinPoolTest extends JS
476      /**
477       * A submitted privileged exception action runs to completion
478       */
479 <    public void testSubmitPrivilegedExceptionAction() throws Throwable {
479 >    public void testSubmitPrivilegedExceptionAction() throws Exception {
480 >        final Callable callable =
481 >            Executors.callable(new PrivilegedExceptionAction() {
482 >                public Object run() { return TEST_STRING; }});
483          Runnable r = new CheckedRunnable() {
484 <            public void realRun() throws Exception {
485 <                ExecutorService e = new ForkJoinPool(1);
486 <                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
487 <                    public Object run() {
488 <                        return TEST_STRING;
489 <                    }}));
490 <
538 <                Object result = future.get();
539 <                assertSame(TEST_STRING, result);
540 <            }};
484 >        public void realRun() throws Exception {
485 >            ExecutorService e = new ForkJoinPool(1);
486 >            try (PoolCleaner cleaner = cleaner(e)) {
487 >                Future future = e.submit(callable);
488 >                assertSame(TEST_STRING, future.get());
489 >            }
490 >        }};
491  
492          runWithPermissions(r, new RuntimePermission("modifyThread"));
493      }
# Line 545 | Line 495 | public class ForkJoinPoolTest extends JS
495      /**
496       * A submitted failed privileged exception action reports exception
497       */
498 <    public void testSubmitFailedPrivilegedExceptionAction() throws Throwable {
498 >    public void testSubmitFailedPrivilegedExceptionAction() throws Exception {
499 >        final Callable callable =
500 >            Executors.callable(new PrivilegedExceptionAction() {
501 >                public Object run() { throw new IndexOutOfBoundsException(); }});
502          Runnable r = new CheckedRunnable() {
503 <            public void realRun() throws Exception {
504 <                ExecutorService e = new ForkJoinPool(1);
505 <                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
506 <                    public Object run() throws Exception {
554 <                        throw new IndexOutOfBoundsException();
555 <                    }}));
556 <
503 >        public void realRun() throws Exception {
504 >            ExecutorService e = new ForkJoinPool(1);
505 >            try (PoolCleaner cleaner = cleaner(e)) {
506 >                Future future = e.submit(callable);
507                  try {
508 <                    Object result = future.get();
508 >                    future.get();
509                      shouldThrow();
510                  } catch (ExecutionException success) {
511                      assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
512 <                }}};
512 >                }
513 >            }
514 >        }};
515  
516          runWithPermissions(r, new RuntimePermission("modifyThread"));
517      }
# Line 568 | Line 520 | public class ForkJoinPoolTest extends JS
520       * execute(null runnable) throws NullPointerException
521       */
522      public void testExecuteNullRunnable() {
523 <        try {
524 <            ExecutorService e = new ForkJoinPool(1);
525 <            TrackedShortRunnable task = null;
526 <            Future<?> future = e.submit(task);
527 <            shouldThrow();
528 <        } catch (NullPointerException success) {}
523 >        ExecutorService e = new ForkJoinPool(1);
524 >        try (PoolCleaner cleaner = cleaner(e)) {
525 >            try {
526 >                Future<?> future = e.submit((Runnable) null);
527 >                shouldThrow();
528 >            } catch (NullPointerException success) {}
529 >        }
530      }
531  
579
532      /**
533       * submit(null callable) throws NullPointerException
534       */
535      public void testSubmitNullCallable() {
536 <        try {
537 <            ExecutorService e = new ForkJoinPool(1);
538 <            StringTask t = null;
539 <            Future<String> future = e.submit(t);
540 <            shouldThrow();
541 <        } catch (NullPointerException success) {}
536 >        ExecutorService e = new ForkJoinPool(1);
537 >        try (PoolCleaner cleaner = cleaner(e)) {
538 >            try {
539 >                Future<String> future = e.submit((Callable) null);
540 >                shouldThrow();
541 >            } catch (NullPointerException success) {}
542 >        }
543      }
544  
592
545      /**
546 <     * Blocking on submit(callable) throws InterruptedException if
595 <     * caller interrupted.
546 >     * submit(callable).get() throws InterruptedException if interrupted
547       */
548      public void testInterruptedSubmit() throws InterruptedException {
549 <        final ForkJoinPool p = new ForkJoinPool(1);
550 <
551 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
552 <            public void realRun() throws Throwable {
553 <                p.submit(new CheckedCallable<Object>() {
554 <                    public Object realCall() throws Throwable {
555 <                        try {
556 <                            Thread.sleep(MEDIUM_DELAY_MS);
557 <                        } catch (InterruptedException ok) {
558 <                        }
559 <                        return null;
560 <                    }}).get();
561 <            }});
562 <
563 <        t.start();
564 <        Thread.sleep(SHORT_DELAY_MS);
565 <        t.interrupt();
566 <        t.join();
567 <        p.shutdownNow();
568 <        joinPool(p);
549 >        final CountDownLatch submitted    = new CountDownLatch(1);
550 >        final CountDownLatch quittingTime = new CountDownLatch(1);
551 >        final Callable<Void> awaiter = new CheckedCallable<Void>() {
552 >            public Void realCall() throws InterruptedException {
553 >                assertTrue(quittingTime.await(2*LONG_DELAY_MS, MILLISECONDS));
554 >                return null;
555 >            }};
556 >        final ExecutorService p = new ForkJoinPool(1);
557 >        try (PoolCleaner cleaner = cleaner(p, quittingTime)) {
558 >            Thread t = new Thread(new CheckedInterruptedRunnable() {
559 >                public void realRun() throws Exception {
560 >                    Future<Void> future = p.submit(awaiter);
561 >                    submitted.countDown();
562 >                    future.get();
563 >                }});
564 >            t.start();
565 >            await(submitted);
566 >            t.interrupt();
567 >            awaitTermination(t);
568 >        }
569      }
570  
571      /**
# Line 623 | Line 574 | public class ForkJoinPoolTest extends JS
574       */
575      public void testSubmitEE() throws Throwable {
576          ForkJoinPool p = new ForkJoinPool(1);
577 <        try {
578 <            p.submit(new Callable() {
579 <                public Object call() {
580 <                    int i = 5/0;
581 <                    return Boolean.TRUE;
582 <                }}).get();
583 <            shouldThrow();
584 <        } catch (ExecutionException success) {
585 <            assertTrue(success.getCause() instanceof ArithmeticException);
577 >        try (PoolCleaner cleaner = cleaner(p)) {
578 >            try {
579 >                p.submit(new Callable() {
580 >                        public Object call() { throw new ArithmeticException(); }})
581 >                    .get();
582 >                shouldThrow();
583 >            } catch (ExecutionException success) {
584 >                assertTrue(success.getCause() instanceof ArithmeticException);
585 >            }
586          }
636
637        joinPool(p);
587      }
588  
589      /**
# Line 642 | Line 591 | public class ForkJoinPoolTest extends JS
591       */
592      public void testInvokeAny1() throws Throwable {
593          ExecutorService e = new ForkJoinPool(1);
594 <        try {
595 <            e.invokeAny(null);
596 <            shouldThrow();
597 <        } catch (NullPointerException success) {
598 <        } finally {
650 <            joinPool(e);
594 >        try (PoolCleaner cleaner = cleaner(e)) {
595 >            try {
596 >                e.invokeAny(null);
597 >                shouldThrow();
598 >            } catch (NullPointerException success) {}
599          }
600      }
601  
# Line 656 | Line 604 | public class ForkJoinPoolTest extends JS
604       */
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) {
611 <        } finally {
664 <            joinPool(e);
607 >        try (PoolCleaner cleaner = cleaner(e)) {
608 >            try {
609 >                e.invokeAny(new ArrayList<Callable<String>>());
610 >                shouldThrow();
611 >            } catch (IllegalArgumentException success) {}
612          }
613      }
614  
# Line 670 | Line 617 | public class ForkJoinPoolTest extends JS
617       */
618      public void testInvokeAny3() throws Throwable {
619          ExecutorService e = new ForkJoinPool(1);
620 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
621 <        l.add(null);
622 <        try {
623 <            e.invokeAny(l);
624 <            shouldThrow();
625 <        } catch (NullPointerException success) {
626 <        } finally {
680 <            joinPool(e);
620 >        try (PoolCleaner cleaner = cleaner(e)) {
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          }
628      }
629  
# Line 687 | Line 633 | public class ForkJoinPoolTest extends JS
633      public void testInvokeAny4() throws Throwable {
634          CountDownLatch latch = new CountDownLatch(1);
635          ExecutorService e = new ForkJoinPool(1);
636 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
637 <        l.add(latchAwaitingStringTask(latch));
638 <        l.add(null);
639 <        try {
640 <            e.invokeAny(l);
641 <            shouldThrow();
642 <        } catch (NullPointerException success) {
643 <        } finally {
636 >        try (PoolCleaner cleaner = cleaner(e)) {
637 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
638 >            l.add(latchAwaitingStringTask(latch));
639 >            l.add(null);
640 >            try {
641 >                e.invokeAny(l);
642 >                shouldThrow();
643 >            } catch (NullPointerException success) {}
644              latch.countDown();
699            joinPool(e);
645          }
646      }
647  
# Line 705 | Line 650 | public class ForkJoinPoolTest extends JS
650       */
651      public void testInvokeAny5() throws Throwable {
652          ExecutorService e = new ForkJoinPool(1);
653 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
654 <        l.add(new NPETask());
655 <        try {
656 <            e.invokeAny(l);
657 <            shouldThrow();
658 <        } catch (ExecutionException success) {
659 <            assertTrue(success.getCause() instanceof NullPointerException);
660 <        } finally {
661 <            joinPool(e);
653 >        try (PoolCleaner cleaner = cleaner(e)) {
654 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
655 >            l.add(new NPETask());
656 >            try {
657 >                e.invokeAny(l);
658 >                shouldThrow();
659 >            } catch (ExecutionException success) {
660 >                assertTrue(success.getCause() instanceof NullPointerException);
661 >            }
662          }
663      }
664  
# Line 722 | Line 667 | public class ForkJoinPoolTest extends JS
667       */
668      public void testInvokeAny6() throws Throwable {
669          ExecutorService e = new ForkJoinPool(1);
670 <        try {
670 >        try (PoolCleaner cleaner = cleaner(e)) {
671              List<Callable<String>> l = new ArrayList<Callable<String>>();
672              l.add(new StringTask());
673              l.add(new StringTask());
674              String result = e.invokeAny(l);
675              assertSame(TEST_STRING, result);
731        } finally {
732            joinPool(e);
676          }
677      }
678  
# Line 738 | Line 681 | public class ForkJoinPoolTest extends JS
681       */
682      public void testInvokeAll1() throws Throwable {
683          ExecutorService e = new ForkJoinPool(1);
684 <        try {
685 <            e.invokeAll(null);
686 <            shouldThrow();
687 <        } catch (NullPointerException success) {
688 <        } finally {
746 <            joinPool(e);
684 >        try (PoolCleaner cleaner = cleaner(e)) {
685 >            try {
686 >                e.invokeAll(null);
687 >                shouldThrow();
688 >            } catch (NullPointerException success) {}
689          }
690      }
691  
# Line 752 | Line 694 | public class ForkJoinPoolTest extends JS
694       */
695      public void testInvokeAll2() throws InterruptedException {
696          ExecutorService e = new ForkJoinPool(1);
697 <        try {
697 >        try (PoolCleaner cleaner = cleaner(e)) {
698              List<Future<String>> r
699                  = e.invokeAll(new ArrayList<Callable<String>>());
700              assertTrue(r.isEmpty());
759        } finally {
760            joinPool(e);
701          }
702      }
703  
# Line 766 | Line 706 | public class ForkJoinPoolTest extends JS
706       */
707      public void testInvokeAll3() throws InterruptedException {
708          ExecutorService e = new ForkJoinPool(1);
709 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
710 <        l.add(new StringTask());
711 <        l.add(null);
712 <        try {
713 <            e.invokeAll(l);
714 <            shouldThrow();
715 <        } catch (NullPointerException success) {
716 <        } finally {
777 <            joinPool(e);
709 >        try (PoolCleaner cleaner = cleaner(e)) {
710 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
711 >            l.add(new StringTask());
712 >            l.add(null);
713 >            try {
714 >                e.invokeAll(l);
715 >                shouldThrow();
716 >            } catch (NullPointerException success) {}
717          }
718      }
719  
# Line 784 | Line 723 | public class ForkJoinPoolTest extends JS
723       */
724      public void testInvokeAll4() throws Throwable {
725          ExecutorService e = new ForkJoinPool(1);
726 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
727 <        l.add(new NPETask());
728 <        List<Future<String>> futures = e.invokeAll(l);
729 <        assertEquals(1, futures.size());
730 <        try {
731 <            futures.get(0).get();
732 <            shouldThrow();
733 <        } catch (ExecutionException success) {
734 <            assertTrue(success.getCause() instanceof NullPointerException);
735 <        } finally {
736 <            joinPool(e);
726 >        try (PoolCleaner cleaner = cleaner(e)) {
727 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
728 >            l.add(new NPETask());
729 >            List<Future<String>> futures = e.invokeAll(l);
730 >            assertEquals(1, futures.size());
731 >            try {
732 >                futures.get(0).get();
733 >                shouldThrow();
734 >            } catch (ExecutionException success) {
735 >                assertTrue(success.getCause() instanceof NullPointerException);
736 >            }
737          }
738      }
739  
# Line 803 | Line 742 | public class ForkJoinPoolTest extends JS
742       */
743      public void testInvokeAll5() throws Throwable {
744          ExecutorService e = new ForkJoinPool(1);
745 <        try {
745 >        try (PoolCleaner cleaner = cleaner(e)) {
746              List<Callable<String>> l = new ArrayList<Callable<String>>();
747              l.add(new StringTask());
748              l.add(new StringTask());
# Line 811 | Line 750 | public class ForkJoinPoolTest extends JS
750              assertEquals(2, futures.size());
751              for (Future<String> future : futures)
752                  assertSame(TEST_STRING, future.get());
814        } finally {
815            joinPool(e);
753          }
754      }
755  
819
756      /**
757       * timed invokeAny(null) throws NullPointerException
758       */
759      public void testTimedInvokeAny1() throws Throwable {
760          ExecutorService e = new ForkJoinPool(1);
761 <        try {
762 <            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
763 <            shouldThrow();
764 <        } catch (NullPointerException success) {
765 <        } finally {
830 <            joinPool(e);
761 >        try (PoolCleaner cleaner = cleaner(e)) {
762 >            try {
763 >                e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
764 >                shouldThrow();
765 >            } catch (NullPointerException success) {}
766          }
767      }
768  
# Line 836 | Line 771 | public class ForkJoinPoolTest extends JS
771       */
772      public void testTimedInvokeAnyNullTimeUnit() throws Throwable {
773          ExecutorService e = new ForkJoinPool(1);
774 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
775 <        l.add(new StringTask());
776 <        try {
777 <            e.invokeAny(l, MEDIUM_DELAY_MS, null);
778 <            shouldThrow();
779 <        } catch (NullPointerException success) {
780 <        } finally {
846 <            joinPool(e);
774 >        try (PoolCleaner cleaner = cleaner(e)) {
775 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
776 >            l.add(new StringTask());
777 >            try {
778 >                e.invokeAny(l, MEDIUM_DELAY_MS, null);
779 >                shouldThrow();
780 >            } catch (NullPointerException success) {}
781          }
782      }
783  
# Line 852 | Line 786 | public class ForkJoinPoolTest extends JS
786       */
787      public void testTimedInvokeAny2() throws Throwable {
788          ExecutorService e = new ForkJoinPool(1);
789 <        try {
790 <            e.invokeAny(new ArrayList<Callable<String>>(),
791 <                        MEDIUM_DELAY_MS, MILLISECONDS);
792 <            shouldThrow();
793 <        } catch (IllegalArgumentException success) {
794 <        } finally {
861 <            joinPool(e);
789 >        try (PoolCleaner cleaner = cleaner(e)) {
790 >            try {
791 >                e.invokeAny(new ArrayList<Callable<String>>(),
792 >                            MEDIUM_DELAY_MS, MILLISECONDS);
793 >                shouldThrow();
794 >            } catch (IllegalArgumentException success) {}
795          }
796      }
797  
# Line 868 | Line 801 | public class ForkJoinPoolTest extends JS
801      public void testTimedInvokeAny3() throws Throwable {
802          CountDownLatch latch = new CountDownLatch(1);
803          ExecutorService e = new ForkJoinPool(1);
804 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
805 <        l.add(latchAwaitingStringTask(latch));
806 <        l.add(null);
807 <        try {
808 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
809 <            shouldThrow();
810 <        } catch (NullPointerException success) {
811 <        } finally {
804 >        try (PoolCleaner cleaner = cleaner(e)) {
805 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
806 >            l.add(latchAwaitingStringTask(latch));
807 >            l.add(null);
808 >            try {
809 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
810 >                shouldThrow();
811 >            } catch (NullPointerException success) {}
812              latch.countDown();
880            joinPool(e);
813          }
814      }
815  
# Line 886 | Line 818 | public class ForkJoinPoolTest extends JS
818       */
819      public void testTimedInvokeAny4() throws Throwable {
820          ExecutorService e = new ForkJoinPool(1);
821 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
822 <        l.add(new NPETask());
823 <        try {
824 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
825 <            shouldThrow();
826 <        } catch (ExecutionException success) {
827 <            assertTrue(success.getCause() instanceof NullPointerException);
828 <        } finally {
829 <            joinPool(e);
821 >        try (PoolCleaner cleaner = cleaner(e)) {
822 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
823 >            l.add(new NPETask());
824 >            try {
825 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
826 >                shouldThrow();
827 >            } catch (ExecutionException success) {
828 >                assertTrue(success.getCause() instanceof NullPointerException);
829 >            }
830          }
831      }
832  
# Line 903 | Line 835 | public class ForkJoinPoolTest extends JS
835       */
836      public void testTimedInvokeAny5() throws Throwable {
837          ExecutorService e = new ForkJoinPool(1);
838 <        try {
838 >        try (PoolCleaner cleaner = cleaner(e)) {
839              List<Callable<String>> l = new ArrayList<Callable<String>>();
840              l.add(new StringTask());
841              l.add(new StringTask());
842              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
843              assertSame(TEST_STRING, result);
912        } finally {
913            joinPool(e);
844          }
845      }
846  
# Line 919 | Line 849 | public class ForkJoinPoolTest extends JS
849       */
850      public void testTimedInvokeAll1() throws Throwable {
851          ExecutorService e = new ForkJoinPool(1);
852 <        try {
853 <            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
854 <            shouldThrow();
855 <        } catch (NullPointerException success) {
856 <        } finally {
927 <            joinPool(e);
852 >        try (PoolCleaner cleaner = cleaner(e)) {
853 >            try {
854 >                e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
855 >                shouldThrow();
856 >            } catch (NullPointerException success) {}
857          }
858      }
859  
# Line 933 | Line 862 | public class ForkJoinPoolTest extends JS
862       */
863      public void testTimedInvokeAllNullTimeUnit() throws Throwable {
864          ExecutorService e = new ForkJoinPool(1);
865 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
866 <        l.add(new StringTask());
867 <        try {
868 <            e.invokeAll(l, MEDIUM_DELAY_MS, null);
869 <            shouldThrow();
870 <        } catch (NullPointerException success) {
871 <        } finally {
943 <            joinPool(e);
865 >        try (PoolCleaner cleaner = cleaner(e)) {
866 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
867 >            l.add(new StringTask());
868 >            try {
869 >                e.invokeAll(l, MEDIUM_DELAY_MS, null);
870 >                shouldThrow();
871 >            } catch (NullPointerException success) {}
872          }
873      }
874  
# Line 949 | Line 877 | public class ForkJoinPoolTest extends JS
877       */
878      public void testTimedInvokeAll2() throws InterruptedException {
879          ExecutorService e = new ForkJoinPool(1);
880 <        try {
880 >        try (PoolCleaner cleaner = cleaner(e)) {
881              List<Future<String>> r
882                  = e.invokeAll(new ArrayList<Callable<String>>(),
883                                MEDIUM_DELAY_MS, MILLISECONDS);
884              assertTrue(r.isEmpty());
957        } finally {
958            joinPool(e);
885          }
886      }
887  
# Line 964 | Line 890 | public class ForkJoinPoolTest extends JS
890       */
891      public void testTimedInvokeAll3() throws InterruptedException {
892          ExecutorService e = new ForkJoinPool(1);
893 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
894 <        l.add(new StringTask());
895 <        l.add(null);
896 <        try {
897 <            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
898 <            shouldThrow();
899 <        } catch (NullPointerException success) {
900 <        } finally {
975 <            joinPool(e);
893 >        try (PoolCleaner cleaner = cleaner(e)) {
894 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
895 >            l.add(new StringTask());
896 >            l.add(null);
897 >            try {
898 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
899 >                shouldThrow();
900 >            } catch (NullPointerException success) {}
901          }
902      }
903  
# Line 981 | Line 906 | public class ForkJoinPoolTest extends JS
906       */
907      public void testTimedInvokeAll4() throws Throwable {
908          ExecutorService e = new ForkJoinPool(1);
909 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
910 <        l.add(new NPETask());
911 <        List<Future<String>> futures
912 <            = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
913 <        assertEquals(1, futures.size());
914 <        try {
915 <            futures.get(0).get();
916 <            shouldThrow();
917 <        } catch (ExecutionException success) {
918 <            assertTrue(success.getCause() instanceof NullPointerException);
919 <        } finally {
920 <            joinPool(e);
909 >        try (PoolCleaner cleaner = cleaner(e)) {
910 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
911 >            l.add(new NPETask());
912 >            List<Future<String>> futures
913 >                = e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
914 >            assertEquals(1, futures.size());
915 >            try {
916 >                futures.get(0).get();
917 >                shouldThrow();
918 >            } catch (ExecutionException success) {
919 >                assertTrue(success.getCause() instanceof NullPointerException);
920 >            }
921          }
922      }
923  
# Line 1000 | Line 925 | public class ForkJoinPoolTest extends JS
925       * timed invokeAll(c) returns results of all completed tasks in c
926       */
927      public void testTimedInvokeAll5() throws Throwable {
928 <        ExecutorService e = new ForkJoinPool(1);
929 <        try {
928 >        ForkJoinPool e = new ForkJoinPool(1);
929 >        try (PoolCleaner cleaner = cleaner(e)) {
930              List<Callable<String>> l = new ArrayList<Callable<String>>();
931              l.add(new StringTask());
932              l.add(new StringTask());
933              List<Future<String>> futures
934 <                = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
934 >                = e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
935              assertEquals(2, futures.size());
936              for (Future<String> future : futures)
937                  assertSame(TEST_STRING, future.get());
1013        } finally {
1014            joinPool(e);
938          }
939      }
940  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines