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

Comparing jsr166/src/test/tck/ScheduledExecutorTest.java (file contents):
Revision 1.7 by dl, Fri Sep 26 15:33:13 2003 UTC vs.
Revision 1.10 by dl, Mon Dec 22 00:48:56 2003 UTC

# Line 23 | Line 23 | public class ScheduledExecutorTest exten
23       */
24      public void testExecute() {
25          try {
26 <            TrackedRunnable runnable =new TrackedRunnable();
27 <            ScheduledExecutor p1 = new ScheduledExecutor(1);
26 >            TrackedShortRunnable runnable =new TrackedShortRunnable();
27 >            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
28              p1.execute(runnable);
29              assertFalse(runnable.done);
30              Thread.sleep(SHORT_DELAY_MS);
# Line 51 | Line 51 | public class ScheduledExecutorTest exten
51      public void testSchedule1() {
52          try {
53              TrackedCallable callable = new TrackedCallable();
54 <            ScheduledExecutor p1 = new ScheduledExecutor(1);
54 >            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
55              Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
56              assertFalse(callable.done);
57              Thread.sleep(MEDIUM_DELAY_MS);
# Line 61 | Line 61 | public class ScheduledExecutorTest exten
61              joinPool(p1);
62          } catch(RejectedExecutionException e){}
63          catch(Exception e){
64 +            e.printStackTrace();
65              unexpectedException();
66          }
67      }
# Line 70 | Line 71 | public class ScheduledExecutorTest exten
71       */
72      public void testSchedule3() {
73          try {
74 <            TrackedRunnable runnable = new TrackedRunnable();
75 <            ScheduledExecutor p1 = new ScheduledExecutor(1);
74 >            TrackedShortRunnable runnable = new TrackedShortRunnable();
75 >            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
76              p1.schedule(runnable, SMALL_DELAY_MS, TimeUnit.MILLISECONDS);
77              Thread.sleep(SHORT_DELAY_MS);
78              assertFalse(runnable.done);
# Line 89 | Line 90 | public class ScheduledExecutorTest exten
90       */
91      public void testSchedule4() {
92          try {
93 <            TrackedRunnable runnable = new TrackedRunnable();
94 <            ScheduledExecutor p1 = new ScheduledExecutor(1);
95 <            ScheduledCancellable h = p1.scheduleAtFixedRate(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
93 >            TrackedShortRunnable runnable = new TrackedShortRunnable();
94 >            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
95 >            ScheduledFuture h = p1.scheduleAtFixedRate(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
96              assertFalse(runnable.done);
97              Thread.sleep(MEDIUM_DELAY_MS);
98              assertTrue(runnable.done);
# Line 108 | Line 109 | public class ScheduledExecutorTest exten
109       */
110      public void testSchedule5() {
111          try {
112 <            TrackedRunnable runnable = new TrackedRunnable();
113 <            ScheduledExecutor p1 = new ScheduledExecutor(1);
114 <            ScheduledCancellable h = p1.scheduleWithFixedDelay(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
112 >            TrackedShortRunnable runnable = new TrackedShortRunnable();
113 >            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
114 >            ScheduledFuture h = p1.scheduleWithFixedDelay(runnable, SHORT_DELAY_MS, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
115              assertFalse(runnable.done);
116              Thread.sleep(MEDIUM_DELAY_MS);
117              assertTrue(runnable.done);
# Line 126 | Line 127 | public class ScheduledExecutorTest exten
127       *  execute (null) throws NPE
128       */
129      public void testExecuteNull() {
130 <        ScheduledExecutor se = null;
130 >        ScheduledThreadPoolExecutor se = null;
131          try {
132 <            se = new ScheduledExecutor(1);
132 >            se = new ScheduledThreadPoolExecutor(1);
133              se.execute(null);
134              shouldThrow();
135          } catch(NullPointerException success){}
# Line 143 | Line 144 | public class ScheduledExecutorTest exten
144       * schedule (null) throws NPE
145       */
146      public void testScheduleNull() {
147 <        ScheduledExecutor se = new ScheduledExecutor(1);
147 >        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
148          try {
149              TrackedCallable callable = null;
150              Future f = se.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
# Line 159 | Line 160 | public class ScheduledExecutorTest exten
160       * execute throws RejectedExecutionException if shutdown
161       */
162      public void testSchedule1_RejectedExecutionException() {
163 <        ScheduledExecutor se = new ScheduledExecutor(1);
163 >        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
164          try {
165              se.shutdown();
166              se.schedule(new NoOpRunnable(),
# Line 175 | Line 176 | public class ScheduledExecutorTest exten
176       * schedule throws RejectedExecutionException if shutdown
177       */
178      public void testSchedule2_RejectedExecutionException() {
179 <        ScheduledExecutor se = new ScheduledExecutor(1);
179 >        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
180          try {
181              se.shutdown();
182              se.schedule(new NoOpCallable(),
# Line 190 | Line 191 | public class ScheduledExecutorTest exten
191       * schedule callable throws RejectedExecutionException if shutdown
192       */
193       public void testSchedule3_RejectedExecutionException() {
194 <         ScheduledExecutor se = new ScheduledExecutor(1);
194 >         ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
195           try {
196              se.shutdown();
197              se.schedule(new NoOpCallable(),
# Line 205 | Line 206 | public class ScheduledExecutorTest exten
206       *  scheduleAtFixedRate throws RejectedExecutionException if shutdown
207       */
208      public void testScheduleAtFixedRate1_RejectedExecutionException() {
209 <        ScheduledExecutor se = new ScheduledExecutor(1);
209 >        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
210          try {
211              se.shutdown();
212              se.scheduleAtFixedRate(new NoOpRunnable(),
# Line 220 | Line 221 | public class ScheduledExecutorTest exten
221       * scheduleWithFixedDelay throws RejectedExecutionException if shutdown
222       */
223      public void testScheduleWithFixedDelay1_RejectedExecutionException() {
224 <        ScheduledExecutor se = new ScheduledExecutor(1);
224 >        ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
225          try {
226              se.shutdown();
227              se.scheduleWithFixedDelay(new NoOpRunnable(),
# Line 236 | Line 237 | public class ScheduledExecutorTest exten
237       *  thread becomes active
238       */
239      public void testGetActiveCount() {
240 <        ScheduledExecutor p2 = new ScheduledExecutor(2);
240 >        ScheduledThreadPoolExecutor p2 = new ScheduledThreadPoolExecutor(2);
241          assertEquals(0, p2.getActiveCount());
242          p2.execute(new SmallRunnable());
243          try {
# Line 253 | Line 254 | public class ScheduledExecutorTest exten
254       *   when tasks complete
255       */
256      public void testGetCompletedTaskCount() {
257 <        ScheduledExecutor p2 = new ScheduledExecutor(2);
257 >        ScheduledThreadPoolExecutor p2 = new ScheduledThreadPoolExecutor(2);
258          assertEquals(0, p2.getCompletedTaskCount());
259          p2.execute(new SmallRunnable());
260          try {
# Line 269 | Line 270 | public class ScheduledExecutorTest exten
270       *  getCorePoolSize returns size given in constructor if not otherwise set
271       */
272      public void testGetCorePoolSize() {
273 <        ScheduledExecutor p1 = new ScheduledExecutor(1);
273 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
274          assertEquals(1, p1.getCorePoolSize());
275          joinPool(p1);
276      }
# Line 279 | Line 280 | public class ScheduledExecutorTest exten
280       *   multiple threads active
281       */
282      public void testGetLargestPoolSize() {
283 <        ScheduledExecutor p2 = new ScheduledExecutor(2);
283 >        ScheduledThreadPoolExecutor p2 = new ScheduledThreadPoolExecutor(2);
284          assertEquals(0, p2.getLargestPoolSize());
285          p2.execute(new SmallRunnable());
286          p2.execute(new SmallRunnable());
# Line 297 | Line 298 | public class ScheduledExecutorTest exten
298       *   become active
299       */
300      public void testGetPoolSize() {
301 <        ScheduledExecutor p1 = new ScheduledExecutor(1);
301 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
302          assertEquals(0, p1.getPoolSize());
303          p1.execute(new SmallRunnable());
304          assertEquals(1, p1.getPoolSize());
# Line 309 | Line 310 | public class ScheduledExecutorTest exten
310       *    submitted
311       */
312      public void testGetTaskCount() {
313 <        ScheduledExecutor p1 = new ScheduledExecutor(1);
313 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
314          assertEquals(0, p1.getTaskCount());
315          for(int i = 0; i < 5; i++)
316              p1.execute(new SmallRunnable());
# Line 321 | Line 322 | public class ScheduledExecutorTest exten
322          assertEquals(5, p1.getTaskCount());
323          joinPool(p1);
324      }
325 +
326 +    /**
327 +     * getThreadFactory returns factory in constructor if not set
328 +     */
329 +    public void testGetThreadFactory() {
330 +        ThreadFactory tf = new SimpleThreadFactory();
331 +        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1, tf);
332 +        assertSame(tf, p.getThreadFactory());
333 +        p.shutdown();
334 +        joinPool(p);
335 +    }
336 +
337 +    /**
338 +     * setThreadFactory sets the thread factory returned by getThreadFactory
339 +     */
340 +    public void testSetThreadFactory() {
341 +        ThreadFactory tf = new SimpleThreadFactory();
342 +        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
343 +        p.setThreadFactory(tf);
344 +        assertSame(tf, p.getThreadFactory());
345 +        p.shutdown();
346 +        joinPool(p);
347 +    }
348 +
349 +    /**
350 +     * setThreadFactory(null) throws NPE
351 +     */
352 +    public void testSetThreadFactoryNull() {
353 +        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
354 +        try {
355 +            p.setThreadFactory(null);
356 +            shouldThrow();
357 +        } catch (NullPointerException success) {
358 +        } finally {
359 +            joinPool(p);
360 +        }
361 +    }
362      
363      /**
364       *   is isShutDown is false before shutdown, true after
365       */
366      public void testIsShutdown() {
367          
368 <        ScheduledExecutor p1 = new ScheduledExecutor(1);
368 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
369          try {
370              assertFalse(p1.isShutdown());
371          }
# Line 342 | Line 380 | public class ScheduledExecutorTest exten
380       *   isTerminated is false before termination, true after
381       */
382      public void testIsTerminated() {
383 <        ScheduledExecutor p1 = new ScheduledExecutor(1);
383 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
384          try {
385              p1.execute(new SmallRunnable());
386          } finally {
# Line 360 | Line 398 | public class ScheduledExecutorTest exten
398       *  isTerminating is not true when running or when terminated
399       */
400      public void testIsTerminating() {
401 <        ScheduledExecutor p1 = new ScheduledExecutor(1);
401 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
402          assertFalse(p1.isTerminating());
403          try {
404              p1.execute(new SmallRunnable());
# Line 378 | Line 416 | public class ScheduledExecutorTest exten
416      }
417  
418      /**
419 <     *   purge removes cancelled tasks from the queue
419 >     * getQueue returns the work queue, which contains queued tasks
420 >     */
421 >    public void testGetQueue() {
422 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
423 >        ScheduledFuture[] tasks = new ScheduledFuture[5];
424 >        for(int i = 0; i < 5; i++){
425 >            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS);
426 >        }
427 >        try {
428 >            Thread.sleep(SHORT_DELAY_MS);
429 >            BlockingQueue<Runnable> q = p1.getQueue();
430 >            assertTrue(q.contains(tasks[4]));
431 >            assertFalse(q.contains(tasks[0]));
432 >            p1.shutdownNow();
433 >        } catch(Exception e) {
434 >            unexpectedException();
435 >        } finally {
436 >            joinPool(p1);
437 >        }
438 >    }
439 >
440 >    /**
441 >     * remove(task) removes queued task, and fails to remove active task
442 >     */
443 >    public void testRemove() {
444 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
445 >        ScheduledFuture[] tasks = new ScheduledFuture[5];
446 >        for(int i = 0; i < 5; i++){
447 >            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS);
448 >        }
449 >        try {
450 >            Thread.sleep(SHORT_DELAY_MS);
451 >            BlockingQueue<Runnable> q = p1.getQueue();
452 >            assertFalse(p1.remove((Runnable)tasks[0]));
453 >            assertTrue(q.contains((Runnable)tasks[4]));
454 >            assertTrue(q.contains((Runnable)tasks[3]));
455 >            assertTrue(p1.remove((Runnable)tasks[4]));
456 >            assertFalse(p1.remove((Runnable)tasks[4]));
457 >            assertFalse(q.contains((Runnable)tasks[4]));
458 >            assertTrue(q.contains((Runnable)tasks[3]));
459 >            assertTrue(p1.remove((Runnable)tasks[3]));
460 >            assertFalse(q.contains((Runnable)tasks[3]));
461 >            p1.shutdownNow();
462 >        } catch(Exception e) {
463 >            unexpectedException();
464 >        } finally {
465 >            joinPool(p1);
466 >        }
467 >    }
468 >
469 >    /**
470 >     *  purge removes cancelled tasks from the queue
471       */
472      public void testPurge() {
473 <        ScheduledExecutor p1 = new ScheduledExecutor(1);
474 <        ScheduledCancellable[] tasks = new ScheduledCancellable[5];
473 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
474 >        ScheduledFuture[] tasks = new ScheduledFuture[5];
475          for(int i = 0; i < 5; i++){
476 <            tasks[i] = p1.schedule(new SmallRunnable(), 1, TimeUnit.MILLISECONDS);
476 >            tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS);
477          }
478          int max = 5;
479          if (tasks[4].cancel(true)) --max;
# Line 399 | Line 488 | public class ScheduledExecutorTest exten
488       *  shutDownNow returns a list containing tasks that were not run
489       */
490      public void testShutDownNow() {
491 <        ScheduledExecutor p1 = new ScheduledExecutor(1);
491 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
492          for(int i = 0; i < 5; i++)
493 <            p1.schedule(new SmallRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
493 >            p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
494          List l = p1.shutdownNow();
495          assertTrue(p1.isShutdown());
496          assertTrue(l.size() > 0 && l.size() <= 5);
# Line 414 | Line 503 | public class ScheduledExecutorTest exten
503       */
504      public void testShutDown1() {
505          try {
506 <            ScheduledExecutor p1 = new ScheduledExecutor(1);
506 >            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
507              assertTrue(p1.getExecuteExistingDelayedTasksAfterShutdownPolicy());
508              assertFalse(p1.getContinueExistingPeriodicTasksAfterShutdownPolicy());
509  
510 <            ScheduledCancellable[] tasks = new ScheduledCancellable[5];
510 >            ScheduledFuture[] tasks = new ScheduledFuture[5];
511              for(int i = 0; i < 5; i++)
512                  tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
513              p1.shutdown();
514              BlockingQueue q = p1.getQueue();
515              for (Iterator it = q.iterator(); it.hasNext();) {
516 <                ScheduledCancellable t = (ScheduledCancellable)it.next();
516 >                ScheduledFuture t = (ScheduledFuture)it.next();
517                  assertFalse(t.isCancelled());
518              }
519              assertTrue(p1.isShutdown());
# Line 447 | Line 536 | public class ScheduledExecutorTest exten
536       */
537      public void testShutDown2() {
538          try {
539 <            ScheduledExecutor p1 = new ScheduledExecutor(1);
539 >            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
540              p1.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
541 <            ScheduledCancellable[] tasks = new ScheduledCancellable[5];
541 >            ScheduledFuture[] tasks = new ScheduledFuture[5];
542              for(int i = 0; i < 5; i++)
543                  tasks[i] = p1.schedule(new NoOpRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
544              p1.shutdown();
# Line 471 | Line 560 | public class ScheduledExecutorTest exten
560       */
561      public void testShutDown3() {
562          try {
563 <            ScheduledExecutor p1 = new ScheduledExecutor(1);
563 >            ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
564              p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
565 <            ScheduledCancellable task =
565 >            ScheduledFuture task =
566                  p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS);
567              p1.shutdown();
568              assertTrue(p1.isShutdown());
# Line 492 | Line 581 | public class ScheduledExecutorTest exten
581       * periodic tasks are cancelled at shutdown
582       */
583      public void testShutDown4() {
584 <        ScheduledExecutor p1 = new ScheduledExecutor(1);
584 >        ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
585          try {
586              p1.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
587 <            ScheduledCancellable task =
587 >            ScheduledFuture task =
588                  p1.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, TimeUnit.MILLISECONDS);
589              assertFalse(task.isCancelled());
590              p1.shutdown();
# Line 517 | Line 606 | public class ScheduledExecutorTest exten
606          }
607      }
608  
609 +    /**
610 +     * completed submit of callable returns result
611 +     */
612 +    public void testSubmitCallable() {
613 +        ExecutorService e = new ScheduledThreadPoolExecutor(2);
614 +        try {
615 +            Future<String> future = e.submit(new StringTask());
616 +            String result = future.get();
617 +            assertSame(TEST_STRING, result);
618 +        }
619 +        catch (ExecutionException ex) {
620 +            unexpectedException();
621 +        }
622 +        catch (InterruptedException ex) {
623 +            unexpectedException();
624 +        } finally {
625 +            joinPool(e);
626 +        }
627 +    }
628 +
629 +    /**
630 +     * completed submit of runnable returns successfully
631 +     */
632 +    public void testSubmitRunnable() {
633 +        ExecutorService e = new ScheduledThreadPoolExecutor(2);
634 +        try {
635 +            Future<?> future = e.submit(new NoOpRunnable());
636 +            future.get();
637 +            assertTrue(future.isDone());
638 +        }
639 +        catch (ExecutionException ex) {
640 +            unexpectedException();
641 +        }
642 +        catch (InterruptedException ex) {
643 +            unexpectedException();
644 +        } finally {
645 +            joinPool(e);
646 +        }
647 +    }
648 +
649 +    /**
650 +     * completed submit of (runnable, result) returns result
651 +     */
652 +    public void testSubmitRunnable2() {
653 +        ExecutorService e = new ScheduledThreadPoolExecutor(2);
654 +        try {
655 +            Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
656 +            String result = future.get();
657 +            assertSame(TEST_STRING, result);
658 +        }
659 +        catch (ExecutionException ex) {
660 +            unexpectedException();
661 +        }
662 +        catch (InterruptedException ex) {
663 +            unexpectedException();
664 +        } finally {
665 +            joinPool(e);
666 +        }
667 +    }
668 +
669 +
670 +
671 +
672 +
673 +    /**
674 +     * invokeAny(null) throws NPE
675 +     */
676 +    public void testInvokeAny1() {
677 +        ExecutorService e = new ScheduledThreadPoolExecutor(2);
678 +        try {
679 +            e.invokeAny(null);
680 +        } catch (NullPointerException success) {
681 +        } catch(Exception ex) {
682 +            unexpectedException();
683 +        } finally {
684 +            joinPool(e);
685 +        }
686 +    }
687 +
688 +    /**
689 +     * invokeAny(empty collection) throws IAE
690 +     */
691 +    public void testInvokeAny2() {
692 +        ExecutorService e = new ScheduledThreadPoolExecutor(2);
693 +        try {
694 +            e.invokeAny(new ArrayList<Callable<String>>());
695 +        } catch (IllegalArgumentException success) {
696 +        } catch(Exception ex) {
697 +            unexpectedException();
698 +        } finally {
699 +            joinPool(e);
700 +        }
701 +    }
702 +
703 +    /**
704 +     * invokeAny(c) throws NPE if c has null elements
705 +     */
706 +    public void testInvokeAny3() {
707 +        ExecutorService e = new ScheduledThreadPoolExecutor(2);
708 +        try {
709 +            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
710 +            l.add(new StringTask());
711 +            l.add(null);
712 +            e.invokeAny(l);
713 +        } catch (NullPointerException success) {
714 +        } catch(Exception ex) {
715 +            unexpectedException();
716 +        } finally {
717 +            joinPool(e);
718 +        }
719 +    }
720 +
721 +    /**
722 +     * invokeAny(c) throws ExecutionException if no task completes
723 +     */
724 +    public void testInvokeAny4() {
725 +        ExecutorService e = new ScheduledThreadPoolExecutor(2);
726 +        try {
727 +            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
728 +            l.add(new NPETask());
729 +            e.invokeAny(l);
730 +        } catch (ExecutionException success) {
731 +        } catch(Exception ex) {
732 +            unexpectedException();
733 +        } finally {
734 +            joinPool(e);
735 +        }
736 +    }
737 +
738 +    /**
739 +     * invokeAny(c) returns result of some task
740 +     */
741 +    public void testInvokeAny5() {
742 +        ExecutorService e = new ScheduledThreadPoolExecutor(2);
743 +        try {
744 +            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
745 +            l.add(new StringTask());
746 +            l.add(new StringTask());
747 +            String result = e.invokeAny(l);
748 +            assertSame(TEST_STRING, result);
749 +        } catch (ExecutionException success) {
750 +        } catch(Exception ex) {
751 +            unexpectedException();
752 +        } finally {
753 +            joinPool(e);
754 +        }
755 +    }
756 +
757 +    /**
758 +     * invokeAll(null) throws NPE
759 +     */
760 +    public void testInvokeAll1() {
761 +        ExecutorService e = new ScheduledThreadPoolExecutor(2);
762 +        try {
763 +            e.invokeAll(null);
764 +        } catch (NullPointerException success) {
765 +        } catch(Exception ex) {
766 +            unexpectedException();
767 +        } finally {
768 +            joinPool(e);
769 +        }
770 +    }
771 +
772 +    /**
773 +     * invokeAll(empty collection) returns empty collection
774 +     */
775 +    public void testInvokeAll2() {
776 +        ExecutorService e = new ScheduledThreadPoolExecutor(2);
777 +        try {
778 +            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
779 +            assertTrue(r.isEmpty());
780 +        } catch(Exception ex) {
781 +            unexpectedException();
782 +        } finally {
783 +            joinPool(e);
784 +        }
785 +    }
786 +
787 +    /**
788 +     * invokeAll(c) throws NPE if c has null elements
789 +     */
790 +    public void testInvokeAll3() {
791 +        ExecutorService e = new ScheduledThreadPoolExecutor(2);
792 +        try {
793 +            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
794 +            l.add(new StringTask());
795 +            l.add(null);
796 +            e.invokeAll(l);
797 +        } catch (NullPointerException success) {
798 +        } catch(Exception ex) {
799 +            unexpectedException();
800 +        } finally {
801 +            joinPool(e);
802 +        }
803 +    }
804 +
805 +    /**
806 +     * get of invokeAll(c) throws exception on failed task
807 +     */
808 +    public void testInvokeAll4() {
809 +        ExecutorService e = new ScheduledThreadPoolExecutor(2);
810 +        try {
811 +            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
812 +            l.add(new NPETask());
813 +            List<Future<String>> result = e.invokeAll(l);
814 +            assertEquals(1, result.size());
815 +            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
816 +                it.next().get();
817 +        } catch(ExecutionException success) {
818 +        } catch(Exception ex) {
819 +            unexpectedException();
820 +        } finally {
821 +            joinPool(e);
822 +        }
823 +    }
824 +
825 +    /**
826 +     * invokeAll(c) returns results of all completed tasks
827 +     */
828 +    public void testInvokeAll5() {
829 +        ExecutorService e = new ScheduledThreadPoolExecutor(2);
830 +        try {
831 +            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
832 +            l.add(new StringTask());
833 +            l.add(new StringTask());
834 +            List<Future<String>> result = e.invokeAll(l);
835 +            assertEquals(2, result.size());
836 +            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
837 +                assertSame(TEST_STRING, it.next().get());
838 +        } catch (ExecutionException success) {
839 +        } catch(Exception ex) {
840 +            unexpectedException();
841 +        } finally {
842 +            joinPool(e);
843 +        }
844 +    }
845 +
846 +
847   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines