ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ScheduledExecutorTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ScheduledExecutorTest.java (file contents):
Revision 1.59 by jsr166, Sat Oct 3 00:37:31 2015 UTC vs.
Revision 1.65 by jsr166, Mon Oct 5 21:42:48 2015 UTC

# Line 43 | Line 43 | public class ScheduledExecutorTest exten
43       */
44      public void testExecute() throws InterruptedException {
45          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
46 <        final CountDownLatch done = new CountDownLatch(1);
47 <        final Runnable task = new CheckedRunnable() {
48 <            public void realRun() {
49 <                done.countDown();
50 <            }};
51 <        try {
46 >        try (PoolCleaner cleaner = cleaner(p)) {
47 >            final CountDownLatch done = new CountDownLatch(1);
48 >            final Runnable task = new CheckedRunnable() {
49 >                public void realRun() { done.countDown(); }};
50              p.execute(task);
51              assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS));
54        } finally {
55            joinPool(p);
52          }
53      }
54  
# Line 61 | Line 57 | public class ScheduledExecutorTest exten
57       */
58      public void testSchedule1() throws Exception {
59          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
60 <        final long startTime = System.nanoTime();
61 <        final CountDownLatch done = new CountDownLatch(1);
62 <        try {
60 >        try (PoolCleaner cleaner = cleaner(p)) {
61 >            final long startTime = System.nanoTime();
62 >            final CountDownLatch done = new CountDownLatch(1);
63              Callable task = new CheckedCallable<Boolean>() {
64                  public Boolean realCall() {
65                      done.countDown();
# Line 74 | Line 70 | public class ScheduledExecutorTest exten
70              assertSame(Boolean.TRUE, f.get());
71              assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
72              assertTrue(done.await(0L, MILLISECONDS));
77        } finally {
78            joinPool(p);
73          }
74      }
75  
# Line 84 | Line 78 | public class ScheduledExecutorTest exten
78       */
79      public void testSchedule3() throws Exception {
80          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
81 <        final long startTime = System.nanoTime();
82 <        final CountDownLatch done = new CountDownLatch(1);
83 <        try {
81 >        try (PoolCleaner cleaner = cleaner(p)) {
82 >            final long startTime = System.nanoTime();
83 >            final CountDownLatch done = new CountDownLatch(1);
84              Runnable task = new CheckedRunnable() {
85                  public void realRun() {
86                      done.countDown();
# Line 96 | Line 90 | public class ScheduledExecutorTest exten
90              await(done);
91              assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
92              assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
99        } finally {
100            joinPool(p);
93          }
94      }
95  
# Line 106 | Line 98 | public class ScheduledExecutorTest exten
98       */
99      public void testSchedule4() throws Exception {
100          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
101 <        final long startTime = System.nanoTime();
102 <        final CountDownLatch done = new CountDownLatch(1);
103 <        try {
101 >        try (PoolCleaner cleaner = cleaner(p)) {
102 >            final long startTime = System.nanoTime();
103 >            final CountDownLatch done = new CountDownLatch(1);
104              Runnable task = new CheckedRunnable() {
105                  public void realRun() {
106                      done.countDown();
# Line 120 | Line 112 | public class ScheduledExecutorTest exten
112              await(done);
113              assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
114              f.cancel(true);
123        } finally {
124            joinPool(p);
115          }
116      }
117  
# Line 130 | Line 120 | public class ScheduledExecutorTest exten
120       */
121      public void testSchedule5() throws Exception {
122          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
123 <        final long startTime = System.nanoTime();
124 <        final CountDownLatch done = new CountDownLatch(1);
125 <        try {
123 >        try (PoolCleaner cleaner = cleaner(p)) {
124 >            final long startTime = System.nanoTime();
125 >            final CountDownLatch done = new CountDownLatch(1);
126              Runnable task = new CheckedRunnable() {
127                  public void realRun() {
128                      done.countDown();
# Line 144 | Line 134 | public class ScheduledExecutorTest exten
134              await(done);
135              assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
136              f.cancel(true);
147        } finally {
148            joinPool(p);
137          }
138      }
139  
# Line 159 | Line 147 | public class ScheduledExecutorTest exten
147       */
148      public void testFixedRateSequence() throws InterruptedException {
149          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
150 <        try {
150 >        try (PoolCleaner cleaner = cleaner(p)) {
151              for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
152                  long startTime = System.nanoTime();
153                  int cycles = 10;
# Line 177 | Line 165 | public class ScheduledExecutorTest exten
165                      return;
166              }
167              throw new AssertionError("unexpected execution rate");
180        } finally {
181            joinPool(p);
168          }
169      }
170  
# Line 187 | Line 173 | public class ScheduledExecutorTest exten
173       */
174      public void testFixedDelaySequence() throws InterruptedException {
175          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
176 <        try {
176 >        try (PoolCleaner cleaner = cleaner(p)) {
177              for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
178                  long startTime = System.nanoTime();
179                  int cycles = 10;
# Line 205 | Line 191 | public class ScheduledExecutorTest exten
191                      return;
192              }
193              throw new AssertionError("unexpected execution rate");
208        } finally {
209            joinPool(p);
194          }
195      }
196  
# Line 214 | Line 198 | public class ScheduledExecutorTest exten
198       * execute(null) throws NPE
199       */
200      public void testExecuteNull() throws InterruptedException {
201 <        ScheduledThreadPoolExecutor se = null;
202 <        try {
203 <            se = new ScheduledThreadPoolExecutor(1);
204 <            se.execute(null);
205 <            shouldThrow();
206 <        } catch (NullPointerException success) {}
207 <
224 <        joinPool(se);
201 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
202 >        try (PoolCleaner cleaner = cleaner(p)) {
203 >            try {
204 >                p.execute(null);
205 >                shouldThrow();
206 >            } catch (NullPointerException success) {}
207 >        }
208      }
209  
210      /**
211       * schedule(null) throws NPE
212       */
213      public void testScheduleNull() throws InterruptedException {
214 <        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
215 <        try {
216 <            TrackedCallable callable = null;
217 <            Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
218 <            shouldThrow();
219 <        } catch (NullPointerException success) {}
220 <        joinPool(se);
214 >        final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
215 >        try (PoolCleaner cleaner = cleaner(p)) {
216 >            try {
217 >                TrackedCallable callable = null;
218 >                Future f = p.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
219 >                shouldThrow();
220 >            } catch (NullPointerException success) {}
221 >        }
222      }
223  
224      /**
225       * execute throws RejectedExecutionException if shutdown
226       */
227      public void testSchedule1_RejectedExecutionException() throws InterruptedException {
228 <        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
229 <        try {
230 <            se.shutdown();
231 <            se.schedule(new NoOpRunnable(),
232 <                        MEDIUM_DELAY_MS, MILLISECONDS);
233 <            shouldThrow();
234 <        } catch (RejectedExecutionException success) {
235 <        } catch (SecurityException ok) {
228 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
229 >        try (PoolCleaner cleaner = cleaner(p)) {
230 >            try {
231 >                p.shutdown();
232 >                p.schedule(new NoOpRunnable(),
233 >                           MEDIUM_DELAY_MS, MILLISECONDS);
234 >                shouldThrow();
235 >            } catch (RejectedExecutionException success) {
236 >            } catch (SecurityException ok) {}
237          }
253
254        joinPool(se);
238      }
239  
240      /**
241       * schedule throws RejectedExecutionException if shutdown
242       */
243      public void testSchedule2_RejectedExecutionException() throws InterruptedException {
244 <        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
245 <        try {
246 <            se.shutdown();
247 <            se.schedule(new NoOpCallable(),
248 <                        MEDIUM_DELAY_MS, MILLISECONDS);
249 <            shouldThrow();
250 <        } catch (RejectedExecutionException success) {
251 <        } catch (SecurityException ok) {
244 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
245 >        try (PoolCleaner cleaner = cleaner(p)) {
246 >            try {
247 >                p.shutdown();
248 >                p.schedule(new NoOpCallable(),
249 >                           MEDIUM_DELAY_MS, MILLISECONDS);
250 >                shouldThrow();
251 >            } catch (RejectedExecutionException success) {
252 >            } catch (SecurityException ok) {}
253          }
270        joinPool(se);
254      }
255  
256      /**
257       * schedule callable throws RejectedExecutionException if shutdown
258       */
259      public void testSchedule3_RejectedExecutionException() throws InterruptedException {
260 <        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
261 <        try {
262 <            se.shutdown();
263 <            se.schedule(new NoOpCallable(),
264 <                        MEDIUM_DELAY_MS, MILLISECONDS);
265 <            shouldThrow();
266 <        } catch (RejectedExecutionException success) {
267 <        } catch (SecurityException ok) {
260 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
261 >        try (PoolCleaner cleaner = cleaner(p)) {
262 >            try {
263 >                p.shutdown();
264 >                p.schedule(new NoOpCallable(),
265 >                           MEDIUM_DELAY_MS, MILLISECONDS);
266 >                shouldThrow();
267 >            } catch (RejectedExecutionException success) {
268 >            } catch (SecurityException ok) {}
269          }
286        joinPool(se);
270      }
271  
272      /**
273       * scheduleAtFixedRate throws RejectedExecutionException if shutdown
274       */
275      public void testScheduleAtFixedRate1_RejectedExecutionException() throws InterruptedException {
276 <        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
277 <        try {
278 <            se.shutdown();
279 <            se.scheduleAtFixedRate(new NoOpRunnable(),
280 <                                   MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
281 <            shouldThrow();
282 <        } catch (RejectedExecutionException success) {
283 <        } catch (SecurityException ok) {
276 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
277 >        try (PoolCleaner cleaner = cleaner(p)) {
278 >            try {
279 >                p.shutdown();
280 >                p.scheduleAtFixedRate(new NoOpRunnable(),
281 >                                      MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
282 >                shouldThrow();
283 >            } catch (RejectedExecutionException success) {
284 >            } catch (SecurityException ok) {}
285          }
302        joinPool(se);
286      }
287  
288      /**
289       * scheduleWithFixedDelay throws RejectedExecutionException if shutdown
290       */
291      public void testScheduleWithFixedDelay1_RejectedExecutionException() throws InterruptedException {
292 <        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
293 <        try {
294 <            se.shutdown();
295 <            se.scheduleWithFixedDelay(new NoOpRunnable(),
296 <                                      MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
297 <            shouldThrow();
298 <        } catch (RejectedExecutionException success) {
299 <        } catch (SecurityException ok) {
292 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
293 >        try (PoolCleaner cleaner = cleaner(p)) {
294 >            try {
295 >                p.shutdown();
296 >                p.scheduleWithFixedDelay(new NoOpRunnable(),
297 >                                         MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
298 >                shouldThrow();
299 >            } catch (RejectedExecutionException success) {
300 >            } catch (SecurityException ok) {}
301          }
318        joinPool(se);
302      }
303  
304      /**
# Line 324 | Line 307 | public class ScheduledExecutorTest exten
307       */
308      public void testGetActiveCount() throws InterruptedException {
309          final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(2);
310 <        final CountDownLatch threadStarted = new CountDownLatch(1);
311 <        final CountDownLatch done = new CountDownLatch(1);
312 <        try {
310 >        try (PoolCleaner cleaner = cleaner(p)) {
311 >            final CountDownLatch threadStarted = new CountDownLatch(1);
312 >            final CountDownLatch done = new CountDownLatch(1);
313              assertEquals(0, p.getActiveCount());
314              p.execute(new CheckedRunnable() {
315                  public void realRun() throws InterruptedException {
# Line 334 | Line 317 | public class ScheduledExecutorTest exten
317                      assertEquals(1, p.getActiveCount());
318                      done.await();
319                  }});
320 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
320 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
321              assertEquals(1, p.getActiveCount());
339        } finally {
322              done.countDown();
341            joinPool(p);
323          }
324      }
325  
# Line 348 | Line 329 | public class ScheduledExecutorTest exten
329       */
330      public void testGetCompletedTaskCount() throws InterruptedException {
331          final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(2);
332 <        final CountDownLatch threadStarted = new CountDownLatch(1);
333 <        final CountDownLatch threadProceed = new CountDownLatch(1);
334 <        final CountDownLatch threadDone = new CountDownLatch(1);
335 <        try {
332 >        try (PoolCleaner cleaner = cleaner(p)) {
333 >            final CountDownLatch threadStarted = new CountDownLatch(1);
334 >            final CountDownLatch threadProceed = new CountDownLatch(1);
335 >            final CountDownLatch threadDone = new CountDownLatch(1);
336              assertEquals(0, p.getCompletedTaskCount());
337              p.execute(new CheckedRunnable() {
338                  public void realRun() throws InterruptedException {
# Line 370 | Line 351 | public class ScheduledExecutorTest exten
351                      fail("timed out");
352                  Thread.yield();
353              }
373        } finally {
374            joinPool(p);
354          }
355      }
356  
# Line 380 | Line 359 | public class ScheduledExecutorTest exten
359       */
360      public void testGetCorePoolSize() throws InterruptedException {
361          ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
362 <        assertEquals(1, p.getCorePoolSize());
363 <        joinPool(p);
362 >        try (PoolCleaner cleaner = cleaner(p)) {
363 >            assertEquals(1, p.getCorePoolSize());
364 >        }
365      }
366  
367      /**
# Line 393 | Line 373 | public class ScheduledExecutorTest exten
373          final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(THREADS);
374          final CountDownLatch threadsStarted = new CountDownLatch(THREADS);
375          final CountDownLatch done = new CountDownLatch(1);
376 <        try {
376 >        try (PoolCleaner cleaner = cleaner(p)) {
377              assertEquals(0, p.getLargestPoolSize());
378              for (int i = 0; i < THREADS; i++)
379                  p.execute(new CheckedRunnable() {
# Line 402 | Line 382 | public class ScheduledExecutorTest exten
382                          done.await();
383                          assertEquals(THREADS, p.getLargestPoolSize());
384                      }});
385 <            assertTrue(threadsStarted.await(SMALL_DELAY_MS, MILLISECONDS));
385 >            assertTrue(threadsStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
386              assertEquals(THREADS, p.getLargestPoolSize());
407        } finally {
387              done.countDown();
409            joinPool(p);
410            assertEquals(THREADS, p.getLargestPoolSize());
388          }
389 +        assertEquals(THREADS, p.getLargestPoolSize());
390      }
391  
392      /**
# Line 419 | Line 397 | public class ScheduledExecutorTest exten
397          final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
398          final CountDownLatch threadStarted = new CountDownLatch(1);
399          final CountDownLatch done = new CountDownLatch(1);
400 <        try {
400 >        try (PoolCleaner cleaner = cleaner(p)) {
401              assertEquals(0, p.getPoolSize());
402              p.execute(new CheckedRunnable() {
403                  public void realRun() throws InterruptedException {
# Line 427 | Line 405 | public class ScheduledExecutorTest exten
405                      assertEquals(1, p.getPoolSize());
406                      done.await();
407                  }});
408 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
408 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
409              assertEquals(1, p.getPoolSize());
432        } finally {
410              done.countDown();
434            joinPool(p);
411          }
412      }
413  
# Line 440 | Line 416 | public class ScheduledExecutorTest exten
416       * submitted
417       */
418      public void testGetTaskCount() throws InterruptedException {
419 <        final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
444 <        final CountDownLatch threadStarted = new CountDownLatch(1);
419 >        final int TASKS = 3;
420          final CountDownLatch done = new CountDownLatch(1);
421 <        final int TASKS = 5;
422 <        try {
421 >        final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
422 >        try (PoolCleaner cleaner = cleaner(p, done)) {
423 >            final CountDownLatch threadStarted = new CountDownLatch(1);
424              assertEquals(0, p.getTaskCount());
425 <            for (int i = 0; i < TASKS; i++)
425 >            assertEquals(0, p.getCompletedTaskCount());
426 >            p.execute(new CheckedRunnable() {
427 >                public void realRun() throws InterruptedException {
428 >                    threadStarted.countDown();
429 >                    done.await();
430 >                }});
431 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
432 >            assertEquals(1, p.getTaskCount());
433 >            assertEquals(0, p.getCompletedTaskCount());
434 >            for (int i = 0; i < TASKS; i++) {
435 >                assertEquals(1 + i, p.getTaskCount());
436                  p.execute(new CheckedRunnable() {
437                      public void realRun() throws InterruptedException {
438                          threadStarted.countDown();
439 +                        assertEquals(1 + TASKS, p.getTaskCount());
440                          done.await();
441                      }});
442 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
443 <            assertEquals(TASKS, p.getTaskCount());
444 <        } finally {
458 <            done.countDown();
459 <            joinPool(p);
442 >            }
443 >            assertEquals(1 + TASKS, p.getTaskCount());
444 >            assertEquals(0, p.getCompletedTaskCount());
445          }
446 +        assertEquals(1 + TASKS, p.getTaskCount());
447 +        assertEquals(1 + TASKS, p.getCompletedTaskCount());
448      }
449  
450      /**
451       * getThreadFactory returns factory in constructor if not set
452       */
453      public void testGetThreadFactory() throws InterruptedException {
454 <        ThreadFactory tf = new SimpleThreadFactory();
455 <        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, tf);
456 <        assertSame(tf, p.getThreadFactory());
457 <        joinPool(p);
454 >        final ThreadFactory threadFactory = new SimpleThreadFactory();
455 >        final ScheduledThreadPoolExecutor p =
456 >            new ScheduledThreadPoolExecutor(1, threadFactory);
457 >        try (PoolCleaner cleaner = cleaner(p)) {
458 >            assertSame(threadFactory, p.getThreadFactory());
459 >        }
460      }
461  
462      /**
463       * setThreadFactory sets the thread factory returned by getThreadFactory
464       */
465      public void testSetThreadFactory() throws InterruptedException {
466 <        ThreadFactory tf = new SimpleThreadFactory();
466 >        ThreadFactory threadFactory = new SimpleThreadFactory();
467          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
468 <        p.setThreadFactory(tf);
469 <        assertSame(tf, p.getThreadFactory());
470 <        joinPool(p);
468 >        try (PoolCleaner cleaner = cleaner(p)) {
469 >            p.setThreadFactory(threadFactory);
470 >            assertSame(threadFactory, p.getThreadFactory());
471 >        }
472      }
473  
474      /**
# Line 486 | Line 476 | public class ScheduledExecutorTest exten
476       */
477      public void testSetThreadFactoryNull() throws InterruptedException {
478          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
479 <        try {
480 <            p.setThreadFactory(null);
481 <            shouldThrow();
482 <        } catch (NullPointerException success) {
483 <        } finally {
494 <            joinPool(p);
479 >        try (PoolCleaner cleaner = cleaner(p)) {
480 >            try {
481 >                p.setThreadFactory(null);
482 >                shouldThrow();
483 >            } catch (NullPointerException success) {}
484          }
485      }
486  
# Line 515 | Line 504 | public class ScheduledExecutorTest exten
504       */
505      public void testIsTerminated() throws InterruptedException {
506          final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
507 <        final CountDownLatch threadStarted = new CountDownLatch(1);
508 <        final CountDownLatch done = new CountDownLatch(1);
509 <        assertFalse(p.isTerminated());
510 <        try {
507 >        try (PoolCleaner cleaner = cleaner(p)) {
508 >            final CountDownLatch threadStarted = new CountDownLatch(1);
509 >            final CountDownLatch done = new CountDownLatch(1);
510 >            assertFalse(p.isTerminated());
511              p.execute(new CheckedRunnable() {
512                  public void realRun() throws InterruptedException {
513                      assertFalse(p.isTerminated());
514                      threadStarted.countDown();
515                      done.await();
516                  }});
517 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
517 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
518              assertFalse(p.isTerminating());
519              done.countDown();
531        } finally {
520              try { p.shutdown(); } catch (SecurityException ok) { return; }
521 +            assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
522 +            assertTrue(p.isTerminated());
523          }
534        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
535        assertTrue(p.isTerminated());
524      }
525  
526      /**
# Line 542 | Line 530 | public class ScheduledExecutorTest exten
530          final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
531          final CountDownLatch threadStarted = new CountDownLatch(1);
532          final CountDownLatch done = new CountDownLatch(1);
533 <        try {
533 >        try (PoolCleaner cleaner = cleaner(p)) {
534              assertFalse(p.isTerminating());
535              p.execute(new CheckedRunnable() {
536                  public void realRun() throws InterruptedException {
# Line 550 | Line 538 | public class ScheduledExecutorTest exten
538                      threadStarted.countDown();
539                      done.await();
540                  }});
541 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
541 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
542              assertFalse(p.isTerminating());
543              done.countDown();
556        } finally {
544              try { p.shutdown(); } catch (SecurityException ok) { return; }
545 +            assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
546 +            assertTrue(p.isTerminated());
547 +            assertFalse(p.isTerminating());
548          }
559        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
560        assertTrue(p.isTerminated());
561        assertFalse(p.isTerminating());
549      }
550  
551      /**
# Line 566 | Line 553 | public class ScheduledExecutorTest exten
553       */
554      public void testGetQueue() throws InterruptedException {
555          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
556 <        final CountDownLatch threadStarted = new CountDownLatch(1);
557 <        final CountDownLatch done = new CountDownLatch(1);
558 <        try {
556 >        try (PoolCleaner cleaner = cleaner(p)) {
557 >            final CountDownLatch threadStarted = new CountDownLatch(1);
558 >            final CountDownLatch done = new CountDownLatch(1);
559              ScheduledFuture[] tasks = new ScheduledFuture[5];
560              for (int i = 0; i < tasks.length; i++) {
561                  Runnable r = new CheckedRunnable() {
# Line 578 | Line 565 | public class ScheduledExecutorTest exten
565                      }};
566                  tasks[i] = p.schedule(r, 1, MILLISECONDS);
567              }
568 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
568 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
569              BlockingQueue<Runnable> q = p.getQueue();
570              assertTrue(q.contains(tasks[tasks.length - 1]));
571              assertFalse(q.contains(tasks[0]));
585        } finally {
572              done.countDown();
587            joinPool(p);
573          }
574      }
575  
# Line 593 | Line 578 | public class ScheduledExecutorTest exten
578       */
579      public void testRemove() throws InterruptedException {
580          final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
581 <        ScheduledFuture[] tasks = new ScheduledFuture[5];
582 <        final CountDownLatch threadStarted = new CountDownLatch(1);
583 <        final CountDownLatch done = new CountDownLatch(1);
584 <        try {
581 >        try (PoolCleaner cleaner = cleaner(p)) {
582 >            ScheduledFuture[] tasks = new ScheduledFuture[5];
583 >            final CountDownLatch threadStarted = new CountDownLatch(1);
584 >            final CountDownLatch done = new CountDownLatch(1);
585              for (int i = 0; i < tasks.length; i++) {
586                  Runnable r = new CheckedRunnable() {
587                      public void realRun() throws InterruptedException {
# Line 605 | Line 590 | public class ScheduledExecutorTest exten
590                      }};
591                  tasks[i] = p.schedule(r, 1, MILLISECONDS);
592              }
593 <            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
593 >            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
594              BlockingQueue<Runnable> q = p.getQueue();
595              assertFalse(p.remove((Runnable)tasks[0]));
596              assertTrue(q.contains((Runnable)tasks[4]));
# Line 616 | Line 601 | public class ScheduledExecutorTest exten
601              assertTrue(q.contains((Runnable)tasks[3]));
602              assertTrue(p.remove((Runnable)tasks[3]));
603              assertFalse(q.contains((Runnable)tasks[3]));
619        } finally {
604              done.countDown();
621            joinPool(p);
605          }
606      }
607  
# Line 662 | Line 645 | public class ScheduledExecutorTest exten
645          final AtomicInteger ran = new AtomicInteger(0);
646          final ScheduledThreadPoolExecutor p =
647              new ScheduledThreadPoolExecutor(poolSize);
648 <        CountDownLatch threadsStarted = new CountDownLatch(poolSize);
648 >        final CountDownLatch threadsStarted = new CountDownLatch(poolSize);
649          Runnable waiter = new CheckedRunnable() { public void realRun() {
650              threadsStarted.countDown();
651              try {
# Line 822 | Line 805 | public class ScheduledExecutorTest exten
805       * completed submit of callable returns result
806       */
807      public void testSubmitCallable() throws Exception {
808 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
809 <        try {
808 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
809 >        try (PoolCleaner cleaner = cleaner(e)) {
810              Future<String> future = e.submit(new StringTask());
811              String result = future.get();
812              assertSame(TEST_STRING, result);
830        } finally {
831            joinPool(e);
813          }
814      }
815  
# Line 836 | Line 817 | public class ScheduledExecutorTest exten
817       * completed submit of runnable returns successfully
818       */
819      public void testSubmitRunnable() throws Exception {
820 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
821 <        try {
820 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
821 >        try (PoolCleaner cleaner = cleaner(e)) {
822              Future<?> future = e.submit(new NoOpRunnable());
823              future.get();
824              assertTrue(future.isDone());
844        } finally {
845            joinPool(e);
825          }
826      }
827  
# Line 850 | Line 829 | public class ScheduledExecutorTest exten
829       * completed submit of (runnable, result) returns result
830       */
831      public void testSubmitRunnable2() throws Exception {
832 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
833 <        try {
832 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
833 >        try (PoolCleaner cleaner = cleaner(e)) {
834              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
835              String result = future.get();
836              assertSame(TEST_STRING, result);
858        } finally {
859            joinPool(e);
837          }
838      }
839  
# Line 864 | Line 841 | public class ScheduledExecutorTest exten
841       * invokeAny(null) throws NPE
842       */
843      public void testInvokeAny1() throws Exception {
844 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
845 <        try {
846 <            e.invokeAny(null);
847 <            shouldThrow();
848 <        } catch (NullPointerException success) {
849 <        } finally {
873 <            joinPool(e);
844 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
845 >        try (PoolCleaner cleaner = cleaner(e)) {
846 >            try {
847 >                e.invokeAny(null);
848 >                shouldThrow();
849 >            } catch (NullPointerException success) {}
850          }
851      }
852  
# Line 878 | Line 854 | public class ScheduledExecutorTest exten
854       * invokeAny(empty collection) throws IAE
855       */
856      public void testInvokeAny2() throws Exception {
857 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
858 <        try {
859 <            e.invokeAny(new ArrayList<Callable<String>>());
860 <            shouldThrow();
861 <        } catch (IllegalArgumentException success) {
862 <        } finally {
887 <            joinPool(e);
857 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
858 >        try (PoolCleaner cleaner = cleaner(e)) {
859 >            try {
860 >                e.invokeAny(new ArrayList<Callable<String>>());
861 >                shouldThrow();
862 >            } catch (IllegalArgumentException success) {}
863          }
864      }
865  
# Line 893 | Line 868 | public class ScheduledExecutorTest exten
868       */
869      public void testInvokeAny3() throws Exception {
870          CountDownLatch latch = new CountDownLatch(1);
871 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
872 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
873 <        l.add(latchAwaitingStringTask(latch));
874 <        l.add(null);
875 <        try {
876 <            e.invokeAny(l);
877 <            shouldThrow();
878 <        } catch (NullPointerException success) {
879 <        } finally {
871 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
872 >        try (PoolCleaner cleaner = cleaner(e)) {
873 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
874 >            l.add(latchAwaitingStringTask(latch));
875 >            l.add(null);
876 >            try {
877 >                e.invokeAny(l);
878 >                shouldThrow();
879 >            } catch (NullPointerException success) {}
880              latch.countDown();
906            joinPool(e);
881          }
882      }
883  
# Line 911 | Line 885 | public class ScheduledExecutorTest exten
885       * invokeAny(c) throws ExecutionException if no task completes
886       */
887      public void testInvokeAny4() throws Exception {
888 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
889 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
890 <        l.add(new NPETask());
891 <        try {
892 <            e.invokeAny(l);
893 <            shouldThrow();
894 <        } catch (ExecutionException success) {
895 <            assertTrue(success.getCause() instanceof NullPointerException);
896 <        } finally {
897 <            joinPool(e);
888 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
889 >        try (PoolCleaner cleaner = cleaner(e)) {
890 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
891 >            l.add(new NPETask());
892 >            try {
893 >                e.invokeAny(l);
894 >                shouldThrow();
895 >            } catch (ExecutionException success) {
896 >                assertTrue(success.getCause() instanceof NullPointerException);
897 >            }
898          }
899      }
900  
# Line 928 | Line 902 | public class ScheduledExecutorTest exten
902       * invokeAny(c) returns result of some task
903       */
904      public void testInvokeAny5() throws Exception {
905 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
906 <        try {
905 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
906 >        try (PoolCleaner cleaner = cleaner(e)) {
907              List<Callable<String>> l = new ArrayList<Callable<String>>();
908              l.add(new StringTask());
909              l.add(new StringTask());
910              String result = e.invokeAny(l);
911              assertSame(TEST_STRING, result);
938        } finally {
939            joinPool(e);
912          }
913      }
914  
# Line 944 | Line 916 | public class ScheduledExecutorTest exten
916       * invokeAll(null) throws NPE
917       */
918      public void testInvokeAll1() throws Exception {
919 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
920 <        try {
921 <            e.invokeAll(null);
922 <            shouldThrow();
923 <        } catch (NullPointerException success) {
924 <        } finally {
953 <            joinPool(e);
919 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
920 >        try (PoolCleaner cleaner = cleaner(e)) {
921 >            try {
922 >                e.invokeAll(null);
923 >                shouldThrow();
924 >            } catch (NullPointerException success) {}
925          }
926      }
927  
# Line 958 | Line 929 | public class ScheduledExecutorTest exten
929       * invokeAll(empty collection) returns empty collection
930       */
931      public void testInvokeAll2() throws Exception {
932 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
933 <        try {
932 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
933 >        try (PoolCleaner cleaner = cleaner(e)) {
934              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
935              assertTrue(r.isEmpty());
965        } finally {
966            joinPool(e);
936          }
937      }
938  
# Line 971 | Line 940 | public class ScheduledExecutorTest exten
940       * invokeAll(c) throws NPE if c has null elements
941       */
942      public void testInvokeAll3() throws Exception {
943 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
944 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
945 <        l.add(new StringTask());
946 <        l.add(null);
947 <        try {
948 <            e.invokeAll(l);
949 <            shouldThrow();
950 <        } catch (NullPointerException success) {
951 <        } finally {
983 <            joinPool(e);
943 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
944 >        try (PoolCleaner cleaner = cleaner(e)) {
945 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
946 >            l.add(new StringTask());
947 >            l.add(null);
948 >            try {
949 >                e.invokeAll(l);
950 >                shouldThrow();
951 >            } catch (NullPointerException success) {}
952          }
953      }
954  
# Line 988 | Line 956 | public class ScheduledExecutorTest exten
956       * get of invokeAll(c) throws exception on failed task
957       */
958      public void testInvokeAll4() throws Exception {
959 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
960 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
961 <        l.add(new NPETask());
962 <        List<Future<String>> futures = e.invokeAll(l);
963 <        assertEquals(1, futures.size());
964 <        try {
965 <            futures.get(0).get();
966 <            shouldThrow();
967 <        } catch (ExecutionException success) {
968 <            assertTrue(success.getCause() instanceof NullPointerException);
969 <        } finally {
970 <            joinPool(e);
959 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
960 >        try (PoolCleaner cleaner = cleaner(e)) {
961 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
962 >            l.add(new NPETask());
963 >            List<Future<String>> futures = e.invokeAll(l);
964 >            assertEquals(1, futures.size());
965 >            try {
966 >                futures.get(0).get();
967 >                shouldThrow();
968 >            } catch (ExecutionException success) {
969 >                assertTrue(success.getCause() instanceof NullPointerException);
970 >            }
971          }
972      }
973  
# Line 1007 | Line 975 | public class ScheduledExecutorTest exten
975       * invokeAll(c) returns results of all completed tasks
976       */
977      public void testInvokeAll5() throws Exception {
978 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
979 <        try {
978 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
979 >        try (PoolCleaner cleaner = cleaner(e)) {
980              List<Callable<String>> l = new ArrayList<Callable<String>>();
981              l.add(new StringTask());
982              l.add(new StringTask());
# Line 1016 | Line 984 | public class ScheduledExecutorTest exten
984              assertEquals(2, futures.size());
985              for (Future<String> future : futures)
986                  assertSame(TEST_STRING, future.get());
1019        } finally {
1020            joinPool(e);
987          }
988      }
989  
# Line 1025 | Line 991 | public class ScheduledExecutorTest exten
991       * timed invokeAny(null) throws NPE
992       */
993      public void testTimedInvokeAny1() throws Exception {
994 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
995 <        try {
996 <            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
997 <            shouldThrow();
998 <        } catch (NullPointerException success) {
999 <        } finally {
1034 <            joinPool(e);
994 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
995 >        try (PoolCleaner cleaner = cleaner(e)) {
996 >            try {
997 >                e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
998 >                shouldThrow();
999 >            } catch (NullPointerException success) {}
1000          }
1001      }
1002  
# Line 1039 | Line 1004 | public class ScheduledExecutorTest exten
1004       * timed invokeAny(,,null) throws NPE
1005       */
1006      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1007 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1008 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1009 <        l.add(new StringTask());
1010 <        try {
1011 <            e.invokeAny(l, MEDIUM_DELAY_MS, null);
1012 <            shouldThrow();
1013 <        } catch (NullPointerException success) {
1014 <        } finally {
1050 <            joinPool(e);
1007 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1008 >        try (PoolCleaner cleaner = cleaner(e)) {
1009 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1010 >            l.add(new StringTask());
1011 >            try {
1012 >                e.invokeAny(l, MEDIUM_DELAY_MS, null);
1013 >                shouldThrow();
1014 >            } catch (NullPointerException success) {}
1015          }
1016      }
1017  
# Line 1055 | Line 1019 | public class ScheduledExecutorTest exten
1019       * timed invokeAny(empty collection) throws IAE
1020       */
1021      public void testTimedInvokeAny2() throws Exception {
1022 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1023 <        try {
1024 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1025 <            shouldThrow();
1026 <        } catch (IllegalArgumentException success) {
1027 <        } finally {
1064 <            joinPool(e);
1022 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1023 >        try (PoolCleaner cleaner = cleaner(e)) {
1024 >            try {
1025 >                e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1026 >                shouldThrow();
1027 >            } catch (IllegalArgumentException success) {}
1028          }
1029      }
1030  
# Line 1070 | Line 1033 | public class ScheduledExecutorTest exten
1033       */
1034      public void testTimedInvokeAny3() throws Exception {
1035          CountDownLatch latch = new CountDownLatch(1);
1036 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1037 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1038 <        l.add(latchAwaitingStringTask(latch));
1039 <        l.add(null);
1040 <        try {
1041 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1042 <            shouldThrow();
1043 <        } catch (NullPointerException success) {
1044 <        } finally {
1036 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1037 >        try (PoolCleaner cleaner = cleaner(e)) {
1038 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1039 >            l.add(latchAwaitingStringTask(latch));
1040 >            l.add(null);
1041 >            try {
1042 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1043 >                shouldThrow();
1044 >            } catch (NullPointerException success) {}
1045              latch.countDown();
1083            joinPool(e);
1046          }
1047      }
1048  
# Line 1088 | Line 1050 | public class ScheduledExecutorTest exten
1050       * timed invokeAny(c) throws ExecutionException if no task completes
1051       */
1052      public void testTimedInvokeAny4() throws Exception {
1053 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1054 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1055 <        l.add(new NPETask());
1056 <        try {
1057 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1058 <            shouldThrow();
1059 <        } catch (ExecutionException success) {
1060 <            assertTrue(success.getCause() instanceof NullPointerException);
1061 <        } finally {
1062 <            joinPool(e);
1053 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1054 >        try (PoolCleaner cleaner = cleaner(e)) {
1055 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1056 >            l.add(new NPETask());
1057 >            try {
1058 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1059 >                shouldThrow();
1060 >            } catch (ExecutionException success) {
1061 >                assertTrue(success.getCause() instanceof NullPointerException);
1062 >            }
1063          }
1064      }
1065  
# Line 1105 | Line 1067 | public class ScheduledExecutorTest exten
1067       * timed invokeAny(c) returns result of some task
1068       */
1069      public void testTimedInvokeAny5() throws Exception {
1070 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1071 <        try {
1070 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1071 >        try (PoolCleaner cleaner = cleaner(e)) {
1072              List<Callable<String>> l = new ArrayList<Callable<String>>();
1073              l.add(new StringTask());
1074              l.add(new StringTask());
1075              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1076              assertSame(TEST_STRING, result);
1115        } finally {
1116            joinPool(e);
1077          }
1078      }
1079  
# Line 1121 | Line 1081 | public class ScheduledExecutorTest exten
1081       * timed invokeAll(null) throws NPE
1082       */
1083      public void testTimedInvokeAll1() throws Exception {
1084 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1085 <        try {
1086 <            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
1087 <            shouldThrow();
1088 <        } catch (NullPointerException success) {
1089 <        } finally {
1130 <            joinPool(e);
1084 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1085 >        try (PoolCleaner cleaner = cleaner(e)) {
1086 >            try {
1087 >                e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
1088 >                shouldThrow();
1089 >            } catch (NullPointerException success) {}
1090          }
1091      }
1092  
# Line 1135 | Line 1094 | public class ScheduledExecutorTest exten
1094       * timed invokeAll(,,null) throws NPE
1095       */
1096      public void testTimedInvokeAllNullTimeUnit() throws Exception {
1097 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1098 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1099 <        l.add(new StringTask());
1100 <        try {
1101 <            e.invokeAll(l, MEDIUM_DELAY_MS, null);
1102 <            shouldThrow();
1103 <        } catch (NullPointerException success) {
1104 <        } finally {
1146 <            joinPool(e);
1097 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1098 >        try (PoolCleaner cleaner = cleaner(e)) {
1099 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1100 >            l.add(new StringTask());
1101 >            try {
1102 >                e.invokeAll(l, MEDIUM_DELAY_MS, null);
1103 >                shouldThrow();
1104 >            } catch (NullPointerException success) {}
1105          }
1106      }
1107  
# Line 1151 | Line 1109 | public class ScheduledExecutorTest exten
1109       * timed invokeAll(empty collection) returns empty collection
1110       */
1111      public void testTimedInvokeAll2() throws Exception {
1112 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1113 <        try {
1114 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1112 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1113 >        try (PoolCleaner cleaner = cleaner(e)) {
1114 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(),
1115 >                                                 MEDIUM_DELAY_MS, MILLISECONDS);
1116              assertTrue(r.isEmpty());
1158        } finally {
1159            joinPool(e);
1117          }
1118      }
1119  
# Line 1164 | Line 1121 | public class ScheduledExecutorTest exten
1121       * timed invokeAll(c) throws NPE if c has null elements
1122       */
1123      public void testTimedInvokeAll3() throws Exception {
1124 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1125 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1126 <        l.add(new StringTask());
1127 <        l.add(null);
1128 <        try {
1129 <            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1130 <            shouldThrow();
1131 <        } catch (NullPointerException success) {
1132 <        } finally {
1176 <            joinPool(e);
1124 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1125 >        try (PoolCleaner cleaner = cleaner(e)) {
1126 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1127 >            l.add(new StringTask());
1128 >            l.add(null);
1129 >            try {
1130 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1131 >                shouldThrow();
1132 >            } catch (NullPointerException success) {}
1133          }
1134      }
1135  
# Line 1181 | Line 1137 | public class ScheduledExecutorTest exten
1137       * get of element of invokeAll(c) throws exception on failed task
1138       */
1139      public void testTimedInvokeAll4() throws Exception {
1140 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1141 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1142 <        l.add(new NPETask());
1143 <        List<Future<String>> futures =
1144 <            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1145 <        assertEquals(1, futures.size());
1146 <        try {
1147 <            futures.get(0).get();
1148 <            shouldThrow();
1149 <        } catch (ExecutionException success) {
1150 <            assertTrue(success.getCause() instanceof NullPointerException);
1151 <        } finally {
1152 <            joinPool(e);
1140 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1141 >        try (PoolCleaner cleaner = cleaner(e)) {
1142 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1143 >            l.add(new NPETask());
1144 >            List<Future<String>> futures =
1145 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1146 >            assertEquals(1, futures.size());
1147 >            try {
1148 >                futures.get(0).get();
1149 >                shouldThrow();
1150 >            } catch (ExecutionException success) {
1151 >                assertTrue(success.getCause() instanceof NullPointerException);
1152 >            }
1153          }
1154      }
1155  
# Line 1201 | Line 1157 | public class ScheduledExecutorTest exten
1157       * timed invokeAll(c) returns results of all completed tasks
1158       */
1159      public void testTimedInvokeAll5() throws Exception {
1160 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1161 <        try {
1160 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1161 >        try (PoolCleaner cleaner = cleaner(e)) {
1162              List<Callable<String>> l = new ArrayList<Callable<String>>();
1163              l.add(new StringTask());
1164              l.add(new StringTask());
# Line 1211 | Line 1167 | public class ScheduledExecutorTest exten
1167              assertEquals(2, futures.size());
1168              for (Future<String> future : futures)
1169                  assertSame(TEST_STRING, future.get());
1214        } finally {
1215            joinPool(e);
1170          }
1171      }
1172  
# Line 1220 | Line 1174 | public class ScheduledExecutorTest exten
1174       * timed invokeAll(c) cancels tasks not completed by timeout
1175       */
1176      public void testTimedInvokeAll6() throws Exception {
1177 <        ExecutorService e = new ScheduledThreadPoolExecutor(2);
1178 <        try {
1177 >        final ExecutorService e = new ScheduledThreadPoolExecutor(2);
1178 >        try (PoolCleaner cleaner = cleaner(e)) {
1179              for (long timeout = timeoutMillis();;) {
1180                  List<Callable<String>> tasks = new ArrayList<>();
1181                  tasks.add(new StringTask("0"));
# Line 1245 | Line 1199 | public class ScheduledExecutorTest exten
1199                          fail("expected exactly one task to be cancelled");
1200                  }
1201              }
1248        } finally {
1249            joinPool(e);
1202          }
1203      }
1204  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines