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.23 by jsr166, Mon Nov 16 04:57:10 2009 UTC vs.
Revision 1.33 by jsr166, Mon Oct 11 07:21:32 2010 UTC

# Line 9 | Line 9
9   import junit.framework.*;
10   import java.util.*;
11   import java.util.concurrent.*;
12 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
13   import java.util.concurrent.atomic.*;
14  
15   public class ScheduledExecutorTest extends JSR166TestCase {
16      public static void main(String[] args) {
17 <        junit.textui.TestRunner.run (suite());
17 >        junit.textui.TestRunner.run(suite());
18      }
19      public static Test suite() {
20 <        return new TestSuite(ScheduledExecutorTest.class);
20 >        return new TestSuite(ScheduledExecutorTest.class);
21      }
22  
23  
24      /**
25       * execute successfully executes a runnable
26       */
27 <    public void testExecute() {
28 <        try {
29 <            TrackedShortRunnable runnable =new TrackedShortRunnable();
30 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
31 <            p1.execute(runnable);
32 <            assertFalse(runnable.done);
33 <            Thread.sleep(SHORT_DELAY_MS);
34 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
35 <            try {
36 <                Thread.sleep(MEDIUM_DELAY_MS);
37 <            } catch (InterruptedException e){
38 <                unexpectedException();
38 <            }
39 <            assertTrue(runnable.done);
40 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
41 <            joinPool(p1);
42 <        }
43 <        catch (Exception e){
44 <            unexpectedException();
27 >    public void testExecute() throws InterruptedException {
28 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
29 >        final CountDownLatch done = new CountDownLatch(1);
30 >        final Runnable task = new CheckedRunnable() {
31 >            public void realRun() {
32 >                done.countDown();
33 >            }};
34 >        try {
35 >            p.execute(task);
36 >            assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS));
37 >        } finally {
38 >            joinPool(p);
39          }
46
40      }
41  
42  
43      /**
44       * delayed schedule of callable successfully executes after delay
45       */
46 <    public void testSchedule1() {
47 <        try {
48 <            TrackedCallable callable = new TrackedCallable();
49 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
50 <            Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
51 <            assertFalse(callable.done);
52 <            Thread.sleep(MEDIUM_DELAY_MS);
53 <            assertTrue(callable.done);
54 <            assertEquals(Boolean.TRUE, f.get());
55 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
56 <            joinPool(p1);
57 <        } catch (RejectedExecutionException e){}
58 <        catch (Exception e){
59 <            e.printStackTrace();
60 <            unexpectedException();
46 >    public void testSchedule1() throws Exception {
47 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
48 >        final long t0 = System.nanoTime();
49 >        final long timeoutNanos = SHORT_DELAY_MS * 1000L * 1000L;
50 >        final CountDownLatch done = new CountDownLatch(1);
51 >        try {
52 >            Callable task = new CheckedCallable<Boolean>() {
53 >                public Boolean realCall() {
54 >                    done.countDown();
55 >                    assertTrue(System.nanoTime() - t0 >= timeoutNanos);
56 >                    return Boolean.TRUE;
57 >                }};
58 >            Future f = p.schedule(task, SHORT_DELAY_MS, MILLISECONDS);
59 >            assertEquals(Boolean.TRUE, f.get());
60 >            assertTrue(System.nanoTime() - t0 >= timeoutNanos);
61 >            assertTrue(done.await(0L, MILLISECONDS));
62 >        } finally {
63 >            joinPool(p);
64          }
65      }
66  
67      /**
68 <     *  delayed schedule of runnable successfully executes after delay
69 <     */
70 <    public void testSchedule3() {
71 <        try {
72 <            TrackedShortRunnable runnable = new TrackedShortRunnable();
73 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
74 <            p1.schedule(runnable, SMALL_DELAY_MS, TimeUnit.MILLISECONDS);
75 <            Thread.sleep(SHORT_DELAY_MS);
76 <            assertFalse(runnable.done);
77 <            Thread.sleep(MEDIUM_DELAY_MS);
78 <            assertTrue(runnable.done);
79 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
80 <            joinPool(p1);
81 <        } catch (Exception e){
82 <            unexpectedException();
68 >     * delayed schedule of runnable successfully executes after delay
69 >     */
70 >    public void testSchedule3() throws Exception {
71 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
72 >        final long t0 = System.nanoTime();
73 >        final long timeoutNanos = SHORT_DELAY_MS * 1000L * 1000L;
74 >        final CountDownLatch done = new CountDownLatch(1);
75 >        try {
76 >            Runnable task = new CheckedRunnable() {
77 >                public void realRun() {
78 >                    done.countDown();
79 >                    assertTrue(System.nanoTime() - t0 >= timeoutNanos);
80 >                }};
81 >            Future f = p.schedule(task, SHORT_DELAY_MS, MILLISECONDS);
82 >            assertNull(f.get());
83 >            assertTrue(System.nanoTime() - t0 >= timeoutNanos);
84 >            assertTrue(done.await(0L, MILLISECONDS));
85 >        } finally {
86 >            joinPool(p);
87          }
88      }
89  
90      /**
91       * scheduleAtFixedRate executes runnable after given initial delay
92       */
93 <    public void testSchedule4() {
94 <        try {
95 <            TrackedShortRunnable runnable = new TrackedShortRunnable();
96 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
97 <            ScheduledFuture h = p1.scheduleAtFixedRate(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
98 <            assertFalse(runnable.done);
99 <            Thread.sleep(MEDIUM_DELAY_MS);
100 <            assertTrue(runnable.done);
101 <            h.cancel(true);
102 <            joinPool(p1);
103 <        } catch (Exception e){
104 <            unexpectedException();
93 >    public void testSchedule4() throws Exception {
94 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
95 >        final long t0 = System.nanoTime();
96 >        final long timeoutNanos = SHORT_DELAY_MS * 1000L * 1000L;
97 >        final CountDownLatch done = new CountDownLatch(1);
98 >        try {
99 >            Runnable task = new CheckedRunnable() {
100 >                public void realRun() {
101 >                    done.countDown();
102 >                    assertTrue(System.nanoTime() - t0 >= timeoutNanos);
103 >                }};
104 >            ScheduledFuture f =
105 >                p.scheduleAtFixedRate(task, SHORT_DELAY_MS,
106 >                                      SHORT_DELAY_MS, MILLISECONDS);
107 >            assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS));
108 >            assertTrue(System.nanoTime() - t0 >= timeoutNanos);
109 >            f.cancel(true);
110 >        } finally {
111 >            joinPool(p);
112          }
113      }
114  
108    static class RunnableCounter implements Runnable {
109        AtomicInteger count = new AtomicInteger(0);
110        public void run() { count.getAndIncrement(); }
111    }
112
115      /**
116       * scheduleWithFixedDelay executes runnable after given initial delay
117       */
118 <    public void testSchedule5() {
119 <        try {
120 <            TrackedShortRunnable runnable = new TrackedShortRunnable();
121 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
122 <            ScheduledFuture h = p1.scheduleWithFixedDelay(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
123 <            assertFalse(runnable.done);
124 <            Thread.sleep(MEDIUM_DELAY_MS);
125 <            assertTrue(runnable.done);
126 <            h.cancel(true);
127 <            joinPool(p1);
128 <        } catch (Exception e){
129 <            unexpectedException();
118 >    public void testSchedule5() throws InterruptedException {
119 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
120 >        final long t0 = System.nanoTime();
121 >        final long timeoutNanos = SHORT_DELAY_MS * 1000L * 1000L;
122 >        final CountDownLatch done = new CountDownLatch(1);
123 >        try {
124 >            Runnable task = new CheckedRunnable() {
125 >                public void realRun() {
126 >                    done.countDown();
127 >                    assertTrue(System.nanoTime() - t0 >= timeoutNanos);
128 >                }};
129 >            ScheduledFuture f =
130 >                p.scheduleWithFixedDelay(task, SHORT_DELAY_MS,
131 >                                         SHORT_DELAY_MS, MILLISECONDS);
132 >            assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS));
133 >            assertTrue(System.nanoTime() - t0 >= timeoutNanos);
134 >            f.cancel(true);
135 >        } finally {
136 >            joinPool(p);
137          }
138      }
139  
140 +    static class RunnableCounter implements Runnable {
141 +        AtomicInteger count = new AtomicInteger(0);
142 +        public void run() { count.getAndIncrement(); }
143 +    }
144 +
145      /**
146       * scheduleAtFixedRate executes series of tasks at given rate
147       */
148 <    public void testFixedRateSequence() {
149 <        try {
150 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
151 <            RunnableCounter counter = new RunnableCounter();
152 <            ScheduledFuture h =
153 <                p1.scheduleAtFixedRate(counter, 0, 1, TimeUnit.MILLISECONDS);
154 <            Thread.sleep(SMALL_DELAY_MS);
155 <            h.cancel(true);
156 <            int c = counter.count.get();
157 <            // By time scaling conventions, we must have at least
158 <            // an execution per SHORT delay, but no more than one SHORT more
159 <            assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
160 <            assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
147 <            joinPool(p1);
148 <        } catch (Exception e){
149 <            unexpectedException();
150 <        }
148 >    public void testFixedRateSequence() throws InterruptedException {
149 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
150 >        RunnableCounter counter = new RunnableCounter();
151 >        ScheduledFuture h =
152 >            p.scheduleAtFixedRate(counter, 0, 1, MILLISECONDS);
153 >        Thread.sleep(SMALL_DELAY_MS);
154 >        h.cancel(true);
155 >        int c = counter.count.get();
156 >        // By time scaling conventions, we must have at least
157 >        // an execution per SHORT delay, but no more than one SHORT more
158 >        assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
159 >        assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
160 >        joinPool(p);
161      }
162  
163      /**
164       * scheduleWithFixedDelay executes series of tasks with given period
165       */
166 <    public void testFixedDelaySequence() {
167 <        try {
168 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
169 <            RunnableCounter counter = new RunnableCounter();
170 <            ScheduledFuture h =
171 <                p1.scheduleWithFixedDelay(counter, 0, 1, TimeUnit.MILLISECONDS);
172 <            Thread.sleep(SMALL_DELAY_MS);
173 <            h.cancel(true);
174 <            int c = counter.count.get();
175 <            assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
176 <            assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
167 <            joinPool(p1);
168 <        } catch (Exception e){
169 <            unexpectedException();
170 <        }
166 >    public void testFixedDelaySequence() throws InterruptedException {
167 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
168 >        RunnableCounter counter = new RunnableCounter();
169 >        ScheduledFuture h =
170 >            p.scheduleWithFixedDelay(counter, 0, 1, MILLISECONDS);
171 >        Thread.sleep(SMALL_DELAY_MS);
172 >        h.cancel(true);
173 >        int c = counter.count.get();
174 >        assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
175 >        assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
176 >        joinPool(p);
177      }
178  
179  
180      /**
181 <     *  execute (null) throws NPE
181 >     * execute(null) throws NPE
182       */
183 <    public void testExecuteNull() {
183 >    public void testExecuteNull() throws InterruptedException {
184          ScheduledThreadPoolExecutor se = null;
185          try {
186 <            se = new ScheduledThreadPoolExecutor(1);
187 <            se.execute(null);
186 >            se = new ScheduledThreadPoolExecutor(1);
187 >            se.execute(null);
188              shouldThrow();
189 <        } catch (NullPointerException success){}
184 <        catch (Exception e){
185 <            unexpectedException();
186 <        }
189 >        } catch (NullPointerException success) {}
190  
191 <        joinPool(se);
191 >        joinPool(se);
192      }
193  
194      /**
195 <     * schedule (null) throws NPE
195 >     * schedule(null) throws NPE
196       */
197 <    public void testScheduleNull() {
197 >    public void testScheduleNull() throws InterruptedException {
198          ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
199 <        try {
199 >        try {
200              TrackedCallable callable = null;
201 <            Future f = se.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
201 >            Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
202              shouldThrow();
203 <        } catch (NullPointerException success){}
204 <        catch (Exception e){
202 <            unexpectedException();
203 <        }
204 <        joinPool(se);
203 >        } catch (NullPointerException success) {}
204 >        joinPool(se);
205      }
206  
207      /**
208       * execute throws RejectedExecutionException if shutdown
209       */
210 <    public void testSchedule1_RejectedExecutionException() {
210 >    public void testSchedule1_RejectedExecutionException() throws InterruptedException {
211          ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
212          try {
213              se.shutdown();
214              se.schedule(new NoOpRunnable(),
215 <                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
215 >                        MEDIUM_DELAY_MS, MILLISECONDS);
216              shouldThrow();
217 <        } catch (RejectedExecutionException success){
217 >        } catch (RejectedExecutionException success) {
218          } catch (SecurityException ok) {
219          }
220  
221          joinPool(se);
222
222      }
223  
224      /**
225       * schedule throws RejectedExecutionException if shutdown
226       */
227 <    public void testSchedule2_RejectedExecutionException() {
227 >    public void testSchedule2_RejectedExecutionException() throws InterruptedException {
228          ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
229          try {
230              se.shutdown();
231              se.schedule(new NoOpCallable(),
232 <                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
232 >                        MEDIUM_DELAY_MS, MILLISECONDS);
233              shouldThrow();
234 <        } catch (RejectedExecutionException success){
234 >        } catch (RejectedExecutionException success) {
235          } catch (SecurityException ok) {
236          }
237          joinPool(se);
# Line 241 | Line 240 | public class ScheduledExecutorTest exten
240      /**
241       * schedule callable throws RejectedExecutionException if shutdown
242       */
243 <     public void testSchedule3_RejectedExecutionException() {
243 >     public void testSchedule3_RejectedExecutionException() throws InterruptedException {
244           ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
245           try {
246              se.shutdown();
247              se.schedule(new NoOpCallable(),
248 <                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
248 >                        MEDIUM_DELAY_MS, MILLISECONDS);
249              shouldThrow();
250 <        } catch (RejectedExecutionException success){
250 >        } catch (RejectedExecutionException success) {
251          } catch (SecurityException ok) {
252          }
253           joinPool(se);
254      }
255  
256      /**
257 <     *  scheduleAtFixedRate throws RejectedExecutionException if shutdown
257 >     * scheduleAtFixedRate throws RejectedExecutionException if shutdown
258       */
259 <    public void testScheduleAtFixedRate1_RejectedExecutionException() {
259 >    public void testScheduleAtFixedRate1_RejectedExecutionException() throws InterruptedException {
260          ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
261          try {
262              se.shutdown();
263              se.scheduleAtFixedRate(new NoOpRunnable(),
264 <                                   MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
264 >                                   MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
265              shouldThrow();
266 <        } catch (RejectedExecutionException success){
266 >        } catch (RejectedExecutionException success) {
267          } catch (SecurityException ok) {
268          }
269          joinPool(se);
# Line 273 | Line 272 | public class ScheduledExecutorTest exten
272      /**
273       * scheduleWithFixedDelay throws RejectedExecutionException if shutdown
274       */
275 <    public void testScheduleWithFixedDelay1_RejectedExecutionException() {
275 >    public void testScheduleWithFixedDelay1_RejectedExecutionException() throws InterruptedException {
276          ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
277          try {
278              se.shutdown();
279              se.scheduleWithFixedDelay(new NoOpRunnable(),
280 <                                      MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
280 >                                      MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
281              shouldThrow();
282 <        } catch (RejectedExecutionException success){
282 >        } catch (RejectedExecutionException success) {
283          } catch (SecurityException ok) {
284          }
285          joinPool(se);
286      }
287  
288      /**
289 <     *  getActiveCount increases but doesn't overestimate, when a
290 <     *  thread becomes active
289 >     * getActiveCount increases but doesn't overestimate, when a
290 >     * thread becomes active
291       */
292 <    public void testGetActiveCount() {
293 <        ScheduledThreadPoolExecutor p2 = new ScheduledThreadPoolExecutor(2);
294 <        assertEquals(0, p2.getActiveCount());
295 <        p2.execute(new SmallRunnable());
296 <        try {
297 <            Thread.sleep(SHORT_DELAY_MS);
298 <        } catch (Exception e){
299 <            unexpectedException();
292 >    public void testGetActiveCount() throws InterruptedException {
293 >        final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(2);
294 >        final CountDownLatch threadStarted = new CountDownLatch(1);
295 >        final CountDownLatch done = new CountDownLatch(1);
296 >        try {
297 >            assertEquals(0, p.getActiveCount());
298 >            p.execute(new CheckedRunnable() {
299 >                public void realRun() throws InterruptedException {
300 >                    threadStarted.countDown();
301 >                    assertEquals(1, p.getActiveCount());
302 >                    done.await();
303 >                }});
304 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
305 >            assertEquals(1, p.getActiveCount());
306 >        } finally {
307 >            done.countDown();
308 >            joinPool(p);
309          }
302        assertEquals(1, p2.getActiveCount());
303        joinPool(p2);
310      }
311  
312      /**
313 <     *    getCompletedTaskCount increases, but doesn't overestimate,
314 <     *   when tasks complete
313 >     * getCompletedTaskCount increases, but doesn't overestimate,
314 >     * when tasks complete
315       */
316 <    public void testGetCompletedTaskCount() {
317 <        ScheduledThreadPoolExecutor p2 = new ScheduledThreadPoolExecutor(2);
318 <        assertEquals(0, p2.getCompletedTaskCount());
319 <        p2.execute(new SmallRunnable());
320 <        try {
321 <            Thread.sleep(MEDIUM_DELAY_MS);
322 <        } catch (Exception e){
323 <            unexpectedException();
316 >    public void testGetCompletedTaskCount() throws InterruptedException {
317 >        final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(2);
318 >        final CountDownLatch threadStarted = new CountDownLatch(1);
319 >        final CountDownLatch threadProceed = new CountDownLatch(1);
320 >        final CountDownLatch threadDone = new CountDownLatch(1);
321 >        try {
322 >            assertEquals(0, p.getCompletedTaskCount());
323 >            p.execute(new CheckedRunnable() {
324 >                public void realRun() throws InterruptedException {
325 >                    threadStarted.countDown();
326 >                    assertEquals(0, p.getCompletedTaskCount());
327 >                    threadProceed.await();
328 >                    threadDone.countDown();
329 >                }});
330 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
331 >            assertEquals(0, p.getCompletedTaskCount());
332 >            threadProceed.countDown();
333 >            threadDone.await();
334 >            Thread.sleep(SHORT_DELAY_MS);
335 >            assertEquals(1, p.getCompletedTaskCount());
336 >        } finally {
337 >            joinPool(p);
338          }
319        assertEquals(1, p2.getCompletedTaskCount());
320        joinPool(p2);
339      }
340  
341      /**
342 <     *  getCorePoolSize returns size given in constructor if not otherwise set
342 >     * getCorePoolSize returns size given in constructor if not otherwise set
343       */
344 <    public void testGetCorePoolSize() {
345 <        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
346 <        assertEquals(1, p1.getCorePoolSize());
347 <        joinPool(p1);
344 >    public void testGetCorePoolSize() throws InterruptedException {
345 >        ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
346 >        assertEquals(1, p.getCorePoolSize());
347 >        joinPool(p);
348      }
349  
350      /**
351 <     *    getLargestPoolSize increases, but doesn't overestimate, when
352 <     *   multiple threads active
351 >     * getLargestPoolSize increases, but doesn't overestimate, when
352 >     * multiple threads active
353       */
354 <    public void testGetLargestPoolSize() {
355 <        ScheduledThreadPoolExecutor p2 = new ScheduledThreadPoolExecutor(2);
356 <        assertEquals(0, p2.getLargestPoolSize());
357 <        p2.execute(new SmallRunnable());
358 <        p2.execute(new SmallRunnable());
359 <        try {
360 <            Thread.sleep(SHORT_DELAY_MS);
361 <        } catch (Exception e){
362 <            unexpectedException();
354 >    public void testGetLargestPoolSize() throws InterruptedException {
355 >        final int THREADS = 3;
356 >        final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(THREADS);
357 >        final CountDownLatch threadsStarted = new CountDownLatch(THREADS);
358 >        final CountDownLatch done = new CountDownLatch(1);
359 >        try {
360 >            assertEquals(0, p.getLargestPoolSize());
361 >            for (int i = 0; i < THREADS; i++)
362 >                p.execute(new CheckedRunnable() {
363 >                    public void realRun() throws InterruptedException {
364 >                        threadsStarted.countDown();
365 >                        done.await();
366 >                        assertEquals(THREADS, p.getLargestPoolSize());
367 >                    }});
368 >            assertTrue(threadsStarted.await(SMALL_DELAY_MS, MILLISECONDS));
369 >            assertEquals(THREADS, p.getLargestPoolSize());
370 >        } finally {
371 >            done.countDown();
372 >            joinPool(p);
373 >            assertEquals(THREADS, p.getLargestPoolSize());
374          }
346        assertEquals(2, p2.getLargestPoolSize());
347        joinPool(p2);
375      }
376  
377      /**
378 <     *   getPoolSize increases, but doesn't overestimate, when threads
379 <     *   become active
378 >     * getPoolSize increases, but doesn't overestimate, when threads
379 >     * become active
380       */
381 <    public void testGetPoolSize() {
382 <        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
383 <        assertEquals(0, p1.getPoolSize());
384 <        p1.execute(new SmallRunnable());
385 <        assertEquals(1, p1.getPoolSize());
386 <        joinPool(p1);
381 >    public void testGetPoolSize() throws InterruptedException {
382 >        final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
383 >        final CountDownLatch threadStarted = new CountDownLatch(1);
384 >        final CountDownLatch done = new CountDownLatch(1);
385 >        try {
386 >            assertEquals(0, p.getPoolSize());
387 >            p.execute(new CheckedRunnable() {
388 >                public void realRun() throws InterruptedException {
389 >                    threadStarted.countDown();
390 >                    assertEquals(1, p.getPoolSize());
391 >                    done.await();
392 >                }});
393 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
394 >            assertEquals(1, p.getPoolSize());
395 >        } finally {
396 >            done.countDown();
397 >            joinPool(p);
398 >        }
399      }
400  
401      /**
402 <     *    getTaskCount increases, but doesn't overestimate, when tasks
403 <     *    submitted
402 >     * getTaskCount increases, but doesn't overestimate, when tasks
403 >     * submitted
404       */
405 <    public void testGetTaskCount() {
406 <        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
407 <        assertEquals(0, p1.getTaskCount());
408 <        for (int i = 0; i < 5; i++)
409 <            p1.execute(new SmallRunnable());
410 <        try {
411 <            Thread.sleep(SHORT_DELAY_MS);
412 <        } catch (Exception e){
413 <            unexpectedException();
405 >    public void testGetTaskCount() throws InterruptedException {
406 >        final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
407 >        final CountDownLatch threadStarted = new CountDownLatch(1);
408 >        final CountDownLatch done = new CountDownLatch(1);
409 >        final int TASKS = 5;
410 >        try {
411 >            assertEquals(0, p.getTaskCount());
412 >            for (int i = 0; i < TASKS; i++)
413 >                p.execute(new CheckedRunnable() {
414 >                    public void realRun() throws InterruptedException {
415 >                        threadStarted.countDown();
416 >                        done.await();
417 >                    }});
418 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
419 >            assertEquals(TASKS, p.getTaskCount());
420 >        } finally {
421 >            done.countDown();
422 >            joinPool(p);
423          }
376        assertEquals(5, p1.getTaskCount());
377        joinPool(p1);
424      }
425  
426      /**
427       * getThreadFactory returns factory in constructor if not set
428       */
429 <    public void testGetThreadFactory() {
429 >    public void testGetThreadFactory() throws InterruptedException {
430          ThreadFactory tf = new SimpleThreadFactory();
431 <        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, tf);
431 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, tf);
432          assertSame(tf, p.getThreadFactory());
433          joinPool(p);
434      }
# Line 390 | Line 436 | public class ScheduledExecutorTest exten
436      /**
437       * setThreadFactory sets the thread factory returned by getThreadFactory
438       */
439 <    public void testSetThreadFactory() {
439 >    public void testSetThreadFactory() throws InterruptedException {
440          ThreadFactory tf = new SimpleThreadFactory();
441 <        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
441 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
442          p.setThreadFactory(tf);
443          assertSame(tf, p.getThreadFactory());
444          joinPool(p);
# Line 401 | Line 447 | public class ScheduledExecutorTest exten
447      /**
448       * setThreadFactory(null) throws NPE
449       */
450 <    public void testSetThreadFactoryNull() {
451 <        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
450 >    public void testSetThreadFactoryNull() throws InterruptedException {
451 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
452          try {
453              p.setThreadFactory(null);
454              shouldThrow();
# Line 413 | Line 459 | public class ScheduledExecutorTest exten
459      }
460  
461      /**
462 <     *   is isShutDown is false before shutdown, true after
462 >     * isShutDown is false before shutdown, true after
463       */
464      public void testIsShutdown() {
465  
466 <        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
466 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
467          try {
468 <            assertFalse(p1.isShutdown());
468 >            assertFalse(p.isShutdown());
469          }
470          finally {
471 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
471 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
472          }
473 <        assertTrue(p1.isShutdown());
473 >        assertTrue(p.isShutdown());
474      }
475  
476  
477      /**
478 <     *   isTerminated is false before termination, true after
478 >     * isTerminated is false before termination, true after
479       */
480 <    public void testIsTerminated() {
481 <        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
480 >    public void testIsTerminated() throws InterruptedException {
481 >        final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
482 >        final CountDownLatch threadStarted = new CountDownLatch(1);
483 >        final CountDownLatch done = new CountDownLatch(1);
484 >        assertFalse(p.isTerminated());
485          try {
486 <            p1.execute(new SmallRunnable());
486 >            p.execute(new CheckedRunnable() {
487 >                public void realRun() throws InterruptedException {
488 >                    threadStarted.countDown();
489 >                    assertFalse(p.isTerminated());
490 >                    done.await();
491 >                }});
492 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
493 >            done.countDown();
494          } finally {
495 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
440 <        }
441 <        try {
442 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
443 <            assertTrue(p1.isTerminated());
444 <        } catch (Exception e){
445 <            unexpectedException();
495 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
496          }
497 +        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
498 +        assertTrue(p.isTerminated());
499      }
500  
501      /**
502 <     *  isTerminating is not true when running or when terminated
502 >     * isTerminating is not true when running or when terminated
503       */
504 <    public void testIsTerminating() {
505 <        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
506 <        assertFalse(p1.isTerminating());
504 >    public void testIsTerminating() throws InterruptedException {
505 >        final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
506 >        final CountDownLatch threadStarted = new CountDownLatch(1);
507 >        final CountDownLatch done = new CountDownLatch(1);
508          try {
509 <            p1.execute(new SmallRunnable());
510 <            assertFalse(p1.isTerminating());
509 >            assertFalse(p.isTerminating());
510 >            p.execute(new CheckedRunnable() {
511 >                public void realRun() throws InterruptedException {
512 >                    threadStarted.countDown();
513 >                    assertFalse(p.isTerminating());
514 >                    done.await();
515 >                }});
516 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
517 >            assertFalse(p.isTerminating());
518 >            done.countDown();
519          } finally {
520 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
460 <        }
461 <        try {
462 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
463 <            assertTrue(p1.isTerminated());
464 <            assertFalse(p1.isTerminating());
465 <        } catch (Exception e){
466 <            unexpectedException();
520 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
521          }
522 +        assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
523 +        assertTrue(p.isTerminated());
524 +        assertFalse(p.isTerminating());
525      }
526  
527      /**
528       * getQueue returns the work queue, which contains queued tasks
529       */
530 <    public void testGetQueue() {
531 <        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
532 <        ScheduledFuture[] tasks = new ScheduledFuture[5];
533 <        for (int i = 0; i < 5; i++){
477 <            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS);
478 <        }
530 >    public void testGetQueue() throws InterruptedException {
531 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
532 >        final CountDownLatch threadStarted = new CountDownLatch(1);
533 >        final CountDownLatch done = new CountDownLatch(1);
534          try {
535 <            Thread.sleep(SHORT_DELAY_MS);
536 <            BlockingQueue<Runnable> q = p1.getQueue();
537 <            assertTrue(q.contains(tasks[4]));
535 >            ScheduledFuture[] tasks = new ScheduledFuture[5];
536 >            for (int i = 0; i < tasks.length; i++) {
537 >                Runnable r = new CheckedRunnable() {
538 >                    public void realRun() throws InterruptedException {
539 >                        threadStarted.countDown();
540 >                        done.await();
541 >                    }};
542 >                tasks[i] = p.schedule(r, 1, MILLISECONDS);
543 >            }
544 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
545 >            BlockingQueue<Runnable> q = p.getQueue();
546 >            assertTrue(q.contains(tasks[tasks.length - 1]));
547              assertFalse(q.contains(tasks[0]));
484        } catch (Exception e) {
485            unexpectedException();
548          } finally {
549 <            joinPool(p1);
549 >            done.countDown();
550 >            joinPool(p);
551          }
552      }
553  
554      /**
555       * remove(task) removes queued task, and fails to remove active task
556       */
557 <    public void testRemove() {
558 <        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
557 >    public void testRemove() throws InterruptedException {
558 >        final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
559          ScheduledFuture[] tasks = new ScheduledFuture[5];
560 <        for (int i = 0; i < 5; i++){
561 <            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS);
499 <        }
560 >        final CountDownLatch threadStarted = new CountDownLatch(1);
561 >        final CountDownLatch done = new CountDownLatch(1);
562          try {
563 <            Thread.sleep(SHORT_DELAY_MS);
564 <            BlockingQueue<Runnable> q = p1.getQueue();
565 <            assertFalse(p1.remove((Runnable)tasks[0]));
563 >            for (int i = 0; i < tasks.length; i++) {
564 >                Runnable r = new CheckedRunnable() {
565 >                    public void realRun() throws InterruptedException {
566 >                        threadStarted.countDown();
567 >                        done.await();
568 >                    }};
569 >                tasks[i] = p.schedule(r, 1, MILLISECONDS);
570 >            }
571 >            assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
572 >            BlockingQueue<Runnable> q = p.getQueue();
573 >            assertFalse(p.remove((Runnable)tasks[0]));
574              assertTrue(q.contains((Runnable)tasks[4]));
575              assertTrue(q.contains((Runnable)tasks[3]));
576 <            assertTrue(p1.remove((Runnable)tasks[4]));
577 <            assertFalse(p1.remove((Runnable)tasks[4]));
576 >            assertTrue(p.remove((Runnable)tasks[4]));
577 >            assertFalse(p.remove((Runnable)tasks[4]));
578              assertFalse(q.contains((Runnable)tasks[4]));
579              assertTrue(q.contains((Runnable)tasks[3]));
580 <            assertTrue(p1.remove((Runnable)tasks[3]));
580 >            assertTrue(p.remove((Runnable)tasks[3]));
581              assertFalse(q.contains((Runnable)tasks[3]));
512        } catch (Exception e) {
513            unexpectedException();
582          } finally {
583 <            joinPool(p1);
583 >            done.countDown();
584 >            joinPool(p);
585          }
586      }
587  
588      /**
589 <     *  purge removes cancelled tasks from the queue
589 >     * purge removes cancelled tasks from the queue
590       */
591 <    public void testPurge() {
592 <        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
591 >    public void testPurge() throws InterruptedException {
592 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
593          ScheduledFuture[] tasks = new ScheduledFuture[5];
594 <        for (int i = 0; i < 5; i++){
595 <            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
594 >        for (int i = 0; i < tasks.length; i++) {
595 >            tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS);
596          }
597          try {
598 <            int max = 5;
598 >            int max = tasks.length;
599              if (tasks[4].cancel(true)) --max;
600              if (tasks[3].cancel(true)) --max;
601              // There must eventually be an interference-free point at
602              // which purge will not fail. (At worst, when queue is empty.)
603              int k;
604              for (k = 0; k < SMALL_DELAY_MS; ++k) {
605 <                p1.purge();
606 <                long count = p1.getTaskCount();
605 >                p.purge();
606 >                long count = p.getTaskCount();
607                  if (count >= 0 && count <= max)
608                      break;
609                  Thread.sleep(1);
610              }
611              assertTrue(k < SMALL_DELAY_MS);
543        } catch (Exception e) {
544            unexpectedException();
612          } finally {
613 <            joinPool(p1);
613 >            for (ScheduledFuture task : tasks)
614 >                task.cancel(true);
615 >            joinPool(p);
616          }
617      }
618  
619      /**
620 <     *  shutDownNow returns a list containing tasks that were not run
620 >     * shutDownNow returns a list containing tasks that were not run
621       */
622 <    public void testShutDownNow() {
623 <        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
622 >    public void testShutDownNow() throws InterruptedException {
623 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
624          for (int i = 0; i < 5; i++)
625 <            p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
625 >            p.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS);
626          List l;
627          try {
628 <            l = p1.shutdownNow();
628 >            l = p.shutdownNow();
629          } catch (SecurityException ok) {
630              return;
631          }
632 <        assertTrue(p1.isShutdown());
633 <        assertTrue(l.size() > 0 && l.size() <= 5);
634 <        joinPool(p1);
632 >        assertTrue(p.isShutdown());
633 >        assertTrue(l.size() > 0 && l.size() <= 5);
634 >        joinPool(p);
635      }
636  
637      /**
638       * In default setting, shutdown cancels periodic but not delayed
639       * tasks at shutdown
640       */
641 <    public void testShutDown1() {
642 <        try {
643 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
644 <            assertTrue(p1.getExecuteExistingDelayedTasksAfterShutdownPolicy());
576 <            assertFalse(p1.getContinueExistingPeriodicTasksAfterShutdownPolicy());
577 <
578 <            ScheduledFuture[] tasks = new ScheduledFuture[5];
579 <            for (int i = 0; i < 5; i++)
580 <                tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
581 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
582 <            BlockingQueue q = p1.getQueue();
583 <            for (Iterator it = q.iterator(); it.hasNext();) {
584 <                ScheduledFuture t = (ScheduledFuture)it.next();
585 <                assertFalse(t.isCancelled());
586 <            }
587 <            assertTrue(p1.isShutdown());
588 <            Thread.sleep(SMALL_DELAY_MS);
589 <            for (int i = 0; i < 5; ++i) {
590 <                assertTrue(tasks[i].isDone());
591 <                assertFalse(tasks[i].isCancelled());
592 <            }
641 >    public void testShutDown1() throws InterruptedException {
642 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
643 >        assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy());
644 >        assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy());
645  
646 +        ScheduledFuture[] tasks = new ScheduledFuture[5];
647 +        for (int i = 0; i < tasks.length; i++)
648 +            tasks[i] = p.schedule(new NoOpRunnable(),
649 +                                  SHORT_DELAY_MS, MILLISECONDS);
650 +        try { p.shutdown(); } catch (SecurityException ok) { return; }
651 +        BlockingQueue<Runnable> q = p.getQueue();
652 +        for (ScheduledFuture task : tasks) {
653 +            assertFalse(task.isDone());
654 +            assertFalse(task.isCancelled());
655 +            assertTrue(q.contains(task));
656          }
657 <        catch (Exception ex) {
658 <            unexpectedException();
657 >        assertTrue(p.isShutdown());
658 >        assertTrue(p.awaitTermination(SMALL_DELAY_MS, MILLISECONDS));
659 >        assertTrue(p.isTerminated());
660 >        for (ScheduledFuture task : tasks) {
661 >            assertTrue(task.isDone());
662 >            assertFalse(task.isCancelled());
663          }
664      }
665  
# Line 602 | Line 668 | public class ScheduledExecutorTest exten
668       * If setExecuteExistingDelayedTasksAfterShutdownPolicy is false,
669       * delayed tasks are cancelled at shutdown
670       */
671 <    public void testShutDown2() {
672 <        try {
673 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
674 <            p1.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
675 <            ScheduledFuture[] tasks = new ScheduledFuture[5];
676 <            for (int i = 0; i < 5; i++)
677 <                tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
678 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
679 <            assertTrue(p1.isShutdown());
680 <            BlockingQueue q = p1.getQueue();
681 <            assertTrue(q.isEmpty());
682 <            Thread.sleep(SMALL_DELAY_MS);
683 <            assertTrue(p1.isTerminated());
684 <        }
685 <        catch (Exception ex) {
686 <            unexpectedException();
671 >    public void testShutDown2() throws InterruptedException {
672 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
673 >        p.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
674 >        ScheduledFuture[] tasks = new ScheduledFuture[5];
675 >        for (int i = 0; i < tasks.length; i++)
676 >            tasks[i] = p.schedule(new NoOpRunnable(),
677 >                                  SHORT_DELAY_MS, MILLISECONDS);
678 >        BlockingQueue q = p.getQueue();
679 >        assertEquals(tasks.length, q.size());
680 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
681 >        assertTrue(p.isShutdown());
682 >        assertTrue(q.isEmpty());
683 >        assertTrue(p.awaitTermination(SMALL_DELAY_MS, MILLISECONDS));
684 >        assertTrue(p.isTerminated());
685 >        for (ScheduledFuture task : tasks) {
686 >            assertTrue(task.isDone());
687 >            assertTrue(task.isCancelled());
688          }
689      }
690  
624
691      /**
692       * If setContinueExistingPeriodicTasksAfterShutdownPolicy is set false,
693 <     * periodic tasks are not cancelled at shutdown
693 >     * periodic tasks are cancelled at shutdown
694       */
695 <    public void testShutDown3() {
696 <        try {
697 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
698 <            p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
699 <            ScheduledFuture task =
700 <                p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS);
701 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
702 <            assertTrue(p1.isShutdown());
703 <            BlockingQueue q = p1.getQueue();
704 <            assertTrue(q.isEmpty());
705 <            Thread.sleep(SHORT_DELAY_MS);
706 <            assertTrue(p1.isTerminated());
707 <        }
642 <        catch (Exception ex) {
643 <            unexpectedException();
644 <        }
695 >    public void testShutDown3() throws InterruptedException {
696 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
697 >        p.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
698 >        ScheduledFuture task =
699 >            p.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, MILLISECONDS);
700 >        try { p.shutdown(); } catch (SecurityException ok) { return; }
701 >        assertTrue(p.isShutdown());
702 >        BlockingQueue q = p.getQueue();
703 >        assertTrue(p.getQueue().isEmpty());
704 >        assertTrue(task.isDone());
705 >        assertTrue(task.isCancelled());
706 >        assertTrue(p.awaitTermination(SMALL_DELAY_MS, MILLISECONDS));
707 >        assertTrue(p.isTerminated());
708      }
709  
710      /**
711       * if setContinueExistingPeriodicTasksAfterShutdownPolicy is true,
712 <     * periodic tasks are cancelled at shutdown
712 >     * periodic tasks are not cancelled at shutdown
713       */
714 <    public void testShutDown4() {
715 <        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
716 <        try {
717 <            p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
714 >    public void testShutDown4() throws InterruptedException {
715 >        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
716 >        p.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
717 >        final CountDownLatch counter = new CountDownLatch(2);
718 >        try {
719 >            final Runnable r = new CheckedRunnable() {
720 >                public void realRun() {
721 >                    counter.countDown();
722 >                }};
723              ScheduledFuture task =
724 <                p1.scheduleAtFixedRate(new NoOpRunnable(), 1, 1, TimeUnit.MILLISECONDS);
724 >                p.scheduleAtFixedRate(r, 1, 1, MILLISECONDS);
725 >            assertFalse(task.isDone());
726              assertFalse(task.isCancelled());
727 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
727 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
728              assertFalse(task.isCancelled());
729 <            assertFalse(p1.isTerminated());
730 <            assertTrue(p1.isShutdown());
731 <            Thread.sleep(SHORT_DELAY_MS);
729 >            assertFalse(p.isTerminated());
730 >            assertTrue(p.isShutdown());
731 >            assertTrue(counter.await(SMALL_DELAY_MS, MILLISECONDS));
732              assertFalse(task.isCancelled());
733 <            assertTrue(task.cancel(true));
733 >            assertTrue(task.cancel(false));
734              assertTrue(task.isDone());
735 <            Thread.sleep(SHORT_DELAY_MS);
736 <            assertTrue(p1.isTerminated());
737 <        }
669 <        catch (Exception ex) {
670 <            unexpectedException();
735 >            assertTrue(task.isCancelled());
736 >            assertTrue(p.awaitTermination(SMALL_DELAY_MS, MILLISECONDS));
737 >            assertTrue(p.isTerminated());
738          }
739          finally {
740 <            joinPool(p1);
740 >            joinPool(p);
741          }
742      }
743  
744      /**
745       * completed submit of callable returns result
746       */
747 <    public void testSubmitCallable() {
747 >    public void testSubmitCallable() throws Exception {
748          ExecutorService e = new ScheduledThreadPoolExecutor(2);
749          try {
750              Future<String> future = e.submit(new StringTask());
751              String result = future.get();
752              assertSame(TEST_STRING, result);
686        }
687        catch (ExecutionException ex) {
688            unexpectedException();
689        }
690        catch (InterruptedException ex) {
691            unexpectedException();
753          } finally {
754              joinPool(e);
755          }
# Line 697 | Line 758 | public class ScheduledExecutorTest exten
758      /**
759       * completed submit of runnable returns successfully
760       */
761 <    public void testSubmitRunnable() {
761 >    public void testSubmitRunnable() throws Exception {
762          ExecutorService e = new ScheduledThreadPoolExecutor(2);
763          try {
764              Future<?> future = e.submit(new NoOpRunnable());
765              future.get();
766              assertTrue(future.isDone());
706        }
707        catch (ExecutionException ex) {
708            unexpectedException();
709        }
710        catch (InterruptedException ex) {
711            unexpectedException();
767          } finally {
768              joinPool(e);
769          }
# Line 717 | Line 772 | public class ScheduledExecutorTest exten
772      /**
773       * completed submit of (runnable, result) returns result
774       */
775 <    public void testSubmitRunnable2() {
775 >    public void testSubmitRunnable2() throws Exception {
776          ExecutorService e = new ScheduledThreadPoolExecutor(2);
777          try {
778              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
779              String result = future.get();
780              assertSame(TEST_STRING, result);
726        }
727        catch (ExecutionException ex) {
728            unexpectedException();
729        }
730        catch (InterruptedException ex) {
731            unexpectedException();
781          } finally {
782              joinPool(e);
783          }
# Line 737 | Line 786 | public class ScheduledExecutorTest exten
786      /**
787       * invokeAny(null) throws NPE
788       */
789 <    public void testInvokeAny1() {
789 >    public void testInvokeAny1() throws Exception {
790          ExecutorService e = new ScheduledThreadPoolExecutor(2);
791          try {
792              e.invokeAny(null);
793 +            shouldThrow();
794          } catch (NullPointerException success) {
745        } catch (Exception ex) {
746            unexpectedException();
795          } finally {
796              joinPool(e);
797          }
# Line 752 | Line 800 | public class ScheduledExecutorTest exten
800      /**
801       * invokeAny(empty collection) throws IAE
802       */
803 <    public void testInvokeAny2() {
803 >    public void testInvokeAny2() throws Exception {
804          ExecutorService e = new ScheduledThreadPoolExecutor(2);
805          try {
806              e.invokeAny(new ArrayList<Callable<String>>());
807 +            shouldThrow();
808          } catch (IllegalArgumentException success) {
760        } catch (Exception ex) {
761            unexpectedException();
809          } finally {
810              joinPool(e);
811          }
# Line 767 | Line 814 | public class ScheduledExecutorTest exten
814      /**
815       * invokeAny(c) throws NPE if c has null elements
816       */
817 <    public void testInvokeAny3() {
817 >    public void testInvokeAny3() throws Exception {
818 >        CountDownLatch latch = new CountDownLatch(1);
819          ExecutorService e = new ScheduledThreadPoolExecutor(2);
820 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
821 +        l.add(latchAwaitingStringTask(latch));
822 +        l.add(null);
823          try {
773            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
774            l.add(new StringTask());
775            l.add(null);
824              e.invokeAny(l);
825 +            shouldThrow();
826          } catch (NullPointerException success) {
778        } catch (Exception ex) {
779            unexpectedException();
827          } finally {
828 +            latch.countDown();
829              joinPool(e);
830          }
831      }
# Line 785 | Line 833 | public class ScheduledExecutorTest exten
833      /**
834       * invokeAny(c) throws ExecutionException if no task completes
835       */
836 <    public void testInvokeAny4() {
836 >    public void testInvokeAny4() throws Exception {
837          ExecutorService e = new ScheduledThreadPoolExecutor(2);
838 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
839 +        l.add(new NPETask());
840          try {
791            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
792            l.add(new NPETask());
841              e.invokeAny(l);
842 +            shouldThrow();
843          } catch (ExecutionException success) {
844 <        } catch (Exception ex) {
796 <            unexpectedException();
844 >            assertTrue(success.getCause() instanceof NullPointerException);
845          } finally {
846              joinPool(e);
847          }
# Line 802 | Line 850 | public class ScheduledExecutorTest exten
850      /**
851       * invokeAny(c) returns result of some task
852       */
853 <    public void testInvokeAny5() {
853 >    public void testInvokeAny5() throws Exception {
854          ExecutorService e = new ScheduledThreadPoolExecutor(2);
855          try {
856 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
856 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
857              l.add(new StringTask());
858              l.add(new StringTask());
859              String result = e.invokeAny(l);
860              assertSame(TEST_STRING, result);
813        } catch (ExecutionException success) {
814        } catch (Exception ex) {
815            unexpectedException();
861          } finally {
862              joinPool(e);
863          }
# Line 821 | Line 866 | public class ScheduledExecutorTest exten
866      /**
867       * invokeAll(null) throws NPE
868       */
869 <    public void testInvokeAll1() {
869 >    public void testInvokeAll1() throws Exception {
870          ExecutorService e = new ScheduledThreadPoolExecutor(2);
871          try {
872              e.invokeAll(null);
873 +            shouldThrow();
874          } catch (NullPointerException success) {
829        } catch (Exception ex) {
830            unexpectedException();
875          } finally {
876              joinPool(e);
877          }
# Line 836 | Line 880 | public class ScheduledExecutorTest exten
880      /**
881       * invokeAll(empty collection) returns empty collection
882       */
883 <    public void testInvokeAll2() {
883 >    public void testInvokeAll2() throws Exception {
884          ExecutorService e = new ScheduledThreadPoolExecutor(2);
885          try {
886              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
887              assertTrue(r.isEmpty());
844        } catch (Exception ex) {
845            unexpectedException();
888          } finally {
889              joinPool(e);
890          }
# Line 851 | Line 893 | public class ScheduledExecutorTest exten
893      /**
894       * invokeAll(c) throws NPE if c has null elements
895       */
896 <    public void testInvokeAll3() {
896 >    public void testInvokeAll3() throws Exception {
897          ExecutorService e = new ScheduledThreadPoolExecutor(2);
898 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
899 +        l.add(new StringTask());
900 +        l.add(null);
901          try {
857            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
858            l.add(new StringTask());
859            l.add(null);
902              e.invokeAll(l);
903 +            shouldThrow();
904          } catch (NullPointerException success) {
862        } catch (Exception ex) {
863            unexpectedException();
905          } finally {
906              joinPool(e);
907          }
# Line 869 | Line 910 | public class ScheduledExecutorTest exten
910      /**
911       * get of invokeAll(c) throws exception on failed task
912       */
913 <    public void testInvokeAll4() {
913 >    public void testInvokeAll4() throws Exception {
914          ExecutorService e = new ScheduledThreadPoolExecutor(2);
915 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
916 +        l.add(new NPETask());
917 +        List<Future<String>> futures = e.invokeAll(l);
918 +        assertEquals(1, futures.size());
919          try {
920 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
921 <            l.add(new NPETask());
877 <            List<Future<String>> result = e.invokeAll(l);
878 <            assertEquals(1, result.size());
879 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
880 <                it.next().get();
920 >            futures.get(0).get();
921 >            shouldThrow();
922          } catch (ExecutionException success) {
923 <        } catch (Exception ex) {
883 <            unexpectedException();
923 >            assertTrue(success.getCause() instanceof NullPointerException);
924          } finally {
925              joinPool(e);
926          }
# Line 889 | Line 929 | public class ScheduledExecutorTest exten
929      /**
930       * invokeAll(c) returns results of all completed tasks
931       */
932 <    public void testInvokeAll5() {
932 >    public void testInvokeAll5() throws Exception {
933          ExecutorService e = new ScheduledThreadPoolExecutor(2);
934          try {
935 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
935 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
936              l.add(new StringTask());
937              l.add(new StringTask());
938 <            List<Future<String>> result = e.invokeAll(l);
939 <            assertEquals(2, result.size());
940 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
941 <                assertSame(TEST_STRING, it.next().get());
902 <        } catch (ExecutionException success) {
903 <        } catch (Exception ex) {
904 <            unexpectedException();
938 >            List<Future<String>> futures = e.invokeAll(l);
939 >            assertEquals(2, futures.size());
940 >            for (Future<String> future : futures)
941 >                assertSame(TEST_STRING, future.get());
942          } finally {
943              joinPool(e);
944          }
# Line 910 | Line 947 | public class ScheduledExecutorTest exten
947      /**
948       * timed invokeAny(null) throws NPE
949       */
950 <    public void testTimedInvokeAny1() {
950 >    public void testTimedInvokeAny1() throws Exception {
951          ExecutorService e = new ScheduledThreadPoolExecutor(2);
952          try {
953 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
953 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
954 >            shouldThrow();
955          } catch (NullPointerException success) {
918        } catch (Exception ex) {
919            unexpectedException();
956          } finally {
957              joinPool(e);
958          }
# Line 925 | Line 961 | public class ScheduledExecutorTest exten
961      /**
962       * timed invokeAny(,,null) throws NPE
963       */
964 <    public void testTimedInvokeAnyNullTimeUnit() {
964 >    public void testTimedInvokeAnyNullTimeUnit() throws Exception {
965          ExecutorService e = new ScheduledThreadPoolExecutor(2);
966 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
967 +        l.add(new StringTask());
968          try {
931            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
932            l.add(new StringTask());
969              e.invokeAny(l, MEDIUM_DELAY_MS, null);
970 +            shouldThrow();
971          } catch (NullPointerException success) {
935        } catch (Exception ex) {
936            unexpectedException();
972          } finally {
973              joinPool(e);
974          }
# Line 942 | Line 977 | public class ScheduledExecutorTest exten
977      /**
978       * timed invokeAny(empty collection) throws IAE
979       */
980 <    public void testTimedInvokeAny2() {
980 >    public void testTimedInvokeAny2() throws Exception {
981          ExecutorService e = new ScheduledThreadPoolExecutor(2);
982          try {
983 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
983 >            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
984 >            shouldThrow();
985          } catch (IllegalArgumentException success) {
950        } catch (Exception ex) {
951            unexpectedException();
986          } finally {
987              joinPool(e);
988          }
# Line 957 | Line 991 | public class ScheduledExecutorTest exten
991      /**
992       * timed invokeAny(c) throws NPE if c has null elements
993       */
994 <    public void testTimedInvokeAny3() {
994 >    public void testTimedInvokeAny3() throws Exception {
995 >        CountDownLatch latch = new CountDownLatch(1);
996          ExecutorService e = new ScheduledThreadPoolExecutor(2);
997 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
998 +        l.add(latchAwaitingStringTask(latch));
999 +        l.add(null);
1000          try {
1001 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1002 <            l.add(new StringTask());
965 <            l.add(null);
966 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1001 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1002 >            shouldThrow();
1003          } catch (NullPointerException success) {
968        } catch (Exception ex) {
969            ex.printStackTrace();
970            unexpectedException();
1004          } finally {
1005 +            latch.countDown();
1006              joinPool(e);
1007          }
1008      }
# Line 976 | Line 1010 | public class ScheduledExecutorTest exten
1010      /**
1011       * timed invokeAny(c) throws ExecutionException if no task completes
1012       */
1013 <    public void testTimedInvokeAny4() {
1013 >    public void testTimedInvokeAny4() throws Exception {
1014          ExecutorService e = new ScheduledThreadPoolExecutor(2);
1015 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1016 +        l.add(new NPETask());
1017          try {
1018 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1019 <            l.add(new NPETask());
984 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1018 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1019 >            shouldThrow();
1020          } catch (ExecutionException success) {
1021 <        } catch (Exception ex) {
987 <            unexpectedException();
1021 >            assertTrue(success.getCause() instanceof NullPointerException);
1022          } finally {
1023              joinPool(e);
1024          }
# Line 993 | Line 1027 | public class ScheduledExecutorTest exten
1027      /**
1028       * timed invokeAny(c) returns result of some task
1029       */
1030 <    public void testTimedInvokeAny5() {
1030 >    public void testTimedInvokeAny5() throws Exception {
1031          ExecutorService e = new ScheduledThreadPoolExecutor(2);
1032          try {
1033 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1033 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1034              l.add(new StringTask());
1035              l.add(new StringTask());
1036 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1036 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1037              assertSame(TEST_STRING, result);
1004        } catch (ExecutionException success) {
1005        } catch (Exception ex) {
1006            unexpectedException();
1038          } finally {
1039              joinPool(e);
1040          }
# Line 1012 | Line 1043 | public class ScheduledExecutorTest exten
1043      /**
1044       * timed invokeAll(null) throws NPE
1045       */
1046 <    public void testTimedInvokeAll1() {
1046 >    public void testTimedInvokeAll1() throws Exception {
1047          ExecutorService e = new ScheduledThreadPoolExecutor(2);
1048          try {
1049 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1049 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
1050 >            shouldThrow();
1051          } catch (NullPointerException success) {
1020        } catch (Exception ex) {
1021            unexpectedException();
1052          } finally {
1053              joinPool(e);
1054          }
# Line 1027 | Line 1057 | public class ScheduledExecutorTest exten
1057      /**
1058       * timed invokeAll(,,null) throws NPE
1059       */
1060 <    public void testTimedInvokeAllNullTimeUnit() {
1060 >    public void testTimedInvokeAllNullTimeUnit() throws Exception {
1061          ExecutorService e = new ScheduledThreadPoolExecutor(2);
1062 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1063 +        l.add(new StringTask());
1064          try {
1033            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1034            l.add(new StringTask());
1065              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1066 +            shouldThrow();
1067          } catch (NullPointerException success) {
1037        } catch (Exception ex) {
1038            unexpectedException();
1068          } finally {
1069              joinPool(e);
1070          }
# Line 1044 | Line 1073 | public class ScheduledExecutorTest exten
1073      /**
1074       * timed invokeAll(empty collection) returns empty collection
1075       */
1076 <    public void testTimedInvokeAll2() {
1076 >    public void testTimedInvokeAll2() throws Exception {
1077          ExecutorService e = new ScheduledThreadPoolExecutor(2);
1078          try {
1079 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1079 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1080              assertTrue(r.isEmpty());
1052        } catch (Exception ex) {
1053            unexpectedException();
1081          } finally {
1082              joinPool(e);
1083          }
# Line 1059 | Line 1086 | public class ScheduledExecutorTest exten
1086      /**
1087       * timed invokeAll(c) throws NPE if c has null elements
1088       */
1089 <    public void testTimedInvokeAll3() {
1089 >    public void testTimedInvokeAll3() throws Exception {
1090          ExecutorService e = new ScheduledThreadPoolExecutor(2);
1091 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1092 +        l.add(new StringTask());
1093 +        l.add(null);
1094          try {
1095 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1096 <            l.add(new StringTask());
1067 <            l.add(null);
1068 <            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1095 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1096 >            shouldThrow();
1097          } catch (NullPointerException success) {
1070        } catch (Exception ex) {
1071            unexpectedException();
1098          } finally {
1099              joinPool(e);
1100          }
# Line 1077 | Line 1103 | public class ScheduledExecutorTest exten
1103      /**
1104       * get of element of invokeAll(c) throws exception on failed task
1105       */
1106 <    public void testTimedInvokeAll4() {
1106 >    public void testTimedInvokeAll4() throws Exception {
1107          ExecutorService e = new ScheduledThreadPoolExecutor(2);
1108 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1109 +        l.add(new NPETask());
1110 +        List<Future<String>> futures =
1111 +            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1112 +        assertEquals(1, futures.size());
1113          try {
1114 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1115 <            l.add(new NPETask());
1085 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1086 <            assertEquals(1, result.size());
1087 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1088 <                it.next().get();
1114 >            futures.get(0).get();
1115 >            shouldThrow();
1116          } catch (ExecutionException success) {
1117 <        } catch (Exception ex) {
1091 <            unexpectedException();
1117 >            assertTrue(success.getCause() instanceof NullPointerException);
1118          } finally {
1119              joinPool(e);
1120          }
# Line 1097 | Line 1123 | public class ScheduledExecutorTest exten
1123      /**
1124       * timed invokeAll(c) returns results of all completed tasks
1125       */
1126 <    public void testTimedInvokeAll5() {
1126 >    public void testTimedInvokeAll5() throws Exception {
1127          ExecutorService e = new ScheduledThreadPoolExecutor(2);
1128          try {
1129 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1129 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1130              l.add(new StringTask());
1131              l.add(new StringTask());
1132 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1133 <            assertEquals(2, result.size());
1134 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1135 <                assertSame(TEST_STRING, it.next().get());
1136 <        } catch (ExecutionException success) {
1111 <        } catch (Exception ex) {
1112 <            unexpectedException();
1132 >            List<Future<String>> futures =
1133 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1134 >            assertEquals(2, futures.size());
1135 >            for (Future<String> future : futures)
1136 >                assertSame(TEST_STRING, future.get());
1137          } finally {
1138              joinPool(e);
1139          }
# Line 1118 | Line 1142 | public class ScheduledExecutorTest exten
1142      /**
1143       * timed invokeAll(c) cancels tasks not completed by timeout
1144       */
1145 <    public void testTimedInvokeAll6() {
1145 >    public void testTimedInvokeAll6() throws Exception {
1146          ExecutorService e = new ScheduledThreadPoolExecutor(2);
1147          try {
1148 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1148 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1149              l.add(new StringTask());
1150              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1151              l.add(new StringTask());
1152 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
1153 <            assertEquals(3, result.size());
1154 <            Iterator<Future<String>> it = result.iterator();
1152 >            List<Future<String>> futures =
1153 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1154 >            assertEquals(3, futures.size());
1155 >            Iterator<Future<String>> it = futures.iterator();
1156              Future<String> f1 = it.next();
1157              Future<String> f2 = it.next();
1158              Future<String> f3 = it.next();
# Line 1136 | Line 1161 | public class ScheduledExecutorTest exten
1161              assertTrue(f3.isDone());
1162              assertFalse(f1.isCancelled());
1163              assertTrue(f2.isCancelled());
1139        } catch (Exception ex) {
1140            unexpectedException();
1164          } finally {
1165              joinPool(e);
1166          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines