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.4 by jsr166, Mon Nov 16 05:30:08 2009 UTC vs.
Revision 1.5 by jsr166, Wed Nov 18 16:51:26 2009 UTC

# Line 188 | Line 188 | public class ThreadPoolExecutorSubclassT
188      /**
189       *  execute successfully executes a runnable
190       */
191 <    public void testExecute() {
191 >    public void testExecute() throws InterruptedException {
192          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
193          try {
194 <            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 <                });
194 >            p1.execute(new ShortRunnable());
195              Thread.sleep(SMALL_DELAY_MS);
196 <        } catch (InterruptedException e) {
197 <            unexpectedException();
196 >        } finally {
197 >            joinPool(p1);
198          }
207        joinPool(p1);
199      }
200  
201      /**
202       *  getActiveCount increases but doesn't overestimate, when a
203       *  thread becomes active
204       */
205 <    public void testGetActiveCount() {
205 >    public void testGetActiveCount() throws InterruptedException {
206          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
207          assertEquals(0, p2.getActiveCount());
208          p2.execute(new MediumRunnable());
209 <        try {
219 <            Thread.sleep(SHORT_DELAY_MS);
220 <        } catch (Exception e) {
221 <            unexpectedException();
222 <        }
209 >        Thread.sleep(SHORT_DELAY_MS);
210          assertEquals(1, p2.getActiveCount());
211          joinPool(p2);
212      }
# Line 256 | Line 243 | public class ThreadPoolExecutorSubclassT
243       *   getCompletedTaskCount increases, but doesn't overestimate,
244       *   when tasks complete
245       */
246 <    public void testGetCompletedTaskCount() {
246 >    public void testGetCompletedTaskCount() throws InterruptedException {
247          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
248          assertEquals(0, p2.getCompletedTaskCount());
249          p2.execute(new ShortRunnable());
250 <        try {
264 <            Thread.sleep(SMALL_DELAY_MS);
265 <        } catch (Exception e) {
266 <            unexpectedException();
267 <        }
250 >        Thread.sleep(SMALL_DELAY_MS);
251          assertEquals(1, p2.getCompletedTaskCount());
252          try { p2.shutdown(); } catch (SecurityException ok) { return; }
253          joinPool(p2);
# Line 367 | Line 350 | public class ThreadPoolExecutorSubclassT
350       *   getLargestPoolSize increases, but doesn't overestimate, when
351       *   multiple threads active
352       */
353 <    public void testGetLargestPoolSize() {
353 >    public void testGetLargestPoolSize() throws InterruptedException {
354          ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
355 <        try {
356 <            assertEquals(0, p2.getLargestPoolSize());
357 <            p2.execute(new MediumRunnable());
358 <            p2.execute(new MediumRunnable());
359 <            Thread.sleep(SHORT_DELAY_MS);
377 <            assertEquals(2, p2.getLargestPoolSize());
378 <        } catch (Exception e) {
379 <            unexpectedException();
380 <        }
355 >        assertEquals(0, p2.getLargestPoolSize());
356 >        p2.execute(new MediumRunnable());
357 >        p2.execute(new MediumRunnable());
358 >        Thread.sleep(SHORT_DELAY_MS);
359 >        assertEquals(2, p2.getLargestPoolSize());
360          joinPool(p2);
361      }
362  
# Line 406 | Line 385 | public class ThreadPoolExecutorSubclassT
385      /**
386       *  getTaskCount increases, but doesn't overestimate, when tasks submitted
387       */
388 <    public void testGetTaskCount() {
388 >    public void testGetTaskCount() throws InterruptedException {
389          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
390 <        try {
391 <            assertEquals(0, p1.getTaskCount());
392 <            p1.execute(new MediumRunnable());
393 <            Thread.sleep(SHORT_DELAY_MS);
415 <            assertEquals(1, p1.getTaskCount());
416 <        } catch (Exception e) {
417 <            unexpectedException();
418 <        }
390 >        assertEquals(0, p1.getTaskCount());
391 >        p1.execute(new MediumRunnable());
392 >        Thread.sleep(SHORT_DELAY_MS);
393 >        assertEquals(1, p1.getTaskCount());
394          joinPool(p1);
395      }
396  
# Line 435 | Line 410 | public class ThreadPoolExecutorSubclassT
410      /**
411       *  isTerminated is false before termination, true after
412       */
413 <    public void testIsTerminated() {
413 >    public void testIsTerminated() throws InterruptedException {
414          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
415          assertFalse(p1.isTerminated());
416          try {
# Line 443 | Line 418 | public class ThreadPoolExecutorSubclassT
418          } finally {
419              try { p1.shutdown(); } catch (SecurityException ok) { return; }
420          }
421 <        try {
422 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
448 <            assertTrue(p1.isTerminated());
449 <        } catch (Exception e) {
450 <            unexpectedException();
451 <        }
421 >        assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
422 >        assertTrue(p1.isTerminated());
423      }
424  
425      /**
426       *  isTerminating is not true when running or when terminated
427       */
428 <    public void testIsTerminating() {
428 >    public void testIsTerminating() throws InterruptedException {
429          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
430          assertFalse(p1.isTerminating());
431          try {
# Line 463 | Line 434 | public class ThreadPoolExecutorSubclassT
434          } finally {
435              try { p1.shutdown(); } catch (SecurityException ok) { return; }
436          }
437 <        try {
438 <            assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
439 <            assertTrue(p1.isTerminated());
469 <            assertFalse(p1.isTerminating());
470 <        } catch (Exception e) {
471 <            unexpectedException();
472 <        }
437 >        assertTrue(p1.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS));
438 >        assertTrue(p1.isTerminated());
439 >        assertFalse(p1.isTerminating());
440      }
441  
442      /**
443       * getQueue returns the work queue, which contains queued tasks
444       */
445 <    public void testGetQueue() {
445 >    public void testGetQueue() throws InterruptedException {
446          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
447          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
448          FutureTask[] tasks = new FutureTask[5];
# Line 492 | Line 459 | public class ThreadPoolExecutorSubclassT
459              for (int i = 1; i < 5; ++i)
460                  tasks[i].cancel(true);
461              p1.shutdownNow();
495        } catch (Exception e) {
496            unexpectedException();
462          } finally {
463              joinPool(p1);
464          }
# Line 502 | Line 467 | public class ThreadPoolExecutorSubclassT
467      /**
468       * remove(task) removes queued task, and fails to remove active task
469       */
470 <    public void testRemove() {
470 >    public void testRemove() throws InterruptedException {
471          BlockingQueue<Runnable> q = new ArrayBlockingQueue<Runnable>(10);
472          ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, TimeUnit.MILLISECONDS, q);
473          FutureTask[] tasks = new FutureTask[5];
# Line 521 | Line 486 | public class ThreadPoolExecutorSubclassT
486              assertTrue(q.contains(tasks[3]));
487              assertTrue(p1.remove(tasks[3]));
488              assertFalse(q.contains(tasks[3]));
524        } catch (Exception e) {
525            unexpectedException();
489          } finally {
490              joinPool(p1);
491          }
# Line 576 | Line 539 | public class ThreadPoolExecutorSubclassT
539          try {
540              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
541              shouldThrow();
542 <        }
580 <        catch (IllegalArgumentException success) {}
542 >        } catch (IllegalArgumentException success) {}
543      }
544  
545      /**
# Line 587 | Line 549 | public class ThreadPoolExecutorSubclassT
549          try {
550              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
551              shouldThrow();
552 <        }
591 <        catch (IllegalArgumentException success) {}
552 >        } catch (IllegalArgumentException success) {}
553      }
554  
555      /**
# Line 598 | Line 559 | public class ThreadPoolExecutorSubclassT
559          try {
560              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
561              shouldThrow();
562 <        }
602 <        catch (IllegalArgumentException success) {}
562 >        } catch (IllegalArgumentException success) {}
563      }
564  
565      /**
# Line 609 | Line 569 | public class ThreadPoolExecutorSubclassT
569          try {
570              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
571              shouldThrow();
572 <        }
613 <        catch (IllegalArgumentException success) {}
572 >        } catch (IllegalArgumentException success) {}
573      }
574  
575      /**
# Line 620 | Line 579 | public class ThreadPoolExecutorSubclassT
579          try {
580              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
581              shouldThrow();
582 <        }
624 <        catch (IllegalArgumentException success) {}
582 >        } catch (IllegalArgumentException success) {}
583      }
584  
585      /**
# Line 631 | Line 589 | public class ThreadPoolExecutorSubclassT
589          try {
590              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null);
591              shouldThrow();
592 <        }
635 <        catch (NullPointerException success) {}
592 >        } catch (NullPointerException success) {}
593      }
594  
595  
# Line 654 | Line 611 | public class ThreadPoolExecutorSubclassT
611          try {
612              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
613              shouldThrow();
614 <        }
658 <        catch (IllegalArgumentException success) {}
614 >        } catch (IllegalArgumentException success) {}
615      }
616  
617      /**
# Line 665 | Line 621 | public class ThreadPoolExecutorSubclassT
621          try {
622              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
623              shouldThrow();
624 <        }
669 <        catch (IllegalArgumentException success) {}
624 >        } catch (IllegalArgumentException success) {}
625      }
626  
627      /**
# Line 676 | Line 631 | public class ThreadPoolExecutorSubclassT
631          try {
632              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
633              shouldThrow();
634 <        }
680 <        catch (IllegalArgumentException success) {}
634 >        } catch (IllegalArgumentException success) {}
635      }
636  
637      /**
# Line 687 | Line 641 | public class ThreadPoolExecutorSubclassT
641          try {
642              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory());
643              shouldThrow();
644 <        }
691 <        catch (IllegalArgumentException success) {}
644 >        } catch (IllegalArgumentException success) {}
645      }
646  
647      /**
# Line 698 | Line 651 | public class ThreadPoolExecutorSubclassT
651          try {
652              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory());
653              shouldThrow();
654 <        }
702 <        catch (NullPointerException success) {}
654 >        } catch (NullPointerException success) {}
655      }
656  
657      /**
# Line 710 | Line 662 | public class ThreadPoolExecutorSubclassT
662              ThreadFactory f = null;
663              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f);
664              shouldThrow();
665 <        }
714 <        catch (NullPointerException success) {}
665 >        } catch (NullPointerException success) {}
666      }
667  
668  
# Line 722 | Line 673 | public class ThreadPoolExecutorSubclassT
673          try {
674              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
675              shouldThrow();
676 <        }
726 <        catch (IllegalArgumentException success) {}
676 >        } catch (IllegalArgumentException success) {}
677      }
678  
679      /**
# Line 733 | Line 683 | public class ThreadPoolExecutorSubclassT
683          try {
684              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
685              shouldThrow();
686 <        }
737 <        catch (IllegalArgumentException success) {}
686 >        } catch (IllegalArgumentException success) {}
687      }
688  
689      /**
# Line 744 | Line 693 | public class ThreadPoolExecutorSubclassT
693          try {
694              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
695              shouldThrow();
696 <        }
748 <        catch (IllegalArgumentException success) {}
696 >        } catch (IllegalArgumentException success) {}
697      }
698  
699      /**
# Line 755 | Line 703 | public class ThreadPoolExecutorSubclassT
703          try {
704              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
705              shouldThrow();
706 <        }
759 <        catch (IllegalArgumentException success) {}
706 >        } catch (IllegalArgumentException success) {}
707      }
708  
709      /**
# Line 766 | Line 713 | public class ThreadPoolExecutorSubclassT
713          try {
714              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler());
715              shouldThrow();
716 <        }
770 <        catch (IllegalArgumentException success) {}
716 >        } catch (IllegalArgumentException success) {}
717      }
718  
719      /**
# Line 777 | Line 723 | public class ThreadPoolExecutorSubclassT
723          try {
724              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new NoOpREHandler());
725              shouldThrow();
726 <        }
781 <        catch (NullPointerException success) {}
726 >        } catch (NullPointerException success) {}
727      }
728  
729      /**
# Line 789 | Line 734 | public class ThreadPoolExecutorSubclassT
734              RejectedExecutionHandler r = null;
735              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r);
736              shouldThrow();
737 <        }
793 <        catch (NullPointerException success) {}
737 >        } catch (NullPointerException success) {}
738      }
739  
740  
# Line 801 | Line 745 | public class ThreadPoolExecutorSubclassT
745          try {
746              new CustomTPE(-1,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
747              shouldThrow();
748 <        }
805 <        catch (IllegalArgumentException success) {}
748 >        } catch (IllegalArgumentException success) {}
749      }
750  
751      /**
# Line 812 | Line 755 | public class ThreadPoolExecutorSubclassT
755          try {
756              new CustomTPE(1,-1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
757              shouldThrow();
758 <        }
816 <        catch (IllegalArgumentException success) {}
758 >        } catch (IllegalArgumentException success) {}
759      }
760  
761      /**
# Line 823 | Line 765 | public class ThreadPoolExecutorSubclassT
765          try {
766              new CustomTPE(1,0,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
767              shouldThrow();
768 <        }
827 <        catch (IllegalArgumentException success) {}
768 >        } catch (IllegalArgumentException success) {}
769      }
770  
771      /**
# Line 834 | Line 775 | public class ThreadPoolExecutorSubclassT
775          try {
776              new CustomTPE(1,2,-1L,TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
777              shouldThrow();
778 <        }
838 <        catch (IllegalArgumentException success) {}
778 >        } catch (IllegalArgumentException success) {}
779      }
780  
781      /**
# Line 845 | Line 785 | public class ThreadPoolExecutorSubclassT
785          try {
786              new CustomTPE(2,1,LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler());
787              shouldThrow();
788 <        }
849 <        catch (IllegalArgumentException success) {}
788 >        } catch (IllegalArgumentException success) {}
789      }
790  
791      /**
# Line 856 | Line 795 | public class ThreadPoolExecutorSubclassT
795          try {
796              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler());
797              shouldThrow();
798 <        }
860 <        catch (NullPointerException success) {}
798 >        } catch (NullPointerException success) {}
799      }
800  
801      /**
# Line 868 | Line 806 | public class ThreadPoolExecutorSubclassT
806              RejectedExecutionHandler r = null;
807              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r);
808              shouldThrow();
809 <        }
872 <        catch (NullPointerException success) {}
809 >        } catch (NullPointerException success) {}
810      }
811  
812      /**
# Line 880 | Line 817 | public class ThreadPoolExecutorSubclassT
817              ThreadFactory f = null;
818              new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f,new NoOpREHandler());
819              shouldThrow();
820 <        }
884 <        catch (NullPointerException successdn8) {}
820 >        } catch (NullPointerException success) {}
821      }
822  
823  
# Line 922 | Line 858 | public class ThreadPoolExecutorSubclassT
858                  assertTrue(tasks[i].done);
859              }
860              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
925        } catch (RejectedExecutionException ex) {
926            unexpectedException();
861          } finally {
862              joinPool(p);
863          }
# Line 949 | Line 883 | public class ThreadPoolExecutorSubclassT
883                  assertFalse(tasks[i].done);
884              }
885              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
952        } catch (RejectedExecutionException ex) {
953            unexpectedException();
886          } finally {
887              joinPool(p);
888          }
# Line 972 | Line 904 | public class ThreadPoolExecutorSubclassT
904              assertFalse(p.getQueue().contains(r2));
905              assertTrue(p.getQueue().contains(r3));
906              try { p.shutdownNow(); } catch (SecurityException ok) { return; }
975        } catch (RejectedExecutionException ex) {
976            unexpectedException();
907          } finally {
908              joinPool(p);
909          }
# Line 1006 | Line 936 | public class ThreadPoolExecutorSubclassT
936              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
937              p.execute(r);
938              assertFalse(r.done);
1009        } catch (RejectedExecutionException success) {
1010            unexpectedException();
939          } finally {
940              joinPool(p);
941          }
# Line 1025 | Line 953 | public class ThreadPoolExecutorSubclassT
953              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
954              p.execute(r);
955              assertFalse(r.done);
1028        } catch (RejectedExecutionException success) {
1029            unexpectedException();
956          } finally {
957              joinPool(p);
958          }
# Line 1045 | Line 971 | public class ThreadPoolExecutorSubclassT
971              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
972              p.execute(r);
973              assertFalse(r.done);
1048        } catch (RejectedExecutionException success) {
1049            unexpectedException();
974          } finally {
975              joinPool(p);
976          }
# Line 1157 | Line 1081 | public class ThreadPoolExecutorSubclassT
1081      /**
1082       * beforeExecute and afterExecute are called when executing task
1083       */
1084 <    public void testBeforeAfter() {
1084 >    public void testBeforeAfter() throws InterruptedException {
1085          CustomTPE tpe = new CustomTPE();
1086          try {
1087              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
# Line 1167 | Line 1091 | public class ThreadPoolExecutorSubclassT
1091              assertTrue(tpe.beforeCalled);
1092              assertTrue(tpe.afterCalled);
1093              try { tpe.shutdown(); } catch (SecurityException ok) { return; }
1170        }
1171        catch (Exception ex) {
1172            unexpectedException();
1094          } finally {
1095              joinPool(tpe);
1096          }
# Line 1178 | Line 1099 | public class ThreadPoolExecutorSubclassT
1099      /**
1100       * completed submit of callable returns result
1101       */
1102 <    public void testSubmitCallable() {
1102 >    public void testSubmitCallable() throws Exception {
1103          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1104          try {
1105              Future<String> future = e.submit(new StringTask());
1106              String result = future.get();
1107              assertSame(TEST_STRING, result);
1187        }
1188        catch (ExecutionException ex) {
1189            unexpectedException();
1190        }
1191        catch (InterruptedException ex) {
1192            unexpectedException();
1108          } finally {
1109              joinPool(e);
1110          }
# Line 1198 | Line 1113 | public class ThreadPoolExecutorSubclassT
1113      /**
1114       * completed submit of runnable returns successfully
1115       */
1116 <    public void testSubmitRunnable() {
1116 >    public void testSubmitRunnable() throws Exception {
1117          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1118          try {
1119              Future<?> future = e.submit(new NoOpRunnable());
1120              future.get();
1121              assertTrue(future.isDone());
1207        }
1208        catch (ExecutionException ex) {
1209            unexpectedException();
1210        }
1211        catch (InterruptedException ex) {
1212            unexpectedException();
1122          } finally {
1123              joinPool(e);
1124          }
# Line 1218 | Line 1127 | public class ThreadPoolExecutorSubclassT
1127      /**
1128       * completed submit of (runnable, result) returns result
1129       */
1130 <    public void testSubmitRunnable2() {
1130 >    public void testSubmitRunnable2() throws Exception {
1131          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1132          try {
1133              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
1134              String result = future.get();
1135              assertSame(TEST_STRING, result);
1227        }
1228        catch (ExecutionException ex) {
1229            unexpectedException();
1230        }
1231        catch (InterruptedException ex) {
1232            unexpectedException();
1136          } finally {
1137              joinPool(e);
1138          }
1139      }
1140  
1141  
1239
1240
1241
1142      /**
1143       * invokeAny(null) throws NPE
1144       */
1145 <    public void testInvokeAny1() {
1145 >    public void testInvokeAny1() throws Exception {
1146          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1147          try {
1148              e.invokeAny(null);
1149 +            shouldThrow();
1150          } catch (NullPointerException success) {
1250        } catch (Exception ex) {
1251            unexpectedException();
1151          } finally {
1152              joinPool(e);
1153          }
# Line 1257 | Line 1156 | public class ThreadPoolExecutorSubclassT
1156      /**
1157       * invokeAny(empty collection) throws IAE
1158       */
1159 <    public void testInvokeAny2() {
1159 >    public void testInvokeAny2() throws Exception {
1160          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1161          try {
1162              e.invokeAny(new ArrayList<Callable<String>>());
1163 +            shouldThrow();
1164          } catch (IllegalArgumentException success) {
1265        } catch (Exception ex) {
1266            unexpectedException();
1165          } finally {
1166              joinPool(e);
1167          }
# Line 1272 | Line 1170 | public class ThreadPoolExecutorSubclassT
1170      /**
1171       * invokeAny(c) throws NPE if c has null elements
1172       */
1173 <    public void testInvokeAny3() {
1173 >    public void testInvokeAny3() throws Exception {
1174 >        final CountDownLatch latch = new CountDownLatch(1);
1175          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1176          try {
1177              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1178 <            l.add(new StringTask());
1178 >            l.add(new CheckedCallable<String>() {
1179 >                      public String realCall() throws InterruptedException {
1180 >                          latch.await();
1181 >                          return TEST_STRING;
1182 >                      }});
1183              l.add(null);
1184              e.invokeAny(l);
1185 +            shouldThrow();
1186          } catch (NullPointerException success) {
1283        } catch (Exception ex) {
1284            unexpectedException();
1187          } finally {
1188 +            latch.countDown();
1189              joinPool(e);
1190          }
1191      }
# Line 1290 | Line 1193 | public class ThreadPoolExecutorSubclassT
1193      /**
1194       * invokeAny(c) throws ExecutionException if no task completes
1195       */
1196 <    public void testInvokeAny4() {
1196 >    public void testInvokeAny4() throws Exception {
1197          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1198          try {
1199              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1200              l.add(new NPETask());
1201              e.invokeAny(l);
1202 +            shouldThrow();
1203          } catch (ExecutionException success) {
1300        } catch (Exception ex) {
1301            unexpectedException();
1204          } finally {
1205              joinPool(e);
1206          }
# Line 1307 | Line 1209 | public class ThreadPoolExecutorSubclassT
1209      /**
1210       * invokeAny(c) returns result of some task
1211       */
1212 <    public void testInvokeAny5() {
1212 >    public void testInvokeAny5() throws Exception {
1213          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1214          try {
1215              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1315 | Line 1217 | public class ThreadPoolExecutorSubclassT
1217              l.add(new StringTask());
1218              String result = e.invokeAny(l);
1219              assertSame(TEST_STRING, result);
1318        } catch (ExecutionException success) {
1319        } catch (Exception ex) {
1320            unexpectedException();
1220          } finally {
1221              joinPool(e);
1222          }
# Line 1326 | Line 1225 | public class ThreadPoolExecutorSubclassT
1225      /**
1226       * invokeAll(null) throws NPE
1227       */
1228 <    public void testInvokeAll1() {
1228 >    public void testInvokeAll1() throws Exception {
1229          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1230          try {
1231              e.invokeAll(null);
1232 +            shouldThrow();
1233          } catch (NullPointerException success) {
1334        } catch (Exception ex) {
1335            unexpectedException();
1234          } finally {
1235              joinPool(e);
1236          }
# Line 1341 | Line 1239 | public class ThreadPoolExecutorSubclassT
1239      /**
1240       * invokeAll(empty collection) returns empty collection
1241       */
1242 <    public void testInvokeAll2() {
1242 >    public void testInvokeAll2() throws Exception {
1243          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1244          try {
1245              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
1246              assertTrue(r.isEmpty());
1349        } catch (Exception ex) {
1350            unexpectedException();
1247          } finally {
1248              joinPool(e);
1249          }
# Line 1356 | Line 1252 | public class ThreadPoolExecutorSubclassT
1252      /**
1253       * invokeAll(c) throws NPE if c has null elements
1254       */
1255 <    public void testInvokeAll3() {
1255 >    public void testInvokeAll3() throws Exception {
1256          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1257          try {
1258              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1259              l.add(new StringTask());
1260              l.add(null);
1261              e.invokeAll(l);
1262 +            shouldThrow();
1263          } catch (NullPointerException success) {
1367        } catch (Exception ex) {
1368            unexpectedException();
1264          } finally {
1265              joinPool(e);
1266          }
# Line 1374 | Line 1269 | public class ThreadPoolExecutorSubclassT
1269      /**
1270       * get of element of invokeAll(c) throws exception on failed task
1271       */
1272 <    public void testInvokeAll4() {
1272 >    public void testInvokeAll4() throws Exception {
1273          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1274          try {
1275              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1383 | Line 1278 | public class ThreadPoolExecutorSubclassT
1278              assertEquals(1, result.size());
1279              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1280                  it.next().get();
1281 +            shouldThrow();
1282          } catch (ExecutionException success) {
1387        } catch (Exception ex) {
1388            unexpectedException();
1283          } finally {
1284              joinPool(e);
1285          }
# Line 1394 | Line 1288 | public class ThreadPoolExecutorSubclassT
1288      /**
1289       * invokeAll(c) returns results of all completed tasks
1290       */
1291 <    public void testInvokeAll5() {
1291 >    public void testInvokeAll5() throws Exception {
1292          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1293          try {
1294              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1404 | Line 1298 | public class ThreadPoolExecutorSubclassT
1298              assertEquals(2, result.size());
1299              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1300                  assertSame(TEST_STRING, it.next().get());
1301 +            shouldThrow();
1302          } catch (ExecutionException success) {
1408        } catch (Exception ex) {
1409            unexpectedException();
1303          } finally {
1304              joinPool(e);
1305          }
# Line 1417 | Line 1310 | public class ThreadPoolExecutorSubclassT
1310      /**
1311       * timed invokeAny(null) throws NPE
1312       */
1313 <    public void testTimedInvokeAny1() {
1313 >    public void testTimedInvokeAny1() throws Exception {
1314          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1315          try {
1316              e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1317 +            shouldThrow();
1318          } catch (NullPointerException success) {
1425        } catch (Exception ex) {
1426            unexpectedException();
1319          } finally {
1320              joinPool(e);
1321          }
# Line 1432 | Line 1324 | public class ThreadPoolExecutorSubclassT
1324      /**
1325       * timed invokeAny(,,null) throws NPE
1326       */
1327 <    public void testTimedInvokeAnyNullTimeUnit() {
1327 >    public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1328          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1329          try {
1330              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1331              l.add(new StringTask());
1332              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1333 +            shouldThrow();
1334          } catch (NullPointerException success) {
1442        } catch (Exception ex) {
1443            unexpectedException();
1335          } finally {
1336              joinPool(e);
1337          }
# Line 1449 | Line 1340 | public class ThreadPoolExecutorSubclassT
1340      /**
1341       * timed invokeAny(empty collection) throws IAE
1342       */
1343 <    public void testTimedInvokeAny2() {
1343 >    public void testTimedInvokeAny2() throws Exception {
1344          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1345          try {
1346              e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1347 +            shouldThrow();
1348          } catch (IllegalArgumentException success) {
1457        } catch (Exception ex) {
1458            unexpectedException();
1349          } finally {
1350              joinPool(e);
1351          }
# Line 1464 | Line 1354 | public class ThreadPoolExecutorSubclassT
1354      /**
1355       * timed invokeAny(c) throws NPE if c has null elements
1356       */
1357 <    public void testTimedInvokeAny3() {
1357 >    public void testTimedInvokeAny3() throws Exception {
1358          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1359          try {
1360              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1361              l.add(new StringTask());
1362              l.add(null);
1363              e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1364 +            shouldThrow();
1365          } catch (NullPointerException success) {
1475        } catch (Exception ex) {
1476            ex.printStackTrace();
1477            unexpectedException();
1366          } finally {
1367              joinPool(e);
1368          }
# Line 1483 | Line 1371 | public class ThreadPoolExecutorSubclassT
1371      /**
1372       * timed invokeAny(c) throws ExecutionException if no task completes
1373       */
1374 <    public void testTimedInvokeAny4() {
1374 >    public void testTimedInvokeAny4() throws Exception {
1375          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1376          try {
1377              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1378              l.add(new NPETask());
1379              e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1380 +            shouldThrow();
1381          } catch (ExecutionException success) {
1493        } catch (Exception ex) {
1494            unexpectedException();
1382          } finally {
1383              joinPool(e);
1384          }
# Line 1500 | Line 1387 | public class ThreadPoolExecutorSubclassT
1387      /**
1388       * timed invokeAny(c) returns result of some task
1389       */
1390 <    public void testTimedInvokeAny5() {
1390 >    public void testTimedInvokeAny5() throws Exception {
1391          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1392          try {
1393              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1508 | Line 1395 | public class ThreadPoolExecutorSubclassT
1395              l.add(new StringTask());
1396              String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1397              assertSame(TEST_STRING, result);
1398 +            shouldThrow();
1399          } catch (ExecutionException success) {
1512        } catch (Exception ex) {
1513            unexpectedException();
1400          } finally {
1401              joinPool(e);
1402          }
# Line 1519 | Line 1405 | public class ThreadPoolExecutorSubclassT
1405      /**
1406       * timed invokeAll(null) throws NPE
1407       */
1408 <    public void testTimedInvokeAll1() {
1408 >    public void testTimedInvokeAll1() throws Exception {
1409          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1410          try {
1411              e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1412 +            shouldThrow();
1413          } catch (NullPointerException success) {
1527        } catch (Exception ex) {
1528            unexpectedException();
1414          } finally {
1415              joinPool(e);
1416          }
# Line 1534 | Line 1419 | public class ThreadPoolExecutorSubclassT
1419      /**
1420       * timed invokeAll(,,null) throws NPE
1421       */
1422 <    public void testTimedInvokeAllNullTimeUnit() {
1422 >    public void testTimedInvokeAllNullTimeUnit() throws Exception {
1423          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1424          try {
1425              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1426              l.add(new StringTask());
1427              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1428 +            shouldThrow();
1429          } catch (NullPointerException success) {
1544        } catch (Exception ex) {
1545            unexpectedException();
1430          } finally {
1431              joinPool(e);
1432          }
# Line 1551 | Line 1435 | public class ThreadPoolExecutorSubclassT
1435      /**
1436       * timed invokeAll(empty collection) returns empty collection
1437       */
1438 <    public void testTimedInvokeAll2() {
1438 >    public void testTimedInvokeAll2() throws Exception {
1439          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1440          try {
1441              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1442              assertTrue(r.isEmpty());
1559        } catch (Exception ex) {
1560            unexpectedException();
1443          } finally {
1444              joinPool(e);
1445          }
# Line 1566 | Line 1448 | public class ThreadPoolExecutorSubclassT
1448      /**
1449       * timed invokeAll(c) throws NPE if c has null elements
1450       */
1451 <    public void testTimedInvokeAll3() {
1451 >    public void testTimedInvokeAll3() throws Exception {
1452          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1453          try {
1454              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1455              l.add(new StringTask());
1456              l.add(null);
1457              e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1458 +            shouldThrow();
1459          } catch (NullPointerException success) {
1577        } catch (Exception ex) {
1578            unexpectedException();
1460          } finally {
1461              joinPool(e);
1462          }
# Line 1584 | Line 1465 | public class ThreadPoolExecutorSubclassT
1465      /**
1466       * get of element of invokeAll(c) throws exception on failed task
1467       */
1468 <    public void testTimedInvokeAll4() {
1468 >    public void testTimedInvokeAll4() throws Exception {
1469          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1470          try {
1471              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1593 | Line 1474 | public class ThreadPoolExecutorSubclassT
1474              assertEquals(1, result.size());
1475              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1476                  it.next().get();
1477 +            shouldThrow();
1478          } catch (ExecutionException success) {
1597        } catch (Exception ex) {
1598            unexpectedException();
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 1614 | Line 1494 | public class ThreadPoolExecutorSubclassT
1494              assertEquals(2, result.size());
1495              for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1496                  assertSame(TEST_STRING, it.next().get());
1497 +            shouldThrow();
1498          } catch (ExecutionException success) {
1618        } catch (Exception ex) {
1619            unexpectedException();
1499          } finally {
1500              joinPool(e);
1501          }
# Line 1625 | Line 1504 | public class ThreadPoolExecutorSubclassT
1504      /**
1505       * timed invokeAll(c) cancels tasks not completed by timeout
1506       */
1507 <    public void testTimedInvokeAll6() {
1507 >    public void testTimedInvokeAll6() throws Exception {
1508          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1509          try {
1510              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1643 | Line 1522 | public class ThreadPoolExecutorSubclassT
1522              assertTrue(f3.isDone());
1523              assertFalse(f1.isCancelled());
1524              assertTrue(f2.isCancelled());
1646        } catch (Exception ex) {
1647            unexpectedException();
1525          } finally {
1526              joinPool(e);
1527          }
# Line 1654 | Line 1531 | public class ThreadPoolExecutorSubclassT
1531       * Execution continues if there is at least one thread even if
1532       * thread factory fails to create more
1533       */
1534 <    public void testFailingThreadFactory() {
1534 >    public void testFailingThreadFactory() throws InterruptedException {
1535          ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1536          try {
1537              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
# Line 1662 | Line 1539 | public class ThreadPoolExecutorSubclassT
1539                  e.execute(new NoOpRunnable());
1540              }
1541              Thread.sleep(LONG_DELAY_MS);
1665        } catch (Exception ex) {
1666            unexpectedException();
1542          } finally {
1543              joinPool(e);
1544          }
# Line 1681 | Line 1556 | public class ThreadPoolExecutorSubclassT
1556      /**
1557       * allowCoreThreadTimeOut(true) causes idle threads to time out
1558       */
1559 <    public void testAllowCoreThreadTimeOut_true() {
1559 >    public void testAllowCoreThreadTimeOut_true() throws InterruptedException {
1560          ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1561          tpe.allowCoreThreadTimeOut(true);
1562          tpe.execute(new NoOpRunnable());
1563          try {
1564              Thread.sleep(MEDIUM_DELAY_MS);
1565              assertEquals(0, tpe.getPoolSize());
1691        } catch (InterruptedException e) {
1692            unexpectedException();
1566          } finally {
1567              joinPool(tpe);
1568          }
# Line 1698 | Line 1571 | public class ThreadPoolExecutorSubclassT
1571      /**
1572       * allowCoreThreadTimeOut(false) causes idle threads not to time out
1573       */
1574 <    public void testAllowCoreThreadTimeOut_false() {
1574 >    public void testAllowCoreThreadTimeOut_false() throws InterruptedException {
1575          ThreadPoolExecutor tpe = new CustomTPE(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1576          tpe.allowCoreThreadTimeOut(false);
1577          tpe.execute(new NoOpRunnable());
1578          try {
1579              Thread.sleep(MEDIUM_DELAY_MS);
1580              assertTrue(tpe.getPoolSize() >= 1);
1708        } catch (InterruptedException e) {
1709            unexpectedException();
1581          } finally {
1582              joinPool(tpe);
1583          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines