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

Comparing jsr166/src/test/tck/AbstractExecutorServiceTest.java (file contents):
Revision 1.19 by jsr166, Fri Nov 20 05:25:10 2009 UTC vs.
Revision 1.31 by jsr166, Sat May 28 22:33:35 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
8  
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.math.BigInteger;
14   import java.security.*;
15  
16   public class AbstractExecutorServiceTest extends JSR166TestCase {
17      public static void main(String[] args) {
18 <        junit.textui.TestRunner.run (suite());
18 >        junit.textui.TestRunner.run(suite());
19      }
20      public static Test suite() {
21          return new TestSuite(AbstractExecutorServiceTest.class);
# Line 28 | Line 28 | public class AbstractExecutorServiceTest
28      static class DirectExecutorService extends AbstractExecutorService {
29          public void execute(Runnable r) { r.run(); }
30          public void shutdown() { shutdown = true; }
31 <        public List<Runnable> shutdownNow() { shutdown = true; return Collections.EMPTY_LIST; }
31 >        public List<Runnable> shutdownNow() {
32 >            shutdown = true;
33 >            return Collections.EMPTY_LIST;
34 >        }
35          public boolean isShutdown() { return shutdown; }
36          public boolean isTerminated() { return isShutdown(); }
37 <        public boolean awaitTermination(long timeout, TimeUnit unit) { return isShutdown(); }
37 >        public boolean awaitTermination(long timeout, TimeUnit unit) {
38 >            return isShutdown();
39 >        }
40          private volatile boolean shutdown = false;
41      }
42  
# Line 47 | Line 52 | public class AbstractExecutorServiceTest
52          assertTrue(task.done);
53      }
54  
50
55      /**
56       * Completed submit(callable) returns result
57       */
# Line 78 | Line 82 | public class AbstractExecutorServiceTest
82          assertSame(TEST_STRING, result);
83      }
84  
81
85      /**
86 <     * A submitted privileged action to completion
86 >     * A submitted privileged action runs to completion
87       */
88      public void testSubmitPrivilegedAction() throws Exception {
89 <        Policy savedPolicy = null;
90 <        try {
91 <            savedPolicy = Policy.getPolicy();
92 <            AdjustablePolicy policy = new AdjustablePolicy();
90 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
91 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
92 <            Policy.setPolicy(policy);
93 <        } catch (AccessControlException ok) {
94 <            return;
95 <        }
96 <        try {
97 <            ExecutorService e = new DirectExecutorService();
98 <            Future future = e.submit(Executors.callable(new PrivilegedAction() {
89 >        Runnable r = new CheckedRunnable() {
90 >            public void realRun() throws Exception {
91 >                ExecutorService e = new DirectExecutorService();
92 >                Future future = e.submit(Executors.callable(new PrivilegedAction() {
93                      public Object run() {
94                          return TEST_STRING;
95                      }}));
96  
97 <            Object result = future.get();
98 <            assertSame(TEST_STRING, result);
99 <        }
100 <        finally {
101 <            try {
102 <                Policy.setPolicy(savedPolicy);
103 <            } catch (AccessControlException ok) {
110 <                return;
111 <            }
112 <        }
97 >                assertSame(TEST_STRING, future.get());
98 >            }};
99 >
100 >        runWithPermissions(r,
101 >                           new RuntimePermission("getClassLoader"),
102 >                           new RuntimePermission("setContextClassLoader"),
103 >                           new RuntimePermission("modifyThread"));
104      }
105  
106      /**
107 <     * A submitted a privileged exception action runs to completion
107 >     * A submitted privileged exception action runs to completion
108       */
109      public void testSubmitPrivilegedExceptionAction() throws Exception {
110 <        Policy savedPolicy = null;
111 <        try {
112 <            savedPolicy = Policy.getPolicy();
113 <            AdjustablePolicy policy = new AdjustablePolicy();
123 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
124 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
125 <            Policy.setPolicy(policy);
126 <        } catch (AccessControlException ok) {
127 <            return;
128 <        }
129 <
130 <        try {
131 <            ExecutorService e = new DirectExecutorService();
132 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
110 >        Runnable r = new CheckedRunnable() {
111 >            public void realRun() throws Exception {
112 >                ExecutorService e = new DirectExecutorService();
113 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
114                      public Object run() {
115                          return TEST_STRING;
116                      }}));
117  
118 <            Object result = future.get();
119 <            assertSame(TEST_STRING, result);
120 <        }
121 <        finally {
141 <            Policy.setPolicy(savedPolicy);
142 <        }
118 >                assertSame(TEST_STRING, future.get());
119 >            }};
120 >
121 >        runWithPermissions(r);
122      }
123  
124      /**
125       * A submitted failed privileged exception action reports exception
126       */
127      public void testSubmitFailedPrivilegedExceptionAction() throws Exception {
128 <        Policy savedPolicy = null;
129 <        try {
130 <            savedPolicy = Policy.getPolicy();
131 <            AdjustablePolicy policy = new AdjustablePolicy();
153 <            policy.addPermission(new RuntimePermission("getContextClassLoader"));
154 <            policy.addPermission(new RuntimePermission("setContextClassLoader"));
155 <            Policy.setPolicy(policy);
156 <        } catch (AccessControlException ok) {
157 <            return;
158 <        }
159 <
160 <        try {
161 <            ExecutorService e = new DirectExecutorService();
162 <            Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
128 >        Runnable r = new CheckedRunnable() {
129 >            public void realRun() throws Exception {
130 >                ExecutorService e = new DirectExecutorService();
131 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
132                      public Object run() throws Exception {
133                          throw new IndexOutOfBoundsException();
134                      }}));
135  
136 <            future.get();
137 <            shouldThrow();
138 <        } catch (ExecutionException success) {
139 <            assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
140 <        }
141 <        finally {
142 <            Policy.setPolicy(savedPolicy);
143 <        }
136 >                try {
137 >                    future.get();
138 >                    shouldThrow();
139 >                } catch (ExecutionException success) {
140 >                    assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
141 >                }}};
142 >
143 >        runWithPermissions(r);
144      }
145  
146      /**
# Line 185 | Line 154 | public class AbstractExecutorServiceTest
154          } catch (NullPointerException success) {}
155      }
156  
188
157      /**
158       * submit(null callable) throws NPE
159       */
# Line 198 | Line 166 | public class AbstractExecutorServiceTest
166      }
167  
168      /**
169 <     * submit(runnable) throws RejectedExecutionException if
202 <     * executor is saturated.
203 <     */
204 <    public void testExecute1() {
205 <        ThreadPoolExecutor p =
206 <            new ThreadPoolExecutor(1, 1,
207 <                                   60, TimeUnit.SECONDS,
208 <                                   new ArrayBlockingQueue<Runnable>(1));
209 <        try {
210 <            for (int i = 0; i < 2; ++i)
211 <                p.submit(new MediumRunnable());
212 <            for (int i = 0; i < 2; ++i) {
213 <                try {
214 <                    p.submit(new MediumRunnable());
215 <                    shouldThrow();
216 <                } catch (RejectedExecutionException success) {}
217 <            }
218 <        } finally {
219 <            joinPool(p);
220 <        }
221 <    }
222 <
223 <    /**
224 <     * submit(callable) throws RejectedExecutionException
225 <     * if executor is saturated.
169 >     * submit(callable).get() throws InterruptedException if interrupted
170       */
171 <    public void testExecute2() {
172 <        ThreadPoolExecutor p =
173 <            new ThreadPoolExecutor(1, 1,
174 <                                   60, TimeUnit.SECONDS,
175 <                                   new ArrayBlockingQueue<Runnable>(1));
176 <        try {
177 <            for (int i = 0; i < 2; ++i)
178 <                p.submit(new MediumRunnable());
179 <            for (int i = 0; i < 2; ++i) {
180 <                try {
181 <                    p.submit(new SmallCallable());
182 <                    shouldThrow();
183 <                } catch (RejectedExecutionException success) {}
184 <            }
171 >    public void testInterruptedSubmit() throws InterruptedException {
172 >        final CountDownLatch submitted    = new CountDownLatch(1);
173 >        final CountDownLatch quittingTime = new CountDownLatch(1);
174 >        final ExecutorService p
175 >            = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS,
176 >                                     new ArrayBlockingQueue<Runnable>(10));
177 >        final Callable<Void> awaiter = new CheckedCallable<Void>() {
178 >            public Void realCall() throws InterruptedException {
179 >                quittingTime.await();
180 >                return null;
181 >            }};
182 >        try {
183 >            Thread t = new Thread(new CheckedInterruptedRunnable() {
184 >                public void realRun() throws Exception {
185 >                    Future<Void> future = p.submit(awaiter);
186 >                    submitted.countDown();
187 >                    future.get();
188 >                }});
189 >            t.start();
190 >            submitted.await();
191 >            t.interrupt();
192 >            t.join();
193          } finally {
194 +            quittingTime.countDown();
195              joinPool(p);
196          }
197      }
198  
246
199      /**
200 <     *  Blocking on submit(callable) throws InterruptedException if
201 <     *  caller interrupted.
250 <     */
251 <    public void testInterruptedSubmit() throws InterruptedException {
252 <        final ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
253 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
254 <            public void realRun() throws Exception {
255 <                p.submit(new CheckedCallable<Object>() {
256 <                             public Object realCall()
257 <                                 throws InterruptedException {
258 <                                 Thread.sleep(SMALL_DELAY_MS);
259 <                                 return null;
260 <                             }}).get();
261 <            }});
262 <
263 <        t.start();
264 <        Thread.sleep(SHORT_DELAY_MS);
265 <        t.interrupt();
266 <        joinPool(p);
267 <    }
268 <
269 <    /**
270 <     *  get of submitted callable throws InterruptedException if callable
271 <     *  interrupted
272 <     */
273 <    public void testSubmitIE() throws InterruptedException {
274 <        final ThreadPoolExecutor p =
275 <            new ThreadPoolExecutor(1, 1,
276 <                                   60, TimeUnit.SECONDS,
277 <                                   new ArrayBlockingQueue<Runnable>(10));
278 <
279 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
280 <            public void realRun() throws Exception {
281 <                p.submit(new SmallCallable()).get();
282 <            }});
283 <
284 <        t.start();
285 <        Thread.sleep(SHORT_DELAY_MS);
286 <        t.interrupt();
287 <        t.join();
288 <        joinPool(p);
289 <    }
290 <
291 <    /**
292 <     *  get of submit(callable) throws ExecutionException if callable
293 <     *  throws exception
200 >     * get of submit(callable) throws ExecutionException if callable
201 >     * throws exception
202       */
203      public void testSubmitEE() throws InterruptedException {
204          ThreadPoolExecutor p =
# Line 313 | Line 221 | public class AbstractExecutorServiceTest
221      /**
222       * invokeAny(null) throws NPE
223       */
224 <    public void testInvokeAny1()
317 <        throws InterruptedException, ExecutionException {
224 >    public void testInvokeAny1() throws Exception {
225          ExecutorService e = new DirectExecutorService();
226          try {
227              e.invokeAny(null);
# Line 328 | Line 235 | public class AbstractExecutorServiceTest
235      /**
236       * invokeAny(empty collection) throws IAE
237       */
238 <    public void testInvokeAny2()
332 <        throws InterruptedException, ExecutionException {
238 >    public void testInvokeAny2() throws Exception {
239          ExecutorService e = new DirectExecutorService();
240          try {
241              e.invokeAny(new ArrayList<Callable<String>>());
# Line 344 | Line 250 | public class AbstractExecutorServiceTest
250       * invokeAny(c) throws NPE if c has null elements
251       */
252      public void testInvokeAny3() throws Exception {
347        final CountDownLatch latch = new CountDownLatch(1);
253          ExecutorService e = new DirectExecutorService();
254 +        List<Callable<Integer>> l = new ArrayList<Callable<Integer>>();
255 +        l.add(new Callable<Integer>() {
256 +                  public Integer call() { return 5/0; }});
257 +        l.add(null);
258          try {
350            ArrayList<Callable<Integer>> l
351                = new ArrayList<Callable<Integer>>();
352            l.add(new Callable<Integer>() {
353                      public Integer call() { return 5/0; }});
354            l.add(null);
259              e.invokeAny(l);
260              shouldThrow();
261          } catch (NullPointerException success) {
262          } finally {
359            latch.countDown();
263              joinPool(e);
264          }
265      }
# Line 366 | Line 269 | public class AbstractExecutorServiceTest
269       */
270      public void testInvokeAny4() throws InterruptedException {
271          ExecutorService e = new DirectExecutorService();
272 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
273 +        l.add(new NPETask());
274          try {
370            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
371            l.add(new NPETask());
275              e.invokeAny(l);
276              shouldThrow();
277          } catch (ExecutionException success) {
# Line 384 | Line 287 | public class AbstractExecutorServiceTest
287      public void testInvokeAny5() throws Exception {
288          ExecutorService e = new DirectExecutorService();
289          try {
290 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
290 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
291              l.add(new StringTask());
292              l.add(new StringTask());
293              String result = e.invokeAny(l);
# Line 426 | Line 329 | public class AbstractExecutorServiceTest
329       */
330      public void testInvokeAll3() throws InterruptedException {
331          ExecutorService e = new DirectExecutorService();
332 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
333 +        l.add(new StringTask());
334 +        l.add(null);
335          try {
430            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
431            l.add(new StringTask());
432            l.add(null);
336              e.invokeAll(l);
337              shouldThrow();
338          } catch (NullPointerException success) {
# Line 444 | Line 347 | public class AbstractExecutorServiceTest
347      public void testInvokeAll4() throws Exception {
348          ExecutorService e = new DirectExecutorService();
349          try {
350 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
350 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
351              l.add(new NPETask());
352 <            List<Future<String>> result = e.invokeAll(l);
353 <            assertEquals(1, result.size());
354 <            for (Future<String> future : result) {
355 <                try {
356 <                    future.get();
357 <                    shouldThrow();
358 <                } catch (ExecutionException success) {
456 <                    Throwable cause = success.getCause();
457 <                    assertTrue(cause instanceof NullPointerException);
458 <                }
352 >            List<Future<String>> futures = e.invokeAll(l);
353 >            assertEquals(1, futures.size());
354 >            try {
355 >                futures.get(0).get();
356 >                shouldThrow();
357 >            } catch (ExecutionException success) {
358 >                assertTrue(success.getCause() instanceof NullPointerException);
359              }
360          } finally {
361              joinPool(e);
# Line 468 | Line 368 | public class AbstractExecutorServiceTest
368      public void testInvokeAll5() throws Exception {
369          ExecutorService e = new DirectExecutorService();
370          try {
371 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
371 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
372              l.add(new StringTask());
373              l.add(new StringTask());
374 <            List<Future<String>> result = e.invokeAll(l);
375 <            assertEquals(2, result.size());
376 <            for (Future<String> future : result)
374 >            List<Future<String>> futures = e.invokeAll(l);
375 >            assertEquals(2, futures.size());
376 >            for (Future<String> future : futures)
377                  assertSame(TEST_STRING, future.get());
378          } finally {
379              joinPool(e);
380          }
381      }
382  
483
383      /**
384       * timed invokeAny(null) throws NPE
385       */
386      public void testTimedInvokeAny1() throws Exception {
387          ExecutorService e = new DirectExecutorService();
388          try {
389 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
389 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
390              shouldThrow();
391          } catch (NullPointerException success) {
392          } finally {
# Line 500 | Line 399 | public class AbstractExecutorServiceTest
399       */
400      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
401          ExecutorService e = new DirectExecutorService();
402 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
403 +        l.add(new StringTask());
404          try {
504            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
505            l.add(new StringTask());
405              e.invokeAny(l, MEDIUM_DELAY_MS, null);
406              shouldThrow();
407          } catch (NullPointerException success) {
# Line 517 | Line 416 | public class AbstractExecutorServiceTest
416      public void testTimedInvokeAny2() throws Exception {
417          ExecutorService e = new DirectExecutorService();
418          try {
419 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
419 >            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
420              shouldThrow();
421          } catch (IllegalArgumentException success) {
422          } finally {
# Line 529 | Line 428 | public class AbstractExecutorServiceTest
428       * timed invokeAny(c) throws NPE if c has null elements
429       */
430      public void testTimedInvokeAny3() throws Exception {
532        final CountDownLatch latch = new CountDownLatch(1);
431          ExecutorService e = new DirectExecutorService();
432 +        List<Callable<Integer>> l = new ArrayList<Callable<Integer>>();
433 +        l.add(new Callable<Integer>() {
434 +                  public Integer call() { return 5/0; }});
435 +        l.add(null);
436          try {
437 <            ArrayList<Callable<Integer>> l
536 <                = new ArrayList<Callable<Integer>>();
537 <            l.add(new Callable<Integer>() {
538 <                      public Integer call() { return 5/0; }});
539 <            l.add(null);
540 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
437 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
438              shouldThrow();
439          } catch (NullPointerException success) {
440          } finally {
544            latch.countDown();
441              joinPool(e);
442          }
443      }
# Line 551 | Line 447 | public class AbstractExecutorServiceTest
447       */
448      public void testTimedInvokeAny4() throws Exception {
449          ExecutorService e = new DirectExecutorService();
450 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
451 +        l.add(new NPETask());
452          try {
453 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
556 <            l.add(new NPETask());
557 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
453 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
454              shouldThrow();
455          } catch (ExecutionException success) {
456              assertTrue(success.getCause() instanceof NullPointerException);
# Line 569 | Line 465 | public class AbstractExecutorServiceTest
465      public void testTimedInvokeAny5() throws Exception {
466          ExecutorService e = new DirectExecutorService();
467          try {
468 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
468 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
469              l.add(new StringTask());
470              l.add(new StringTask());
471 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
471 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
472              assertSame(TEST_STRING, result);
473          } finally {
474              joinPool(e);
# Line 585 | Line 481 | public class AbstractExecutorServiceTest
481      public void testTimedInvokeAll1() throws InterruptedException {
482          ExecutorService e = new DirectExecutorService();
483          try {
484 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
484 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
485              shouldThrow();
486          } catch (NullPointerException success) {
487          } finally {
# Line 598 | Line 494 | public class AbstractExecutorServiceTest
494       */
495      public void testTimedInvokeAllNullTimeUnit() throws InterruptedException {
496          ExecutorService e = new DirectExecutorService();
497 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
498 +        l.add(new StringTask());
499          try {
602            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
603            l.add(new StringTask());
500              e.invokeAll(l, MEDIUM_DELAY_MS, null);
501              shouldThrow();
502          } catch (NullPointerException success) {
# Line 615 | Line 511 | public class AbstractExecutorServiceTest
511      public void testTimedInvokeAll2() throws InterruptedException {
512          ExecutorService e = new DirectExecutorService();
513          try {
514 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
514 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
515              assertTrue(r.isEmpty());
516          } finally {
517              joinPool(e);
# Line 627 | Line 523 | public class AbstractExecutorServiceTest
523       */
524      public void testTimedInvokeAll3() throws InterruptedException {
525          ExecutorService e = new DirectExecutorService();
526 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
527 +        l.add(new StringTask());
528 +        l.add(null);
529          try {
530 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
632 <            l.add(new StringTask());
633 <            l.add(null);
634 <            e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
530 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
531              shouldThrow();
532          } catch (NullPointerException success) {
533          } finally {
# Line 645 | Line 541 | public class AbstractExecutorServiceTest
541      public void testTimedInvokeAll4() throws Exception {
542          ExecutorService e = new DirectExecutorService();
543          try {
544 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
544 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
545              l.add(new NPETask());
546 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
547 <            assertEquals(1, result.size());
548 <            for (Future<String> future : result) {
549 <                try {
550 <                    future.get();
551 <                } catch (ExecutionException success) {
552 <                    assertTrue(success.getCause() instanceof NullPointerException);
553 <                }
546 >            List<Future<String>> futures =
547 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
548 >            assertEquals(1, futures.size());
549 >            try {
550 >                futures.get(0).get();
551 >                shouldThrow();
552 >            } catch (ExecutionException success) {
553 >                assertTrue(success.getCause() instanceof NullPointerException);
554              }
555          } finally {
556              joinPool(e);
# Line 667 | Line 563 | public class AbstractExecutorServiceTest
563      public void testTimedInvokeAll5() throws Exception {
564          ExecutorService e = new DirectExecutorService();
565          try {
566 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
566 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
567              l.add(new StringTask());
568              l.add(new StringTask());
569 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
570 <            assertEquals(2, result.size());
571 <            for (Future<String> future : result)
569 >            List<Future<String>> futures =
570 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
571 >            assertEquals(2, futures.size());
572 >            for (Future<String> future : futures)
573                  assertSame(TEST_STRING, future.get());
574          } finally {
575              joinPool(e);
# Line 685 | Line 582 | public class AbstractExecutorServiceTest
582      public void testTimedInvokeAll6() throws InterruptedException {
583          ExecutorService e = new DirectExecutorService();
584          try {
585 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
585 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
586              l.add(new StringTask());
587 <            l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
587 >            l.add(Executors.callable(possiblyInterruptedRunnable(2 * SHORT_DELAY_MS), TEST_STRING));
588              l.add(new StringTask());
589 <            List<Future<String>> result = e.invokeAll(l, SMALL_DELAY_MS, TimeUnit.MILLISECONDS);
590 <            assertEquals(3, result.size());
591 <            Iterator<Future<String>> it = result.iterator();
589 >            List<Future<String>> futures =
590 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
591 >            assertEquals(3, futures.size());
592 >            Iterator<Future<String>> it = futures.iterator();
593              Future<String> f1 = it.next();
594              Future<String> f2 = it.next();
595              Future<String> f3 = it.next();
596              assertTrue(f1.isDone());
597              assertFalse(f1.isCancelled());
598              assertTrue(f2.isDone());
599 +            assertFalse(f2.isCancelled());
600              assertTrue(f3.isDone());
601              assertTrue(f3.isCancelled());
602          } finally {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines