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.33 by jsr166, Mon Jan 14 22:05:39 2013 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 java.math.BigInteger;
12 > import java.util.concurrent.atomic.AtomicBoolean;
13 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
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 40 | Line 45 | public class AbstractExecutorServiceTest
45       */
46      public void testExecuteRunnable() throws Exception {
47          ExecutorService e = new DirectExecutorService();
48 <        TrackedShortRunnable task = new TrackedShortRunnable();
49 <        assertFalse(task.done);
48 >        final AtomicBoolean done = new AtomicBoolean(false);
49 >        CheckedRunnable task = new CheckedRunnable() {
50 >            public void realRun() {
51 >                done.set(true);
52 >            }};
53          Future<?> future = e.submit(task);
54 <        future.get();
55 <        assertTrue(task.done);
54 >        assertNull(future.get());
55 >        assertNull(future.get(0, MILLISECONDS));
56 >        assertTrue(done.get());
57 >        assertTrue(future.isDone());
58 >        assertFalse(future.isCancelled());
59      }
60  
50
61      /**
62       * Completed submit(callable) returns result
63       */
# Line 78 | Line 88 | public class AbstractExecutorServiceTest
88          assertSame(TEST_STRING, result);
89      }
90  
81
91      /**
92 <     * A submitted privileged action to completion
92 >     * A submitted privileged action runs to completion
93       */
94      public void testSubmitPrivilegedAction() throws Exception {
95 <        Policy savedPolicy = null;
96 <        try {
97 <            savedPolicy = Policy.getPolicy();
98 <            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() {
95 >        Runnable r = new CheckedRunnable() {
96 >            public void realRun() throws Exception {
97 >                ExecutorService e = new DirectExecutorService();
98 >                Future future = e.submit(Executors.callable(new PrivilegedAction() {
99                      public Object run() {
100                          return TEST_STRING;
101                      }}));
102  
103 <            Object result = future.get();
104 <            assertSame(TEST_STRING, result);
105 <        }
106 <        finally {
107 <            try {
108 <                Policy.setPolicy(savedPolicy);
109 <            } catch (AccessControlException ok) {
110 <                return;
111 <            }
112 <        }
103 >                assertSame(TEST_STRING, future.get());
104 >            }};
105 >
106 >        runWithPermissions(r,
107 >                           new RuntimePermission("getClassLoader"),
108 >                           new RuntimePermission("setContextClassLoader"),
109 >                           new RuntimePermission("modifyThread"));
110      }
111  
112      /**
113 <     * A submitted a privileged exception action runs to completion
113 >     * A submitted privileged exception action runs to completion
114       */
115      public void testSubmitPrivilegedExceptionAction() throws Exception {
116 <        Policy savedPolicy = null;
117 <        try {
118 <            savedPolicy = Policy.getPolicy();
119 <            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() {
116 >        Runnable r = new CheckedRunnable() {
117 >            public void realRun() throws Exception {
118 >                ExecutorService e = new DirectExecutorService();
119 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
120                      public Object run() {
121                          return TEST_STRING;
122                      }}));
123  
124 <            Object result = future.get();
125 <            assertSame(TEST_STRING, result);
126 <        }
127 <        finally {
141 <            Policy.setPolicy(savedPolicy);
142 <        }
124 >                assertSame(TEST_STRING, future.get());
125 >            }};
126 >
127 >        runWithPermissions(r);
128      }
129  
130      /**
131       * A submitted failed privileged exception action reports exception
132       */
133      public void testSubmitFailedPrivilegedExceptionAction() throws Exception {
134 <        Policy savedPolicy = null;
135 <        try {
136 <            savedPolicy = Policy.getPolicy();
137 <            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() {
134 >        Runnable r = new CheckedRunnable() {
135 >            public void realRun() throws Exception {
136 >                ExecutorService e = new DirectExecutorService();
137 >                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
138                      public Object run() throws Exception {
139                          throw new IndexOutOfBoundsException();
140                      }}));
141  
142 <            future.get();
143 <            shouldThrow();
144 <        } catch (ExecutionException success) {
145 <            assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
146 <        }
147 <        finally {
148 <            Policy.setPolicy(savedPolicy);
149 <        }
142 >                try {
143 >                    future.get();
144 >                    shouldThrow();
145 >                } catch (ExecutionException success) {
146 >                    assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
147 >                }}};
148 >
149 >        runWithPermissions(r);
150      }
151  
152      /**
# Line 185 | Line 160 | public class AbstractExecutorServiceTest
160          } catch (NullPointerException success) {}
161      }
162  
188
163      /**
164       * submit(null callable) throws NPE
165       */
# Line 198 | Line 172 | public class AbstractExecutorServiceTest
172      }
173  
174      /**
175 <     * 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.
175 >     * submit(callable).get() throws InterruptedException if interrupted
176       */
177 <    public void testExecute2() {
178 <        ThreadPoolExecutor p =
179 <            new ThreadPoolExecutor(1, 1,
180 <                                   60, TimeUnit.SECONDS,
181 <                                   new ArrayBlockingQueue<Runnable>(1));
182 <        try {
183 <            for (int i = 0; i < 2; ++i)
184 <                p.submit(new MediumRunnable());
185 <            for (int i = 0; i < 2; ++i) {
186 <                try {
187 <                    p.submit(new SmallCallable());
188 <                    shouldThrow();
189 <                } catch (RejectedExecutionException success) {}
190 <            }
177 >    public void testInterruptedSubmit() throws InterruptedException {
178 >        final CountDownLatch submitted    = new CountDownLatch(1);
179 >        final CountDownLatch quittingTime = new CountDownLatch(1);
180 >        final ExecutorService p
181 >            = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS,
182 >                                     new ArrayBlockingQueue<Runnable>(10));
183 >        final Callable<Void> awaiter = new CheckedCallable<Void>() {
184 >            public Void realCall() throws InterruptedException {
185 >                quittingTime.await();
186 >                return null;
187 >            }};
188 >        try {
189 >            Thread t = new Thread(new CheckedInterruptedRunnable() {
190 >                public void realRun() throws Exception {
191 >                    Future<Void> future = p.submit(awaiter);
192 >                    submitted.countDown();
193 >                    future.get();
194 >                }});
195 >            t.start();
196 >            submitted.await();
197 >            t.interrupt();
198 >            t.join();
199          } finally {
200 +            quittingTime.countDown();
201              joinPool(p);
202          }
203      }
204  
246
247    /**
248     *  Blocking on submit(callable) throws InterruptedException if
249     *  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
205      /**
206 <     *  get of submit(callable) throws ExecutionException if callable
207 <     *  throws exception
206 >     * get of submit(callable) throws ExecutionException if callable
207 >     * throws exception
208       */
209      public void testSubmitEE() throws InterruptedException {
210          ThreadPoolExecutor p =
# Line 299 | Line 213 | public class AbstractExecutorServiceTest
213                                     new ArrayBlockingQueue<Runnable>(10));
214  
215          Callable c = new Callable() {
216 <            public Object call() { return 5/0; }};
216 >            public Object call() { throw new ArithmeticException(); }};
217  
218          try {
219              p.submit(c).get();
# Line 313 | Line 227 | public class AbstractExecutorServiceTest
227      /**
228       * invokeAny(null) throws NPE
229       */
230 <    public void testInvokeAny1()
317 <        throws InterruptedException, ExecutionException {
230 >    public void testInvokeAny1() throws Exception {
231          ExecutorService e = new DirectExecutorService();
232          try {
233              e.invokeAny(null);
# Line 328 | Line 241 | public class AbstractExecutorServiceTest
241      /**
242       * invokeAny(empty collection) throws IAE
243       */
244 <    public void testInvokeAny2()
332 <        throws InterruptedException, ExecutionException {
244 >    public void testInvokeAny2() throws Exception {
245          ExecutorService e = new DirectExecutorService();
246          try {
247              e.invokeAny(new ArrayList<Callable<String>>());
# Line 344 | Line 256 | public class AbstractExecutorServiceTest
256       * invokeAny(c) throws NPE if c has null elements
257       */
258      public void testInvokeAny3() throws Exception {
347        final CountDownLatch latch = new CountDownLatch(1);
259          ExecutorService e = new DirectExecutorService();
260 +        List<Callable<Long>> l = new ArrayList<Callable<Long>>();
261 +        l.add(new Callable<Long>() {
262 +            public Long call() { throw new ArithmeticException(); }});
263 +        l.add(null);
264          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);
265              e.invokeAny(l);
266              shouldThrow();
267          } catch (NullPointerException success) {
268          } finally {
359            latch.countDown();
269              joinPool(e);
270          }
271      }
# Line 366 | Line 275 | public class AbstractExecutorServiceTest
275       */
276      public void testInvokeAny4() throws InterruptedException {
277          ExecutorService e = new DirectExecutorService();
278 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
279 +        l.add(new NPETask());
280          try {
370            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
371            l.add(new NPETask());
281              e.invokeAny(l);
282              shouldThrow();
283          } catch (ExecutionException success) {
# Line 384 | Line 293 | public class AbstractExecutorServiceTest
293      public void testInvokeAny5() throws Exception {
294          ExecutorService e = new DirectExecutorService();
295          try {
296 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
296 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
297              l.add(new StringTask());
298              l.add(new StringTask());
299              String result = e.invokeAny(l);
# Line 426 | Line 335 | public class AbstractExecutorServiceTest
335       */
336      public void testInvokeAll3() throws InterruptedException {
337          ExecutorService e = new DirectExecutorService();
338 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
339 +        l.add(new StringTask());
340 +        l.add(null);
341          try {
430            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
431            l.add(new StringTask());
432            l.add(null);
342              e.invokeAll(l);
343              shouldThrow();
344          } catch (NullPointerException success) {
# Line 444 | Line 353 | public class AbstractExecutorServiceTest
353      public void testInvokeAll4() throws Exception {
354          ExecutorService e = new DirectExecutorService();
355          try {
356 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
356 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
357              l.add(new NPETask());
358 <            List<Future<String>> result = e.invokeAll(l);
359 <            assertEquals(1, result.size());
360 <            for (Future<String> future : result) {
361 <                try {
362 <                    future.get();
363 <                    shouldThrow();
364 <                } catch (ExecutionException success) {
456 <                    Throwable cause = success.getCause();
457 <                    assertTrue(cause instanceof NullPointerException);
458 <                }
358 >            List<Future<String>> futures = e.invokeAll(l);
359 >            assertEquals(1, futures.size());
360 >            try {
361 >                futures.get(0).get();
362 >                shouldThrow();
363 >            } catch (ExecutionException success) {
364 >                assertTrue(success.getCause() instanceof NullPointerException);
365              }
366          } finally {
367              joinPool(e);
# Line 468 | Line 374 | public class AbstractExecutorServiceTest
374      public void testInvokeAll5() throws Exception {
375          ExecutorService e = new DirectExecutorService();
376          try {
377 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
377 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
378              l.add(new StringTask());
379              l.add(new StringTask());
380 <            List<Future<String>> result = e.invokeAll(l);
381 <            assertEquals(2, result.size());
382 <            for (Future<String> future : result)
380 >            List<Future<String>> futures = e.invokeAll(l);
381 >            assertEquals(2, futures.size());
382 >            for (Future<String> future : futures)
383                  assertSame(TEST_STRING, future.get());
384          } finally {
385              joinPool(e);
386          }
387      }
388  
483
389      /**
390       * timed invokeAny(null) throws NPE
391       */
392      public void testTimedInvokeAny1() throws Exception {
393          ExecutorService e = new DirectExecutorService();
394          try {
395 <            e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
395 >            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
396              shouldThrow();
397          } catch (NullPointerException success) {
398          } finally {
# Line 500 | Line 405 | public class AbstractExecutorServiceTest
405       */
406      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
407          ExecutorService e = new DirectExecutorService();
408 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
409 +        l.add(new StringTask());
410          try {
504            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
505            l.add(new StringTask());
411              e.invokeAny(l, MEDIUM_DELAY_MS, null);
412              shouldThrow();
413          } catch (NullPointerException success) {
# Line 517 | Line 422 | public class AbstractExecutorServiceTest
422      public void testTimedInvokeAny2() throws Exception {
423          ExecutorService e = new DirectExecutorService();
424          try {
425 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
425 >            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
426              shouldThrow();
427          } catch (IllegalArgumentException success) {
428          } finally {
# Line 529 | Line 434 | public class AbstractExecutorServiceTest
434       * timed invokeAny(c) throws NPE if c has null elements
435       */
436      public void testTimedInvokeAny3() throws Exception {
532        final CountDownLatch latch = new CountDownLatch(1);
437          ExecutorService e = new DirectExecutorService();
438 +        List<Callable<Long>> l = new ArrayList<Callable<Long>>();
439 +        l.add(new Callable<Long>() {
440 +            public Long call() { throw new ArithmeticException(); }});
441 +        l.add(null);
442          try {
443 <            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);
443 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
444              shouldThrow();
445          } catch (NullPointerException success) {
446          } finally {
544            latch.countDown();
447              joinPool(e);
448          }
449      }
# Line 551 | Line 453 | public class AbstractExecutorServiceTest
453       */
454      public void testTimedInvokeAny4() throws Exception {
455          ExecutorService e = new DirectExecutorService();
456 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
457 +        l.add(new NPETask());
458          try {
459 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
556 <            l.add(new NPETask());
557 <            e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
459 >            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
460              shouldThrow();
461          } catch (ExecutionException success) {
462              assertTrue(success.getCause() instanceof NullPointerException);
# Line 569 | Line 471 | public class AbstractExecutorServiceTest
471      public void testTimedInvokeAny5() throws Exception {
472          ExecutorService e = new DirectExecutorService();
473          try {
474 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
474 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
475              l.add(new StringTask());
476              l.add(new StringTask());
477 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
477 >            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
478              assertSame(TEST_STRING, result);
479          } finally {
480              joinPool(e);
# Line 585 | Line 487 | public class AbstractExecutorServiceTest
487      public void testTimedInvokeAll1() throws InterruptedException {
488          ExecutorService e = new DirectExecutorService();
489          try {
490 <            e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
490 >            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
491              shouldThrow();
492          } catch (NullPointerException success) {
493          } finally {
# Line 598 | Line 500 | public class AbstractExecutorServiceTest
500       */
501      public void testTimedInvokeAllNullTimeUnit() throws InterruptedException {
502          ExecutorService e = new DirectExecutorService();
503 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
504 +        l.add(new StringTask());
505          try {
602            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
603            l.add(new StringTask());
506              e.invokeAll(l, MEDIUM_DELAY_MS, null);
507              shouldThrow();
508          } catch (NullPointerException success) {
# Line 615 | Line 517 | public class AbstractExecutorServiceTest
517      public void testTimedInvokeAll2() throws InterruptedException {
518          ExecutorService e = new DirectExecutorService();
519          try {
520 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
520 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
521              assertTrue(r.isEmpty());
522          } finally {
523              joinPool(e);
# Line 627 | Line 529 | public class AbstractExecutorServiceTest
529       */
530      public void testTimedInvokeAll3() throws InterruptedException {
531          ExecutorService e = new DirectExecutorService();
532 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
533 +        l.add(new StringTask());
534 +        l.add(null);
535          try {
536 <            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);
536 >            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
537              shouldThrow();
538          } catch (NullPointerException success) {
539          } finally {
# Line 645 | Line 547 | public class AbstractExecutorServiceTest
547      public void testTimedInvokeAll4() throws Exception {
548          ExecutorService e = new DirectExecutorService();
549          try {
550 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
550 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
551              l.add(new NPETask());
552 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
553 <            assertEquals(1, result.size());
554 <            for (Future<String> future : result) {
555 <                try {
556 <                    future.get();
557 <                } catch (ExecutionException success) {
558 <                    assertTrue(success.getCause() instanceof NullPointerException);
559 <                }
552 >            List<Future<String>> futures =
553 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
554 >            assertEquals(1, futures.size());
555 >            try {
556 >                futures.get(0).get();
557 >                shouldThrow();
558 >            } catch (ExecutionException success) {
559 >                assertTrue(success.getCause() instanceof NullPointerException);
560              }
561          } finally {
562              joinPool(e);
# Line 667 | Line 569 | public class AbstractExecutorServiceTest
569      public void testTimedInvokeAll5() throws Exception {
570          ExecutorService e = new DirectExecutorService();
571          try {
572 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
572 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
573              l.add(new StringTask());
574              l.add(new StringTask());
575 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
576 <            assertEquals(2, result.size());
577 <            for (Future<String> future : result)
575 >            List<Future<String>> futures =
576 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
577 >            assertEquals(2, futures.size());
578 >            for (Future<String> future : futures)
579                  assertSame(TEST_STRING, future.get());
580          } finally {
581              joinPool(e);
# Line 685 | Line 588 | public class AbstractExecutorServiceTest
588      public void testTimedInvokeAll6() throws InterruptedException {
589          ExecutorService e = new DirectExecutorService();
590          try {
591 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
591 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
592              l.add(new StringTask());
593 <            l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
593 >            l.add(Executors.callable(possiblyInterruptedRunnable(2 * SHORT_DELAY_MS), TEST_STRING));
594              l.add(new StringTask());
595 <            List<Future<String>> result = e.invokeAll(l, SMALL_DELAY_MS, TimeUnit.MILLISECONDS);
596 <            assertEquals(3, result.size());
597 <            Iterator<Future<String>> it = result.iterator();
598 <            Future<String> f1 = it.next();
599 <            Future<String> f2 = it.next();
600 <            Future<String> f3 = it.next();
601 <            assertTrue(f1.isDone());
602 <            assertFalse(f1.isCancelled());
700 <            assertTrue(f2.isDone());
701 <            assertTrue(f3.isDone());
702 <            assertTrue(f3.isCancelled());
595 >            List<Future<String>> futures =
596 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
597 >            assertEquals(l.size(), futures.size());
598 >            for (Future future : futures)
599 >                assertTrue(future.isDone());
600 >            assertFalse(futures.get(0).isCancelled());
601 >            assertFalse(futures.get(1).isCancelled());
602 >            assertTrue(futures.get(2).isCancelled());
603          } finally {
604              joinPool(e);
605          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines