6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
– |
import junit.framework.*; |
10 |
– |
import java.util.concurrent.*; |
9 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
10 |
|
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
11 |
< |
import java.util.*; |
11 |
> |
import static java.util.concurrent.TimeUnit.SECONDS; |
12 |
> |
|
13 |
> |
import java.util.ArrayList; |
14 |
> |
import java.util.List; |
15 |
> |
import java.util.concurrent.ArrayBlockingQueue; |
16 |
> |
import java.util.concurrent.BlockingQueue; |
17 |
> |
import java.util.concurrent.Callable; |
18 |
> |
import java.util.concurrent.CountDownLatch; |
19 |
> |
import java.util.concurrent.ExecutionException; |
20 |
> |
import java.util.concurrent.Executors; |
21 |
> |
import java.util.concurrent.ExecutorService; |
22 |
> |
import java.util.concurrent.Future; |
23 |
> |
import java.util.concurrent.FutureTask; |
24 |
> |
import java.util.concurrent.LinkedBlockingQueue; |
25 |
> |
import java.util.concurrent.RejectedExecutionException; |
26 |
> |
import java.util.concurrent.RejectedExecutionHandler; |
27 |
> |
import java.util.concurrent.SynchronousQueue; |
28 |
> |
import java.util.concurrent.ThreadFactory; |
29 |
> |
import java.util.concurrent.ThreadPoolExecutor; |
30 |
> |
import java.util.concurrent.TimeUnit; |
31 |
> |
|
32 |
> |
import junit.framework.Test; |
33 |
> |
import junit.framework.TestSuite; |
34 |
|
|
35 |
|
public class ThreadPoolExecutorTest extends JSR166TestCase { |
36 |
|
public static void main(String[] args) { |
37 |
< |
junit.textui.TestRunner.run(suite()); |
37 |
> |
main(suite(), args); |
38 |
|
} |
39 |
|
public static Test suite() { |
40 |
|
return new TestSuite(ThreadPoolExecutorTest.class); |
651 |
|
*/ |
652 |
|
public void testConstructor1() { |
653 |
|
try { |
654 |
< |
new ThreadPoolExecutor(-1, 1, |
635 |
< |
LONG_DELAY_MS, MILLISECONDS, |
654 |
> |
new ThreadPoolExecutor(-1, 1, 1L, SECONDS, |
655 |
|
new ArrayBlockingQueue<Runnable>(10)); |
656 |
|
shouldThrow(); |
657 |
|
} catch (IllegalArgumentException success) {} |
662 |
|
*/ |
663 |
|
public void testConstructor2() { |
664 |
|
try { |
665 |
< |
new ThreadPoolExecutor(1, -1, |
647 |
< |
LONG_DELAY_MS, MILLISECONDS, |
665 |
> |
new ThreadPoolExecutor(1, -1, 1L, SECONDS, |
666 |
|
new ArrayBlockingQueue<Runnable>(10)); |
667 |
|
shouldThrow(); |
668 |
|
} catch (IllegalArgumentException success) {} |
673 |
|
*/ |
674 |
|
public void testConstructor3() { |
675 |
|
try { |
676 |
< |
new ThreadPoolExecutor(1, 0, |
659 |
< |
LONG_DELAY_MS, MILLISECONDS, |
676 |
> |
new ThreadPoolExecutor(1, 0, 1L, SECONDS, |
677 |
|
new ArrayBlockingQueue<Runnable>(10)); |
678 |
|
shouldThrow(); |
679 |
|
} catch (IllegalArgumentException success) {} |
684 |
|
*/ |
685 |
|
public void testConstructor4() { |
686 |
|
try { |
687 |
< |
new ThreadPoolExecutor(1, 2, |
671 |
< |
-1L, MILLISECONDS, |
687 |
> |
new ThreadPoolExecutor(1, 2, -1L, SECONDS, |
688 |
|
new ArrayBlockingQueue<Runnable>(10)); |
689 |
|
shouldThrow(); |
690 |
|
} catch (IllegalArgumentException success) {} |
695 |
|
*/ |
696 |
|
public void testConstructor5() { |
697 |
|
try { |
698 |
< |
new ThreadPoolExecutor(2, 1, |
683 |
< |
LONG_DELAY_MS, MILLISECONDS, |
698 |
> |
new ThreadPoolExecutor(2, 1, 1L, SECONDS, |
699 |
|
new ArrayBlockingQueue<Runnable>(10)); |
700 |
|
shouldThrow(); |
701 |
|
} catch (IllegalArgumentException success) {} |
706 |
|
*/ |
707 |
|
public void testConstructorNullPointerException() { |
708 |
|
try { |
709 |
< |
new ThreadPoolExecutor(1, 2, |
695 |
< |
LONG_DELAY_MS, MILLISECONDS, |
709 |
> |
new ThreadPoolExecutor(1, 2, 1L, SECONDS, |
710 |
|
(BlockingQueue) null); |
711 |
|
shouldThrow(); |
712 |
|
} catch (NullPointerException success) {} |
717 |
|
*/ |
718 |
|
public void testConstructor6() { |
719 |
|
try { |
720 |
< |
new ThreadPoolExecutor(-1, 1, |
707 |
< |
LONG_DELAY_MS, MILLISECONDS, |
720 |
> |
new ThreadPoolExecutor(-1, 1, 1L, SECONDS, |
721 |
|
new ArrayBlockingQueue<Runnable>(10), |
722 |
|
new SimpleThreadFactory()); |
723 |
|
shouldThrow(); |
729 |
|
*/ |
730 |
|
public void testConstructor7() { |
731 |
|
try { |
732 |
< |
new ThreadPoolExecutor(1, -1, |
720 |
< |
LONG_DELAY_MS, MILLISECONDS, |
732 |
> |
new ThreadPoolExecutor(1, -1, 1L, SECONDS, |
733 |
|
new ArrayBlockingQueue<Runnable>(10), |
734 |
|
new SimpleThreadFactory()); |
735 |
|
shouldThrow(); |
741 |
|
*/ |
742 |
|
public void testConstructor8() { |
743 |
|
try { |
744 |
< |
new ThreadPoolExecutor(1, 0, |
733 |
< |
LONG_DELAY_MS, MILLISECONDS, |
744 |
> |
new ThreadPoolExecutor(1, 0, 1L, SECONDS, |
745 |
|
new ArrayBlockingQueue<Runnable>(10), |
746 |
|
new SimpleThreadFactory()); |
747 |
|
shouldThrow(); |
753 |
|
*/ |
754 |
|
public void testConstructor9() { |
755 |
|
try { |
756 |
< |
new ThreadPoolExecutor(1, 2, |
746 |
< |
-1L, MILLISECONDS, |
756 |
> |
new ThreadPoolExecutor(1, 2, -1L, SECONDS, |
757 |
|
new ArrayBlockingQueue<Runnable>(10), |
758 |
|
new SimpleThreadFactory()); |
759 |
|
shouldThrow(); |
765 |
|
*/ |
766 |
|
public void testConstructor10() { |
767 |
|
try { |
768 |
< |
new ThreadPoolExecutor(2, 1, |
759 |
< |
LONG_DELAY_MS, MILLISECONDS, |
768 |
> |
new ThreadPoolExecutor(2, 1, 1L, SECONDS, |
769 |
|
new ArrayBlockingQueue<Runnable>(10), |
770 |
|
new SimpleThreadFactory()); |
771 |
|
shouldThrow(); |
777 |
|
*/ |
778 |
|
public void testConstructorNullPointerException2() { |
779 |
|
try { |
780 |
< |
new ThreadPoolExecutor(1, 2, |
772 |
< |
LONG_DELAY_MS, MILLISECONDS, |
780 |
> |
new ThreadPoolExecutor(1, 2, 1L, SECONDS, |
781 |
|
(BlockingQueue) null, |
782 |
|
new SimpleThreadFactory()); |
783 |
|
shouldThrow(); |
789 |
|
*/ |
790 |
|
public void testConstructorNullPointerException3() { |
791 |
|
try { |
792 |
< |
new ThreadPoolExecutor(1, 2, |
785 |
< |
LONG_DELAY_MS, MILLISECONDS, |
792 |
> |
new ThreadPoolExecutor(1, 2, 1L, SECONDS, |
793 |
|
new ArrayBlockingQueue<Runnable>(10), |
794 |
|
(ThreadFactory) null); |
795 |
|
shouldThrow(); |
801 |
|
*/ |
802 |
|
public void testConstructor11() { |
803 |
|
try { |
804 |
< |
new ThreadPoolExecutor(-1, 1, |
798 |
< |
LONG_DELAY_MS, MILLISECONDS, |
804 |
> |
new ThreadPoolExecutor(-1, 1, 1L, SECONDS, |
805 |
|
new ArrayBlockingQueue<Runnable>(10), |
806 |
|
new NoOpREHandler()); |
807 |
|
shouldThrow(); |
813 |
|
*/ |
814 |
|
public void testConstructor12() { |
815 |
|
try { |
816 |
< |
new ThreadPoolExecutor(1, -1, |
811 |
< |
LONG_DELAY_MS, MILLISECONDS, |
816 |
> |
new ThreadPoolExecutor(1, -1, 1L, SECONDS, |
817 |
|
new ArrayBlockingQueue<Runnable>(10), |
818 |
|
new NoOpREHandler()); |
819 |
|
shouldThrow(); |
825 |
|
*/ |
826 |
|
public void testConstructor13() { |
827 |
|
try { |
828 |
< |
new ThreadPoolExecutor(1, 0, |
824 |
< |
LONG_DELAY_MS, MILLISECONDS, |
828 |
> |
new ThreadPoolExecutor(1, 0, 1L, SECONDS, |
829 |
|
new ArrayBlockingQueue<Runnable>(10), |
830 |
|
new NoOpREHandler()); |
831 |
|
shouldThrow(); |
837 |
|
*/ |
838 |
|
public void testConstructor14() { |
839 |
|
try { |
840 |
< |
new ThreadPoolExecutor(1, 2, |
837 |
< |
-1L, MILLISECONDS, |
840 |
> |
new ThreadPoolExecutor(1, 2, -1L, SECONDS, |
841 |
|
new ArrayBlockingQueue<Runnable>(10), |
842 |
|
new NoOpREHandler()); |
843 |
|
shouldThrow(); |
849 |
|
*/ |
850 |
|
public void testConstructor15() { |
851 |
|
try { |
852 |
< |
new ThreadPoolExecutor(2, 1, |
850 |
< |
LONG_DELAY_MS, MILLISECONDS, |
852 |
> |
new ThreadPoolExecutor(2, 1, 1L, SECONDS, |
853 |
|
new ArrayBlockingQueue<Runnable>(10), |
854 |
|
new NoOpREHandler()); |
855 |
|
shouldThrow(); |
861 |
|
*/ |
862 |
|
public void testConstructorNullPointerException4() { |
863 |
|
try { |
864 |
< |
new ThreadPoolExecutor(1, 2, |
863 |
< |
LONG_DELAY_MS, MILLISECONDS, |
864 |
> |
new ThreadPoolExecutor(1, 2, 1L, SECONDS, |
865 |
|
(BlockingQueue) null, |
866 |
|
new NoOpREHandler()); |
867 |
|
shouldThrow(); |
873 |
|
*/ |
874 |
|
public void testConstructorNullPointerException5() { |
875 |
|
try { |
876 |
< |
new ThreadPoolExecutor(1, 2, |
876 |
< |
LONG_DELAY_MS, MILLISECONDS, |
876 |
> |
new ThreadPoolExecutor(1, 2, 1L, SECONDS, |
877 |
|
new ArrayBlockingQueue<Runnable>(10), |
878 |
|
(RejectedExecutionHandler) null); |
879 |
|
shouldThrow(); |
885 |
|
*/ |
886 |
|
public void testConstructor16() { |
887 |
|
try { |
888 |
< |
new ThreadPoolExecutor(-1, 1, |
889 |
< |
LONG_DELAY_MS, MILLISECONDS, |
888 |
> |
new ThreadPoolExecutor(-1, 1, 1L, SECONDS, |
889 |
|
new ArrayBlockingQueue<Runnable>(10), |
890 |
|
new SimpleThreadFactory(), |
891 |
|
new NoOpREHandler()); |
898 |
|
*/ |
899 |
|
public void testConstructor17() { |
900 |
|
try { |
901 |
< |
new ThreadPoolExecutor(1, -1, |
903 |
< |
LONG_DELAY_MS, MILLISECONDS, |
901 |
> |
new ThreadPoolExecutor(1, -1, 1L, SECONDS, |
902 |
|
new ArrayBlockingQueue<Runnable>(10), |
903 |
|
new SimpleThreadFactory(), |
904 |
|
new NoOpREHandler()); |
911 |
|
*/ |
912 |
|
public void testConstructor18() { |
913 |
|
try { |
914 |
< |
new ThreadPoolExecutor(1, 0, |
917 |
< |
LONG_DELAY_MS, MILLISECONDS, |
914 |
> |
new ThreadPoolExecutor(1, 0, 1L, SECONDS, |
915 |
|
new ArrayBlockingQueue<Runnable>(10), |
916 |
|
new SimpleThreadFactory(), |
917 |
|
new NoOpREHandler()); |
924 |
|
*/ |
925 |
|
public void testConstructor19() { |
926 |
|
try { |
927 |
< |
new ThreadPoolExecutor(1, 2, |
931 |
< |
-1L, MILLISECONDS, |
927 |
> |
new ThreadPoolExecutor(1, 2, -1L, SECONDS, |
928 |
|
new ArrayBlockingQueue<Runnable>(10), |
929 |
|
new SimpleThreadFactory(), |
930 |
|
new NoOpREHandler()); |
937 |
|
*/ |
938 |
|
public void testConstructor20() { |
939 |
|
try { |
940 |
< |
new ThreadPoolExecutor(2, 1, |
945 |
< |
LONG_DELAY_MS, MILLISECONDS, |
940 |
> |
new ThreadPoolExecutor(2, 1, 1L, SECONDS, |
941 |
|
new ArrayBlockingQueue<Runnable>(10), |
942 |
|
new SimpleThreadFactory(), |
943 |
|
new NoOpREHandler()); |
950 |
|
*/ |
951 |
|
public void testConstructorNullPointerException6() { |
952 |
|
try { |
953 |
< |
new ThreadPoolExecutor(1, 2, |
959 |
< |
LONG_DELAY_MS, MILLISECONDS, |
953 |
> |
new ThreadPoolExecutor(1, 2, 1L, SECONDS, |
954 |
|
(BlockingQueue) null, |
955 |
|
new SimpleThreadFactory(), |
956 |
|
new NoOpREHandler()); |
963 |
|
*/ |
964 |
|
public void testConstructorNullPointerException7() { |
965 |
|
try { |
966 |
< |
new ThreadPoolExecutor(1, 2, |
973 |
< |
LONG_DELAY_MS, MILLISECONDS, |
966 |
> |
new ThreadPoolExecutor(1, 2, 1L, SECONDS, |
967 |
|
new ArrayBlockingQueue<Runnable>(10), |
968 |
|
new SimpleThreadFactory(), |
969 |
|
(RejectedExecutionHandler) null); |
976 |
|
*/ |
977 |
|
public void testConstructorNullPointerException8() { |
978 |
|
try { |
979 |
< |
new ThreadPoolExecutor(1, 2, |
987 |
< |
LONG_DELAY_MS, MILLISECONDS, |
979 |
> |
new ThreadPoolExecutor(1, 2, 1L, SECONDS, |
980 |
|
new ArrayBlockingQueue<Runnable>(10), |
981 |
|
(ThreadFactory) null, |
982 |
|
new NoOpREHandler()); |
1367 |
|
ExtendedTPE p = new ExtendedTPE(); |
1368 |
|
try { |
1369 |
|
final CountDownLatch done = new CountDownLatch(1); |
1370 |
< |
final CheckedRunnable task = new CheckedRunnable() { |
1370 |
> |
p.execute(new CheckedRunnable() { |
1371 |
|
public void realRun() { |
1372 |
|
done.countDown(); |
1373 |
< |
}}; |
1382 |
< |
p.execute(task); |
1373 |
> |
}}); |
1374 |
|
await(p.afterCalled); |
1375 |
|
assertEquals(0, done.getCount()); |
1376 |
|
assertTrue(p.afterCalled()); |