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

Comparing jsr166/src/test/tck/ScheduledExecutorSubclassTest.java (file contents):
Revision 1.10 by jsr166, Tue Dec 1 09:48:12 2009 UTC vs.
Revision 1.18 by jsr166, Tue Nov 30 02:12:52 2010 UTC

# Line 12 | Line 12 | import java.util.concurrent.atomic.*;
12  
13   public class ScheduledExecutorSubclassTest extends JSR166TestCase {
14      public static void main(String[] args) {
15 <        junit.textui.TestRunner.run (suite());
15 >        junit.textui.TestRunner.run(suite());
16      }
17      public static Test suite() {
18          return new TestSuite(ScheduledExecutorSubclassTest.class);
# Line 78 | Line 78 | public class ScheduledExecutorSubclassTe
78       * execute successfully executes a runnable
79       */
80      public void testExecute() throws InterruptedException {
81 <        TrackedShortRunnable runnable =new TrackedShortRunnable();
82 <        CustomExecutor p1 = new CustomExecutor(1);
83 <        p1.execute(runnable);
84 <        assertFalse(runnable.done);
85 <        Thread.sleep(SHORT_DELAY_MS);
86 <        try { p1.shutdown(); } catch (SecurityException ok) { return; }
87 <        Thread.sleep(MEDIUM_DELAY_MS);
88 <        assertTrue(runnable.done);
89 <        try { p1.shutdown(); } catch (SecurityException ok) { return; }
90 <        joinPool(p1);
81 >        CustomExecutor p = new CustomExecutor(1);
82 >        final CountDownLatch done = new CountDownLatch(1);
83 >        final Runnable task = new CheckedRunnable() {
84 >            public void realRun() {
85 >                done.countDown();
86 >            }};
87 >        try {
88 >            p.execute(task);
89 >            assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS));
90 >        } finally {
91 >            joinPool(p);
92 >        }
93      }
94  
95  
# Line 95 | Line 97 | public class ScheduledExecutorSubclassTe
97       * delayed schedule of callable successfully executes after delay
98       */
99      public void testSchedule1() throws Exception {
100 <        TrackedCallable callable = new TrackedCallable();
101 <        CustomExecutor p1 = new CustomExecutor(1);
102 <        Future f = p1.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
103 <        assertFalse(callable.done);
104 <        Thread.sleep(MEDIUM_DELAY_MS);
105 <        assertTrue(callable.done);
106 <        assertEquals(Boolean.TRUE, f.get());
107 <        try { p1.shutdown(); } catch (SecurityException ok) { return; }
108 <        joinPool(p1);
100 >        CustomExecutor p = new CustomExecutor(1);
101 >        final long t0 = System.nanoTime();
102 >        final long timeoutNanos = SHORT_DELAY_MS * 1000L * 1000L;
103 >        final CountDownLatch done = new CountDownLatch(1);
104 >        try {
105 >            Callable task = new CheckedCallable<Boolean>() {
106 >                public Boolean realCall() {
107 >                    done.countDown();
108 >                    assertTrue(System.nanoTime() - t0 >= timeoutNanos);
109 >                    return Boolean.TRUE;
110 >                }};
111 >            Future f = p.schedule(task, SHORT_DELAY_MS, MILLISECONDS);
112 >            assertEquals(Boolean.TRUE, f.get());
113 >            assertTrue(System.nanoTime() - t0 >= timeoutNanos);
114 >            assertTrue(done.await(0L, MILLISECONDS));
115 >        } finally {
116 >            joinPool(p);
117 >        }
118      }
119  
120      /**
121 <     *  delayed schedule of runnable successfully executes after delay
122 <     */
123 <    public void testSchedule3() throws InterruptedException {
124 <        TrackedShortRunnable runnable = new TrackedShortRunnable();
125 <        CustomExecutor p1 = new CustomExecutor(1);
126 <        p1.schedule(runnable, SMALL_DELAY_MS, MILLISECONDS);
127 <        Thread.sleep(SHORT_DELAY_MS);
128 <        assertFalse(runnable.done);
129 <        Thread.sleep(MEDIUM_DELAY_MS);
130 <        assertTrue(runnable.done);
131 <        try { p1.shutdown(); } catch (SecurityException ok) { return; }
132 <        joinPool(p1);
121 >     * delayed schedule of runnable successfully executes after delay
122 >     */
123 >    public void testSchedule3() throws Exception {
124 >        CustomExecutor p = new CustomExecutor(1);
125 >        final long t0 = System.nanoTime();
126 >        final long timeoutNanos = SHORT_DELAY_MS * 1000L * 1000L;
127 >        final CountDownLatch done = new CountDownLatch(1);
128 >        try {
129 >            Runnable task = new CheckedRunnable() {
130 >                public void realRun() {
131 >                    done.countDown();
132 >                    assertTrue(System.nanoTime() - t0 >= timeoutNanos);
133 >                }};
134 >            Future f = p.schedule(task, SHORT_DELAY_MS, MILLISECONDS);
135 >            assertNull(f.get());
136 >            assertTrue(System.nanoTime() - t0 >= timeoutNanos);
137 >            assertTrue(done.await(0L, MILLISECONDS));
138 >        } finally {
139 >            joinPool(p);
140 >        }
141      }
142  
143      /**
144       * scheduleAtFixedRate executes runnable after given initial delay
145       */
146      public void testSchedule4() throws InterruptedException {
147 <        TrackedShortRunnable runnable = new TrackedShortRunnable();
148 <        CustomExecutor p1 = new CustomExecutor(1);
149 <        ScheduledFuture h = p1.scheduleAtFixedRate(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, MILLISECONDS);
150 <        assertFalse(runnable.done);
151 <        Thread.sleep(MEDIUM_DELAY_MS);
152 <        assertTrue(runnable.done);
153 <        h.cancel(true);
154 <        joinPool(p1);
155 <    }
156 <
157 <    static class RunnableCounter implements Runnable {
158 <        AtomicInteger count = new AtomicInteger(0);
159 <        public void run() { count.getAndIncrement(); }
147 >        CustomExecutor p = new CustomExecutor(1);
148 >        final long t0 = System.nanoTime();
149 >        final long timeoutNanos = SHORT_DELAY_MS * 1000L * 1000L;
150 >        final CountDownLatch done = new CountDownLatch(1);
151 >        try {
152 >            Runnable task = new CheckedRunnable() {
153 >                public void realRun() {
154 >                    done.countDown();
155 >                    assertTrue(System.nanoTime() - t0 >= timeoutNanos);
156 >                }};
157 >            ScheduledFuture f =
158 >                p.scheduleAtFixedRate(task, SHORT_DELAY_MS,
159 >                                      SHORT_DELAY_MS, MILLISECONDS);
160 >            assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS));
161 >            assertTrue(System.nanoTime() - t0 >= timeoutNanos);
162 >            f.cancel(true);
163 >        } finally {
164 >            joinPool(p);
165 >        }
166      }
167  
168      /**
169       * scheduleWithFixedDelay executes runnable after given initial delay
170       */
171      public void testSchedule5() throws InterruptedException {
172 <        TrackedShortRunnable runnable = new TrackedShortRunnable();
173 <        CustomExecutor p1 = new CustomExecutor(1);
174 <        ScheduledFuture h = p1.scheduleWithFixedDelay(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, MILLISECONDS);
175 <        assertFalse(runnable.done);
176 <        Thread.sleep(MEDIUM_DELAY_MS);
177 <        assertTrue(runnable.done);
178 <        h.cancel(true);
179 <        joinPool(p1);
172 >        CustomExecutor p = new CustomExecutor(1);
173 >        final long t0 = System.nanoTime();
174 >        final long timeoutNanos = SHORT_DELAY_MS * 1000L * 1000L;
175 >        final CountDownLatch done = new CountDownLatch(1);
176 >        try {
177 >            Runnable task = new CheckedRunnable() {
178 >                public void realRun() {
179 >                    done.countDown();
180 >                    assertTrue(System.nanoTime() - t0 >= timeoutNanos);
181 >                }};
182 >            ScheduledFuture f =
183 >                p.scheduleWithFixedDelay(task, SHORT_DELAY_MS,
184 >                                         SHORT_DELAY_MS, MILLISECONDS);
185 >            assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS));
186 >            assertTrue(System.nanoTime() - t0 >= timeoutNanos);
187 >            f.cancel(true);
188 >        } finally {
189 >            joinPool(p);
190 >        }
191 >    }
192 >
193 >    static class RunnableCounter implements Runnable {
194 >        AtomicInteger count = new AtomicInteger(0);
195 >        public void run() { count.getAndIncrement(); }
196      }
197  
198      /**
199       * scheduleAtFixedRate executes series of tasks at given rate
200       */
201      public void testFixedRateSequence() throws InterruptedException {
202 <        CustomExecutor p1 = new CustomExecutor(1);
202 >        CustomExecutor p = new CustomExecutor(1);
203          RunnableCounter counter = new RunnableCounter();
204          ScheduledFuture h =
205 <            p1.scheduleAtFixedRate(counter, 0, 1, MILLISECONDS);
205 >            p.scheduleAtFixedRate(counter, 0, 1, MILLISECONDS);
206          Thread.sleep(SMALL_DELAY_MS);
207          h.cancel(true);
208          int c = counter.count.get();
# Line 169 | Line 210 | public class ScheduledExecutorSubclassTe
210          // an execution per SHORT delay, but no more than one SHORT more
211          assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
212          assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
213 <        joinPool(p1);
213 >        joinPool(p);
214      }
215  
216      /**
217       * scheduleWithFixedDelay executes series of tasks with given period
218       */
219      public void testFixedDelaySequence() throws InterruptedException {
220 <        CustomExecutor p1 = new CustomExecutor(1);
220 >        CustomExecutor p = new CustomExecutor(1);
221          RunnableCounter counter = new RunnableCounter();
222          ScheduledFuture h =
223 <            p1.scheduleWithFixedDelay(counter, 0, 1, MILLISECONDS);
223 >            p.scheduleWithFixedDelay(counter, 0, 1, MILLISECONDS);
224          Thread.sleep(SMALL_DELAY_MS);
225          h.cancel(true);
226          int c = counter.count.get();
227          assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
228          assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
229 <        joinPool(p1);
229 >        joinPool(p);
230      }
231  
232  
233      /**
234 <     *  execute (null) throws NPE
234 >     * execute(null) throws NPE
235       */
236      public void testExecuteNull() throws InterruptedException {
237          CustomExecutor se = new CustomExecutor(1);
# Line 202 | Line 243 | public class ScheduledExecutorSubclassTe
243      }
244  
245      /**
246 <     * schedule (null) throws NPE
246 >     * schedule(null) throws NPE
247       */
248      public void testScheduleNull() throws InterruptedException {
249          CustomExecutor se = new CustomExecutor(1);
# Line 264 | Line 305 | public class ScheduledExecutorSubclassTe
305      }
306  
307      /**
308 <     *  scheduleAtFixedRate throws RejectedExecutionException if shutdown
308 >     * scheduleAtFixedRate throws RejectedExecutionException if shutdown
309       */
310      public void testScheduleAtFixedRate1_RejectedExecutionException() {
311          CustomExecutor se = new CustomExecutor(1);
# Line 296 | Line 337 | public class ScheduledExecutorSubclassTe
337      }
338  
339      /**
340 <     *  getActiveCount increases but doesn't overestimate, when a
341 <     *  thread becomes active
340 >     * getActiveCount increases but doesn't overestimate, when a
341 >     * thread becomes active
342       */
343      public void testGetActiveCount() throws InterruptedException {
344 <        CustomExecutor p2 = new CustomExecutor(2);
345 <        assertEquals(0, p2.getActiveCount());
346 <        p2.execute(new SmallRunnable());
347 <        Thread.sleep(SHORT_DELAY_MS);
348 <        assertEquals(1, p2.getActiveCount());
349 <        joinPool(p2);
344 >        final ThreadPoolExecutor p = new CustomExecutor(2);
345 >        final CountDownLatch threadStarted = new CountDownLatch(1);
346 >        final CountDownLatch done = new CountDownLatch(1);
347 >        try {
348 >            assertEquals(0, p.getActiveCount());
349 >            p.execute(new CheckedRunnable() {
350 >                public void realRun() throws InterruptedException {
351 >                    threadStarted.countDown();
352 >                    assertEquals(1, p.getActiveCount());
353 >                    done.await();
354 >                }});
355 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
356 >            assertEquals(1, p.getActiveCount());
357 >        } finally {
358 >            done.countDown();
359 >            joinPool(p);
360 >        }
361      }
362  
363      /**
364 <     *    getCompletedTaskCount increases, but doesn't overestimate,
365 <     *   when tasks complete
364 >     * getCompletedTaskCount increases, but doesn't overestimate,
365 >     * when tasks complete
366       */
367      public void testGetCompletedTaskCount() throws InterruptedException {
368 <        CustomExecutor p2 = new CustomExecutor(2);
369 <        assertEquals(0, p2.getCompletedTaskCount());
370 <        p2.execute(new SmallRunnable());
371 <        Thread.sleep(MEDIUM_DELAY_MS);
372 <        assertEquals(1, p2.getCompletedTaskCount());
373 <        joinPool(p2);
368 >        final ThreadPoolExecutor p = new CustomExecutor(2);
369 >        final CountDownLatch threadStarted = new CountDownLatch(1);
370 >        final CountDownLatch threadProceed = new CountDownLatch(1);
371 >        final CountDownLatch threadDone = new CountDownLatch(1);
372 >        try {
373 >            assertEquals(0, p.getCompletedTaskCount());
374 >            p.execute(new CheckedRunnable() {
375 >                public void realRun() throws InterruptedException {
376 >                    threadStarted.countDown();
377 >                    assertEquals(0, p.getCompletedTaskCount());
378 >                    threadProceed.await();
379 >                    threadDone.countDown();
380 >                }});
381 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
382 >            assertEquals(0, p.getCompletedTaskCount());
383 >            threadProceed.countDown();
384 >            threadDone.await();
385 >            Thread.sleep(SHORT_DELAY_MS);
386 >            assertEquals(1, p.getCompletedTaskCount());
387 >        } finally {
388 >            joinPool(p);
389 >        }
390      }
391  
392      /**
393 <     *  getCorePoolSize returns size given in constructor if not otherwise set
393 >     * getCorePoolSize returns size given in constructor if not otherwise set
394       */
395      public void testGetCorePoolSize() {
396 <        CustomExecutor p1 = new CustomExecutor(1);
397 <        assertEquals(1, p1.getCorePoolSize());
398 <        joinPool(p1);
396 >        CustomExecutor p = new CustomExecutor(1);
397 >        assertEquals(1, p.getCorePoolSize());
398 >        joinPool(p);
399      }
400  
401      /**
402 <     *    getLargestPoolSize increases, but doesn't overestimate, when
403 <     *   multiple threads active
402 >     * getLargestPoolSize increases, but doesn't overestimate, when
403 >     * multiple threads active
404       */
405      public void testGetLargestPoolSize() throws InterruptedException {
406 <        CustomExecutor p2 = new CustomExecutor(2);
407 <        assertEquals(0, p2.getLargestPoolSize());
408 <        p2.execute(new SmallRunnable());
409 <        p2.execute(new SmallRunnable());
410 <        Thread.sleep(SHORT_DELAY_MS);
411 <        assertEquals(2, p2.getLargestPoolSize());
412 <        joinPool(p2);
406 >        final int THREADS = 3;
407 >        final ThreadPoolExecutor p = new CustomExecutor(THREADS);
408 >        final CountDownLatch threadsStarted = new CountDownLatch(THREADS);
409 >        final CountDownLatch done = new CountDownLatch(1);
410 >        try {
411 >            assertEquals(0, p.getLargestPoolSize());
412 >            for (int i = 0; i < THREADS; i++)
413 >                p.execute(new CheckedRunnable() {
414 >                    public void realRun() throws InterruptedException {
415 >                        threadsStarted.countDown();
416 >                        done.await();
417 >                        assertEquals(THREADS, p.getLargestPoolSize());
418 >                    }});
419 >            assertTrue(threadsStarted.await(SMALL_DELAY_MS, MILLISECONDS));
420 >            assertEquals(THREADS, p.getLargestPoolSize());
421 >        } finally {
422 >            done.countDown();
423 >            joinPool(p);
424 >            assertEquals(THREADS, p.getLargestPoolSize());
425 >        }
426      }
427  
428      /**
429 <     *   getPoolSize increases, but doesn't overestimate, when threads
430 <     *   become active
429 >     * getPoolSize increases, but doesn't overestimate, when threads
430 >     * become active
431       */
432 <    public void testGetPoolSize() {
433 <        CustomExecutor p1 = new CustomExecutor(1);
434 <        assertEquals(0, p1.getPoolSize());
435 <        p1.execute(new SmallRunnable());
436 <        assertEquals(1, p1.getPoolSize());
437 <        joinPool(p1);
432 >    public void testGetPoolSize() throws InterruptedException {
433 >        final ThreadPoolExecutor p = new CustomExecutor(1);
434 >        final CountDownLatch threadStarted = new CountDownLatch(1);
435 >        final CountDownLatch done = new CountDownLatch(1);
436 >        try {
437 >            assertEquals(0, p.getPoolSize());
438 >            p.execute(new CheckedRunnable() {
439 >                public void realRun() throws InterruptedException {
440 >                    threadStarted.countDown();
441 >                    assertEquals(1, p.getPoolSize());
442 >                    done.await();
443 >                }});
444 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
445 >            assertEquals(1, p.getPoolSize());
446 >        } finally {
447 >            done.countDown();
448 >            joinPool(p);
449 >        }
450      }
451  
452      /**
453 <     *    getTaskCount increases, but doesn't overestimate, when tasks
454 <     *    submitted
453 >     * getTaskCount increases, but doesn't overestimate, when tasks
454 >     * submitted
455       */
456      public void testGetTaskCount() throws InterruptedException {
457 <        CustomExecutor p1 = new CustomExecutor(1);
458 <        assertEquals(0, p1.getTaskCount());
459 <        for (int i = 0; i < 5; i++)
460 <            p1.execute(new SmallRunnable());
461 <        Thread.sleep(SHORT_DELAY_MS);
462 <        assertEquals(5, p1.getTaskCount());
463 <        joinPool(p1);
457 >        final ThreadPoolExecutor p = new CustomExecutor(1);
458 >        final CountDownLatch threadStarted = new CountDownLatch(1);
459 >        final CountDownLatch done = new CountDownLatch(1);
460 >        final int TASKS = 5;
461 >        try {
462 >            assertEquals(0, p.getTaskCount());
463 >            for (int i = 0; i < TASKS; i++)
464 >                p.execute(new CheckedRunnable() {
465 >                    public void realRun() throws InterruptedException {
466 >                        threadStarted.countDown();
467 >                        done.await();
468 >                    }});
469 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
470 >            assertEquals(TASKS, p.getTaskCount());
471 >        } finally {
472 >            done.countDown();
473 >            joinPool(p);
474 >        }
475      }
476  
477      /**
# Line 406 | Line 510 | public class ScheduledExecutorSubclassTe
510      }
511  
512      /**
513 <     *   is isShutDown is false before shutdown, true after
513 >     * isShutDown is false before shutdown, true after
514       */
515      public void testIsShutdown() {
516 <        CustomExecutor p1 = new CustomExecutor(1);
516 >        CustomExecutor p = new CustomExecutor(1);
517          try {
518 <            assertFalse(p1.isShutdown());
518 >            assertFalse(p.isShutdown());
519          }
520          finally {
521 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
521 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
522          }
523 <        assertTrue(p1.isShutdown());
523 >        assertTrue(p.isShutdown());
524      }
525  
526  
527      /**
528 <     *  isTerminated is false before termination, true after
528 >     * isTerminated is false before termination, true after
529       */
530      public void testIsTerminated() throws InterruptedException {
531 <        CustomExecutor p1 = new CustomExecutor(1);
531 >        final ThreadPoolExecutor p = new CustomExecutor(1);
532 >        final CountDownLatch threadStarted = new CountDownLatch(1);
533 >        final CountDownLatch done = new CountDownLatch(1);
534 >        assertFalse(p.isTerminated());
535          try {
536 <            p1.execute(new SmallRunnable());
536 >            p.execute(new CheckedRunnable() {
537 >                public void realRun() throws InterruptedException {
538 >                    assertFalse(p.isTerminated());
539 >                    threadStarted.countDown();
540 >                    done.await();
541 >                }});
542 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
543 >            assertFalse(p.isTerminating());
544 >            done.countDown();
545          } finally {
546 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
546 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
547          }
548 <        assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
549 <        assertTrue(p1.isTerminated());
548 >        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
549 >        assertTrue(p.isTerminated());
550      }
551  
552      /**
553 <     *  isTerminating is not true when running or when terminated
553 >     * isTerminating is not true when running or when terminated
554       */
555      public void testIsTerminating() throws InterruptedException {
556 <        CustomExecutor p1 = new CustomExecutor(1);
557 <        assertFalse(p1.isTerminating());
558 <        try {
559 <            p1.execute(new SmallRunnable());
560 <            assertFalse(p1.isTerminating());
561 <        } finally {
562 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
563 <        }
564 <        assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
565 <        assertTrue(p1.isTerminated());
566 <        assertFalse(p1.isTerminating());
556 >        final ThreadPoolExecutor p = new CustomExecutor(1);
557 >        final CountDownLatch threadStarted = new CountDownLatch(1);
558 >        final CountDownLatch done = new CountDownLatch(1);
559 >        try {
560 >            assertFalse(p.isTerminating());
561 >            p.execute(new CheckedRunnable() {
562 >                public void realRun() throws InterruptedException {
563 >                    assertFalse(p.isTerminating());
564 >                    threadStarted.countDown();
565 >                    done.await();
566 >                }});
567 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
568 >            assertFalse(p.isTerminating());
569 >            done.countDown();
570 >        } finally {
571 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
572 >        }
573 >        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
574 >        assertTrue(p.isTerminated());
575 >        assertFalse(p.isTerminating());
576      }
577  
578      /**
579       * getQueue returns the work queue, which contains queued tasks
580       */
581      public void testGetQueue() throws InterruptedException {
582 <        CustomExecutor p1 = new CustomExecutor(1);
583 <        ScheduledFuture[] tasks = new ScheduledFuture[5];
584 <        for (int i = 0; i < 5; i++) {
585 <            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, MILLISECONDS);
586 <        }
587 <        try {
588 <            Thread.sleep(SHORT_DELAY_MS);
589 <            BlockingQueue<Runnable> q = p1.getQueue();
590 <            assertTrue(q.contains(tasks[4]));
582 >        ScheduledThreadPoolExecutor p = new CustomExecutor(1);
583 >        final CountDownLatch threadStarted = new CountDownLatch(1);
584 >        final CountDownLatch done = new CountDownLatch(1);
585 >        try {
586 >            ScheduledFuture[] tasks = new ScheduledFuture[5];
587 >            for (int i = 0; i < tasks.length; i++) {
588 >                Runnable r = new CheckedRunnable() {
589 >                    public void realRun() throws InterruptedException {
590 >                        threadStarted.countDown();
591 >                        done.await();
592 >                    }};
593 >                tasks[i] = p.schedule(r, 1, MILLISECONDS);
594 >            }
595 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
596 >            BlockingQueue<Runnable> q = p.getQueue();
597 >            assertTrue(q.contains(tasks[tasks.length - 1]));
598              assertFalse(q.contains(tasks[0]));
599          } finally {
600 <            joinPool(p1);
600 >            done.countDown();
601 >            joinPool(p);
602          }
603      }
604  
# Line 474 | Line 606 | public class ScheduledExecutorSubclassTe
606       * remove(task) removes queued task, and fails to remove active task
607       */
608      public void testRemove() throws InterruptedException {
609 <        CustomExecutor p1 = new CustomExecutor(1);
609 >        final ScheduledThreadPoolExecutor p = new CustomExecutor(1);
610          ScheduledFuture[] tasks = new ScheduledFuture[5];
611 <        for (int i = 0; i < 5; i++) {
612 <            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, MILLISECONDS);
481 <        }
611 >        final CountDownLatch threadStarted = new CountDownLatch(1);
612 >        final CountDownLatch done = new CountDownLatch(1);
613          try {
614 <            Thread.sleep(SHORT_DELAY_MS);
615 <            BlockingQueue<Runnable> q = p1.getQueue();
616 <            assertFalse(p1.remove((Runnable)tasks[0]));
614 >            for (int i = 0; i < tasks.length; i++) {
615 >                Runnable r = new CheckedRunnable() {
616 >                    public void realRun() throws InterruptedException {
617 >                        threadStarted.countDown();
618 >                        done.await();
619 >                    }};
620 >                tasks[i] = p.schedule(r, 1, MILLISECONDS);
621 >            }
622 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
623 >            BlockingQueue<Runnable> q = p.getQueue();
624 >            assertFalse(p.remove((Runnable)tasks[0]));
625              assertTrue(q.contains((Runnable)tasks[4]));
626              assertTrue(q.contains((Runnable)tasks[3]));
627 <            assertTrue(p1.remove((Runnable)tasks[4]));
628 <            assertFalse(p1.remove((Runnable)tasks[4]));
627 >            assertTrue(p.remove((Runnable)tasks[4]));
628 >            assertFalse(p.remove((Runnable)tasks[4]));
629              assertFalse(q.contains((Runnable)tasks[4]));
630              assertTrue(q.contains((Runnable)tasks[3]));
631 <            assertTrue(p1.remove((Runnable)tasks[3]));
631 >            assertTrue(p.remove((Runnable)tasks[3]));
632              assertFalse(q.contains((Runnable)tasks[3]));
633          } finally {
634 <            joinPool(p1);
634 >            done.countDown();
635 >            joinPool(p);
636          }
637      }
638  
639      /**
640 <     *  purge removes cancelled tasks from the queue
640 >     * purge removes cancelled tasks from the queue
641       */
642      public void testPurge() throws InterruptedException {
643 <        CustomExecutor p1 = new CustomExecutor(1);
643 >        CustomExecutor p = new CustomExecutor(1);
644          ScheduledFuture[] tasks = new ScheduledFuture[5];
645 <        for (int i = 0; i < 5; i++) {
646 <            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS);
645 >        for (int i = 0; i < tasks.length; i++) {
646 >            tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS);
647          }
648          try {
649 <            int max = 5;
649 >            int max = tasks.length;
650              if (tasks[4].cancel(true)) --max;
651              if (tasks[3].cancel(true)) --max;
652              // There must eventually be an interference-free point at
653              // which purge will not fail. (At worst, when queue is empty.)
654              int k;
655              for (k = 0; k < SMALL_DELAY_MS; ++k) {
656 <                p1.purge();
657 <                long count = p1.getTaskCount();
656 >                p.purge();
657 >                long count = p.getTaskCount();
658                  if (count >= 0 && count <= max)
659                      break;
660                  Thread.sleep(1);
661              }
662              assertTrue(k < SMALL_DELAY_MS);
663          } finally {
664 <            joinPool(p1);
664 >            for (ScheduledFuture task : tasks)
665 >                task.cancel(true);
666 >            joinPool(p);
667          }
668      }
669  
670      /**
671 <     *  shutDownNow returns a list containing tasks that were not run
671 >     * shutDownNow returns a list containing tasks that were not run
672       */
673      public void testShutDownNow() {
674 <        CustomExecutor p1 = new CustomExecutor(1);
674 >        CustomExecutor p = new CustomExecutor(1);
675          for (int i = 0; i < 5; i++)
676 <            p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS);
676 >            p.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS);
677          List l;
678          try {
679 <            l = p1.shutdownNow();
679 >            l = p.shutdownNow();
680          } catch (SecurityException ok) {
681              return;
682          }
683 <        assertTrue(p1.isShutdown());
683 >        assertTrue(p.isShutdown());
684          assertTrue(l.size() > 0 && l.size() <= 5);
685 <        joinPool(p1);
685 >        joinPool(p);
686      }
687  
688      /**
# Line 548 | Line 690 | public class ScheduledExecutorSubclassTe
690       * tasks at shutdown
691       */
692      public void testShutDown1() throws InterruptedException {
693 <        CustomExecutor p1 = new CustomExecutor(1);
694 <        assertTrue(p1.getExecuteExistingDelayedTasksAfterShutdownPolicy());
695 <        assertFalse(p1.getContinueExistingPeriodicTasksAfterShutdownPolicy());
693 >        CustomExecutor p = new CustomExecutor(1);
694 >        assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy());
695 >        assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy());
696  
697          ScheduledFuture[] tasks = new ScheduledFuture[5];
698 <        for (int i = 0; i < 5; i++)
699 <            tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, MILLISECONDS);
700 <        try { p1.shutdown(); } catch (SecurityException ok) { return; }
701 <        BlockingQueue q = p1.getQueue();
702 <        for (Iterator it = q.iterator(); it.hasNext();) {
703 <            ScheduledFuture t = (ScheduledFuture)it.next();
704 <            assertFalse(t.isCancelled());
698 >        for (int i = 0; i < tasks.length; i++)
699 >            tasks[i] = p.schedule(new NoOpRunnable(),
700 >                                  SHORT_DELAY_MS, MILLISECONDS);
701 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
702 >        BlockingQueue<Runnable> q = p.getQueue();
703 >        for (ScheduledFuture task : tasks) {
704 >            assertFalse(task.isDone());
705 >            assertFalse(task.isCancelled());
706 >            assertTrue(q.contains(task));
707          }
708 <        assertTrue(p1.isShutdown());
709 <        Thread.sleep(SMALL_DELAY_MS);
710 <        for (int i = 0; i < 5; ++i) {
711 <            assertTrue(tasks[i].isDone());
712 <            assertFalse(tasks[i].isCancelled());
708 >        assertTrue(p.isShutdown());
709 >        assertTrue(p.awaitTermination(SMALL_DELAY_MS, MILLISECONDS));
710 >        assertTrue(p.isTerminated());
711 >        for (ScheduledFuture task : tasks) {
712 >            assertTrue(task.isDone());
713 >            assertFalse(task.isCancelled());
714          }
715      }
716  
# Line 575 | Line 720 | public class ScheduledExecutorSubclassTe
720       * delayed tasks are cancelled at shutdown
721       */
722      public void testShutDown2() throws InterruptedException {
723 <        CustomExecutor p1 = new CustomExecutor(1);
724 <        p1.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
723 >        CustomExecutor p = new CustomExecutor(1);
724 >        p.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
725 >        assertFalse(p.getExecuteExistingDelayedTasksAfterShutdownPolicy());
726 >        assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy());
727          ScheduledFuture[] tasks = new ScheduledFuture[5];
728 <        for (int i = 0; i < 5; i++)
729 <            tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, MILLISECONDS);
730 <        try { p1.shutdown(); } catch (SecurityException ok) { return; }
731 <        assertTrue(p1.isShutdown());
732 <        BlockingQueue q = p1.getQueue();
728 >        for (int i = 0; i < tasks.length; i++)
729 >            tasks[i] = p.schedule(new NoOpRunnable(),
730 >                                  SHORT_DELAY_MS, MILLISECONDS);
731 >        BlockingQueue q = p.getQueue();
732 >        assertEquals(tasks.length, q.size());
733 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
734 >        assertTrue(p.isShutdown());
735          assertTrue(q.isEmpty());
736 <        Thread.sleep(SMALL_DELAY_MS);
737 <        assertTrue(p1.isTerminated());
736 >        assertTrue(p.awaitTermination(SMALL_DELAY_MS, MILLISECONDS));
737 >        assertTrue(p.isTerminated());
738 >        for (ScheduledFuture task : tasks) {
739 >            assertTrue(task.isDone());
740 >            assertTrue(task.isCancelled());
741 >        }
742      }
743  
744  
745      /**
746       * If setContinueExistingPeriodicTasksAfterShutdownPolicy is set false,
747 <     * periodic tasks are not cancelled at shutdown
747 >     * periodic tasks are cancelled at shutdown
748       */
749      public void testShutDown3() throws InterruptedException {
750 <        CustomExecutor p1 = new CustomExecutor(1);
751 <        p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
750 >        CustomExecutor p = new CustomExecutor(1);
751 >        assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy());
752 >        assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy());
753 >        p.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
754 >        assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy());
755 >        assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy());
756          ScheduledFuture task =
757 <            p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, MILLISECONDS);
758 <        try { p1.shutdown(); } catch (SecurityException ok) { return; }
759 <        assertTrue(p1.isShutdown());
760 <        BlockingQueue q = p1.getQueue();
761 <        assertTrue(q.isEmpty());
762 <        Thread.sleep(SHORT_DELAY_MS);
763 <        assertTrue(p1.isTerminated());
757 >            p.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, MILLISECONDS);
758 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
759 >        assertTrue(p.isShutdown());
760 >        BlockingQueue q = p.getQueue();
761 >        assertTrue(p.getQueue().isEmpty());
762 >        assertTrue(task.isDone());
763 >        assertTrue(task.isCancelled());
764 >        assertTrue(p.awaitTermination(SMALL_DELAY_MS, MILLISECONDS));
765 >        assertTrue(p.isTerminated());
766      }
767  
768      /**
769       * if setContinueExistingPeriodicTasksAfterShutdownPolicy is true,
770 <     * periodic tasks are cancelled at shutdown
770 >     * periodic tasks are not cancelled at shutdown
771       */
772      public void testShutDown4() throws InterruptedException {
773 <        CustomExecutor p1 = new CustomExecutor(1);
773 >        CustomExecutor p = new CustomExecutor(1);
774 >        final CountDownLatch counter = new CountDownLatch(2);
775          try {
776 <            p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
776 >            p.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
777 >            assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy());
778 >            assertTrue(p.getContinueExistingPeriodicTasksAfterShutdownPolicy());
779 >            final Runnable r = new CheckedRunnable() {
780 >                public void realRun() {
781 >                    counter.countDown();
782 >                }};
783              ScheduledFuture task =
784 <                p1.scheduleAtFixedRate(new NoOpRunnable(), 1, 1, MILLISECONDS);
784 >                p.scheduleAtFixedRate(r, 1, 1, MILLISECONDS);
785 >            assertFalse(task.isDone());
786              assertFalse(task.isCancelled());
787 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
787 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
788              assertFalse(task.isCancelled());
789 <            assertFalse(p1.isTerminated());
790 <            assertTrue(p1.isShutdown());
791 <            Thread.sleep(SHORT_DELAY_MS);
789 >            assertFalse(p.isTerminated());
790 >            assertTrue(p.isShutdown());
791 >            assertTrue(counter.await(SMALL_DELAY_MS, MILLISECONDS));
792              assertFalse(task.isCancelled());
793 <            assertTrue(task.cancel(true));
793 >            assertTrue(task.cancel(false));
794              assertTrue(task.isDone());
795 <            Thread.sleep(SHORT_DELAY_MS);
796 <            assertTrue(p1.isTerminated());
795 >            assertTrue(task.isCancelled());
796 >            assertTrue(p.awaitTermination(SMALL_DELAY_MS, MILLISECONDS));
797 >            assertTrue(p.isTerminated());
798          }
799          finally {
800 <            joinPool(p1);
800 >            joinPool(p);
801          }
802      }
803  
# Line 707 | Line 875 | public class ScheduledExecutorSubclassTe
875       * invokeAny(c) throws NPE if c has null elements
876       */
877      public void testInvokeAny3() throws Exception {
878 <        final CountDownLatch latch = new CountDownLatch(1);
878 >        CountDownLatch latch = new CountDownLatch(1);
879          ExecutorService e = new CustomExecutor(2);
880 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
881 +        l.add(latchAwaitingStringTask(latch));
882 +        l.add(null);
883          try {
713            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
714            l.add(new Callable<String>() {
715                      public String call() {
716                          try {
717                              latch.await();
718                          } catch (InterruptedException quittingTime) {}
719                          return TEST_STRING;
720                      }});
721            l.add(null);
884              e.invokeAny(l);
885              shouldThrow();
886          } catch (NullPointerException success) {
# Line 733 | Line 895 | public class ScheduledExecutorSubclassTe
895       */
896      public void testInvokeAny4() throws Exception {
897          ExecutorService e = new CustomExecutor(2);
898 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
899 +        l.add(new NPETask());
900          try {
737            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
738            l.add(new NPETask());
901              e.invokeAny(l);
902              shouldThrow();
903          } catch (ExecutionException success) {
# Line 751 | Line 913 | public class ScheduledExecutorSubclassTe
913      public void testInvokeAny5() throws Exception {
914          ExecutorService e = new CustomExecutor(2);
915          try {
916 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
916 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
917              l.add(new StringTask());
918              l.add(new StringTask());
919              String result = e.invokeAny(l);
# Line 793 | Line 955 | public class ScheduledExecutorSubclassTe
955       */
956      public void testInvokeAll3() throws Exception {
957          ExecutorService e = new CustomExecutor(2);
958 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
959 +        l.add(new StringTask());
960 +        l.add(null);
961          try {
797            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
798            l.add(new StringTask());
799            l.add(null);
962              e.invokeAll(l);
963              shouldThrow();
964          } catch (NullPointerException success) {
# Line 810 | Line 972 | public class ScheduledExecutorSubclassTe
972       */
973      public void testInvokeAll4() throws Exception {
974          ExecutorService e = new CustomExecutor(2);
975 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
976 +        l.add(new NPETask());
977 +        List<Future<String>> futures = e.invokeAll(l);
978 +        assertEquals(1, futures.size());
979          try {
980 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
815 <            l.add(new NPETask());
816 <            List<Future<String>> result = e.invokeAll(l);
817 <            assertEquals(1, result.size());
818 <            for (Future<String> future : result)
819 <                future.get();
980 >            futures.get(0).get();
981              shouldThrow();
982          } catch (ExecutionException success) {
983              assertTrue(success.getCause() instanceof NullPointerException);
# Line 831 | Line 992 | public class ScheduledExecutorSubclassTe
992      public void testInvokeAll5() throws Exception {
993          ExecutorService e = new CustomExecutor(2);
994          try {
995 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
995 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
996              l.add(new StringTask());
997              l.add(new StringTask());
998 <            List<Future<String>> result = e.invokeAll(l);
999 <            assertEquals(2, result.size());
1000 <            for (Future<String> future : result)
998 >            List<Future<String>> futures = e.invokeAll(l);
999 >            assertEquals(2, futures.size());
1000 >            for (Future<String> future : futures)
1001                  assertSame(TEST_STRING, future.get());
1002          } finally {
1003              joinPool(e);
# Line 862 | Line 1023 | public class ScheduledExecutorSubclassTe
1023       */
1024      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1025          ExecutorService e = new CustomExecutor(2);
1026 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1027 +        l.add(new StringTask());
1028          try {
866            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
867            l.add(new StringTask());
1029              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1030              shouldThrow();
1031          } catch (NullPointerException success) {
# Line 891 | Line 1052 | public class ScheduledExecutorSubclassTe
1052       * timed invokeAny(c) throws NPE if c has null elements
1053       */
1054      public void testTimedInvokeAny3() throws Exception {
1055 <        final CountDownLatch latch = new CountDownLatch(1);
1055 >        CountDownLatch latch = new CountDownLatch(1);
1056          ExecutorService e = new CustomExecutor(2);
1057 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1058 +        l.add(latchAwaitingStringTask(latch));
1059 +        l.add(null);
1060          try {
897            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
898            l.add(new Callable<String>() {
899                      public String call() {
900                          try {
901                              latch.await();
902                          } catch (InterruptedException quittingTime) {}
903                          return TEST_STRING;
904                      }});
905            l.add(null);
1061              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1062              shouldThrow();
1063          } catch (NullPointerException success) {
# Line 917 | Line 1072 | public class ScheduledExecutorSubclassTe
1072       */
1073      public void testTimedInvokeAny4() throws Exception {
1074          ExecutorService e = new CustomExecutor(2);
1075 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1076 +        l.add(new NPETask());
1077          try {
921            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
922            l.add(new NPETask());
1078              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1079              shouldThrow();
1080          } catch (ExecutionException success) {
# Line 935 | Line 1090 | public class ScheduledExecutorSubclassTe
1090      public void testTimedInvokeAny5() throws Exception {
1091          ExecutorService e = new CustomExecutor(2);
1092          try {
1093 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1093 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1094              l.add(new StringTask());
1095              l.add(new StringTask());
1096              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
# Line 964 | Line 1119 | public class ScheduledExecutorSubclassTe
1119       */
1120      public void testTimedInvokeAllNullTimeUnit() throws Exception {
1121          ExecutorService e = new CustomExecutor(2);
1122 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1123 +        l.add(new StringTask());
1124          try {
968            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
969            l.add(new StringTask());
1125              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1126              shouldThrow();
1127          } catch (NullPointerException success) {
# Line 993 | Line 1148 | public class ScheduledExecutorSubclassTe
1148       */
1149      public void testTimedInvokeAll3() throws Exception {
1150          ExecutorService e = new CustomExecutor(2);
1151 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1152 +        l.add(new StringTask());
1153 +        l.add(null);
1154          try {
997            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
998            l.add(new StringTask());
999            l.add(null);
1155              e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1156              shouldThrow();
1157          } catch (NullPointerException success) {
# Line 1010 | Line 1165 | public class ScheduledExecutorSubclassTe
1165       */
1166      public void testTimedInvokeAll4() throws Exception {
1167          ExecutorService e = new CustomExecutor(2);
1168 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1169 +        l.add(new NPETask());
1170 +        List<Future<String>> futures =
1171 +            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1172 +        assertEquals(1, futures.size());
1173          try {
1174 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1015 <            l.add(new NPETask());
1016 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1017 <            assertEquals(1, result.size());
1018 <            for (Future<String> future : result)
1019 <                future.get();
1174 >            futures.get(0).get();
1175              shouldThrow();
1176          } catch (ExecutionException success) {
1177              assertTrue(success.getCause() instanceof NullPointerException);
# Line 1031 | Line 1186 | public class ScheduledExecutorSubclassTe
1186      public void testTimedInvokeAll5() throws Exception {
1187          ExecutorService e = new CustomExecutor(2);
1188          try {
1189 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1189 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1190              l.add(new StringTask());
1191              l.add(new StringTask());
1192 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1193 <            assertEquals(2, result.size());
1194 <            for (Future<String> future : result)
1192 >            List<Future<String>> futures =
1193 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1194 >            assertEquals(2, futures.size());
1195 >            for (Future<String> future : futures)
1196                  assertSame(TEST_STRING, future.get());
1197          } finally {
1198              joinPool(e);
# Line 1049 | Line 1205 | public class ScheduledExecutorSubclassTe
1205      public void testTimedInvokeAll6() throws Exception {
1206          ExecutorService e = new CustomExecutor(2);
1207          try {
1208 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1208 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1209              l.add(new StringTask());
1210              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1211              l.add(new StringTask());
1212 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1213 <            assertEquals(3, result.size());
1214 <            Iterator<Future<String>> it = result.iterator();
1212 >            List<Future<String>> futures =
1213 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1214 >            assertEquals(3, futures.size());
1215 >            Iterator<Future<String>> it = futures.iterator();
1216              Future<String> f1 = it.next();
1217              Future<String> f2 = it.next();
1218              Future<String> f3 = it.next();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines