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

Comparing jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java (file contents):
Revision 1.3 by jsr166, Mon Nov 16 04:57:10 2009 UTC vs.
Revision 1.6 by jsr166, Fri Nov 20 06:33:25 2009 UTC

# Line 14 | Line 14 | import java.util.*;
14  
15   public class ThreadPoolExecutorSubclassTest extends JSR166TestCase {
16      public static void main(String[] args) {
17 <        junit.textui.TestRunner.run (suite());
17 >        junit.textui.TestRunner.run(suite());
18      }
19      public static Test suite() {
20 <        return new TestSuite(ThreadPoolExecutorTest.class);
20 >        return new TestSuite(ThreadPoolExecutorSubclassTest.class);
21      }
22  
23      static class CustomTask<V> implements RunnableFuture<V> {
# Line 29 | Line 29 | public class ThreadPoolExecutorSubclassT
29          V result;
30          Thread thread;
31          Exception exception;
32 <        CustomTask(Callable<V> c) { callable = c; }
33 <        CustomTask(final Runnable r, final V res) { callable = new Callable<V>() {
32 >        CustomTask(Callable<V> c) {
33 >            if (c == null) throw new NullPointerException();
34 >            callable = c;
35 >        }
36 >        CustomTask(final Runnable r, final V res) {
37 >            if (r == null) throw new NullPointerException();
38 >            callable = new Callable<V>() {
39              public V call() throws Exception { r.run(); return res; }};
40          }
41          public boolean isDone() {
# Line 93 | Line 98 | public class ThreadPoolExecutorSubclassT
98              finally { lock.unlock(); }
99          }
100          public V get(long timeout, TimeUnit unit)
101 <            throws InterruptedException, ExecutionException, TimeoutException{
101 >            throws InterruptedException, ExecutionException, TimeoutException {
102              long nanos = unit.toNanos(timeout);
103              lock.lock();
104              try {
# Line 176 | Line 181 | public class ThreadPoolExecutorSubclassT
181  
182      }
183  
184 <    static class FailingThreadFactory implements ThreadFactory{
184 >    static class FailingThreadFactory implements ThreadFactory {
185          int calls = 0;
186 <        public Thread newThread(Runnable r){
186 >        public Thread newThread(Runnable r) {
187              if (++calls > 1) return null;
188              return new Thread(r);
189          }
# Line 188 | Line 193 | public class ThreadPoolExecutorSubclassT
193      /**
194       *  execute successfully executes a runnable
195       */
196 <    public void testExecute() {
196 >    public void testExecute() throws InterruptedException {
197          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
198          try {
199 <            p1.execute(new Runnable() {
195 <                    public void run() {
196 <                        try {
197 <                            Thread.sleep(SHORT_DELAY_MS);
198 <                        } catch (InterruptedException e){
199 <                            threadUnexpectedException();
200 <                        }
201 <                    }
202 <                });
199 >            p1.execute(new ShortRunnable());
200              Thread.sleep(SMALL_DELAY_MS);
201 <        } catch (InterruptedException e){
202 <            unexpectedException();
201 >        } finally {
202 >            joinPool(p1);
203          }
207        joinPool(p1);
204      }
205  
206      /**
207       *  getActiveCount increases but doesn't overestimate, when a
208       *  thread becomes active
209       */
210 <    public void testGetActiveCount() {
210 >    public void testGetActiveCount() throws InterruptedException {
211          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
212          assertEquals(0, p2.getActiveCount());
213          p2.execute(new MediumRunnable());
214 <        try {
219 <            Thread.sleep(SHORT_DELAY_MS);
220 <        } catch (Exception e){
221 <            unexpectedException();
222 <        }
214 >        Thread.sleep(SHORT_DELAY_MS);
215          assertEquals(1, p2.getActiveCount());
216          joinPool(p2);
217      }
# Line 256 | Line 248 | public class ThreadPoolExecutorSubclassT
248       *   getCompletedTaskCount increases, but doesn't overestimate,
249       *   when tasks complete
250       */
251 <    public void testGetCompletedTaskCount() {
251 >    public void testGetCompletedTaskCount() throws InterruptedException {
252          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
253          assertEquals(0, p2.getCompletedTaskCount());
254          p2.execute(new ShortRunnable());
255 <        try {
264 <            Thread.sleep(SMALL_DELAY_MS);
265 <        } catch (Exception e){
266 <            unexpectedException();
267 <        }
255 >        Thread.sleep(SMALL_DELAY_MS);
256          assertEquals(1, p2.getCompletedTaskCount());
257          try { p2.shutdown(); } catch (SecurityException ok) { return; }
258          joinPool(p2);
# Line 367 | Line 355 | public class ThreadPoolExecutorSubclassT
355       *   getLargestPoolSize increases, but doesn't overestimate, when
356       *   multiple threads active
357       */
358 <    public void testGetLargestPoolSize() {
358 >    public void testGetLargestPoolSize() throws InterruptedException {
359          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
360 <        try {
361 <            assertEquals(0, p2.getLargestPoolSize());
362 <            p2.execute(new MediumRunnable());
363 <            p2.execute(new MediumRunnable());
364 <            Thread.sleep(SHORT_DELAY_MS);
377 <            assertEquals(2, p2.getLargestPoolSize());
378 <        } catch (Exception e){
379 <            unexpectedException();
380 <        }
360 >        assertEquals(0, p2.getLargestPoolSize());
361 >        p2.execute(new MediumRunnable());
362 >        p2.execute(new MediumRunnable());
363 >        Thread.sleep(SHORT_DELAY_MS);
364 >        assertEquals(2, p2.getLargestPoolSize());
365          joinPool(p2);
366      }
367  
# Line 406 | Line 390 | public class ThreadPoolExecutorSubclassT
390      /**
391       *  getTaskCount increases, but doesn't overestimate, when tasks submitted
392       */
393 <    public void testGetTaskCount() {
393 >    public void testGetTaskCount() throws InterruptedException {
394          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
395 <        try {
396 <            assertEquals(0, p1.getTaskCount());
397 <            p1.execute(new MediumRunnable());
398 <            Thread.sleep(SHORT_DELAY_MS);
415 <            assertEquals(1, p1.getTaskCount());
416 <        } catch (Exception e){
417 <            unexpectedException();
418 <        }
395 >        assertEquals(0, p1.getTaskCount());
396 >        p1.execute(new MediumRunnable());
397 >        Thread.sleep(SHORT_DELAY_MS);
398 >        assertEquals(1, p1.getTaskCount());
399          joinPool(p1);
400      }
401  
# Line 435 | Line 415 | public class ThreadPoolExecutorSubclassT
415      /**
416       *  isTerminated is false before termination, true after
417       */
418 <    public void testIsTerminated() {
418 >    public void testIsTerminated() throws InterruptedException {
419          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
420          assertFalse(p1.isTerminated());
421          try {
# Line 443 | Line 423 | public class ThreadPoolExecutorSubclassT
423          } finally {
424              try { p1.shutdown(); } catch (SecurityException ok) { return; }
425          }
426 <        try {
427 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
448 <            assertTrue(p1.isTerminated());
449 <        } catch (Exception e){
450 <            unexpectedException();
451 <        }
426 >        assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
427 >        assertTrue(p1.isTerminated());
428      }
429  
430      /**
431       *  isTerminating is not true when running or when terminated
432       */
433 <    public void testIsTerminating() {
433 >    public void testIsTerminating() throws InterruptedException {
434          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
435          assertFalse(p1.isTerminating());
436          try {
# Line 463 | Line 439 | public class ThreadPoolExecutorSubclassT
439          } finally {
440              try { p1.shutdown(); } catch (SecurityException ok) { return; }
441          }
442 <        try {
443 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
444 <            assertTrue(p1.isTerminated());
469 <            assertFalse(p1.isTerminating());
470 <        } catch (Exception e){
471 <            unexpectedException();
472 <        }
442 >        assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
443 >        assertTrue(p1.isTerminated());
444 >        assertFalse(p1.isTerminating());
445      }
446  
447      /**
448       * getQueue returns the work queue, which contains queued tasks
449       */
450 <    public void testGetQueue() {
450 >    public void testGetQueue() throws InterruptedException {
451          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
452          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
453          FutureTask[] tasks = new FutureTask[5];
454 <        for (int i = 0; i < 5; i++){
454 >        for (int i = 0; i < 5; i++) {
455              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
456              p1.execute(tasks[i]);
457          }
# Line 492 | Line 464 | public class ThreadPoolExecutorSubclassT
464              for (int i = 1; i < 5; ++i)
465                  tasks[i].cancel(true);
466              p1.shutdownNow();
495        } catch (Exception e) {
496            unexpectedException();
467          } finally {
468              joinPool(p1);
469          }
# Line 502 | Line 472 | public class ThreadPoolExecutorSubclassT
472      /**
473       * remove(task) removes queued task, and fails to remove active task
474       */
475 <    public void testRemove() {
475 >    public void testRemove() throws InterruptedException {
476          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
477          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
478          FutureTask[] tasks = new FutureTask[5];
479 <        for (int i = 0; i < 5; i++){
479 >        for (int i = 0; i < 5; i++) {
480              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
481              p1.execute(tasks[i]);
482          }
# Line 521 | Line 491 | public class ThreadPoolExecutorSubclassT
491              assertTrue(q.contains(tasks[3]));
492              assertTrue(p1.remove(tasks[3]));
493              assertFalse(q.contains(tasks[3]));
524        } catch (Exception e) {
525            unexpectedException();
494          } finally {
495              joinPool(p1);
496          }
# Line 534 | Line 502 | public class ThreadPoolExecutorSubclassT
502      public void testPurge() {
503          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
504          FutureTask[] tasks = new FutureTask[5];
505 <        for (int i = 0; i < 5; i++){
505 >        for (int i = 0; i < 5; i++) {
506              tasks[i] = new FutureTask(new MediumPossiblyInterruptedRunnable(), Boolean.TRUE);
507              p1.execute(tasks[i]);
508          }
# Line 576 | Line 544 | public class ThreadPoolExecutorSubclassT
544          try {
545              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
546              shouldThrow();
547 <        }
580 <        catch (IllegalArgumentException success){}
547 >        } catch (IllegalArgumentException success) {}
548      }
549  
550      /**
# Line 587 | Line 554 | public class ThreadPoolExecutorSubclassT
554          try {
555              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
556              shouldThrow();
557 <        }
591 <        catch (IllegalArgumentException success){}
557 >        } catch (IllegalArgumentException success) {}
558      }
559  
560      /**
# Line 598 | Line 564 | public class ThreadPoolExecutorSubclassT
564          try {
565              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
566              shouldThrow();
567 <        }
602 <        catch (IllegalArgumentException success){}
567 >        } catch (IllegalArgumentException success) {}
568      }
569  
570      /**
# Line 609 | Line 574 | public class ThreadPoolExecutorSubclassT
574          try {
575              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
576              shouldThrow();
577 <        }
613 <        catch (IllegalArgumentException success){}
577 >        } catch (IllegalArgumentException success) {}
578      }
579  
580      /**
# Line 620 | Line 584 | public class ThreadPoolExecutorSubclassT
584          try {
585              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
586              shouldThrow();
587 <        }
624 <        catch (IllegalArgumentException success){}
587 >        } catch (IllegalArgumentException success) {}
588      }
589  
590      /**
# Line 631 | Line 594 | public class ThreadPoolExecutorSubclassT
594          try {
595              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null);
596              shouldThrow();
597 <        }
635 <        catch (NullPointerException success){}
597 >        } catch (NullPointerException success) {}
598      }
599  
600  
# Line 644 | Line 606 | public class ThreadPoolExecutorSubclassT
606          try {
607              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
608              shouldThrow();
609 <        } catch (IllegalArgumentException success){}
609 >        } catch (IllegalArgumentException success) {}
610      }
611  
612      /**
# Line 654 | Line 616 | public class ThreadPoolExecutorSubclassT
616          try {
617              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
618              shouldThrow();
619 <        }
658 <        catch (IllegalArgumentException success){}
619 >        } catch (IllegalArgumentException success) {}
620      }
621  
622      /**
# Line 665 | Line 626 | public class ThreadPoolExecutorSubclassT
626          try {
627              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
628              shouldThrow();
629 <        }
669 <        catch (IllegalArgumentException success){}
629 >        } catch (IllegalArgumentException success) {}
630      }
631  
632      /**
# Line 676 | Line 636 | public class ThreadPoolExecutorSubclassT
636          try {
637              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
638              shouldThrow();
639 <        }
680 <        catch (IllegalArgumentException success){}
639 >        } catch (IllegalArgumentException success) {}
640      }
641  
642      /**
# Line 687 | Line 646 | public class ThreadPoolExecutorSubclassT
646          try {
647              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
648              shouldThrow();
649 <        }
691 <        catch (IllegalArgumentException success){}
649 >        } catch (IllegalArgumentException success) {}
650      }
651  
652      /**
# Line 698 | Line 656 | public class ThreadPoolExecutorSubclassT
656          try {
657              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory());
658              shouldThrow();
659 <        }
702 <        catch (NullPointerException success){}
659 >        } catch (NullPointerException success) {}
660      }
661  
662      /**
# Line 710 | Line 667 | public class ThreadPoolExecutorSubclassT
667              ThreadFactory f = null;
668              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
669              shouldThrow();
670 <        }
714 <        catch (NullPointerException success){}
670 >        } catch (NullPointerException success) {}
671      }
672  
673  
# Line 722 | Line 678 | public class ThreadPoolExecutorSubclassT
678          try {
679              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
680              shouldThrow();
681 <        }
726 <        catch (IllegalArgumentException success){}
681 >        } catch (IllegalArgumentException success) {}
682      }
683  
684      /**
# Line 733 | Line 688 | public class ThreadPoolExecutorSubclassT
688          try {
689              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
690              shouldThrow();
691 <        }
737 <        catch (IllegalArgumentException success){}
691 >        } catch (IllegalArgumentException success) {}
692      }
693  
694      /**
# Line 744 | Line 698 | public class ThreadPoolExecutorSubclassT
698          try {
699              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
700              shouldThrow();
701 <        }
748 <        catch (IllegalArgumentException success){}
701 >        } catch (IllegalArgumentException success) {}
702      }
703  
704      /**
# Line 755 | Line 708 | public class ThreadPoolExecutorSubclassT
708          try {
709              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
710              shouldThrow();
711 <        }
759 <        catch (IllegalArgumentException success){}
711 >        } catch (IllegalArgumentException success) {}
712      }
713  
714      /**
# Line 766 | Line 718 | public class ThreadPoolExecutorSubclassT
718          try {
719              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
720              shouldThrow();
721 <        }
770 <        catch (IllegalArgumentException success){}
721 >        } catch (IllegalArgumentException success) {}
722      }
723  
724      /**
# Line 777 | Line 728 | public class ThreadPoolExecutorSubclassT
728          try {
729              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler());
730              shouldThrow();
731 <        }
781 <        catch (NullPointerException success){}
731 >        } catch (NullPointerException success) {}
732      }
733  
734      /**
# Line 789 | Line 739 | public class ThreadPoolExecutorSubclassT
739              RejectedExecutionHandler r = null;
740              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
741              shouldThrow();
742 <        }
793 <        catch (NullPointerException success){}
742 >        } catch (NullPointerException success) {}
743      }
744  
745  
# Line 801 | Line 750 | public class ThreadPoolExecutorSubclassT
750          try {
751              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
752              shouldThrow();
753 <        }
805 <        catch (IllegalArgumentException success){}
753 >        } catch (IllegalArgumentException success) {}
754      }
755  
756      /**
# Line 812 | Line 760 | public class ThreadPoolExecutorSubclassT
760          try {
761              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
762              shouldThrow();
763 <        }
816 <        catch (IllegalArgumentException success){}
763 >        } catch (IllegalArgumentException success) {}
764      }
765  
766      /**
# Line 823 | Line 770 | public class ThreadPoolExecutorSubclassT
770          try {
771              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
772              shouldThrow();
773 <        }
827 <        catch (IllegalArgumentException success){}
773 >        } catch (IllegalArgumentException success) {}
774      }
775  
776      /**
# Line 834 | Line 780 | public class ThreadPoolExecutorSubclassT
780          try {
781              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
782              shouldThrow();
783 <        }
838 <        catch (IllegalArgumentException success){}
783 >        } catch (IllegalArgumentException success) {}
784      }
785  
786      /**
# Line 845 | Line 790 | public class ThreadPoolExecutorSubclassT
790          try {
791              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
792              shouldThrow();
793 <        }
849 <        catch (IllegalArgumentException success){}
793 >        } catch (IllegalArgumentException success) {}
794      }
795  
796      /**
# Line 856 | Line 800 | public class ThreadPoolExecutorSubclassT
800          try {
801              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
802              shouldThrow();
803 <        }
860 <        catch (NullPointerException success){}
803 >        } catch (NullPointerException success) {}
804      }
805  
806      /**
# Line 868 | Line 811 | public class ThreadPoolExecutorSubclassT
811              RejectedExecutionHandler r = null;
812              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
813              shouldThrow();
814 <        }
872 <        catch (NullPointerException success){}
814 >        } catch (NullPointerException success) {}
815      }
816  
817      /**
# Line 880 | Line 822 | public class ThreadPoolExecutorSubclassT
822              ThreadFactory f = null;
823              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
824              shouldThrow();
825 <        }
884 <        catch (NullPointerException successdn8){}
825 >        } catch (NullPointerException success) {}
826      }
827  
828  
# Line 893 | Line 834 | public class ThreadPoolExecutorSubclassT
834          ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
835          try {
836  
837 <            for (int i = 0; i < 5; ++i){
837 >            for (int i = 0; i < 5; ++i) {
838                  p.execute(new MediumRunnable());
839              }
840              shouldThrow();
841 <        } catch (RejectedExecutionException success){}
841 >        } catch (RejectedExecutionException success) {}
842          joinPool(p);
843      }
844  
# Line 910 | Line 851 | public class ThreadPoolExecutorSubclassT
851          try {
852  
853              TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
854 <            for (int i = 0; i < 5; ++i){
854 >            for (int i = 0; i < 5; ++i) {
855                  tasks[i] = new TrackedNoOpRunnable();
856              }
857              TrackedLongRunnable mr = new TrackedLongRunnable();
858              p.execute(mr);
859 <            for (int i = 0; i < 5; ++i){
859 >            for (int i = 0; i < 5; ++i) {
860                  p.execute(tasks[i]);
861              }
862              for (int i = 1; i < 5; ++i) {
863                  assertTrue(tasks[i].done);
864              }
865              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
925        } catch (RejectedExecutionException ex){
926            unexpectedException();
866          } finally {
867              joinPool(p);
868          }
# Line 938 | Line 877 | public class ThreadPoolExecutorSubclassT
877          try {
878  
879              TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5];
880 <            for (int i = 0; i < 5; ++i){
880 >            for (int i = 0; i < 5; ++i) {
881                  tasks[i] = new TrackedNoOpRunnable();
882              }
883              p.execute(new TrackedLongRunnable());
884 <            for (int i = 0; i < 5; ++i){
884 >            for (int i = 0; i < 5; ++i) {
885                  p.execute(tasks[i]);
886              }
887 <            for (int i = 0; i < 5; ++i){
887 >            for (int i = 0; i < 5; ++i) {
888                  assertFalse(tasks[i].done);
889              }
890              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
952        } catch (RejectedExecutionException ex){
953            unexpectedException();
891          } finally {
892              joinPool(p);
893          }
# Line 972 | Line 909 | public class ThreadPoolExecutorSubclassT
909              assertFalse(p.getQueue().contains(r2));
910              assertTrue(p.getQueue().contains(r3));
911              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
975        } catch (RejectedExecutionException ex){
976            unexpectedException();
912          } finally {
913              joinPool(p);
914          }
# Line 989 | Line 924 | public class ThreadPoolExecutorSubclassT
924          try {
925              tpe.execute(new NoOpRunnable());
926              shouldThrow();
927 <        } catch (RejectedExecutionException success){}
927 >        } catch (RejectedExecutionException success) {}
928  
929          joinPool(tpe);
930      }
# Line 1006 | Line 941 | public class ThreadPoolExecutorSubclassT
941              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
942              p.execute(r);
943              assertFalse(r.done);
1009        } catch (RejectedExecutionException success){
1010            unexpectedException();
944          } finally {
945              joinPool(p);
946          }
# Line 1025 | Line 958 | public class ThreadPoolExecutorSubclassT
958              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
959              p.execute(r);
960              assertFalse(r.done);
1028        } catch (RejectedExecutionException success){
1029            unexpectedException();
961          } finally {
962              joinPool(p);
963          }
# Line 1045 | Line 976 | public class ThreadPoolExecutorSubclassT
976              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
977              p.execute(r);
978              assertFalse(r.done);
1048        } catch (RejectedExecutionException success){
1049            unexpectedException();
979          } finally {
980              joinPool(p);
981          }
# Line 1062 | Line 991 | public class ThreadPoolExecutorSubclassT
991              tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
992              tpe.execute(null);
993              shouldThrow();
994 <        } catch (NullPointerException success){}
994 >        } catch (NullPointerException success) {}
995  
996          joinPool(tpe);
997      }
# Line 1071 | Line 1000 | public class ThreadPoolExecutorSubclassT
1000       *  setCorePoolSize of negative value throws IllegalArgumentException
1001       */
1002      public void testCorePoolSizeIllegalArgumentException() {
1003 <        ThreadPoolExecutor tpe = null;
1004 <        try {
1076 <            tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1077 <        } catch (Exception e){}
1003 >        ThreadPoolExecutor tpe =
1004 >            new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1005          try {
1006              tpe.setCorePoolSize(-1);
1007              shouldThrow();
1008 <        } catch (IllegalArgumentException success){
1008 >        } catch (IllegalArgumentException success) {
1009          } finally {
1010              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1011          }
# Line 1093 | Line 1020 | public class ThreadPoolExecutorSubclassT
1020          ThreadPoolExecutor tpe = null;
1021          try {
1022              tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1023 <        } catch (Exception e){}
1023 >        } catch (Exception e) {}
1024          try {
1025              tpe.setMaximumPoolSize(1);
1026              shouldThrow();
1027 <        } catch (IllegalArgumentException success){
1027 >        } catch (IllegalArgumentException success) {
1028          } finally {
1029              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1030          }
# Line 1112 | Line 1039 | public class ThreadPoolExecutorSubclassT
1039          ThreadPoolExecutor tpe = null;
1040          try {
1041              tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1042 <        } catch (Exception e){}
1042 >        } catch (Exception e) {}
1043          try {
1044              tpe.setMaximumPoolSize(-1);
1045              shouldThrow();
1046 <        } catch (IllegalArgumentException success){
1046 >        } catch (IllegalArgumentException success) {
1047          } finally {
1048              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1049          }
# Line 1132 | Line 1059 | public class ThreadPoolExecutorSubclassT
1059          ThreadPoolExecutor tpe = null;
1060          try {
1061              tpe = new CustomTPE(2,3,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1062 <        } catch (Exception e){}
1062 >        } catch (Exception e) {}
1063  
1064          try {
1065              tpe.setKeepAliveTime(-1,TimeUnit.MILLISECONDS);
1066              shouldThrow();
1067 <        } catch (IllegalArgumentException success){
1067 >        } catch (IllegalArgumentException success) {
1068          } finally {
1069              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1070          }
# Line 1157 | Line 1084 | public class ThreadPoolExecutorSubclassT
1084      /**
1085       * beforeExecute and afterExecute are called when executing task
1086       */
1087 <    public void testBeforeAfter() {
1087 >    public void testBeforeAfter() throws InterruptedException {
1088          CustomTPE tpe = new CustomTPE();
1089          try {
1090              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
# Line 1167 | Line 1094 | public class ThreadPoolExecutorSubclassT
1094              assertTrue(tpe.beforeCalled);
1095              assertTrue(tpe.afterCalled);
1096              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1170        }
1171        catch (Exception ex) {
1172            unexpectedException();
1097          } finally {
1098              joinPool(tpe);
1099          }
# Line 1178 | Line 1102 | public class ThreadPoolExecutorSubclassT
1102      /**
1103       * completed submit of callable returns result
1104       */
1105 <    public void testSubmitCallable() {
1105 >    public void testSubmitCallable() throws Exception {
1106          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1107          try {
1108              Future<String> future = e.submit(new StringTask());
1109              String result = future.get();
1110              assertSame(TEST_STRING, result);
1187        }
1188        catch (ExecutionException ex) {
1189            unexpectedException();
1190        }
1191        catch (InterruptedException ex) {
1192            unexpectedException();
1111          } finally {
1112              joinPool(e);
1113          }
# Line 1198 | Line 1116 | public class ThreadPoolExecutorSubclassT
1116      /**
1117       * completed submit of runnable returns successfully
1118       */
1119 <    public void testSubmitRunnable() {
1119 >    public void testSubmitRunnable() throws Exception {
1120          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1121          try {
1122              Future<?> future = e.submit(new NoOpRunnable());
1123              future.get();
1124              assertTrue(future.isDone());
1207        }
1208        catch (ExecutionException ex) {
1209            unexpectedException();
1210        }
1211        catch (InterruptedException ex) {
1212            unexpectedException();
1125          } finally {
1126              joinPool(e);
1127          }
# Line 1218 | Line 1130 | public class ThreadPoolExecutorSubclassT
1130      /**
1131       * completed submit of (runnable, result) returns result
1132       */
1133 <    public void testSubmitRunnable2() {
1133 >    public void testSubmitRunnable2() throws Exception {
1134          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1135          try {
1136              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
1137              String result = future.get();
1138              assertSame(TEST_STRING, result);
1227        }
1228        catch (ExecutionException ex) {
1229            unexpectedException();
1230        }
1231        catch (InterruptedException ex) {
1232            unexpectedException();
1139          } finally {
1140              joinPool(e);
1141          }
1142      }
1143  
1144  
1239
1240
1241
1145      /**
1146       * invokeAny(null) throws NPE
1147       */
1148 <    public void testInvokeAny1() {
1148 >    public void testInvokeAny1() throws Exception {
1149          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1150          try {
1151              e.invokeAny(null);
1152 +            shouldThrow();
1153          } catch (NullPointerException success) {
1250        } catch (Exception ex) {
1251            unexpectedException();
1154          } finally {
1155              joinPool(e);
1156          }
# Line 1257 | Line 1159 | public class ThreadPoolExecutorSubclassT
1159      /**
1160       * invokeAny(empty collection) throws IAE
1161       */
1162 <    public void testInvokeAny2() {
1162 >    public void testInvokeAny2() throws Exception {
1163          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1164          try {
1165              e.invokeAny(new ArrayList<Callable<String>>());
1166 +            shouldThrow();
1167          } catch (IllegalArgumentException success) {
1265        } catch (Exception ex) {
1266            unexpectedException();
1168          } finally {
1169              joinPool(e);
1170          }
# Line 1272 | Line 1173 | public class ThreadPoolExecutorSubclassT
1173      /**
1174       * invokeAny(c) throws NPE if c has null elements
1175       */
1176 <    public void testInvokeAny3() {
1176 >    public void testInvokeAny3() throws Exception {
1177 >        final CountDownLatch latch = new CountDownLatch(1);
1178          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1179          try {
1180              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1181 <            l.add(new StringTask());
1181 >            l.add(new CheckedCallable<String>() {
1182 >                      public String realCall() throws InterruptedException {
1183 >                          latch.await();
1184 >                          return TEST_STRING;
1185 >                      }});
1186              l.add(null);
1187              e.invokeAny(l);
1188 +            shouldThrow();
1189          } catch (NullPointerException success) {
1283        } catch (Exception ex) {
1284            unexpectedException();
1190          } finally {
1191 +            latch.countDown();
1192              joinPool(e);
1193          }
1194      }
# Line 1290 | Line 1196 | public class ThreadPoolExecutorSubclassT
1196      /**
1197       * invokeAny(c) throws ExecutionException if no task completes
1198       */
1199 <    public void testInvokeAny4() {
1199 >    public void testInvokeAny4() throws Exception {
1200          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1201          try {
1202              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1203              l.add(new NPETask());
1204              e.invokeAny(l);
1205 +            shouldThrow();
1206          } catch (ExecutionException success) {
1300        } catch (Exception ex) {
1301            unexpectedException();
1207          } finally {
1208              joinPool(e);
1209          }
# Line 1307 | Line 1212 | public class ThreadPoolExecutorSubclassT
1212      /**
1213       * invokeAny(c) returns result of some task
1214       */
1215 <    public void testInvokeAny5() {
1215 >    public void testInvokeAny5() throws Exception {
1216          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1217          try {
1218              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1315 | Line 1220 | public class ThreadPoolExecutorSubclassT
1220              l.add(new StringTask());
1221              String result = e.invokeAny(l);
1222              assertSame(TEST_STRING, result);
1318        } catch (ExecutionException success) {
1319        } catch (Exception ex) {
1320            unexpectedException();
1223          } finally {
1224              joinPool(e);
1225          }
# Line 1326 | Line 1228 | public class ThreadPoolExecutorSubclassT
1228      /**
1229       * invokeAll(null) throws NPE
1230       */
1231 <    public void testInvokeAll1() {
1231 >    public void testInvokeAll1() throws Exception {
1232          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1233          try {
1234              e.invokeAll(null);
1235 +            shouldThrow();
1236          } catch (NullPointerException success) {
1334        } catch (Exception ex) {
1335            unexpectedException();
1237          } finally {
1238              joinPool(e);
1239          }
# Line 1341 | Line 1242 | public class ThreadPoolExecutorSubclassT
1242      /**
1243       * invokeAll(empty collection) returns empty collection
1244       */
1245 <    public void testInvokeAll2() {
1245 >    public void testInvokeAll2() throws Exception {
1246          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1247          try {
1248              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
1249              assertTrue(r.isEmpty());
1349        } catch (Exception ex) {
1350            unexpectedException();
1250          } finally {
1251              joinPool(e);
1252          }
# Line 1356 | Line 1255 | public class ThreadPoolExecutorSubclassT
1255      /**
1256       * invokeAll(c) throws NPE if c has null elements
1257       */
1258 <    public void testInvokeAll3() {
1258 >    public void testInvokeAll3() throws Exception {
1259          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1260          try {
1261              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1262              l.add(new StringTask());
1263              l.add(null);
1264              e.invokeAll(l);
1265 +            shouldThrow();
1266          } catch (NullPointerException success) {
1367        } catch (Exception ex) {
1368            unexpectedException();
1267          } finally {
1268              joinPool(e);
1269          }
# Line 1374 | Line 1272 | public class ThreadPoolExecutorSubclassT
1272      /**
1273       * get of element of invokeAll(c) throws exception on failed task
1274       */
1275 <    public void testInvokeAll4() {
1275 >    public void testInvokeAll4() throws Exception {
1276          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1277          try {
1278              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1279              l.add(new NPETask());
1280              List<Future<String>> result = e.invokeAll(l);
1281              assertEquals(1, result.size());
1282 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1283 <                it.next().get();
1282 >            for (Future<String> future : result)
1283 >                future.get();
1284 >            shouldThrow();
1285          } catch (ExecutionException success) {
1387        } catch (Exception ex) {
1388            unexpectedException();
1286          } finally {
1287              joinPool(e);
1288          }
# Line 1394 | Line 1291 | public class ThreadPoolExecutorSubclassT
1291      /**
1292       * invokeAll(c) returns results of all completed tasks
1293       */
1294 <    public void testInvokeAll5() {
1294 >    public void testInvokeAll5() throws Exception {
1295          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1296          try {
1297              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1402 | Line 1299 | public class ThreadPoolExecutorSubclassT
1299              l.add(new StringTask());
1300              List<Future<String>> result = e.invokeAll(l);
1301              assertEquals(2, result.size());
1302 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1303 <                assertSame(TEST_STRING, it.next().get());
1407 <        } catch (ExecutionException success) {
1408 <        } catch (Exception ex) {
1409 <            unexpectedException();
1302 >            for (Future<String> future : result)
1303 >                assertSame(TEST_STRING, future.get());
1304          } finally {
1305              joinPool(e);
1306          }
# Line 1417 | Line 1311 | public class ThreadPoolExecutorSubclassT
1311      /**
1312       * timed invokeAny(null) throws NPE
1313       */
1314 <    public void testTimedInvokeAny1() {
1314 >    public void testTimedInvokeAny1() throws Exception {
1315          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1316          try {
1317              e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1318 +            shouldThrow();
1319          } catch (NullPointerException success) {
1425        } catch (Exception ex) {
1426            unexpectedException();
1320          } finally {
1321              joinPool(e);
1322          }
# Line 1432 | Line 1325 | public class ThreadPoolExecutorSubclassT
1325      /**
1326       * timed invokeAny(,,null) throws NPE
1327       */
1328 <    public void testTimedInvokeAnyNullTimeUnit() {
1328 >    public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1329          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1330          try {
1331              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1332              l.add(new StringTask());
1333              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1334 +            shouldThrow();
1335          } catch (NullPointerException success) {
1442        } catch (Exception ex) {
1443            unexpectedException();
1336          } finally {
1337              joinPool(e);
1338          }
# Line 1449 | Line 1341 | public class ThreadPoolExecutorSubclassT
1341      /**
1342       * timed invokeAny(empty collection) throws IAE
1343       */
1344 <    public void testTimedInvokeAny2() {
1344 >    public void testTimedInvokeAny2() throws Exception {
1345          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1346          try {
1347              e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1348 +            shouldThrow();
1349          } catch (IllegalArgumentException success) {
1457        } catch (Exception ex) {
1458            unexpectedException();
1350          } finally {
1351              joinPool(e);
1352          }
# Line 1464 | Line 1355 | public class ThreadPoolExecutorSubclassT
1355      /**
1356       * timed invokeAny(c) throws NPE if c has null elements
1357       */
1358 <    public void testTimedInvokeAny3() {
1358 >    public void testTimedInvokeAny3() throws Exception {
1359          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1360          try {
1361              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1362              l.add(new StringTask());
1363              l.add(null);
1364              e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1365 +            shouldThrow();
1366          } catch (NullPointerException success) {
1475        } catch (Exception ex) {
1476            ex.printStackTrace();
1477            unexpectedException();
1367          } finally {
1368              joinPool(e);
1369          }
# Line 1483 | Line 1372 | public class ThreadPoolExecutorSubclassT
1372      /**
1373       * timed invokeAny(c) throws ExecutionException if no task completes
1374       */
1375 <    public void testTimedInvokeAny4() {
1375 >    public void testTimedInvokeAny4() throws Exception {
1376          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1377          try {
1378              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1379              l.add(new NPETask());
1380              e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1381 +            shouldThrow();
1382          } catch (ExecutionException success) {
1493        } catch (Exception ex) {
1494            unexpectedException();
1383          } finally {
1384              joinPool(e);
1385          }
# Line 1500 | Line 1388 | public class ThreadPoolExecutorSubclassT
1388      /**
1389       * timed invokeAny(c) returns result of some task
1390       */
1391 <    public void testTimedInvokeAny5() {
1391 >    public void testTimedInvokeAny5() throws Exception {
1392          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1393          try {
1394              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1508 | Line 1396 | public class ThreadPoolExecutorSubclassT
1396              l.add(new StringTask());
1397              String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1398              assertSame(TEST_STRING, result);
1511        } catch (ExecutionException success) {
1512        } catch (Exception ex) {
1513            unexpectedException();
1399          } finally {
1400              joinPool(e);
1401          }
# Line 1519 | Line 1404 | public class ThreadPoolExecutorSubclassT
1404      /**
1405       * timed invokeAll(null) throws NPE
1406       */
1407 <    public void testTimedInvokeAll1() {
1407 >    public void testTimedInvokeAll1() throws Exception {
1408          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1409          try {
1410              e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1411 +            shouldThrow();
1412          } catch (NullPointerException success) {
1527        } catch (Exception ex) {
1528            unexpectedException();
1413          } finally {
1414              joinPool(e);
1415          }
# Line 1534 | Line 1418 | public class ThreadPoolExecutorSubclassT
1418      /**
1419       * timed invokeAll(,,null) throws NPE
1420       */
1421 <    public void testTimedInvokeAllNullTimeUnit() {
1421 >    public void testTimedInvokeAllNullTimeUnit() throws Exception {
1422          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1423          try {
1424              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1425              l.add(new StringTask());
1426              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1427 +            shouldThrow();
1428          } catch (NullPointerException success) {
1544        } catch (Exception ex) {
1545            unexpectedException();
1429          } finally {
1430              joinPool(e);
1431          }
# Line 1551 | Line 1434 | public class ThreadPoolExecutorSubclassT
1434      /**
1435       * timed invokeAll(empty collection) returns empty collection
1436       */
1437 <    public void testTimedInvokeAll2() {
1437 >    public void testTimedInvokeAll2() throws Exception {
1438          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1439          try {
1440              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1441              assertTrue(r.isEmpty());
1559        } catch (Exception ex) {
1560            unexpectedException();
1442          } finally {
1443              joinPool(e);
1444          }
# Line 1566 | Line 1447 | public class ThreadPoolExecutorSubclassT
1447      /**
1448       * timed invokeAll(c) throws NPE if c has null elements
1449       */
1450 <    public void testTimedInvokeAll3() {
1450 >    public void testTimedInvokeAll3() throws Exception {
1451          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1452          try {
1453              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1454              l.add(new StringTask());
1455              l.add(null);
1456              e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1457 +            shouldThrow();
1458          } catch (NullPointerException success) {
1577        } catch (Exception ex) {
1578            unexpectedException();
1459          } finally {
1460              joinPool(e);
1461          }
# Line 1584 | Line 1464 | public class ThreadPoolExecutorSubclassT
1464      /**
1465       * get of element of invokeAll(c) throws exception on failed task
1466       */
1467 <    public void testTimedInvokeAll4() {
1467 >    public void testTimedInvokeAll4() throws Exception {
1468          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1469          try {
1470              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1471              l.add(new NPETask());
1472              List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1473              assertEquals(1, result.size());
1474 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1475 <                it.next().get();
1474 >            for (Future<String> future : result)
1475 >                future.get();
1476 >            shouldThrow();
1477          } catch (ExecutionException success) {
1478 <        } catch (Exception ex) {
1598 <            unexpectedException();
1478 >            assertTrue(success.getCause() instanceof NullPointerException);
1479          } finally {
1480              joinPool(e);
1481          }
# Line 1604 | Line 1484 | public class ThreadPoolExecutorSubclassT
1484      /**
1485       * timed invokeAll(c) returns results of all completed tasks
1486       */
1487 <    public void testTimedInvokeAll5() {
1487 >    public void testTimedInvokeAll5() throws Exception {
1488          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1489          try {
1490              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1612 | Line 1492 | public class ThreadPoolExecutorSubclassT
1492              l.add(new StringTask());
1493              List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1494              assertEquals(2, result.size());
1495 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1496 <                assertSame(TEST_STRING, it.next().get());
1495 >            for (Future<String> future : result)
1496 >                assertSame(TEST_STRING, future.get());
1497          } catch (ExecutionException success) {
1618        } catch (Exception ex) {
1619            unexpectedException();
1498          } finally {
1499              joinPool(e);
1500          }
# Line 1625 | Line 1503 | public class ThreadPoolExecutorSubclassT
1503      /**
1504       * timed invokeAll(c) cancels tasks not completed by timeout
1505       */
1506 <    public void testTimedInvokeAll6() {
1506 >    public void testTimedInvokeAll6() throws Exception {
1507          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1508          try {
1509              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1643 | Line 1521 | public class ThreadPoolExecutorSubclassT
1521              assertTrue(f3.isDone());
1522              assertFalse(f1.isCancelled());
1523              assertTrue(f2.isCancelled());
1646        } catch (Exception ex) {
1647            unexpectedException();
1524          } finally {
1525              joinPool(e);
1526          }
# Line 1654 | Line 1530 | public class ThreadPoolExecutorSubclassT
1530       * Execution continues if there is at least one thread even if
1531       * thread factory fails to create more
1532       */
1533 <    public void testFailingThreadFactory() {
1533 >    public void testFailingThreadFactory() throws InterruptedException {
1534          ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1535          try {
1660            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1536              for (int k = 0; k < 100; ++k) {
1537                  e.execute(new NoOpRunnable());
1538              }
1539              Thread.sleep(LONG_DELAY_MS);
1665        } catch (Exception ex) {
1666            unexpectedException();
1540          } finally {
1541              joinPool(e);
1542          }
# Line 1681 | Line 1554 | public class ThreadPoolExecutorSubclassT
1554      /**
1555       * allowCoreThreadTimeOut(true) causes idle threads to time out
1556       */
1557 <    public void testAllowCoreThreadTimeOut_true() {
1557 >    public void testAllowCoreThreadTimeOut_true() throws InterruptedException {
1558          ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1559          tpe.allowCoreThreadTimeOut(true);
1560          tpe.execute(new NoOpRunnable());
1561          try {
1562              Thread.sleep(MEDIUM_DELAY_MS);
1563              assertEquals(0, tpe.getPoolSize());
1691        } catch (InterruptedException e){
1692            unexpectedException();
1564          } finally {
1565              joinPool(tpe);
1566          }
# Line 1698 | Line 1569 | public class ThreadPoolExecutorSubclassT
1569      /**
1570       * allowCoreThreadTimeOut(false) causes idle threads not to time out
1571       */
1572 <    public void testAllowCoreThreadTimeOut_false() {
1572 >    public void testAllowCoreThreadTimeOut_false() throws InterruptedException {
1573          ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1574          tpe.allowCoreThreadTimeOut(false);
1575          tpe.execute(new NoOpRunnable());
1576          try {
1577              Thread.sleep(MEDIUM_DELAY_MS);
1578              assertTrue(tpe.getPoolSize() >= 1);
1708        } catch (InterruptedException e){
1709            unexpectedException();
1579          } finally {
1580              joinPool(tpe);
1581          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines