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.24 by jsr166, Mon Nov 16 05:30:08 2009 UTC vs.
Revision 1.25 by jsr166, Fri Nov 20 22:58:48 2009 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 {
# Line 23 | Line 24 | public class ScheduledExecutorTest exten
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) {
37 <                unexpectedException();
38 <            }
39 <            assertTrue(runnable.done);
40 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
41 <            joinPool(p1);
42 <        }
43 <        catch (Exception e) {
44 <            unexpectedException();
45 <        }
46 <
27 >    public void testExecute() throws InterruptedException {
28 >        TrackedShortRunnable runnable =new TrackedShortRunnable();
29 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
30 >        p1.execute(runnable);
31 >        assertFalse(runnable.done);
32 >        Thread.sleep(SHORT_DELAY_MS);
33 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
34 >        Thread.sleep(MEDIUM_DELAY_MS);
35 >        assertTrue(runnable.done);
36 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
37 >        joinPool(p1);
38      }
39  
40  
41      /**
42       * delayed schedule of callable successfully executes after delay
43       */
44 <    public void testSchedule1() {
45 <        try {
46 <            TrackedCallable callable = new TrackedCallable();
47 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
48 <            Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
49 <            assertFalse(callable.done);
50 <            Thread.sleep(MEDIUM_DELAY_MS);
51 <            assertTrue(callable.done);
52 <            assertEquals(Boolean.TRUE, f.get());
53 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
63 <            joinPool(p1);
64 <        } catch (RejectedExecutionException e) {}
65 <        catch (Exception e) {
66 <            e.printStackTrace();
67 <            unexpectedException();
68 <        }
44 >    public void testSchedule1() throws Exception {
45 >        TrackedCallable callable = new TrackedCallable();
46 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
47 >        Future f = p1.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
48 >        assertFalse(callable.done);
49 >        Thread.sleep(MEDIUM_DELAY_MS);
50 >        assertTrue(callable.done);
51 >        assertEquals(Boolean.TRUE, f.get());
52 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
53 >        joinPool(p1);
54      }
55  
56      /**
57       *  delayed schedule of runnable successfully executes after delay
58       */
59 <    public void testSchedule3() {
60 <        try {
61 <            TrackedShortRunnable runnable = new TrackedShortRunnable();
62 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
63 <            p1.schedule(runnable, SMALL_DELAY_MS, TimeUnit.MILLISECONDS);
64 <            Thread.sleep(SHORT_DELAY_MS);
65 <            assertFalse(runnable.done);
66 <            Thread.sleep(MEDIUM_DELAY_MS);
67 <            assertTrue(runnable.done);
68 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
84 <            joinPool(p1);
85 <        } catch (Exception e) {
86 <            unexpectedException();
87 <        }
59 >    public void testSchedule3() throws InterruptedException {
60 >        TrackedShortRunnable runnable = new TrackedShortRunnable();
61 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
62 >        p1.schedule(runnable, SMALL_DELAY_MS, MILLISECONDS);
63 >        Thread.sleep(SHORT_DELAY_MS);
64 >        assertFalse(runnable.done);
65 >        Thread.sleep(MEDIUM_DELAY_MS);
66 >        assertTrue(runnable.done);
67 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
68 >        joinPool(p1);
69      }
70  
71      /**
72       * scheduleAtFixedRate executes runnable after given initial delay
73       */
74 <    public void testSchedule4() {
75 <        try {
76 <            TrackedShortRunnable runnable = new TrackedShortRunnable();
77 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
78 <            ScheduledFuture h = p1.scheduleAtFixedRate(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
79 <            assertFalse(runnable.done);
80 <            Thread.sleep(MEDIUM_DELAY_MS);
81 <            assertTrue(runnable.done);
82 <            h.cancel(true);
102 <            joinPool(p1);
103 <        } catch (Exception e) {
104 <            unexpectedException();
105 <        }
74 >    public void testSchedule4() throws InterruptedException {
75 >        TrackedShortRunnable runnable = new TrackedShortRunnable();
76 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
77 >        ScheduledFuture h = p1.scheduleAtFixedRate(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, MILLISECONDS);
78 >        assertFalse(runnable.done);
79 >        Thread.sleep(MEDIUM_DELAY_MS);
80 >        assertTrue(runnable.done);
81 >        h.cancel(true);
82 >        joinPool(p1);
83      }
84  
85      static class RunnableCounter implements Runnable {
# Line 113 | Line 90 | public class ScheduledExecutorTest exten
90      /**
91       * scheduleWithFixedDelay executes runnable after given initial delay
92       */
93 <    public void testSchedule5() {
94 <        try {
95 <            TrackedShortRunnable runnable = new TrackedShortRunnable();
96 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
97 <            ScheduledFuture h = p1.scheduleWithFixedDelay(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);
125 <            joinPool(p1);
126 <        } catch (Exception e) {
127 <            unexpectedException();
128 <        }
93 >    public void testSchedule5() throws InterruptedException {
94 >        TrackedShortRunnable runnable = new TrackedShortRunnable();
95 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
96 >        ScheduledFuture h = p1.scheduleWithFixedDelay(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, MILLISECONDS);
97 >        assertFalse(runnable.done);
98 >        Thread.sleep(MEDIUM_DELAY_MS);
99 >        assertTrue(runnable.done);
100 >        h.cancel(true);
101 >        joinPool(p1);
102      }
103  
104      /**
105       * scheduleAtFixedRate executes series of tasks at given rate
106       */
107 <    public void testFixedRateSequence() {
108 <        try {
109 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
110 <            RunnableCounter counter = new RunnableCounter();
111 <            ScheduledFuture h =
112 <                p1.scheduleAtFixedRate(counter, 0, 1, TimeUnit.MILLISECONDS);
113 <            Thread.sleep(SMALL_DELAY_MS);
114 <            h.cancel(true);
115 <            int c = counter.count.get();
116 <            // By time scaling conventions, we must have at least
117 <            // an execution per SHORT delay, but no more than one SHORT more
118 <            assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
119 <            assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
147 <            joinPool(p1);
148 <        } catch (Exception e) {
149 <            unexpectedException();
150 <        }
107 >    public void testFixedRateSequence() throws InterruptedException {
108 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
109 >        RunnableCounter counter = new RunnableCounter();
110 >        ScheduledFuture h =
111 >            p1.scheduleAtFixedRate(counter, 0, 1, MILLISECONDS);
112 >        Thread.sleep(SMALL_DELAY_MS);
113 >        h.cancel(true);
114 >        int c = counter.count.get();
115 >        // By time scaling conventions, we must have at least
116 >        // an execution per SHORT delay, but no more than one SHORT more
117 >        assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
118 >        assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
119 >        joinPool(p1);
120      }
121  
122      /**
123       * scheduleWithFixedDelay executes series of tasks with given period
124       */
125 <    public void testFixedDelaySequence() {
126 <        try {
127 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
128 <            RunnableCounter counter = new RunnableCounter();
129 <            ScheduledFuture h =
130 <                p1.scheduleWithFixedDelay(counter, 0, 1, TimeUnit.MILLISECONDS);
131 <            Thread.sleep(SMALL_DELAY_MS);
132 <            h.cancel(true);
133 <            int c = counter.count.get();
134 <            assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
135 <            assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
167 <            joinPool(p1);
168 <        } catch (Exception e) {
169 <            unexpectedException();
170 <        }
125 >    public void testFixedDelaySequence() throws InterruptedException {
126 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
127 >        RunnableCounter counter = new RunnableCounter();
128 >        ScheduledFuture h =
129 >            p1.scheduleWithFixedDelay(counter, 0, 1, MILLISECONDS);
130 >        Thread.sleep(SMALL_DELAY_MS);
131 >        h.cancel(true);
132 >        int c = counter.count.get();
133 >        assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
134 >        assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
135 >        joinPool(p1);
136      }
137  
138  
139      /**
140       *  execute (null) throws NPE
141       */
142 <    public void testExecuteNull() {
142 >    public void testExecuteNull() throws InterruptedException {
143          ScheduledThreadPoolExecutor se = null;
144          try {
145              se = new ScheduledThreadPoolExecutor(1);
146              se.execute(null);
147              shouldThrow();
148          } catch (NullPointerException success) {}
184        catch (Exception e) {
185            unexpectedException();
186        }
149  
150          joinPool(se);
151      }
# Line 191 | Line 153 | public class ScheduledExecutorTest exten
153      /**
154       * schedule (null) throws NPE
155       */
156 <    public void testScheduleNull() {
156 >    public void testScheduleNull() throws InterruptedException {
157          ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
158          try {
159              TrackedCallable callable = null;
160 <            Future f = se.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
160 >            Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
161              shouldThrow();
162          } catch (NullPointerException success) {}
201        catch (Exception e) {
202            unexpectedException();
203        }
163          joinPool(se);
164      }
165  
166      /**
167       * execute throws RejectedExecutionException if shutdown
168       */
169 <    public void testSchedule1_RejectedExecutionException() {
169 >    public void testSchedule1_RejectedExecutionException() throws InterruptedException {
170          ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
171          try {
172              se.shutdown();
173              se.schedule(new NoOpRunnable(),
174 <                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
174 >                        MEDIUM_DELAY_MS, MILLISECONDS);
175              shouldThrow();
176          } catch (RejectedExecutionException success) {
177          } catch (SecurityException ok) {
# Line 225 | Line 184 | public class ScheduledExecutorTest exten
184      /**
185       * schedule throws RejectedExecutionException if shutdown
186       */
187 <    public void testSchedule2_RejectedExecutionException() {
187 >    public void testSchedule2_RejectedExecutionException() throws InterruptedException {
188          ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
189          try {
190              se.shutdown();
191              se.schedule(new NoOpCallable(),
192 <                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
192 >                        MEDIUM_DELAY_MS, MILLISECONDS);
193              shouldThrow();
194          } catch (RejectedExecutionException success) {
195          } catch (SecurityException ok) {
# Line 241 | Line 200 | public class ScheduledExecutorTest exten
200      /**
201       * schedule callable throws RejectedExecutionException if shutdown
202       */
203 <     public void testSchedule3_RejectedExecutionException() {
203 >     public void testSchedule3_RejectedExecutionException() throws InterruptedException {
204           ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
205           try {
206              se.shutdown();
207              se.schedule(new NoOpCallable(),
208 <                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
208 >                        MEDIUM_DELAY_MS, MILLISECONDS);
209              shouldThrow();
210          } catch (RejectedExecutionException success) {
211          } catch (SecurityException ok) {
# Line 257 | Line 216 | public class ScheduledExecutorTest exten
216      /**
217       *  scheduleAtFixedRate throws RejectedExecutionException if shutdown
218       */
219 <    public void testScheduleAtFixedRate1_RejectedExecutionException() {
219 >    public void testScheduleAtFixedRate1_RejectedExecutionException() throws InterruptedException {
220          ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
221          try {
222              se.shutdown();
223              se.scheduleAtFixedRate(new NoOpRunnable(),
224 <                                   MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
224 >                                   MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
225              shouldThrow();
226          } catch (RejectedExecutionException success) {
227          } catch (SecurityException ok) {
# Line 273 | Line 232 | public class ScheduledExecutorTest exten
232      /**
233       * scheduleWithFixedDelay throws RejectedExecutionException if shutdown
234       */
235 <    public void testScheduleWithFixedDelay1_RejectedExecutionException() {
235 >    public void testScheduleWithFixedDelay1_RejectedExecutionException() throws InterruptedException {
236          ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
237          try {
238              se.shutdown();
239              se.scheduleWithFixedDelay(new NoOpRunnable(),
240 <                                      MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
240 >                                      MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
241              shouldThrow();
242          } catch (RejectedExecutionException success) {
243          } catch (SecurityException ok) {
# Line 290 | Line 249 | public class ScheduledExecutorTest exten
249       *  getActiveCount increases but doesn't overestimate, when a
250       *  thread becomes active
251       */
252 <    public void testGetActiveCount() {
252 >    public void testGetActiveCount() throws InterruptedException {
253          ScheduledThreadPoolExecutor p2 = new ScheduledThreadPoolExecutor(2);
254          assertEquals(0, p2.getActiveCount());
255          p2.execute(new SmallRunnable());
256 <        try {
298 <            Thread.sleep(SHORT_DELAY_MS);
299 <        } catch (Exception e) {
300 <            unexpectedException();
301 <        }
256 >        Thread.sleep(SHORT_DELAY_MS);
257          assertEquals(1, p2.getActiveCount());
258          joinPool(p2);
259      }
# Line 307 | Line 262 | public class ScheduledExecutorTest exten
262       *    getCompletedTaskCount increases, but doesn't overestimate,
263       *   when tasks complete
264       */
265 <    public void testGetCompletedTaskCount() {
265 >    public void testGetCompletedTaskCount() throws InterruptedException {
266          ScheduledThreadPoolExecutor p2 = new ScheduledThreadPoolExecutor(2);
267          assertEquals(0, p2.getCompletedTaskCount());
268          p2.execute(new SmallRunnable());
269 <        try {
315 <            Thread.sleep(MEDIUM_DELAY_MS);
316 <        } catch (Exception e) {
317 <            unexpectedException();
318 <        }
269 >        Thread.sleep(MEDIUM_DELAY_MS);
270          assertEquals(1, p2.getCompletedTaskCount());
271          joinPool(p2);
272      }
# Line 323 | Line 274 | public class ScheduledExecutorTest exten
274      /**
275       *  getCorePoolSize returns size given in constructor if not otherwise set
276       */
277 <    public void testGetCorePoolSize() {
277 >    public void testGetCorePoolSize() throws InterruptedException {
278          ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
279          assertEquals(1, p1.getCorePoolSize());
280          joinPool(p1);
# Line 333 | Line 284 | public class ScheduledExecutorTest exten
284       *    getLargestPoolSize increases, but doesn't overestimate, when
285       *   multiple threads active
286       */
287 <    public void testGetLargestPoolSize() {
287 >    public void testGetLargestPoolSize() throws InterruptedException {
288          ScheduledThreadPoolExecutor p2 = new ScheduledThreadPoolExecutor(2);
289          assertEquals(0, p2.getLargestPoolSize());
290          p2.execute(new SmallRunnable());
291          p2.execute(new SmallRunnable());
292 <        try {
342 <            Thread.sleep(SHORT_DELAY_MS);
343 <        } catch (Exception e) {
344 <            unexpectedException();
345 <        }
292 >        Thread.sleep(SHORT_DELAY_MS);
293          assertEquals(2, p2.getLargestPoolSize());
294          joinPool(p2);
295      }
# Line 351 | Line 298 | public class ScheduledExecutorTest exten
298       *   getPoolSize increases, but doesn't overestimate, when threads
299       *   become active
300       */
301 <    public void testGetPoolSize() {
301 >    public void testGetPoolSize() throws InterruptedException {
302          ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
303          assertEquals(0, p1.getPoolSize());
304          p1.execute(new SmallRunnable());
# Line 363 | Line 310 | public class ScheduledExecutorTest exten
310       *    getTaskCount increases, but doesn't overestimate, when tasks
311       *    submitted
312       */
313 <    public void testGetTaskCount() {
313 >    public void testGetTaskCount() throws InterruptedException {
314          ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
315          assertEquals(0, p1.getTaskCount());
316          for (int i = 0; i < 5; i++)
317              p1.execute(new SmallRunnable());
318 <        try {
372 <            Thread.sleep(SHORT_DELAY_MS);
373 <        } catch (Exception e) {
374 <            unexpectedException();
375 <        }
318 >        Thread.sleep(SHORT_DELAY_MS);
319          assertEquals(5, p1.getTaskCount());
320          joinPool(p1);
321      }
# Line 380 | Line 323 | public class ScheduledExecutorTest exten
323      /**
324       * getThreadFactory returns factory in constructor if not set
325       */
326 <    public void testGetThreadFactory() {
326 >    public void testGetThreadFactory() throws InterruptedException {
327          ThreadFactory tf = new SimpleThreadFactory();
328          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, tf);
329          assertSame(tf, p.getThreadFactory());
# Line 390 | Line 333 | public class ScheduledExecutorTest exten
333      /**
334       * setThreadFactory sets the thread factory returned by getThreadFactory
335       */
336 <    public void testSetThreadFactory() {
336 >    public void testSetThreadFactory() throws InterruptedException {
337          ThreadFactory tf = new SimpleThreadFactory();
338          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
339          p.setThreadFactory(tf);
# Line 401 | Line 344 | public class ScheduledExecutorTest exten
344      /**
345       * setThreadFactory(null) throws NPE
346       */
347 <    public void testSetThreadFactoryNull() {
347 >    public void testSetThreadFactoryNull() throws InterruptedException {
348          ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
349          try {
350              p.setThreadFactory(null);
# Line 431 | Line 374 | public class ScheduledExecutorTest exten
374      /**
375       *   isTerminated is false before termination, true after
376       */
377 <    public void testIsTerminated() {
377 >    public void testIsTerminated() throws InterruptedException {
378          ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
379          try {
380              p1.execute(new SmallRunnable());
381          } finally {
382              try { p1.shutdown(); } catch (SecurityException ok) { return; }
383          }
384 <        try {
385 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
443 <            assertTrue(p1.isTerminated());
444 <        } catch (Exception e) {
445 <            unexpectedException();
446 <        }
384 >        assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
385 >        assertTrue(p1.isTerminated());
386      }
387  
388      /**
389       *  isTerminating is not true when running or when terminated
390       */
391 <    public void testIsTerminating() {
391 >    public void testIsTerminating() throws InterruptedException {
392          ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
393          assertFalse(p1.isTerminating());
394          try {
# Line 458 | Line 397 | public class ScheduledExecutorTest exten
397          } finally {
398              try { p1.shutdown(); } catch (SecurityException ok) { return; }
399          }
400 <        try {
401 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
402 <            assertTrue(p1.isTerminated());
403 <            assertFalse(p1.isTerminating());
465 <        } catch (Exception e) {
466 <            unexpectedException();
467 <        }
400 >
401 >        assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
402 >        assertTrue(p1.isTerminated());
403 >        assertFalse(p1.isTerminating());
404      }
405  
406      /**
407       * getQueue returns the work queue, which contains queued tasks
408       */
409 <    public void testGetQueue() {
409 >    public void testGetQueue() throws InterruptedException {
410          ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
411          ScheduledFuture[] tasks = new ScheduledFuture[5];
412          for (int i = 0; i < 5; i++) {
413 <            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS);
413 >            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, MILLISECONDS);
414          }
415          try {
416              Thread.sleep(SHORT_DELAY_MS);
417              BlockingQueue<Runnable> q = p1.getQueue();
418              assertTrue(q.contains(tasks[4]));
419              assertFalse(q.contains(tasks[0]));
484        } catch (Exception e) {
485            unexpectedException();
420          } finally {
421              joinPool(p1);
422          }
# Line 491 | Line 425 | public class ScheduledExecutorTest exten
425      /**
426       * remove(task) removes queued task, and fails to remove active task
427       */
428 <    public void testRemove() {
428 >    public void testRemove() throws InterruptedException {
429          ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
430          ScheduledFuture[] tasks = new ScheduledFuture[5];
431          for (int i = 0; i < 5; i++) {
432 <            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS);
432 >            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, MILLISECONDS);
433          }
434          try {
435              Thread.sleep(SHORT_DELAY_MS);
# Line 509 | Line 443 | public class ScheduledExecutorTest exten
443              assertTrue(q.contains((Runnable)tasks[3]));
444              assertTrue(p1.remove((Runnable)tasks[3]));
445              assertFalse(q.contains((Runnable)tasks[3]));
512        } catch (Exception e) {
513            unexpectedException();
446          } finally {
447              joinPool(p1);
448          }
# Line 519 | Line 451 | public class ScheduledExecutorTest exten
451      /**
452       *  purge removes cancelled tasks from the queue
453       */
454 <    public void testPurge() {
454 >    public void testPurge() throws InterruptedException {
455          ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
456          ScheduledFuture[] tasks = new ScheduledFuture[5];
457          for (int i = 0; i < 5; i++) {
458 <            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
458 >            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS);
459          }
460          try {
461              int max = 5;
# Line 540 | Line 472 | public class ScheduledExecutorTest exten
472                  Thread.sleep(1);
473              }
474              assertTrue(k < SMALL_DELAY_MS);
543        } catch (Exception e) {
544            unexpectedException();
475          } finally {
476              joinPool(p1);
477          }
# Line 550 | Line 480 | public class ScheduledExecutorTest exten
480      /**
481       *  shutDownNow returns a list containing tasks that were not run
482       */
483 <    public void testShutDownNow() {
483 >    public void testShutDownNow() throws InterruptedException {
484          ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
485          for (int i = 0; i < 5; i++)
486 <            p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
486 >            p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS);
487          List l;
488          try {
489              l = p1.shutdownNow();
# Line 569 | Line 499 | public class ScheduledExecutorTest exten
499       * In default setting, shutdown cancels periodic but not delayed
500       * tasks at shutdown
501       */
502 <    public void testShutDown1() {
503 <        try {
504 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
505 <            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 <            }
502 >    public void testShutDown1() throws InterruptedException {
503 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
504 >        assertTrue(p1.getExecuteExistingDelayedTasksAfterShutdownPolicy());
505 >        assertFalse(p1.getContinueExistingPeriodicTasksAfterShutdownPolicy());
506  
507 <        }
508 <        catch (Exception ex) {
509 <            unexpectedException();
507 >        ScheduledFuture[] tasks = new ScheduledFuture[5];
508 >        for (int i = 0; i < 5; i++)
509 >            tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, MILLISECONDS);
510 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
511 >        BlockingQueue q = p1.getQueue();
512 >        for (Iterator it = q.iterator(); it.hasNext();) {
513 >            ScheduledFuture t = (ScheduledFuture)it.next();
514 >            assertFalse(t.isCancelled());
515 >        }
516 >        assertTrue(p1.isShutdown());
517 >        Thread.sleep(SMALL_DELAY_MS);
518 >        for (int i = 0; i < 5; ++i) {
519 >            assertTrue(tasks[i].isDone());
520 >            assertFalse(tasks[i].isCancelled());
521          }
522      }
523  
# Line 602 | Line 526 | public class ScheduledExecutorTest exten
526       * If setExecuteExistingDelayedTasksAfterShutdownPolicy is false,
527       * delayed tasks are cancelled at shutdown
528       */
529 <    public void testShutDown2() {
530 <        try {
531 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
532 <            p1.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
533 <            ScheduledFuture[] tasks = new ScheduledFuture[5];
534 <            for (int i = 0; i < 5; i++)
535 <                tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
536 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
537 <            assertTrue(p1.isShutdown());
538 <            BlockingQueue q = p1.getQueue();
539 <            assertTrue(q.isEmpty());
540 <            Thread.sleep(SMALL_DELAY_MS);
617 <            assertTrue(p1.isTerminated());
618 <        }
619 <        catch (Exception ex) {
620 <            unexpectedException();
621 <        }
529 >    public void testShutDown2() throws InterruptedException {
530 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
531 >        p1.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
532 >        ScheduledFuture[] tasks = new ScheduledFuture[5];
533 >        for (int i = 0; i < 5; i++)
534 >            tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, MILLISECONDS);
535 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
536 >        assertTrue(p1.isShutdown());
537 >        BlockingQueue q = p1.getQueue();
538 >        assertTrue(q.isEmpty());
539 >        Thread.sleep(SMALL_DELAY_MS);
540 >        assertTrue(p1.isTerminated());
541      }
542  
543  
# Line 626 | Line 545 | public class ScheduledExecutorTest exten
545       * If setContinueExistingPeriodicTasksAfterShutdownPolicy is set false,
546       * periodic tasks are not cancelled at shutdown
547       */
548 <    public void testShutDown3() {
549 <        try {
550 <            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
551 <            p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
552 <            ScheduledFuture task =
553 <                p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS);
554 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
555 <            assertTrue(p1.isShutdown());
556 <            BlockingQueue q = p1.getQueue();
557 <            assertTrue(q.isEmpty());
558 <            Thread.sleep(SHORT_DELAY_MS);
640 <            assertTrue(p1.isTerminated());
641 <        }
642 <        catch (Exception ex) {
643 <            unexpectedException();
644 <        }
548 >    public void testShutDown3() throws InterruptedException {
549 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
550 >        p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
551 >        ScheduledFuture task =
552 >            p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, MILLISECONDS);
553 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
554 >        assertTrue(p1.isShutdown());
555 >        BlockingQueue q = p1.getQueue();
556 >        assertTrue(q.isEmpty());
557 >        Thread.sleep(SHORT_DELAY_MS);
558 >        assertTrue(p1.isTerminated());
559      }
560  
561      /**
562       * if setContinueExistingPeriodicTasksAfterShutdownPolicy is true,
563       * periodic tasks are cancelled at shutdown
564       */
565 <    public void testShutDown4() {
565 >    public void testShutDown4() throws InterruptedException {
566          ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
567          try {
568              p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
569              ScheduledFuture task =
570 <                p1.scheduleAtFixedRate(new NoOpRunnable(), 1, 1, TimeUnit.MILLISECONDS);
570 >                p1.scheduleAtFixedRate(new NoOpRunnable(), 1, 1, MILLISECONDS);
571              assertFalse(task.isCancelled());
572              try { p1.shutdown(); } catch (SecurityException ok) { return; }
573              assertFalse(task.isCancelled());
# Line 666 | Line 580 | public class ScheduledExecutorTest exten
580              Thread.sleep(SHORT_DELAY_MS);
581              assertTrue(p1.isTerminated());
582          }
669        catch (Exception ex) {
670            unexpectedException();
671        }
583          finally {
584              joinPool(p1);
585          }
# Line 677 | Line 588 | public class ScheduledExecutorTest exten
588      /**
589       * completed submit of callable returns result
590       */
591 <    public void testSubmitCallable() {
591 >    public void testSubmitCallable() throws Exception {
592          ExecutorService e = new ScheduledThreadPoolExecutor(2);
593          try {
594              Future<String> future = e.submit(new StringTask());
595              String result = future.get();
596              assertSame(TEST_STRING, result);
686        }
687        catch (ExecutionException ex) {
688            unexpectedException();
689        }
690        catch (InterruptedException ex) {
691            unexpectedException();
597          } finally {
598              joinPool(e);
599          }
# Line 697 | Line 602 | public class ScheduledExecutorTest exten
602      /**
603       * completed submit of runnable returns successfully
604       */
605 <    public void testSubmitRunnable() {
605 >    public void testSubmitRunnable() throws Exception {
606          ExecutorService e = new ScheduledThreadPoolExecutor(2);
607          try {
608              Future<?> future = e.submit(new NoOpRunnable());
609              future.get();
610              assertTrue(future.isDone());
706        }
707        catch (ExecutionException ex) {
708            unexpectedException();
709        }
710        catch (InterruptedException ex) {
711            unexpectedException();
611          } finally {
612              joinPool(e);
613          }
# Line 717 | Line 616 | public class ScheduledExecutorTest exten
616      /**
617       * completed submit of (runnable, result) returns result
618       */
619 <    public void testSubmitRunnable2() {
619 >    public void testSubmitRunnable2() throws Exception {
620          ExecutorService e = new ScheduledThreadPoolExecutor(2);
621          try {
622              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
623              String result = future.get();
624              assertSame(TEST_STRING, result);
726        }
727        catch (ExecutionException ex) {
728            unexpectedException();
729        }
730        catch (InterruptedException ex) {
731            unexpectedException();
625          } finally {
626              joinPool(e);
627          }
# Line 737 | Line 630 | public class ScheduledExecutorTest exten
630      /**
631       * invokeAny(null) throws NPE
632       */
633 <    public void testInvokeAny1() {
633 >    public void testInvokeAny1() throws Exception {
634          ExecutorService e = new ScheduledThreadPoolExecutor(2);
635          try {
636              e.invokeAny(null);
637 +            shouldThrow();
638          } catch (NullPointerException success) {
745        } catch (Exception ex) {
746            unexpectedException();
639          } finally {
640              joinPool(e);
641          }
# Line 752 | Line 644 | public class ScheduledExecutorTest exten
644      /**
645       * invokeAny(empty collection) throws IAE
646       */
647 <    public void testInvokeAny2() {
647 >    public void testInvokeAny2() throws Exception {
648          ExecutorService e = new ScheduledThreadPoolExecutor(2);
649          try {
650              e.invokeAny(new ArrayList<Callable<String>>());
651 +            shouldThrow();
652          } catch (IllegalArgumentException success) {
760        } catch (Exception ex) {
761            unexpectedException();
653          } finally {
654              joinPool(e);
655          }
# Line 767 | Line 658 | public class ScheduledExecutorTest exten
658      /**
659       * invokeAny(c) throws NPE if c has null elements
660       */
661 <    public void testInvokeAny3() {
661 >    public void testInvokeAny3() throws Exception {
662 >        final CountDownLatch latch = new CountDownLatch(1);
663          ExecutorService e = new ScheduledThreadPoolExecutor(2);
664          try {
665              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
666 <            l.add(new StringTask());
666 >            l.add(new Callable<String>() {
667 >                      public String call() {
668 >                          try {
669 >                              latch.await();
670 >                          } catch (InterruptedException ok) {}
671 >                          return TEST_STRING;
672 >                      }});
673              l.add(null);
674              e.invokeAny(l);
675 +            shouldThrow();
676          } catch (NullPointerException success) {
778        } catch (Exception ex) {
779            unexpectedException();
677          } finally {
678 +            latch.countDown();
679              joinPool(e);
680          }
681      }
# Line 785 | Line 683 | public class ScheduledExecutorTest exten
683      /**
684       * invokeAny(c) throws ExecutionException if no task completes
685       */
686 <    public void testInvokeAny4() {
686 >    public void testInvokeAny4() throws Exception {
687          ExecutorService e = new ScheduledThreadPoolExecutor(2);
688          try {
689              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
690              l.add(new NPETask());
691              e.invokeAny(l);
692 +            shouldThrow();
693          } catch (ExecutionException success) {
694 <        } catch (Exception ex) {
796 <            unexpectedException();
694 >            assertTrue(success.getCause() instanceof NullPointerException);
695          } finally {
696              joinPool(e);
697          }
# Line 802 | Line 700 | public class ScheduledExecutorTest exten
700      /**
701       * invokeAny(c) returns result of some task
702       */
703 <    public void testInvokeAny5() {
703 >    public void testInvokeAny5() throws Exception {
704          ExecutorService e = new ScheduledThreadPoolExecutor(2);
705          try {
706              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 810 | Line 708 | public class ScheduledExecutorTest exten
708              l.add(new StringTask());
709              String result = e.invokeAny(l);
710              assertSame(TEST_STRING, result);
813        } catch (ExecutionException success) {
814        } catch (Exception ex) {
815            unexpectedException();
711          } finally {
712              joinPool(e);
713          }
# Line 821 | Line 716 | public class ScheduledExecutorTest exten
716      /**
717       * invokeAll(null) throws NPE
718       */
719 <    public void testInvokeAll1() {
719 >    public void testInvokeAll1() throws Exception {
720          ExecutorService e = new ScheduledThreadPoolExecutor(2);
721          try {
722              e.invokeAll(null);
723 +            shouldThrow();
724          } catch (NullPointerException success) {
829        } catch (Exception ex) {
830            unexpectedException();
725          } finally {
726              joinPool(e);
727          }
# Line 836 | Line 730 | public class ScheduledExecutorTest exten
730      /**
731       * invokeAll(empty collection) returns empty collection
732       */
733 <    public void testInvokeAll2() {
733 >    public void testInvokeAll2() throws Exception {
734          ExecutorService e = new ScheduledThreadPoolExecutor(2);
735          try {
736              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
737              assertTrue(r.isEmpty());
844        } catch (Exception ex) {
845            unexpectedException();
738          } finally {
739              joinPool(e);
740          }
# Line 851 | Line 743 | public class ScheduledExecutorTest exten
743      /**
744       * invokeAll(c) throws NPE if c has null elements
745       */
746 <    public void testInvokeAll3() {
746 >    public void testInvokeAll3() throws Exception {
747          ExecutorService e = new ScheduledThreadPoolExecutor(2);
748          try {
749              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
750              l.add(new StringTask());
751              l.add(null);
752              e.invokeAll(l);
753 +            shouldThrow();
754          } catch (NullPointerException success) {
862        } catch (Exception ex) {
863            unexpectedException();
755          } finally {
756              joinPool(e);
757          }
# Line 869 | Line 760 | public class ScheduledExecutorTest exten
760      /**
761       * get of invokeAll(c) throws exception on failed task
762       */
763 <    public void testInvokeAll4() {
763 >    public void testInvokeAll4() throws Exception {
764          ExecutorService e = new ScheduledThreadPoolExecutor(2);
765          try {
766              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
767              l.add(new NPETask());
768              List<Future<String>> result = e.invokeAll(l);
769              assertEquals(1, result.size());
770 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
771 <                it.next().get();
770 >            for (Future<String> future : result)
771 >                future.get();
772 >            shouldThrow();
773          } catch (ExecutionException success) {
774 <        } catch (Exception ex) {
883 <            unexpectedException();
774 >            assertTrue(success.getCause() instanceof NullPointerException);
775          } finally {
776              joinPool(e);
777          }
# Line 889 | Line 780 | public class ScheduledExecutorTest exten
780      /**
781       * invokeAll(c) returns results of all completed tasks
782       */
783 <    public void testInvokeAll5() {
783 >    public void testInvokeAll5() throws Exception {
784          ExecutorService e = new ScheduledThreadPoolExecutor(2);
785          try {
786              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 897 | Line 788 | public class ScheduledExecutorTest exten
788              l.add(new StringTask());
789              List<Future<String>> result = e.invokeAll(l);
790              assertEquals(2, result.size());
791 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
792 <                assertSame(TEST_STRING, it.next().get());
902 <        } catch (ExecutionException success) {
903 <        } catch (Exception ex) {
904 <            unexpectedException();
791 >            for (Future<String> future : result)
792 >                assertSame(TEST_STRING, future.get());
793          } finally {
794              joinPool(e);
795          }
# Line 910 | Line 798 | public class ScheduledExecutorTest exten
798      /**
799       * timed invokeAny(null) throws NPE
800       */
801 <    public void testTimedInvokeAny1() {
801 >    public void testTimedInvokeAny1() throws Exception {
802          ExecutorService e = new ScheduledThreadPoolExecutor(2);
803          try {
804 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
804 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
805 >            shouldThrow();
806          } catch (NullPointerException success) {
918        } catch (Exception ex) {
919            unexpectedException();
807          } finally {
808              joinPool(e);
809          }
# Line 925 | Line 812 | public class ScheduledExecutorTest exten
812      /**
813       * timed invokeAny(,,null) throws NPE
814       */
815 <    public void testTimedInvokeAnyNullTimeUnit() {
815 >    public void testTimedInvokeAnyNullTimeUnit() throws Exception {
816          ExecutorService e = new ScheduledThreadPoolExecutor(2);
817          try {
818              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
819              l.add(new StringTask());
820              e.invokeAny(l, MEDIUM_DELAY_MS, null);
821 +            shouldThrow();
822          } catch (NullPointerException success) {
935        } catch (Exception ex) {
936            unexpectedException();
823          } finally {
824              joinPool(e);
825          }
# Line 942 | Line 828 | public class ScheduledExecutorTest exten
828      /**
829       * timed invokeAny(empty collection) throws IAE
830       */
831 <    public void testTimedInvokeAny2() {
831 >    public void testTimedInvokeAny2() throws Exception {
832          ExecutorService e = new ScheduledThreadPoolExecutor(2);
833          try {
834 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
834 >            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
835 >            shouldThrow();
836          } catch (IllegalArgumentException success) {
950        } catch (Exception ex) {
951            unexpectedException();
837          } finally {
838              joinPool(e);
839          }
# Line 957 | Line 842 | public class ScheduledExecutorTest exten
842      /**
843       * timed invokeAny(c) throws NPE if c has null elements
844       */
845 <    public void testTimedInvokeAny3() {
845 >    public void testTimedInvokeAny3() throws Exception {
846 >        final CountDownLatch latch = new CountDownLatch(1);
847          ExecutorService e = new ScheduledThreadPoolExecutor(2);
848          try {
849              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
850 <            l.add(new StringTask());
850 >            l.add(new Callable<String>() {
851 >                      public String call() {
852 >                          try {
853 >                              latch.await();
854 >                          } catch (InterruptedException ok) {}
855 >                          return TEST_STRING;
856 >                      }});
857              l.add(null);
858 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
858 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
859 >            shouldThrow();
860          } catch (NullPointerException success) {
968        } catch (Exception ex) {
969            ex.printStackTrace();
970            unexpectedException();
861          } finally {
862 +            latch.countDown();
863              joinPool(e);
864          }
865      }
# Line 976 | Line 867 | public class ScheduledExecutorTest exten
867      /**
868       * timed invokeAny(c) throws ExecutionException if no task completes
869       */
870 <    public void testTimedInvokeAny4() {
870 >    public void testTimedInvokeAny4() throws Exception {
871          ExecutorService e = new ScheduledThreadPoolExecutor(2);
872          try {
873              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
874              l.add(new NPETask());
875 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
875 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
876 >            shouldThrow();
877          } catch (ExecutionException success) {
878 <        } catch (Exception ex) {
987 <            unexpectedException();
878 >            assertTrue(success.getCause() instanceof NullPointerException);
879          } finally {
880              joinPool(e);
881          }
# Line 993 | Line 884 | public class ScheduledExecutorTest exten
884      /**
885       * timed invokeAny(c) returns result of some task
886       */
887 <    public void testTimedInvokeAny5() {
887 >    public void testTimedInvokeAny5() throws Exception {
888          ExecutorService e = new ScheduledThreadPoolExecutor(2);
889          try {
890              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
891              l.add(new StringTask());
892              l.add(new StringTask());
893 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
893 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
894              assertSame(TEST_STRING, result);
1004        } catch (ExecutionException success) {
1005        } catch (Exception ex) {
1006            unexpectedException();
895          } finally {
896              joinPool(e);
897          }
# Line 1012 | Line 900 | public class ScheduledExecutorTest exten
900      /**
901       * timed invokeAll(null) throws NPE
902       */
903 <    public void testTimedInvokeAll1() {
903 >    public void testTimedInvokeAll1() throws Exception {
904          ExecutorService e = new ScheduledThreadPoolExecutor(2);
905          try {
906 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
906 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
907 >            shouldThrow();
908          } catch (NullPointerException success) {
1020        } catch (Exception ex) {
1021            unexpectedException();
909          } finally {
910              joinPool(e);
911          }
# Line 1027 | Line 914 | public class ScheduledExecutorTest exten
914      /**
915       * timed invokeAll(,,null) throws NPE
916       */
917 <    public void testTimedInvokeAllNullTimeUnit() {
917 >    public void testTimedInvokeAllNullTimeUnit() throws Exception {
918          ExecutorService e = new ScheduledThreadPoolExecutor(2);
919          try {
920              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
921              l.add(new StringTask());
922              e.invokeAll(l, MEDIUM_DELAY_MS, null);
923 +            shouldThrow();
924          } catch (NullPointerException success) {
1037        } catch (Exception ex) {
1038            unexpectedException();
925          } finally {
926              joinPool(e);
927          }
# Line 1044 | Line 930 | public class ScheduledExecutorTest exten
930      /**
931       * timed invokeAll(empty collection) returns empty collection
932       */
933 <    public void testTimedInvokeAll2() {
933 >    public void testTimedInvokeAll2() throws Exception {
934          ExecutorService e = new ScheduledThreadPoolExecutor(2);
935          try {
936 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
936 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
937              assertTrue(r.isEmpty());
1052        } catch (Exception ex) {
1053            unexpectedException();
938          } finally {
939              joinPool(e);
940          }
# Line 1059 | Line 943 | public class ScheduledExecutorTest exten
943      /**
944       * timed invokeAll(c) throws NPE if c has null elements
945       */
946 <    public void testTimedInvokeAll3() {
946 >    public void testTimedInvokeAll3() throws Exception {
947          ExecutorService e = new ScheduledThreadPoolExecutor(2);
948          try {
949              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
950              l.add(new StringTask());
951              l.add(null);
952 <            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
952 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
953 >            shouldThrow();
954          } catch (NullPointerException success) {
1070        } catch (Exception ex) {
1071            unexpectedException();
955          } finally {
956              joinPool(e);
957          }
# Line 1077 | Line 960 | public class ScheduledExecutorTest exten
960      /**
961       * get of element of invokeAll(c) throws exception on failed task
962       */
963 <    public void testTimedInvokeAll4() {
963 >    public void testTimedInvokeAll4() throws Exception {
964          ExecutorService e = new ScheduledThreadPoolExecutor(2);
965          try {
966              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
967              l.add(new NPETask());
968 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
968 >            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
969              assertEquals(1, result.size());
970 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
971 <                it.next().get();
970 >            for (Future<String> future : result)
971 >                future.get();
972 >            shouldThrow();
973          } catch (ExecutionException success) {
974 <        } catch (Exception ex) {
1091 <            unexpectedException();
974 >            assertTrue(success.getCause() instanceof NullPointerException);
975          } finally {
976              joinPool(e);
977          }
# Line 1097 | Line 980 | public class ScheduledExecutorTest exten
980      /**
981       * timed invokeAll(c) returns results of all completed tasks
982       */
983 <    public void testTimedInvokeAll5() {
983 >    public void testTimedInvokeAll5() throws Exception {
984          ExecutorService e = new ScheduledThreadPoolExecutor(2);
985          try {
986              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
987              l.add(new StringTask());
988              l.add(new StringTask());
989 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
989 >            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
990              assertEquals(2, result.size());
991 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
992 <                assertSame(TEST_STRING, it.next().get());
1110 <        } catch (ExecutionException success) {
1111 <        } catch (Exception ex) {
1112 <            unexpectedException();
991 >            for (Future<String> future : result)
992 >                assertSame(TEST_STRING, future.get());
993          } finally {
994              joinPool(e);
995          }
# Line 1118 | Line 998 | public class ScheduledExecutorTest exten
998      /**
999       * timed invokeAll(c) cancels tasks not completed by timeout
1000       */
1001 <    public void testTimedInvokeAll6() {
1001 >    public void testTimedInvokeAll6() throws Exception {
1002          ExecutorService e = new ScheduledThreadPoolExecutor(2);
1003          try {
1004              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1005              l.add(new StringTask());
1006              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1007              l.add(new StringTask());
1008 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
1008 >            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1009              assertEquals(3, result.size());
1010              Iterator<Future<String>> it = result.iterator();
1011              Future<String> f1 = it.next();
# Line 1136 | Line 1016 | public class ScheduledExecutorTest exten
1016              assertTrue(f3.isDone());
1017              assertFalse(f1.isCancelled());
1018              assertTrue(f2.isCancelled());
1139        } catch (Exception ex) {
1140            unexpectedException();
1019          } finally {
1020              joinPool(e);
1021          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines