7 |
|
*/ |
8 |
|
|
9 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
10 |
+ |
import static java.util.concurrent.TimeUnit.SECONDS; |
11 |
|
|
12 |
|
import java.util.ArrayList; |
13 |
|
import java.util.List; |
37 |
|
|
38 |
|
public class ThreadPoolExecutorSubclassTest extends JSR166TestCase { |
39 |
|
public static void main(String[] args) { |
40 |
< |
junit.textui.TestRunner.run(suite()); |
40 |
> |
main(suite(), args); |
41 |
|
} |
42 |
|
public static Test suite() { |
43 |
|
return new TestSuite(ThreadPoolExecutorSubclassTest.class); |
59 |
|
CustomTask(final Runnable r, final V res) { |
60 |
|
if (r == null) throw new NullPointerException(); |
61 |
|
callable = new Callable<V>() { |
62 |
< |
public V call() throws Exception { r.run(); return res; }}; |
62 |
> |
public V call() throws Exception { r.run(); return res; }}; |
63 |
|
} |
64 |
|
public boolean isDone() { |
65 |
|
lock.lock(); try { return done; } finally { lock.unlock() ; } |
345 |
|
*/ |
346 |
|
public void testGetKeepAliveTime() { |
347 |
|
ThreadPoolExecutor p = new CustomTPE(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
348 |
< |
assertEquals(1, p.getKeepAliveTime(TimeUnit.SECONDS)); |
348 |
> |
assertEquals(1, p.getKeepAliveTime(SECONDS)); |
349 |
|
joinPool(p); |
350 |
|
} |
351 |
|
|
723 |
|
*/ |
724 |
|
public void testConstructor1() { |
725 |
|
try { |
726 |
< |
new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
726 |
> |
new CustomTPE(-1, 1, 1L, SECONDS, |
727 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
728 |
|
shouldThrow(); |
729 |
|
} catch (IllegalArgumentException success) {} |
730 |
|
} |
734 |
|
*/ |
735 |
|
public void testConstructor2() { |
736 |
|
try { |
737 |
< |
new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
737 |
> |
new CustomTPE(1, -1, 1L, SECONDS, |
738 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
739 |
|
shouldThrow(); |
740 |
|
} catch (IllegalArgumentException success) {} |
741 |
|
} |
745 |
|
*/ |
746 |
|
public void testConstructor3() { |
747 |
|
try { |
748 |
< |
new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
748 |
> |
new CustomTPE(1, 0, 1L, SECONDS, |
749 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
750 |
|
shouldThrow(); |
751 |
|
} catch (IllegalArgumentException success) {} |
752 |
|
} |
756 |
|
*/ |
757 |
|
public void testConstructor4() { |
758 |
|
try { |
759 |
< |
new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
759 |
> |
new CustomTPE(1, 2, -1L, SECONDS, |
760 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
761 |
|
shouldThrow(); |
762 |
|
} catch (IllegalArgumentException success) {} |
763 |
|
} |
767 |
|
*/ |
768 |
|
public void testConstructor5() { |
769 |
|
try { |
770 |
< |
new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
770 |
> |
new CustomTPE(2, 1, 1L, SECONDS, |
771 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
772 |
|
shouldThrow(); |
773 |
|
} catch (IllegalArgumentException success) {} |
774 |
|
} |
778 |
|
*/ |
779 |
|
public void testConstructorNullPointerException() { |
780 |
|
try { |
781 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null); |
781 |
> |
new CustomTPE(1, 2, 1L, SECONDS, null); |
782 |
|
shouldThrow(); |
783 |
|
} catch (NullPointerException success) {} |
784 |
|
} |
788 |
|
*/ |
789 |
|
public void testConstructor6() { |
790 |
|
try { |
791 |
< |
new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
791 |
> |
new CustomTPE(-1, 1, 1L, SECONDS, |
792 |
> |
new ArrayBlockingQueue<Runnable>(10), |
793 |
> |
new SimpleThreadFactory()); |
794 |
|
shouldThrow(); |
795 |
|
} catch (IllegalArgumentException success) {} |
796 |
|
} |
800 |
|
*/ |
801 |
|
public void testConstructor7() { |
802 |
|
try { |
803 |
< |
new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
803 |
> |
new CustomTPE(1,-1, 1L, SECONDS, |
804 |
> |
new ArrayBlockingQueue<Runnable>(10), |
805 |
> |
new SimpleThreadFactory()); |
806 |
|
shouldThrow(); |
807 |
|
} catch (IllegalArgumentException success) {} |
808 |
|
} |
812 |
|
*/ |
813 |
|
public void testConstructor8() { |
814 |
|
try { |
815 |
< |
new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
815 |
> |
new CustomTPE(1, 0, 1L, SECONDS, |
816 |
> |
new ArrayBlockingQueue<Runnable>(10), |
817 |
> |
new SimpleThreadFactory()); |
818 |
|
shouldThrow(); |
819 |
|
} catch (IllegalArgumentException success) {} |
820 |
|
} |
824 |
|
*/ |
825 |
|
public void testConstructor9() { |
826 |
|
try { |
827 |
< |
new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
827 |
> |
new CustomTPE(1, 2, -1L, SECONDS, |
828 |
> |
new ArrayBlockingQueue<Runnable>(10), |
829 |
> |
new SimpleThreadFactory()); |
830 |
|
shouldThrow(); |
831 |
|
} catch (IllegalArgumentException success) {} |
832 |
|
} |
836 |
|
*/ |
837 |
|
public void testConstructor10() { |
838 |
|
try { |
839 |
< |
new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory()); |
839 |
> |
new CustomTPE(2, 1, 1L, SECONDS, |
840 |
> |
new ArrayBlockingQueue<Runnable>(10), |
841 |
> |
new SimpleThreadFactory()); |
842 |
|
shouldThrow(); |
843 |
|
} catch (IllegalArgumentException success) {} |
844 |
|
} |
848 |
|
*/ |
849 |
|
public void testConstructorNullPointerException2() { |
850 |
|
try { |
851 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory()); |
851 |
> |
new CustomTPE(1, 2, 1L, SECONDS, null, new SimpleThreadFactory()); |
852 |
|
shouldThrow(); |
853 |
|
} catch (NullPointerException success) {} |
854 |
|
} |
858 |
|
*/ |
859 |
|
public void testConstructorNullPointerException3() { |
860 |
|
try { |
861 |
< |
ThreadFactory f = null; |
862 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),f); |
861 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
862 |
> |
new ArrayBlockingQueue<Runnable>(10), |
863 |
> |
(ThreadFactory) null); |
864 |
|
shouldThrow(); |
865 |
|
} catch (NullPointerException success) {} |
866 |
|
} |
870 |
|
*/ |
871 |
|
public void testConstructor11() { |
872 |
|
try { |
873 |
< |
new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
873 |
> |
new CustomTPE(-1, 1, 1L, SECONDS, |
874 |
> |
new ArrayBlockingQueue<Runnable>(10), |
875 |
> |
new NoOpREHandler()); |
876 |
|
shouldThrow(); |
877 |
|
} catch (IllegalArgumentException success) {} |
878 |
|
} |
882 |
|
*/ |
883 |
|
public void testConstructor12() { |
884 |
|
try { |
885 |
< |
new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
885 |
> |
new CustomTPE(1, -1, 1L, SECONDS, |
886 |
> |
new ArrayBlockingQueue<Runnable>(10), |
887 |
> |
new NoOpREHandler()); |
888 |
|
shouldThrow(); |
889 |
|
} catch (IllegalArgumentException success) {} |
890 |
|
} |
894 |
|
*/ |
895 |
|
public void testConstructor13() { |
896 |
|
try { |
897 |
< |
new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
897 |
> |
new CustomTPE(1, 0, 1L, SECONDS, |
898 |
> |
new ArrayBlockingQueue<Runnable>(10), |
899 |
> |
new NoOpREHandler()); |
900 |
|
shouldThrow(); |
901 |
|
} catch (IllegalArgumentException success) {} |
902 |
|
} |
906 |
|
*/ |
907 |
|
public void testConstructor14() { |
908 |
|
try { |
909 |
< |
new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
909 |
> |
new CustomTPE(1, 2, -1L, SECONDS, |
910 |
> |
new ArrayBlockingQueue<Runnable>(10), |
911 |
> |
new NoOpREHandler()); |
912 |
|
shouldThrow(); |
913 |
|
} catch (IllegalArgumentException success) {} |
914 |
|
} |
918 |
|
*/ |
919 |
|
public void testConstructor15() { |
920 |
|
try { |
921 |
< |
new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new NoOpREHandler()); |
921 |
> |
new CustomTPE(2, 1, 1L, SECONDS, |
922 |
> |
new ArrayBlockingQueue<Runnable>(10), |
923 |
> |
new NoOpREHandler()); |
924 |
|
shouldThrow(); |
925 |
|
} catch (IllegalArgumentException success) {} |
926 |
|
} |
930 |
|
*/ |
931 |
|
public void testConstructorNullPointerException4() { |
932 |
|
try { |
933 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new NoOpREHandler()); |
933 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
934 |
> |
null, |
935 |
> |
new NoOpREHandler()); |
936 |
|
shouldThrow(); |
937 |
|
} catch (NullPointerException success) {} |
938 |
|
} |
942 |
|
*/ |
943 |
|
public void testConstructorNullPointerException5() { |
944 |
|
try { |
945 |
< |
RejectedExecutionHandler r = null; |
946 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),r); |
945 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
946 |
> |
new ArrayBlockingQueue<Runnable>(10), |
947 |
> |
(RejectedExecutionHandler) null); |
948 |
|
shouldThrow(); |
949 |
|
} catch (NullPointerException success) {} |
950 |
|
} |
954 |
|
*/ |
955 |
|
public void testConstructor16() { |
956 |
|
try { |
957 |
< |
new CustomTPE(-1,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
957 |
> |
new CustomTPE(-1, 1, 1L, SECONDS, |
958 |
> |
new ArrayBlockingQueue<Runnable>(10), |
959 |
> |
new SimpleThreadFactory(), |
960 |
> |
new NoOpREHandler()); |
961 |
|
shouldThrow(); |
962 |
|
} catch (IllegalArgumentException success) {} |
963 |
|
} |
967 |
|
*/ |
968 |
|
public void testConstructor17() { |
969 |
|
try { |
970 |
< |
new CustomTPE(1,-1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
970 |
> |
new CustomTPE(1, -1, 1L, SECONDS, |
971 |
> |
new ArrayBlockingQueue<Runnable>(10), |
972 |
> |
new SimpleThreadFactory(), |
973 |
> |
new NoOpREHandler()); |
974 |
|
shouldThrow(); |
975 |
|
} catch (IllegalArgumentException success) {} |
976 |
|
} |
980 |
|
*/ |
981 |
|
public void testConstructor18() { |
982 |
|
try { |
983 |
< |
new CustomTPE(1,0,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
983 |
> |
new CustomTPE(1, 0, 1L, SECONDS, |
984 |
> |
new ArrayBlockingQueue<Runnable>(10), |
985 |
> |
new SimpleThreadFactory(), |
986 |
> |
new NoOpREHandler()); |
987 |
|
shouldThrow(); |
988 |
|
} catch (IllegalArgumentException success) {} |
989 |
|
} |
993 |
|
*/ |
994 |
|
public void testConstructor19() { |
995 |
|
try { |
996 |
< |
new CustomTPE(1,2,-1L,MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
996 |
> |
new CustomTPE(1, 2, -1L, SECONDS, |
997 |
> |
new ArrayBlockingQueue<Runnable>(10), |
998 |
> |
new SimpleThreadFactory(), |
999 |
> |
new NoOpREHandler()); |
1000 |
|
shouldThrow(); |
1001 |
|
} catch (IllegalArgumentException success) {} |
1002 |
|
} |
1006 |
|
*/ |
1007 |
|
public void testConstructor20() { |
1008 |
|
try { |
1009 |
< |
new CustomTPE(2,1,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),new NoOpREHandler()); |
1009 |
> |
new CustomTPE(2, 1, 1L, SECONDS, |
1010 |
> |
new ArrayBlockingQueue<Runnable>(10), |
1011 |
> |
new SimpleThreadFactory(), |
1012 |
> |
new NoOpREHandler()); |
1013 |
|
shouldThrow(); |
1014 |
|
} catch (IllegalArgumentException success) {} |
1015 |
|
} |
1019 |
|
*/ |
1020 |
|
public void testConstructorNullPointerException6() { |
1021 |
|
try { |
1022 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,null,new SimpleThreadFactory(),new NoOpREHandler()); |
1022 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
1023 |
> |
null, |
1024 |
> |
new SimpleThreadFactory(), |
1025 |
> |
new NoOpREHandler()); |
1026 |
|
shouldThrow(); |
1027 |
|
} catch (NullPointerException success) {} |
1028 |
|
} |
1032 |
|
*/ |
1033 |
|
public void testConstructorNullPointerException7() { |
1034 |
|
try { |
1035 |
< |
RejectedExecutionHandler r = null; |
1036 |
< |
new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10),new SimpleThreadFactory(),r); |
1035 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
1036 |
> |
new ArrayBlockingQueue<Runnable>(10), |
1037 |
> |
new SimpleThreadFactory(), |
1038 |
> |
(RejectedExecutionHandler) null); |
1039 |
|
shouldThrow(); |
1040 |
|
} catch (NullPointerException success) {} |
1041 |
|
} |
1045 |
|
*/ |
1046 |
|
public void testConstructorNullPointerException8() { |
1047 |
|
try { |
1048 |
< |
new CustomTPE(1, 2, |
999 |
< |
LONG_DELAY_MS, MILLISECONDS, |
1048 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
1049 |
|
new ArrayBlockingQueue<Runnable>(10), |
1050 |
|
(ThreadFactory) null, |
1051 |
|
new NoOpREHandler()); |
1223 |
|
* execute(null) throws NPE |
1224 |
|
*/ |
1225 |
|
public void testExecuteNull() { |
1226 |
< |
ThreadPoolExecutor p = null; |
1226 |
> |
ThreadPoolExecutor p = |
1227 |
> |
new CustomTPE(1, 2, 1L, SECONDS, |
1228 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
1229 |
|
try { |
1179 |
– |
p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1230 |
|
p.execute(null); |
1231 |
|
shouldThrow(); |
1232 |
|
} catch (NullPointerException success) {} |