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

Comparing jsr166/src/test/tck/ScheduledExecutorSubclassTest.java (file contents):
Revision 1.5 by jsr166, Fri Nov 20 16:00:19 2009 UTC vs.
Revision 1.6 by jsr166, Fri Nov 20 22:58:48 2009 UTC

# Line 7 | Line 7
7   import junit.framework.*;
8   import java.util.*;
9   import java.util.concurrent.*;
10 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
11   import java.util.concurrent.atomic.*;
12  
13   public class ScheduledExecutorSubclassTest extends JSR166TestCase {
# Line 77 | Line 78 | public class ScheduledExecutorSubclassTe
78      /**
79       * execute successfully executes a runnable
80       */
81 <    public void testExecute() {
82 <        try {
83 <            TrackedShortRunnable runnable =new TrackedShortRunnable();
84 <            CustomExecutor p1 = new CustomExecutor(1);
85 <            p1.execute(runnable);
86 <            assertFalse(runnable.done);
87 <            Thread.sleep(SHORT_DELAY_MS);
88 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
89 <            try {
90 <                Thread.sleep(MEDIUM_DELAY_MS);
91 <            } catch (InterruptedException e) {
91 <                unexpectedException();
92 <            }
93 <            assertTrue(runnable.done);
94 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
95 <            joinPool(p1);
96 <        }
97 <        catch (Exception e) {
98 <            unexpectedException();
99 <        }
100 <
81 >    public void testExecute() throws InterruptedException {
82 >        TrackedShortRunnable runnable =new TrackedShortRunnable();
83 >        CustomExecutor p1 = new CustomExecutor(1);
84 >        p1.execute(runnable);
85 >        assertFalse(runnable.done);
86 >        Thread.sleep(SHORT_DELAY_MS);
87 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
88 >        Thread.sleep(MEDIUM_DELAY_MS);
89 >        assertTrue(runnable.done);
90 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
91 >        joinPool(p1);
92      }
93  
94  
95      /**
96       * delayed schedule of callable successfully executes after delay
97       */
98 <    public void testSchedule1() {
99 <        try {
100 <            TrackedCallable callable = new TrackedCallable();
101 <            CustomExecutor p1 = new CustomExecutor(1);
102 <            Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
103 <            assertFalse(callable.done);
104 <            Thread.sleep(MEDIUM_DELAY_MS);
105 <            assertTrue(callable.done);
106 <            assertEquals(Boolean.TRUE, f.get());
107 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
117 <            joinPool(p1);
118 <        } catch (RejectedExecutionException e) {}
119 <        catch (Exception e) {
120 <            e.printStackTrace();
121 <            unexpectedException();
122 <        }
98 >    public void testSchedule1() throws Exception {
99 >        TrackedCallable callable = new TrackedCallable();
100 >        CustomExecutor p1 = new CustomExecutor(1);
101 >        Future f = p1.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
102 >        assertFalse(callable.done);
103 >        Thread.sleep(MEDIUM_DELAY_MS);
104 >        assertTrue(callable.done);
105 >        assertEquals(Boolean.TRUE, f.get());
106 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
107 >        joinPool(p1);
108      }
109  
110      /**
111       *  delayed schedule of runnable successfully executes after delay
112       */
113 <    public void testSchedule3() {
114 <        try {
115 <            TrackedShortRunnable runnable = new TrackedShortRunnable();
116 <            CustomExecutor p1 = new CustomExecutor(1);
117 <            p1.schedule(runnable, SMALL_DELAY_MS, TimeUnit.MILLISECONDS);
118 <            Thread.sleep(SHORT_DELAY_MS);
119 <            assertFalse(runnable.done);
120 <            Thread.sleep(MEDIUM_DELAY_MS);
121 <            assertTrue(runnable.done);
122 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
138 <            joinPool(p1);
139 <        } catch (Exception e) {
140 <            unexpectedException();
141 <        }
113 >    public void testSchedule3() throws InterruptedException {
114 >        TrackedShortRunnable runnable = new TrackedShortRunnable();
115 >        CustomExecutor p1 = new CustomExecutor(1);
116 >        p1.schedule(runnable, SMALL_DELAY_MS, MILLISECONDS);
117 >        Thread.sleep(SHORT_DELAY_MS);
118 >        assertFalse(runnable.done);
119 >        Thread.sleep(MEDIUM_DELAY_MS);
120 >        assertTrue(runnable.done);
121 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
122 >        joinPool(p1);
123      }
124  
125      /**
126       * scheduleAtFixedRate executes runnable after given initial delay
127       */
128 <    public void testSchedule4() {
129 <        try {
130 <            TrackedShortRunnable runnable = new TrackedShortRunnable();
131 <            CustomExecutor p1 = new CustomExecutor(1);
132 <            ScheduledFuture h = p1.scheduleAtFixedRate(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
133 <            assertFalse(runnable.done);
134 <            Thread.sleep(MEDIUM_DELAY_MS);
135 <            assertTrue(runnable.done);
136 <            h.cancel(true);
156 <            joinPool(p1);
157 <        } catch (Exception e) {
158 <            unexpectedException();
159 <        }
128 >    public void testSchedule4() throws InterruptedException {
129 >        TrackedShortRunnable runnable = new TrackedShortRunnable();
130 >        CustomExecutor p1 = new CustomExecutor(1);
131 >        ScheduledFuture h = p1.scheduleAtFixedRate(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, MILLISECONDS);
132 >        assertFalse(runnable.done);
133 >        Thread.sleep(MEDIUM_DELAY_MS);
134 >        assertTrue(runnable.done);
135 >        h.cancel(true);
136 >        joinPool(p1);
137      }
138  
139      static class RunnableCounter implements Runnable {
# Line 167 | Line 144 | public class ScheduledExecutorSubclassTe
144      /**
145       * scheduleWithFixedDelay executes runnable after given initial delay
146       */
147 <    public void testSchedule5() {
148 <        try {
149 <            TrackedShortRunnable runnable = new TrackedShortRunnable();
150 <            CustomExecutor p1 = new CustomExecutor(1);
151 <            ScheduledFuture h = p1.scheduleWithFixedDelay(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
152 <            assertFalse(runnable.done);
153 <            Thread.sleep(MEDIUM_DELAY_MS);
154 <            assertTrue(runnable.done);
155 <            h.cancel(true);
179 <            joinPool(p1);
180 <        } catch (Exception e) {
181 <            unexpectedException();
182 <        }
147 >    public void testSchedule5() throws InterruptedException {
148 >        TrackedShortRunnable runnable = new TrackedShortRunnable();
149 >        CustomExecutor p1 = new CustomExecutor(1);
150 >        ScheduledFuture h = p1.scheduleWithFixedDelay(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, MILLISECONDS);
151 >        assertFalse(runnable.done);
152 >        Thread.sleep(MEDIUM_DELAY_MS);
153 >        assertTrue(runnable.done);
154 >        h.cancel(true);
155 >        joinPool(p1);
156      }
157  
158      /**
159       * scheduleAtFixedRate executes series of tasks at given rate
160       */
161 <    public void testFixedRateSequence() {
162 <        try {
163 <            CustomExecutor p1 = new CustomExecutor(1);
164 <            RunnableCounter counter = new RunnableCounter();
165 <            ScheduledFuture h =
166 <                p1.scheduleAtFixedRate(counter, 0, 1, TimeUnit.MILLISECONDS);
167 <            Thread.sleep(SMALL_DELAY_MS);
168 <            h.cancel(true);
169 <            int c = counter.count.get();
170 <            // By time scaling conventions, we must have at least
171 <            // an execution per SHORT delay, but no more than one SHORT more
172 <            assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
173 <            assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
201 <            joinPool(p1);
202 <        } catch (Exception e) {
203 <            unexpectedException();
204 <        }
161 >    public void testFixedRateSequence() throws InterruptedException {
162 >        CustomExecutor p1 = new CustomExecutor(1);
163 >        RunnableCounter counter = new RunnableCounter();
164 >        ScheduledFuture h =
165 >            p1.scheduleAtFixedRate(counter, 0, 1, MILLISECONDS);
166 >        Thread.sleep(SMALL_DELAY_MS);
167 >        h.cancel(true);
168 >        int c = counter.count.get();
169 >        // By time scaling conventions, we must have at least
170 >        // an execution per SHORT delay, but no more than one SHORT more
171 >        assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
172 >        assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
173 >        joinPool(p1);
174      }
175  
176      /**
177       * scheduleWithFixedDelay executes series of tasks with given period
178       */
179 <    public void testFixedDelaySequence() {
180 <        try {
181 <            CustomExecutor p1 = new CustomExecutor(1);
182 <            RunnableCounter counter = new RunnableCounter();
183 <            ScheduledFuture h =
184 <                p1.scheduleWithFixedDelay(counter, 0, 1, TimeUnit.MILLISECONDS);
185 <            Thread.sleep(SMALL_DELAY_MS);
186 <            h.cancel(true);
187 <            int c = counter.count.get();
188 <            assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
189 <            assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
221 <            joinPool(p1);
222 <        } catch (Exception e) {
223 <            unexpectedException();
224 <        }
179 >    public void testFixedDelaySequence() throws InterruptedException {
180 >        CustomExecutor p1 = new CustomExecutor(1);
181 >        RunnableCounter counter = new RunnableCounter();
182 >        ScheduledFuture h =
183 >            p1.scheduleWithFixedDelay(counter, 0, 1, MILLISECONDS);
184 >        Thread.sleep(SMALL_DELAY_MS);
185 >        h.cancel(true);
186 >        int c = counter.count.get();
187 >        assertTrue(c >= SMALL_DELAY_MS / SHORT_DELAY_MS);
188 >        assertTrue(c <= SMALL_DELAY_MS + SHORT_DELAY_MS);
189 >        joinPool(p1);
190      }
191  
192  
193      /**
194       *  execute (null) throws NPE
195       */
196 <    public void testExecuteNull() {
197 <        CustomExecutor se = null;
196 >    public void testExecuteNull() throws InterruptedException {
197 >        CustomExecutor se = new CustomExecutor(1);
198          try {
234            se = new CustomExecutor(1);
199              se.execute(null);
200              shouldThrow();
201          } catch (NullPointerException success) {}
238        catch (Exception e) {
239            unexpectedException();
240        }
241
202          joinPool(se);
203      }
204  
205      /**
206       * schedule (null) throws NPE
207       */
208 <    public void testScheduleNull() {
208 >    public void testScheduleNull() throws InterruptedException {
209          CustomExecutor se = new CustomExecutor(1);
210          try {
211              TrackedCallable callable = null;
212 <            Future f = se.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
212 >            Future f = se.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
213              shouldThrow();
214          } catch (NullPointerException success) {}
255        catch (Exception e) {
256            unexpectedException();
257        }
215          joinPool(se);
216      }
217  
# Line 266 | Line 223 | public class ScheduledExecutorSubclassTe
223          try {
224              se.shutdown();
225              se.schedule(new NoOpRunnable(),
226 <                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
226 >                        MEDIUM_DELAY_MS, MILLISECONDS);
227              shouldThrow();
228          } catch (RejectedExecutionException success) {
229          } catch (SecurityException ok) {
230          }
231  
232          joinPool(se);
276
233      }
234  
235      /**
# Line 284 | Line 240 | public class ScheduledExecutorSubclassTe
240          try {
241              se.shutdown();
242              se.schedule(new NoOpCallable(),
243 <                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
243 >                        MEDIUM_DELAY_MS, MILLISECONDS);
244              shouldThrow();
245          } catch (RejectedExecutionException success) {
246          } catch (SecurityException ok) {
# Line 298 | Line 254 | public class ScheduledExecutorSubclassTe
254       public void testSchedule3_RejectedExecutionException() {
255           CustomExecutor se = new CustomExecutor(1);
256           try {
257 <            se.shutdown();
258 <            se.schedule(new NoOpCallable(),
259 <                        MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
260 <            shouldThrow();
261 <        } catch (RejectedExecutionException success) {
262 <        } catch (SecurityException ok) {
263 <        }
257 >             se.shutdown();
258 >             se.schedule(new NoOpCallable(),
259 >                         MEDIUM_DELAY_MS, MILLISECONDS);
260 >             shouldThrow();
261 >         } catch (RejectedExecutionException success) {
262 >         } catch (SecurityException ok) {
263 >         }
264           joinPool(se);
265      }
266  
# Line 316 | Line 272 | public class ScheduledExecutorSubclassTe
272          try {
273              se.shutdown();
274              se.scheduleAtFixedRate(new NoOpRunnable(),
275 <                                   MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
275 >                                   MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
276              shouldThrow();
277          } catch (RejectedExecutionException success) {
278          } catch (SecurityException ok) {
# Line 332 | Line 288 | public class ScheduledExecutorSubclassTe
288          try {
289              se.shutdown();
290              se.scheduleWithFixedDelay(new NoOpRunnable(),
291 <                                      MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
291 >                                      MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS);
292              shouldThrow();
293          } catch (RejectedExecutionException success) {
294          } catch (SecurityException ok) {
# Line 344 | Line 300 | public class ScheduledExecutorSubclassTe
300       *  getActiveCount increases but doesn't overestimate, when a
301       *  thread becomes active
302       */
303 <    public void testGetActiveCount() {
303 >    public void testGetActiveCount() throws InterruptedException {
304          CustomExecutor p2 = new CustomExecutor(2);
305          assertEquals(0, p2.getActiveCount());
306          p2.execute(new SmallRunnable());
307 <        try {
352 <            Thread.sleep(SHORT_DELAY_MS);
353 <        } catch (Exception e) {
354 <            unexpectedException();
355 <        }
307 >        Thread.sleep(SHORT_DELAY_MS);
308          assertEquals(1, p2.getActiveCount());
309          joinPool(p2);
310      }
# Line 361 | Line 313 | public class ScheduledExecutorSubclassTe
313       *    getCompletedTaskCount increases, but doesn't overestimate,
314       *   when tasks complete
315       */
316 <    public void testGetCompletedTaskCount() {
316 >    public void testGetCompletedTaskCount()throws InterruptedException  {
317          CustomExecutor p2 = new CustomExecutor(2);
318          assertEquals(0, p2.getCompletedTaskCount());
319          p2.execute(new SmallRunnable());
320 <        try {
369 <            Thread.sleep(MEDIUM_DELAY_MS);
370 <        } catch (Exception e) {
371 <            unexpectedException();
372 <        }
320 >        Thread.sleep(MEDIUM_DELAY_MS);
321          assertEquals(1, p2.getCompletedTaskCount());
322          joinPool(p2);
323      }
# Line 387 | Line 335 | public class ScheduledExecutorSubclassTe
335       *    getLargestPoolSize increases, but doesn't overestimate, when
336       *   multiple threads active
337       */
338 <    public void testGetLargestPoolSize() {
338 >    public void testGetLargestPoolSize() throws InterruptedException {
339          CustomExecutor p2 = new CustomExecutor(2);
340          assertEquals(0, p2.getLargestPoolSize());
341          p2.execute(new SmallRunnable());
342          p2.execute(new SmallRunnable());
343 <        try {
396 <            Thread.sleep(SHORT_DELAY_MS);
397 <        } catch (Exception e) {
398 <            unexpectedException();
399 <        }
343 >        Thread.sleep(SHORT_DELAY_MS);
344          assertEquals(2, p2.getLargestPoolSize());
345          joinPool(p2);
346      }
# Line 417 | Line 361 | public class ScheduledExecutorSubclassTe
361       *    getTaskCount increases, but doesn't overestimate, when tasks
362       *    submitted
363       */
364 <    public void testGetTaskCount() {
364 >    public void testGetTaskCount() throws InterruptedException {
365          CustomExecutor p1 = new CustomExecutor(1);
366          assertEquals(0, p1.getTaskCount());
367          for (int i = 0; i < 5; i++)
368              p1.execute(new SmallRunnable());
369 <        try {
426 <            Thread.sleep(SHORT_DELAY_MS);
427 <        } catch (Exception e) {
428 <            unexpectedException();
429 <        }
369 >        Thread.sleep(SHORT_DELAY_MS);
370          assertEquals(5, p1.getTaskCount());
371          joinPool(p1);
372      }
# Line 470 | Line 410 | public class ScheduledExecutorSubclassTe
410       *   is isShutDown is false before shutdown, true after
411       */
412      public void testIsShutdown() {
473
413          CustomExecutor p1 = new CustomExecutor(1);
414          try {
415              assertFalse(p1.isShutdown());
# Line 483 | Line 422 | public class ScheduledExecutorSubclassTe
422  
423  
424      /**
425 <     *   isTerminated is false before termination, true after
425 >     *  isTerminated is false before termination, true after
426       */
427 <    public void testIsTerminated() {
427 >    public void testIsTerminated() throws InterruptedException {
428          CustomExecutor p1 = new CustomExecutor(1);
429          try {
430              p1.execute(new SmallRunnable());
431          } finally {
432              try { p1.shutdown(); } catch (SecurityException ok) { return; }
433          }
434 <        try {
435 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
497 <            assertTrue(p1.isTerminated());
498 <        } catch (Exception e) {
499 <            unexpectedException();
500 <        }
434 >        assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
435 >        assertTrue(p1.isTerminated());
436      }
437  
438      /**
439       *  isTerminating is not true when running or when terminated
440       */
441 <    public void testIsTerminating() {
441 >    public void testIsTerminating() throws InterruptedException {
442          CustomExecutor p1 = new CustomExecutor(1);
443          assertFalse(p1.isTerminating());
444          try {
# Line 512 | Line 447 | public class ScheduledExecutorSubclassTe
447          } finally {
448              try { p1.shutdown(); } catch (SecurityException ok) { return; }
449          }
450 <        try {
451 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
452 <            assertTrue(p1.isTerminated());
518 <            assertFalse(p1.isTerminating());
519 <        } catch (Exception e) {
520 <            unexpectedException();
521 <        }
450 >        assertTrue(p1.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
451 >        assertTrue(p1.isTerminated());
452 >        assertFalse(p1.isTerminating());
453      }
454  
455      /**
456       * getQueue returns the work queue, which contains queued tasks
457       */
458 <    public void testGetQueue() {
458 >    public void testGetQueue() throws InterruptedException {
459          CustomExecutor p1 = new CustomExecutor(1);
460          ScheduledFuture[] tasks = new ScheduledFuture[5];
461          for (int i = 0; i < 5; i++) {
462 <            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS);
462 >            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, MILLISECONDS);
463          }
464          try {
465              Thread.sleep(SHORT_DELAY_MS);
466              BlockingQueue<Runnable> q = p1.getQueue();
467              assertTrue(q.contains(tasks[4]));
468              assertFalse(q.contains(tasks[0]));
538        } catch (Exception e) {
539            unexpectedException();
469          } finally {
470              joinPool(p1);
471          }
# Line 545 | Line 474 | public class ScheduledExecutorSubclassTe
474      /**
475       * remove(task) removes queued task, and fails to remove active task
476       */
477 <    public void testRemove() {
477 >    public void testRemove() throws InterruptedException {
478          CustomExecutor p1 = new CustomExecutor(1);
479          ScheduledFuture[] tasks = new ScheduledFuture[5];
480          for (int i = 0; i < 5; i++) {
481 <            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS);
481 >            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, MILLISECONDS);
482          }
483          try {
484              Thread.sleep(SHORT_DELAY_MS);
# Line 563 | Line 492 | public class ScheduledExecutorSubclassTe
492              assertTrue(q.contains((Runnable)tasks[3]));
493              assertTrue(p1.remove((Runnable)tasks[3]));
494              assertFalse(q.contains((Runnable)tasks[3]));
566        } catch (Exception e) {
567            unexpectedException();
495          } finally {
496              joinPool(p1);
497          }
# Line 573 | Line 500 | public class ScheduledExecutorSubclassTe
500      /**
501       *  purge removes cancelled tasks from the queue
502       */
503 <    public void testPurge() {
503 >    public void testPurge() throws InterruptedException {
504          CustomExecutor p1 = new CustomExecutor(1);
505          ScheduledFuture[] tasks = new ScheduledFuture[5];
506          for (int i = 0; i < 5; i++) {
507 <            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
507 >            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS);
508          }
509          try {
510              int max = 5;
# Line 594 | Line 521 | public class ScheduledExecutorSubclassTe
521                  Thread.sleep(1);
522              }
523              assertTrue(k < SMALL_DELAY_MS);
597        } catch (Exception e) {
598            unexpectedException();
524          } finally {
525              joinPool(p1);
526          }
# Line 607 | Line 532 | public class ScheduledExecutorSubclassTe
532      public void testShutDownNow() {
533          CustomExecutor p1 = new CustomExecutor(1);
534          for (int i = 0; i < 5; i++)
535 <            p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
535 >            p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, MILLISECONDS);
536          List l;
537          try {
538              l = p1.shutdownNow();
# Line 623 | Line 548 | public class ScheduledExecutorSubclassTe
548       * In default setting, shutdown cancels periodic but not delayed
549       * tasks at shutdown
550       */
551 <    public void testShutDown1() {
552 <        try {
553 <            CustomExecutor p1 = new CustomExecutor(1);
554 <            assertTrue(p1.getExecuteExistingDelayedTasksAfterShutdownPolicy());
630 <            assertFalse(p1.getContinueExistingPeriodicTasksAfterShutdownPolicy());
631 <
632 <            ScheduledFuture[] tasks = new ScheduledFuture[5];
633 <            for (int i = 0; i < 5; i++)
634 <                tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
635 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
636 <            BlockingQueue q = p1.getQueue();
637 <            for (Iterator it = q.iterator(); it.hasNext();) {
638 <                ScheduledFuture t = (ScheduledFuture)it.next();
639 <                assertFalse(t.isCancelled());
640 <            }
641 <            assertTrue(p1.isShutdown());
642 <            Thread.sleep(SMALL_DELAY_MS);
643 <            for (int i = 0; i < 5; ++i) {
644 <                assertTrue(tasks[i].isDone());
645 <                assertFalse(tasks[i].isCancelled());
646 <            }
551 >    public void testShutDown1() throws InterruptedException {
552 >        CustomExecutor p1 = new CustomExecutor(1);
553 >        assertTrue(p1.getExecuteExistingDelayedTasksAfterShutdownPolicy());
554 >        assertFalse(p1.getContinueExistingPeriodicTasksAfterShutdownPolicy());
555  
556 <        }
557 <        catch (Exception ex) {
558 <            unexpectedException();
556 >        ScheduledFuture[] tasks = new ScheduledFuture[5];
557 >        for (int i = 0; i < 5; i++)
558 >            tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, MILLISECONDS);
559 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
560 >        BlockingQueue q = p1.getQueue();
561 >        for (Iterator it = q.iterator(); it.hasNext();) {
562 >            ScheduledFuture t = (ScheduledFuture)it.next();
563 >            assertFalse(t.isCancelled());
564 >        }
565 >        assertTrue(p1.isShutdown());
566 >        Thread.sleep(SMALL_DELAY_MS);
567 >        for (int i = 0; i < 5; ++i) {
568 >            assertTrue(tasks[i].isDone());
569 >            assertFalse(tasks[i].isCancelled());
570          }
571      }
572  
# Line 656 | Line 575 | public class ScheduledExecutorSubclassTe
575       * If setExecuteExistingDelayedTasksAfterShutdownPolicy is false,
576       * delayed tasks are cancelled at shutdown
577       */
578 <    public void testShutDown2() {
579 <        try {
580 <            CustomExecutor p1 = new CustomExecutor(1);
581 <            p1.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
582 <            ScheduledFuture[] tasks = new ScheduledFuture[5];
583 <            for (int i = 0; i < 5; i++)
584 <                tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
585 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
586 <            assertTrue(p1.isShutdown());
587 <            BlockingQueue q = p1.getQueue();
588 <            assertTrue(q.isEmpty());
589 <            Thread.sleep(SMALL_DELAY_MS);
671 <            assertTrue(p1.isTerminated());
672 <        }
673 <        catch (Exception ex) {
674 <            unexpectedException();
675 <        }
578 >    public void testShutDown2() throws InterruptedException {
579 >        CustomExecutor p1 = new CustomExecutor(1);
580 >        p1.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
581 >        ScheduledFuture[] tasks = new ScheduledFuture[5];
582 >        for (int i = 0; i < 5; i++)
583 >            tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, MILLISECONDS);
584 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
585 >        assertTrue(p1.isShutdown());
586 >        BlockingQueue q = p1.getQueue();
587 >        assertTrue(q.isEmpty());
588 >        Thread.sleep(SMALL_DELAY_MS);
589 >        assertTrue(p1.isTerminated());
590      }
591  
592  
# Line 680 | Line 594 | public class ScheduledExecutorSubclassTe
594       * If setContinueExistingPeriodicTasksAfterShutdownPolicy is set false,
595       * periodic tasks are not cancelled at shutdown
596       */
597 <    public void testShutDown3() {
598 <        try {
599 <            CustomExecutor p1 = new CustomExecutor(1);
600 <            p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
601 <            ScheduledFuture task =
602 <                p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS);
603 <            try { p1.shutdown(); } catch (SecurityException ok) { return; }
604 <            assertTrue(p1.isShutdown());
605 <            BlockingQueue q = p1.getQueue();
606 <            assertTrue(q.isEmpty());
607 <            Thread.sleep(SHORT_DELAY_MS);
694 <            assertTrue(p1.isTerminated());
695 <        }
696 <        catch (Exception ex) {
697 <            unexpectedException();
698 <        }
597 >    public void testShutDown3() throws InterruptedException {
598 >        CustomExecutor p1 = new CustomExecutor(1);
599 >        p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
600 >        ScheduledFuture task =
601 >            p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, MILLISECONDS);
602 >        try { p1.shutdown(); } catch (SecurityException ok) { return; }
603 >        assertTrue(p1.isShutdown());
604 >        BlockingQueue q = p1.getQueue();
605 >        assertTrue(q.isEmpty());
606 >        Thread.sleep(SHORT_DELAY_MS);
607 >        assertTrue(p1.isTerminated());
608      }
609  
610      /**
611       * if setContinueExistingPeriodicTasksAfterShutdownPolicy is true,
612       * periodic tasks are cancelled at shutdown
613       */
614 <    public void testShutDown4() {
614 >    public void testShutDown4() throws InterruptedException {
615          CustomExecutor p1 = new CustomExecutor(1);
616          try {
617              p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
618              ScheduledFuture task =
619 <                p1.scheduleAtFixedRate(new NoOpRunnable(), 1, 1, TimeUnit.MILLISECONDS);
619 >                p1.scheduleAtFixedRate(new NoOpRunnable(), 1, 1, MILLISECONDS);
620              assertFalse(task.isCancelled());
621              try { p1.shutdown(); } catch (SecurityException ok) { return; }
622              assertFalse(task.isCancelled());
# Line 720 | Line 629 | public class ScheduledExecutorSubclassTe
629              Thread.sleep(SHORT_DELAY_MS);
630              assertTrue(p1.isTerminated());
631          }
723        catch (Exception ex) {
724            unexpectedException();
725        }
632          finally {
633              joinPool(p1);
634          }
# Line 731 | Line 637 | public class ScheduledExecutorSubclassTe
637      /**
638       * completed submit of callable returns result
639       */
640 <    public void testSubmitCallable() {
640 >    public void testSubmitCallable() throws Exception {
641          ExecutorService e = new CustomExecutor(2);
642          try {
643              Future<String> future = e.submit(new StringTask());
644              String result = future.get();
645              assertSame(TEST_STRING, result);
740        }
741        catch (ExecutionException ex) {
742            unexpectedException();
743        }
744        catch (InterruptedException ex) {
745            unexpectedException();
646          } finally {
647              joinPool(e);
648          }
# Line 751 | Line 651 | public class ScheduledExecutorSubclassTe
651      /**
652       * completed submit of runnable returns successfully
653       */
654 <    public void testSubmitRunnable() {
654 >    public void testSubmitRunnable() throws Exception {
655          ExecutorService e = new CustomExecutor(2);
656          try {
657              Future<?> future = e.submit(new NoOpRunnable());
658              future.get();
659              assertTrue(future.isDone());
760        }
761        catch (ExecutionException ex) {
762            unexpectedException();
763        }
764        catch (InterruptedException ex) {
765            unexpectedException();
660          } finally {
661              joinPool(e);
662          }
# Line 771 | Line 665 | public class ScheduledExecutorSubclassTe
665      /**
666       * completed submit of (runnable, result) returns result
667       */
668 <    public void testSubmitRunnable2() {
668 >    public void testSubmitRunnable2() throws Exception {
669          ExecutorService e = new CustomExecutor(2);
670          try {
671              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
672              String result = future.get();
673              assertSame(TEST_STRING, result);
780        }
781        catch (ExecutionException ex) {
782            unexpectedException();
783        }
784        catch (InterruptedException ex) {
785            unexpectedException();
674          } finally {
675              joinPool(e);
676          }
# Line 791 | Line 679 | public class ScheduledExecutorSubclassTe
679      /**
680       * invokeAny(null) throws NPE
681       */
682 <    public void testInvokeAny1() {
682 >    public void testInvokeAny1() throws Exception {
683          ExecutorService e = new CustomExecutor(2);
684          try {
685              e.invokeAny(null);
686 +            shouldThrow();
687          } catch (NullPointerException success) {
799        } catch (Exception ex) {
800            unexpectedException();
688          } finally {
689              joinPool(e);
690          }
# Line 806 | Line 693 | public class ScheduledExecutorSubclassTe
693      /**
694       * invokeAny(empty collection) throws IAE
695       */
696 <    public void testInvokeAny2() {
696 >    public void testInvokeAny2() throws Exception {
697          ExecutorService e = new CustomExecutor(2);
698          try {
699              e.invokeAny(new ArrayList<Callable<String>>());
700 +            shouldThrow();
701          } catch (IllegalArgumentException success) {
814        } catch (Exception ex) {
815            unexpectedException();
702          } finally {
703              joinPool(e);
704          }
# Line 821 | Line 707 | public class ScheduledExecutorSubclassTe
707      /**
708       * invokeAny(c) throws NPE if c has null elements
709       */
710 <    public void testInvokeAny3() {
710 >    public void testInvokeAny3() throws Exception {
711 >        final CountDownLatch latch = new CountDownLatch(1);
712          ExecutorService e = new CustomExecutor(2);
713          try {
714              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
715 <            l.add(new StringTask());
715 >            l.add(new Callable<String>() {
716 >                      public String call() {
717 >                          try {
718 >                              latch.await();
719 >                          } catch (InterruptedException ok) {}
720 >                          return TEST_STRING;
721 >                      }});
722              l.add(null);
723              e.invokeAny(l);
724 +            shouldThrow();
725          } catch (NullPointerException success) {
832        } catch (Exception ex) {
833            unexpectedException();
726          } finally {
727 +            latch.countDown();
728              joinPool(e);
729          }
730      }
# Line 839 | Line 732 | public class ScheduledExecutorSubclassTe
732      /**
733       * invokeAny(c) throws ExecutionException if no task completes
734       */
735 <    public void testInvokeAny4() {
735 >    public void testInvokeAny4() throws Exception {
736          ExecutorService e = new CustomExecutor(2);
737          try {
738              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
739              l.add(new NPETask());
740              e.invokeAny(l);
741 +            shouldThrow();
742          } catch (ExecutionException success) {
743 <        } catch (Exception ex) {
850 <            unexpectedException();
743 >            assertTrue(success.getCause() instanceof NullPointerException);
744          } finally {
745              joinPool(e);
746          }
# Line 856 | Line 749 | public class ScheduledExecutorSubclassTe
749      /**
750       * invokeAny(c) returns result of some task
751       */
752 <    public void testInvokeAny5() {
752 >    public void testInvokeAny5() throws Exception {
753          ExecutorService e = new CustomExecutor(2);
754          try {
755              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 864 | Line 757 | public class ScheduledExecutorSubclassTe
757              l.add(new StringTask());
758              String result = e.invokeAny(l);
759              assertSame(TEST_STRING, result);
867        } catch (ExecutionException success) {
868        } catch (Exception ex) {
869            unexpectedException();
760          } finally {
761              joinPool(e);
762          }
# Line 875 | Line 765 | public class ScheduledExecutorSubclassTe
765      /**
766       * invokeAll(null) throws NPE
767       */
768 <    public void testInvokeAll1() {
768 >    public void testInvokeAll1() throws Exception {
769          ExecutorService e = new CustomExecutor(2);
770          try {
771              e.invokeAll(null);
772 +            shouldThrow();
773          } catch (NullPointerException success) {
883        } catch (Exception ex) {
884            unexpectedException();
774          } finally {
775              joinPool(e);
776          }
# Line 890 | Line 779 | public class ScheduledExecutorSubclassTe
779      /**
780       * invokeAll(empty collection) returns empty collection
781       */
782 <    public void testInvokeAll2() {
782 >    public void testInvokeAll2() throws Exception {
783          ExecutorService e = new CustomExecutor(2);
784          try {
785              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
786              assertTrue(r.isEmpty());
898        } catch (Exception ex) {
899            unexpectedException();
787          } finally {
788              joinPool(e);
789          }
# Line 905 | Line 792 | public class ScheduledExecutorSubclassTe
792      /**
793       * invokeAll(c) throws NPE if c has null elements
794       */
795 <    public void testInvokeAll3() {
795 >    public void testInvokeAll3() throws Exception {
796          ExecutorService e = new CustomExecutor(2);
797          try {
798              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
799              l.add(new StringTask());
800              l.add(null);
801              e.invokeAll(l);
802 +            shouldThrow();
803          } catch (NullPointerException success) {
916        } catch (Exception ex) {
917            unexpectedException();
804          } finally {
805              joinPool(e);
806          }
# Line 923 | Line 809 | public class ScheduledExecutorSubclassTe
809      /**
810       * get of invokeAll(c) throws exception on failed task
811       */
812 <    public void testInvokeAll4() {
812 >    public void testInvokeAll4() throws Exception {
813          ExecutorService e = new CustomExecutor(2);
814          try {
815              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
816              l.add(new NPETask());
817              List<Future<String>> result = e.invokeAll(l);
818              assertEquals(1, result.size());
819 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
820 <                it.next().get();
819 >            for (Future<String> future : result)
820 >                future.get();
821 >            shouldThrow();
822          } catch (ExecutionException success) {
823 <        } catch (Exception ex) {
937 <            unexpectedException();
823 >            assertTrue(success.getCause() instanceof NullPointerException);
824          } finally {
825              joinPool(e);
826          }
# Line 943 | Line 829 | public class ScheduledExecutorSubclassTe
829      /**
830       * invokeAll(c) returns results of all completed tasks
831       */
832 <    public void testInvokeAll5() {
832 >    public void testInvokeAll5() throws Exception {
833          ExecutorService e = new CustomExecutor(2);
834          try {
835              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 951 | Line 837 | public class ScheduledExecutorSubclassTe
837              l.add(new StringTask());
838              List<Future<String>> result = e.invokeAll(l);
839              assertEquals(2, result.size());
840 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
841 <                assertSame(TEST_STRING, it.next().get());
956 <        } catch (ExecutionException success) {
957 <        } catch (Exception ex) {
958 <            unexpectedException();
840 >            for (Future<String> future : result)
841 >                assertSame(TEST_STRING, future.get());
842          } finally {
843              joinPool(e);
844          }
# Line 964 | Line 847 | public class ScheduledExecutorSubclassTe
847      /**
848       * timed invokeAny(null) throws NPE
849       */
850 <    public void testTimedInvokeAny1() {
850 >    public void testTimedInvokeAny1() throws Exception {
851          ExecutorService e = new CustomExecutor(2);
852          try {
853 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
853 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
854 >            shouldThrow();
855          } catch (NullPointerException success) {
972        } catch (Exception ex) {
973            unexpectedException();
856          } finally {
857              joinPool(e);
858          }
# Line 979 | Line 861 | public class ScheduledExecutorSubclassTe
861      /**
862       * timed invokeAny(,,null) throws NPE
863       */
864 <    public void testTimedInvokeAnyNullTimeUnit() {
864 >    public void testTimedInvokeAnyNullTimeUnit() throws Exception {
865          ExecutorService e = new CustomExecutor(2);
866          try {
867              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
868              l.add(new StringTask());
869              e.invokeAny(l, MEDIUM_DELAY_MS, null);
870 +            shouldThrow();
871          } catch (NullPointerException success) {
989        } catch (Exception ex) {
990            unexpectedException();
872          } finally {
873              joinPool(e);
874          }
# Line 996 | Line 877 | public class ScheduledExecutorSubclassTe
877      /**
878       * timed invokeAny(empty collection) throws IAE
879       */
880 <    public void testTimedInvokeAny2() {
880 >    public void testTimedInvokeAny2() throws Exception {
881          ExecutorService e = new CustomExecutor(2);
882          try {
883 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
883 >            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
884 >            shouldThrow();
885          } catch (IllegalArgumentException success) {
1004        } catch (Exception ex) {
1005            unexpectedException();
886          } finally {
887              joinPool(e);
888          }
# Line 1011 | Line 891 | public class ScheduledExecutorSubclassTe
891      /**
892       * timed invokeAny(c) throws NPE if c has null elements
893       */
894 <    public void testTimedInvokeAny3() {
894 >    public void testTimedInvokeAny3() throws Exception {
895 >        final CountDownLatch latch = new CountDownLatch(1);
896          ExecutorService e = new CustomExecutor(2);
897          try {
898              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
899 <            l.add(new StringTask());
899 >            l.add(new Callable<String>() {
900 >                      public String call() {
901 >                          try {
902 >                              latch.await();
903 >                          } catch (InterruptedException ok) {}
904 >                          return TEST_STRING;
905 >                      }});
906              l.add(null);
907 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
907 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
908 >            shouldThrow();
909          } catch (NullPointerException success) {
1022        } catch (Exception ex) {
1023            ex.printStackTrace();
1024            unexpectedException();
910          } finally {
911 +            latch.countDown();
912              joinPool(e);
913          }
914      }
# Line 1030 | Line 916 | public class ScheduledExecutorSubclassTe
916      /**
917       * timed invokeAny(c) throws ExecutionException if no task completes
918       */
919 <    public void testTimedInvokeAny4() {
919 >    public void testTimedInvokeAny4() throws Exception {
920          ExecutorService e = new CustomExecutor(2);
921          try {
922              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
923              l.add(new NPETask());
924 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
924 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
925 >            shouldThrow();
926          } catch (ExecutionException success) {
927 <        } catch (Exception ex) {
1041 <            unexpectedException();
927 >            assertTrue(success.getCause() instanceof NullPointerException);
928          } finally {
929              joinPool(e);
930          }
# Line 1047 | Line 933 | public class ScheduledExecutorSubclassTe
933      /**
934       * timed invokeAny(c) returns result of some task
935       */
936 <    public void testTimedInvokeAny5() {
936 >    public void testTimedInvokeAny5() throws Exception {
937          ExecutorService e = new CustomExecutor(2);
938          try {
939              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
940              l.add(new StringTask());
941              l.add(new StringTask());
942 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
942 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
943              assertSame(TEST_STRING, result);
1058        } catch (ExecutionException success) {
1059        } catch (Exception ex) {
1060            unexpectedException();
944          } finally {
945              joinPool(e);
946          }
# Line 1066 | Line 949 | public class ScheduledExecutorSubclassTe
949      /**
950       * timed invokeAll(null) throws NPE
951       */
952 <    public void testTimedInvokeAll1() {
952 >    public void testTimedInvokeAll1() throws Exception {
953          ExecutorService e = new CustomExecutor(2);
954          try {
955 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
955 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
956 >            shouldThrow();
957          } catch (NullPointerException success) {
1074        } catch (Exception ex) {
1075            unexpectedException();
958          } finally {
959              joinPool(e);
960          }
# Line 1081 | Line 963 | public class ScheduledExecutorSubclassTe
963      /**
964       * timed invokeAll(,,null) throws NPE
965       */
966 <    public void testTimedInvokeAllNullTimeUnit() {
966 >    public void testTimedInvokeAllNullTimeUnit() throws Exception {
967          ExecutorService e = new CustomExecutor(2);
968          try {
969              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
970              l.add(new StringTask());
971              e.invokeAll(l, MEDIUM_DELAY_MS, null);
972 +            shouldThrow();
973          } catch (NullPointerException success) {
1091        } catch (Exception ex) {
1092            unexpectedException();
974          } finally {
975              joinPool(e);
976          }
# Line 1098 | Line 979 | public class ScheduledExecutorSubclassTe
979      /**
980       * timed invokeAll(empty collection) returns empty collection
981       */
982 <    public void testTimedInvokeAll2() {
982 >    public void testTimedInvokeAll2() throws Exception {
983          ExecutorService e = new CustomExecutor(2);
984          try {
985 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
985 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
986              assertTrue(r.isEmpty());
1106        } catch (Exception ex) {
1107            unexpectedException();
987          } finally {
988              joinPool(e);
989          }
# Line 1113 | Line 992 | public class ScheduledExecutorSubclassTe
992      /**
993       * timed invokeAll(c) throws NPE if c has null elements
994       */
995 <    public void testTimedInvokeAll3() {
995 >    public void testTimedInvokeAll3() throws Exception {
996          ExecutorService e = new CustomExecutor(2);
997          try {
998              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
999              l.add(new StringTask());
1000              l.add(null);
1001 <            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1001 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1002 >            shouldThrow();
1003          } catch (NullPointerException success) {
1124        } catch (Exception ex) {
1125            unexpectedException();
1004          } finally {
1005              joinPool(e);
1006          }
# Line 1131 | Line 1009 | public class ScheduledExecutorSubclassTe
1009      /**
1010       * get of element of invokeAll(c) throws exception on failed task
1011       */
1012 <    public void testTimedInvokeAll4() {
1012 >    public void testTimedInvokeAll4() throws Exception {
1013          ExecutorService e = new CustomExecutor(2);
1014          try {
1015              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1016              l.add(new NPETask());
1017 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1017 >            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1018              assertEquals(1, result.size());
1019 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1020 <                it.next().get();
1019 >            for (Future<String> future : result)
1020 >                future.get();
1021 >            shouldThrow();
1022          } catch (ExecutionException success) {
1023 <        } catch (Exception ex) {
1145 <            unexpectedException();
1023 >            assertTrue(success.getCause() instanceof NullPointerException);
1024          } finally {
1025              joinPool(e);
1026          }
# Line 1151 | Line 1029 | public class ScheduledExecutorSubclassTe
1029      /**
1030       * timed invokeAll(c) returns results of all completed tasks
1031       */
1032 <    public void testTimedInvokeAll5() {
1032 >    public void testTimedInvokeAll5() throws Exception {
1033          ExecutorService e = new CustomExecutor(2);
1034          try {
1035              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1036              l.add(new StringTask());
1037              l.add(new StringTask());
1038 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1038 >            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1039              assertEquals(2, result.size());
1040 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1041 <                assertSame(TEST_STRING, it.next().get());
1164 <        } catch (ExecutionException success) {
1165 <        } catch (Exception ex) {
1166 <            unexpectedException();
1040 >            for (Future<String> future : result)
1041 >                assertSame(TEST_STRING, future.get());
1042          } finally {
1043              joinPool(e);
1044          }
# Line 1172 | Line 1047 | public class ScheduledExecutorSubclassTe
1047      /**
1048       * timed invokeAll(c) cancels tasks not completed by timeout
1049       */
1050 <    public void testTimedInvokeAll6() {
1050 >    public void testTimedInvokeAll6() throws Exception {
1051          ExecutorService e = new CustomExecutor(2);
1052          try {
1053              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1054              l.add(new StringTask());
1055              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1056              l.add(new StringTask());
1057 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
1057 >            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1058              assertEquals(3, result.size());
1059              Iterator<Future<String>> it = result.iterator();
1060              Future<String> f1 = it.next();
# Line 1190 | Line 1065 | public class ScheduledExecutorSubclassTe
1065              assertTrue(f3.isDone());
1066              assertFalse(f1.isCancelled());
1067              assertTrue(f2.isCancelled());
1193        } catch (Exception ex) {
1194            unexpectedException();
1068          } finally {
1069              joinPool(e);
1070          }
1071      }
1072  
1200
1073   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines