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.18 by jsr166, Mon Nov 16 05:30:07 2009 UTC vs.
Revision 1.19 by jsr166, Fri Nov 20 05:25:10 2009 UTC

# Line 38 | Line 38 | public class AbstractExecutorServiceTest
38      /**
39       * execute(runnable) runs it to completion
40       */
41 <    public void testExecuteRunnable() {
42 <        try {
43 <            ExecutorService e = new DirectExecutorService();
44 <            TrackedShortRunnable task = new TrackedShortRunnable();
45 <            assertFalse(task.done);
46 <            Future<?> future = e.submit(task);
47 <            future.get();
48 <            assertTrue(task.done);
49 <        }
50 <        catch (ExecutionException ex) {
51 <            unexpectedException();
52 <        }
53 <        catch (InterruptedException ex) {
54 <            unexpectedException();
55 <        }
41 >    public void testExecuteRunnable() throws Exception {
42 >        ExecutorService e = new DirectExecutorService();
43 >        TrackedShortRunnable task = new TrackedShortRunnable();
44 >        assertFalse(task.done);
45 >        Future<?> future = e.submit(task);
46 >        future.get();
47 >        assertTrue(task.done);
48      }
49  
50  
51      /**
52       * Completed submit(callable) returns result
53       */
54 <    public void testSubmitCallable() {
55 <        try {
56 <            ExecutorService e = new DirectExecutorService();
57 <            Future<String> future = e.submit(new StringTask());
58 <            String result = future.get();
67 <            assertSame(TEST_STRING, result);
68 <        }
69 <        catch (ExecutionException ex) {
70 <            unexpectedException();
71 <        }
72 <        catch (InterruptedException ex) {
73 <            unexpectedException();
74 <        }
54 >    public void testSubmitCallable() throws Exception {
55 >        ExecutorService e = new DirectExecutorService();
56 >        Future<String> future = e.submit(new StringTask());
57 >        String result = future.get();
58 >        assertSame(TEST_STRING, result);
59      }
60  
61      /**
62       * Completed submit(runnable) returns successfully
63       */
64 <    public void testSubmitRunnable() {
65 <        try {
66 <            ExecutorService e = new DirectExecutorService();
67 <            Future<?> future = e.submit(new NoOpRunnable());
68 <            future.get();
85 <            assertTrue(future.isDone());
86 <        }
87 <        catch (ExecutionException ex) {
88 <            unexpectedException();
89 <        }
90 <        catch (InterruptedException ex) {
91 <            unexpectedException();
92 <        }
64 >    public void testSubmitRunnable() throws Exception {
65 >        ExecutorService e = new DirectExecutorService();
66 >        Future<?> future = e.submit(new NoOpRunnable());
67 >        future.get();
68 >        assertTrue(future.isDone());
69      }
70  
71      /**
72       * Completed submit(runnable, result) returns result
73       */
74 <    public void testSubmitRunnable2() {
75 <        try {
76 <            ExecutorService e = new DirectExecutorService();
77 <            Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
78 <            String result = future.get();
103 <            assertSame(TEST_STRING, result);
104 <        }
105 <        catch (ExecutionException ex) {
106 <            unexpectedException();
107 <        }
108 <        catch (InterruptedException ex) {
109 <            unexpectedException();
110 <        }
74 >    public void testSubmitRunnable2() throws Exception {
75 >        ExecutorService e = new DirectExecutorService();
76 >        Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
77 >        String result = future.get();
78 >        assertSame(TEST_STRING, result);
79      }
80  
81  
82      /**
83       * A submitted privileged action to completion
84       */
85 <    public void testSubmitPrivilegedAction() {
85 >    public void testSubmitPrivilegedAction() throws Exception {
86          Policy savedPolicy = null;
87          try {
88              savedPolicy = Policy.getPolicy();
# Line 135 | Line 103 | public class AbstractExecutorServiceTest
103              Object result = future.get();
104              assertSame(TEST_STRING, result);
105          }
138        catch (ExecutionException ex) {
139            unexpectedException();
140        }
141        catch (InterruptedException ex) {
142            unexpectedException();
143        }
106          finally {
107              try {
108                  Policy.setPolicy(savedPolicy);
# Line 153 | Line 115 | public class AbstractExecutorServiceTest
115      /**
116       * A submitted a privileged exception action runs to completion
117       */
118 <    public void testSubmitPrivilegedExceptionAction() {
118 >    public void testSubmitPrivilegedExceptionAction() throws Exception {
119          Policy savedPolicy = null;
120          try {
121              savedPolicy = Policy.getPolicy();
# Line 175 | Line 137 | public class AbstractExecutorServiceTest
137              Object result = future.get();
138              assertSame(TEST_STRING, result);
139          }
178        catch (ExecutionException ex) {
179            unexpectedException();
180        }
181        catch (InterruptedException ex) {
182            unexpectedException();
183        }
140          finally {
141              Policy.setPolicy(savedPolicy);
142          }
# Line 189 | Line 145 | public class AbstractExecutorServiceTest
145      /**
146       * A submitted failed privileged exception action reports exception
147       */
148 <    public void testSubmitFailedPrivilegedExceptionAction() {
148 >    public void testSubmitFailedPrivilegedExceptionAction() throws Exception {
149          Policy savedPolicy = null;
150          try {
151              savedPolicy = Policy.getPolicy();
# Line 201 | Line 157 | public class AbstractExecutorServiceTest
157              return;
158          }
159  
204
160          try {
161              ExecutorService e = new DirectExecutorService();
162              Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
# Line 209 | Line 164 | public class AbstractExecutorServiceTest
164                          throw new IndexOutOfBoundsException();
165                      }}));
166  
167 <            Object result = future.get();
167 >            future.get();
168              shouldThrow();
169 <        }
170 <        catch (ExecutionException success) {
216 <        }
217 <        catch (InterruptedException ex) {
218 <            unexpectedException();
169 >        } catch (ExecutionException success) {
170 >            assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
171          }
172          finally {
173              Policy.setPolicy(savedPolicy);
# Line 228 | Line 180 | public class AbstractExecutorServiceTest
180      public void testExecuteNullRunnable() {
181          try {
182              ExecutorService e = new DirectExecutorService();
183 <            TrackedShortRunnable task = null;
232 <            Future<?> future = e.submit(task);
183 >            e.submit((Runnable) null);
184              shouldThrow();
185 <        }
235 <        catch (NullPointerException success) {
236 <        }
237 <        catch (Exception ex) {
238 <            unexpectedException();
239 <        }
185 >        } catch (NullPointerException success) {}
186      }
187  
188  
# Line 246 | Line 192 | public class AbstractExecutorServiceTest
192      public void testSubmitNullCallable() {
193          try {
194              ExecutorService e = new DirectExecutorService();
195 <            StringTask t = null;
250 <            Future<String> future = e.submit(t);
195 >            e.submit((Callable) null);
196              shouldThrow();
197 <        }
253 <        catch (NullPointerException success) {
254 <        }
255 <        catch (Exception ex) {
256 <            unexpectedException();
257 <        }
197 >        } catch (NullPointerException success) {}
198      }
199  
200      /**
# Line 262 | Line 202 | public class AbstractExecutorServiceTest
202       * executor is saturated.
203       */
204      public void testExecute1() {
205 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1));
205 >        ThreadPoolExecutor p =
206 >            new ThreadPoolExecutor(1, 1,
207 >                                   60, TimeUnit.SECONDS,
208 >                                   new ArrayBlockingQueue<Runnable>(1));
209          try {
210 <
268 <            for (int i = 0; i < 5; ++i) {
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 <            shouldThrow();
219 <        } catch (RejectedExecutionException success) {}
220 <        joinPool(p);
218 >        } finally {
219 >            joinPool(p);
220 >        }
221      }
222  
223      /**
# Line 278 | Line 225 | public class AbstractExecutorServiceTest
225       * if executor is saturated.
226       */
227      public void testExecute2() {
228 <         ThreadPoolExecutor p = new ThreadPoolExecutor(1,1, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1));
228 >        ThreadPoolExecutor p =
229 >            new ThreadPoolExecutor(1, 1,
230 >                                   60, TimeUnit.SECONDS,
231 >                                   new ArrayBlockingQueue<Runnable>(1));
232          try {
233 <            for (int i = 0; i < 5; ++i) {
234 <                p.submit(new SmallCallable());
233 >            for (int i = 0; i < 2; ++i)
234 >                p.submit(new MediumRunnable());
235 >            for (int i = 0; i < 2; ++i) {
236 >                try {
237 >                    p.submit(new SmallCallable());
238 >                    shouldThrow();
239 >                } catch (RejectedExecutionException success) {}
240              }
241 <            shouldThrow();
242 <        } catch (RejectedExecutionException e) {}
243 <        joinPool(p);
241 >        } finally {
242 >            joinPool(p);
243 >        }
244      }
245  
246  
# Line 293 | Line 248 | public class AbstractExecutorServiceTest
248       *  Blocking on submit(callable) throws InterruptedException if
249       *  caller interrupted.
250       */
251 <    public void testInterruptedSubmit() {
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 Runnable() {
254 <                public void run() {
255 <                    try {
256 <                        p.submit(new Callable<Object>() {
257 <                                public Object call() {
258 <                                    try {
259 <                                        Thread.sleep(MEDIUM_DELAY_MS);
260 <                                        shouldThrow();
261 <                                    } catch (InterruptedException e) {
262 <                                    }
263 <                                    return null;
264 <                                }
265 <                            }).get();
311 <                    } catch (InterruptedException success) {
312 <                    } catch (Exception e) {
313 <                        unexpectedException();
314 <                    }
315 <
316 <                }
317 <            });
318 <        try {
319 <            t.start();
320 <            Thread.sleep(SHORT_DELAY_MS);
321 <            t.interrupt();
322 <        } catch (Exception e) {
323 <            unexpectedException();
324 <        }
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 Exception if callable
270 >     *  get of submitted callable throws InterruptedException if callable
271       *  interrupted
272       */
273 <    public void testSubmitIE() {
274 <        final ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
275 <
276 <        final Callable c = new Callable() {
277 <                public Object call() {
278 <                    try {
279 <                        p.submit(new SmallCallable()).get();
280 <                        shouldThrow();
281 <                    } catch (InterruptedException e) {}
282 <                    catch (RejectedExecutionException e2) {}
283 <                    catch (ExecutionException e3) {}
284 <                    return Boolean.TRUE;
285 <                }
286 <            };
287 <
347 <
348 <
349 <        Thread t = new Thread(new Runnable() {
350 <                public void run() {
351 <                    try {
352 <                        c.call();
353 <                    } catch (Exception e) {}
354 <                }
355 <          });
356 <        try {
357 <            t.start();
358 <            Thread.sleep(SHORT_DELAY_MS);
359 <            t.interrupt();
360 <            t.join();
361 <        } catch (InterruptedException e) {
362 <            unexpectedException();
363 <        }
364 <
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  
# Line 369 | Line 292 | public class AbstractExecutorServiceTest
292       *  get of submit(callable) throws ExecutionException if callable
293       *  throws exception
294       */
295 <    public void testSubmitEE() {
296 <        ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10));
295 >    public void testSubmitEE() throws InterruptedException {
296 >        ThreadPoolExecutor p =
297 >            new ThreadPoolExecutor(1, 1,
298 >                                   60, TimeUnit.SECONDS,
299 >                                   new ArrayBlockingQueue<Runnable>(10));
300  
301 <        try {
302 <            Callable c = new Callable() {
377 <                    public Object call() {
378 <                        int i = 5/0;
379 <                        return Boolean.TRUE;
380 <                    }
381 <                };
382 <
383 <            for (int i =0; i < 5; i++) {
384 <                p.submit(c).get();
385 <            }
301 >        Callable c = new Callable() {
302 >            public Object call() { return 5/0; }};
303  
304 +        try {
305 +            p.submit(c).get();
306              shouldThrow();
307 <        }
308 <        catch (ExecutionException success) {
390 <        } catch (Exception e) {
391 <            unexpectedException();
307 >        } catch (ExecutionException success) {
308 >            assertTrue(success.getCause() instanceof ArithmeticException);
309          }
310          joinPool(p);
311      }
# Line 396 | Line 313 | public class AbstractExecutorServiceTest
313      /**
314       * invokeAny(null) throws NPE
315       */
316 <    public void testInvokeAny1() {
316 >    public void testInvokeAny1()
317 >        throws InterruptedException, ExecutionException {
318          ExecutorService e = new DirectExecutorService();
319          try {
320              e.invokeAny(null);
321 +            shouldThrow();
322          } catch (NullPointerException success) {
404        } catch (Exception ex) {
405            unexpectedException();
323          } finally {
324              joinPool(e);
325          }
# Line 411 | Line 328 | public class AbstractExecutorServiceTest
328      /**
329       * invokeAny(empty collection) throws IAE
330       */
331 <    public void testInvokeAny2() {
331 >    public void testInvokeAny2()
332 >        throws InterruptedException, ExecutionException {
333          ExecutorService e = new DirectExecutorService();
334          try {
335              e.invokeAny(new ArrayList<Callable<String>>());
336 +            shouldThrow();
337          } catch (IllegalArgumentException success) {
419        } catch (Exception ex) {
420            unexpectedException();
338          } finally {
339              joinPool(e);
340          }
# Line 426 | Line 343 | public class AbstractExecutorServiceTest
343      /**
344       * invokeAny(c) throws NPE if c has null elements
345       */
346 <    public void testInvokeAny3() {
346 >    public void testInvokeAny3() throws Exception {
347 >        final CountDownLatch latch = new CountDownLatch(1);
348          ExecutorService e = new DirectExecutorService();
349          try {
350 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
351 <            l.add(new StringTask());
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);
355              e.invokeAny(l);
356 +            shouldThrow();
357          } catch (NullPointerException success) {
437        } catch (Exception ex) {
438            ex.printStackTrace();
439            unexpectedException();
358          } finally {
359 +            latch.countDown();
360              joinPool(e);
361          }
362      }
# Line 445 | Line 364 | public class AbstractExecutorServiceTest
364      /**
365       * invokeAny(c) throws ExecutionException if no task in c completes
366       */
367 <    public void testInvokeAny4() {
367 >    public void testInvokeAny4() throws InterruptedException {
368          ExecutorService e = new DirectExecutorService();
369          try {
370              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
371              l.add(new NPETask());
372              e.invokeAny(l);
373 +            shouldThrow();
374          } catch (ExecutionException success) {
375 <        } catch (Exception ex) {
456 <            unexpectedException();
375 >            assertTrue(success.getCause() instanceof NullPointerException);
376          } finally {
377              joinPool(e);
378          }
# Line 462 | Line 381 | public class AbstractExecutorServiceTest
381      /**
382       * invokeAny(c) returns result of some task in c if at least one completes
383       */
384 <    public void testInvokeAny5() {
384 >    public void testInvokeAny5() throws Exception {
385          ExecutorService e = new DirectExecutorService();
386          try {
387              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 470 | Line 389 | public class AbstractExecutorServiceTest
389              l.add(new StringTask());
390              String result = e.invokeAny(l);
391              assertSame(TEST_STRING, result);
473        } catch (ExecutionException success) {
474        } catch (Exception ex) {
475            unexpectedException();
392          } finally {
393              joinPool(e);
394          }
# Line 481 | Line 397 | public class AbstractExecutorServiceTest
397      /**
398       * invokeAll(null) throws NPE
399       */
400 <    public void testInvokeAll1() {
400 >    public void testInvokeAll1() throws InterruptedException {
401          ExecutorService e = new DirectExecutorService();
402          try {
403              e.invokeAll(null);
404 +            shouldThrow();
405          } catch (NullPointerException success) {
489        } catch (Exception ex) {
490            unexpectedException();
406          } finally {
407              joinPool(e);
408          }
# Line 496 | Line 411 | public class AbstractExecutorServiceTest
411      /**
412       * invokeAll(empty collection) returns empty collection
413       */
414 <    public void testInvokeAll2() {
414 >    public void testInvokeAll2() throws InterruptedException {
415          ExecutorService e = new DirectExecutorService();
416          try {
417              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
418              assertTrue(r.isEmpty());
504        } catch (Exception ex) {
505            unexpectedException();
419          } finally {
420              joinPool(e);
421          }
# Line 511 | Line 424 | public class AbstractExecutorServiceTest
424      /**
425       * invokeAll(c) throws NPE if c has null elements
426       */
427 <    public void testInvokeAll3() {
427 >    public void testInvokeAll3() throws InterruptedException {
428          ExecutorService e = new DirectExecutorService();
429          try {
430              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
431              l.add(new StringTask());
432              l.add(null);
433              e.invokeAll(l);
434 +            shouldThrow();
435          } catch (NullPointerException success) {
522        } catch (Exception ex) {
523            unexpectedException();
436          } finally {
437              joinPool(e);
438          }
# Line 529 | Line 441 | public class AbstractExecutorServiceTest
441      /**
442       * get of returned element of invokeAll(c) throws exception on failed task
443       */
444 <    public void testInvokeAll4() {
444 >    public void testInvokeAll4() throws Exception {
445          ExecutorService e = new DirectExecutorService();
446          try {
447              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
448              l.add(new NPETask());
449              List<Future<String>> result = e.invokeAll(l);
450              assertEquals(1, result.size());
451 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
452 <                it.next().get();
453 <        } catch (ExecutionException success) {
454 <        } catch (Exception ex) {
455 <            unexpectedException();
451 >            for (Future<String> future : result) {
452 >                try {
453 >                    future.get();
454 >                    shouldThrow();
455 >                } catch (ExecutionException success) {
456 >                    Throwable cause = success.getCause();
457 >                    assertTrue(cause instanceof NullPointerException);
458 >                }
459 >            }
460          } finally {
461              joinPool(e);
462          }
# Line 549 | Line 465 | public class AbstractExecutorServiceTest
465      /**
466       * invokeAll(c) returns results of all completed tasks in c
467       */
468 <    public void testInvokeAll5() {
468 >    public void testInvokeAll5() throws Exception {
469          ExecutorService e = new DirectExecutorService();
470          try {
471              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 557 | Line 473 | public class AbstractExecutorServiceTest
473              l.add(new StringTask());
474              List<Future<String>> result = e.invokeAll(l);
475              assertEquals(2, result.size());
476 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
477 <                assertSame(TEST_STRING, it.next().get());
562 <        } catch (ExecutionException success) {
563 <        } catch (Exception ex) {
564 <            unexpectedException();
476 >            for (Future<String> future : result)
477 >                assertSame(TEST_STRING, future.get());
478          } finally {
479              joinPool(e);
480          }
# Line 571 | Line 484 | public class AbstractExecutorServiceTest
484      /**
485       * timed invokeAny(null) throws NPE
486       */
487 <    public void testTimedInvokeAny1() {
487 >    public void testTimedInvokeAny1() throws Exception {
488          ExecutorService e = new DirectExecutorService();
489          try {
490              e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
491 +            shouldThrow();
492          } catch (NullPointerException success) {
579        } catch (Exception ex) {
580            unexpectedException();
493          } finally {
494              joinPool(e);
495          }
# Line 586 | Line 498 | public class AbstractExecutorServiceTest
498      /**
499       * timed invokeAny(null time unit) throws NPE
500       */
501 <    public void testTimedInvokeAnyNullTimeUnit() {
501 >    public void testTimedInvokeAnyNullTimeUnit() throws Exception {
502          ExecutorService e = new DirectExecutorService();
503          try {
504              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
505              l.add(new StringTask());
506              e.invokeAny(l, MEDIUM_DELAY_MS, null);
507 +            shouldThrow();
508          } catch (NullPointerException success) {
596        } catch (Exception ex) {
597            unexpectedException();
509          } finally {
510              joinPool(e);
511          }
# Line 603 | Line 514 | public class AbstractExecutorServiceTest
514      /**
515       * timed invokeAny(empty collection) throws IAE
516       */
517 <    public void testTimedInvokeAny2() {
517 >    public void testTimedInvokeAny2() throws Exception {
518          ExecutorService e = new DirectExecutorService();
519          try {
520              e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
521 +            shouldThrow();
522          } catch (IllegalArgumentException success) {
611        } catch (Exception ex) {
612            unexpectedException();
523          } finally {
524              joinPool(e);
525          }
# Line 618 | Line 528 | public class AbstractExecutorServiceTest
528      /**
529       * timed invokeAny(c) throws NPE if c has null elements
530       */
531 <    public void testTimedInvokeAny3() {
531 >    public void testTimedInvokeAny3() throws Exception {
532 >        final CountDownLatch latch = new CountDownLatch(1);
533          ExecutorService e = new DirectExecutorService();
534          try {
535 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
536 <            l.add(new StringTask());
535 >            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);
541 +            shouldThrow();
542          } catch (NullPointerException success) {
629        } catch (Exception ex) {
630            ex.printStackTrace();
631            unexpectedException();
543          } finally {
544 +            latch.countDown();
545              joinPool(e);
546          }
547      }
# Line 637 | Line 549 | public class AbstractExecutorServiceTest
549      /**
550       * timed invokeAny(c) throws ExecutionException if no task completes
551       */
552 <    public void testTimedInvokeAny4() {
552 >    public void testTimedInvokeAny4() throws Exception {
553          ExecutorService e = new DirectExecutorService();
554          try {
555              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
556              l.add(new NPETask());
557              e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
558 +            shouldThrow();
559          } catch (ExecutionException success) {
560 <        } catch (Exception ex) {
648 <            unexpectedException();
560 >            assertTrue(success.getCause() instanceof NullPointerException);
561          } finally {
562              joinPool(e);
563          }
# Line 654 | Line 566 | public class AbstractExecutorServiceTest
566      /**
567       * timed invokeAny(c) returns result of some task in c
568       */
569 <    public void testTimedInvokeAny5() {
569 >    public void testTimedInvokeAny5() throws Exception {
570          ExecutorService e = new DirectExecutorService();
571          try {
572              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 662 | Line 574 | public class AbstractExecutorServiceTest
574              l.add(new StringTask());
575              String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
576              assertSame(TEST_STRING, result);
665        } catch (ExecutionException success) {
666        } catch (Exception ex) {
667            unexpectedException();
577          } finally {
578              joinPool(e);
579          }
# Line 673 | Line 582 | public class AbstractExecutorServiceTest
582      /**
583       * timed invokeAll(null) throws NPE
584       */
585 <    public void testTimedInvokeAll1() {
585 >    public void testTimedInvokeAll1() throws InterruptedException {
586          ExecutorService e = new DirectExecutorService();
587          try {
588              e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
589 +            shouldThrow();
590          } catch (NullPointerException success) {
681        } catch (Exception ex) {
682            unexpectedException();
591          } finally {
592              joinPool(e);
593          }
# Line 688 | Line 596 | public class AbstractExecutorServiceTest
596      /**
597       * timed invokeAll(null time unit) throws NPE
598       */
599 <    public void testTimedInvokeAllNullTimeUnit() {
599 >    public void testTimedInvokeAllNullTimeUnit() throws InterruptedException {
600          ExecutorService e = new DirectExecutorService();
601          try {
602              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
603              l.add(new StringTask());
604              e.invokeAll(l, MEDIUM_DELAY_MS, null);
605 +            shouldThrow();
606          } catch (NullPointerException success) {
698        } catch (Exception ex) {
699            unexpectedException();
607          } finally {
608              joinPool(e);
609          }
# Line 705 | Line 612 | public class AbstractExecutorServiceTest
612      /**
613       * timed invokeAll(empty collection) returns empty collection
614       */
615 <    public void testTimedInvokeAll2() {
615 >    public void testTimedInvokeAll2() throws InterruptedException {
616          ExecutorService e = new DirectExecutorService();
617          try {
618              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
619              assertTrue(r.isEmpty());
713        } catch (Exception ex) {
714            unexpectedException();
620          } finally {
621              joinPool(e);
622          }
# Line 720 | Line 625 | public class AbstractExecutorServiceTest
625      /**
626       * timed invokeAll(c) throws NPE if c has null elements
627       */
628 <    public void testTimedInvokeAll3() {
628 >    public void testTimedInvokeAll3() throws InterruptedException {
629          ExecutorService e = new DirectExecutorService();
630          try {
631              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);
635 +            shouldThrow();
636          } catch (NullPointerException success) {
731        } catch (Exception ex) {
732            unexpectedException();
637          } finally {
638              joinPool(e);
639          }
# Line 738 | Line 642 | public class AbstractExecutorServiceTest
642      /**
643       * get of returned element of invokeAll(c) throws exception on failed task
644       */
645 <    public void testTimedInvokeAll4() {
645 >    public void testTimedInvokeAll4() throws Exception {
646          ExecutorService e = new DirectExecutorService();
647          try {
648              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
649              l.add(new NPETask());
650              List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
651              assertEquals(1, result.size());
652 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
653 <                it.next().get();
654 <        } catch (ExecutionException success) {
655 <        } catch (Exception ex) {
656 <            unexpectedException();
652 >            for (Future<String> future : result) {
653 >                try {
654 >                    future.get();
655 >                } catch (ExecutionException success) {
656 >                    assertTrue(success.getCause() instanceof NullPointerException);
657 >                }
658 >            }
659          } finally {
660              joinPool(e);
661          }
# Line 758 | Line 664 | public class AbstractExecutorServiceTest
664      /**
665       * timed invokeAll(c) returns results of all completed tasks in c
666       */
667 <    public void testTimedInvokeAll5() {
667 >    public void testTimedInvokeAll5() throws Exception {
668          ExecutorService e = new DirectExecutorService();
669          try {
670              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 766 | Line 672 | public class AbstractExecutorServiceTest
672              l.add(new StringTask());
673              List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
674              assertEquals(2, result.size());
675 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
676 <                assertSame(TEST_STRING, it.next().get());
771 <        } catch (ExecutionException success) {
772 <        } catch (Exception ex) {
773 <            unexpectedException();
675 >            for (Future<String> future : result)
676 >                assertSame(TEST_STRING, future.get());
677          } finally {
678              joinPool(e);
679          }
# Line 779 | Line 682 | public class AbstractExecutorServiceTest
682      /**
683       * timed invokeAll cancels tasks not completed by timeout
684       */
685 <    public void testTimedInvokeAll6() {
685 >    public void testTimedInvokeAll6() throws InterruptedException {
686          ExecutorService e = new DirectExecutorService();
687          try {
688              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 797 | Line 700 | public class AbstractExecutorServiceTest
700              assertTrue(f2.isDone());
701              assertTrue(f3.isDone());
702              assertTrue(f3.isCancelled());
800        } catch (Exception ex) {
801            unexpectedException();
703          } finally {
704              joinPool(e);
705          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines