6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
– |
import java.util.concurrent.*; |
9 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
10 |
< |
import java.util.concurrent.locks.*; |
10 |
> |
import static java.util.concurrent.TimeUnit.SECONDS; |
11 |
|
|
12 |
< |
import junit.framework.*; |
13 |
< |
import java.util.*; |
12 |
> |
import java.util.ArrayList; |
13 |
> |
import java.util.List; |
14 |
> |
import java.util.concurrent.ArrayBlockingQueue; |
15 |
> |
import java.util.concurrent.BlockingQueue; |
16 |
> |
import java.util.concurrent.Callable; |
17 |
> |
import java.util.concurrent.CountDownLatch; |
18 |
> |
import java.util.concurrent.ExecutionException; |
19 |
> |
import java.util.concurrent.Executors; |
20 |
> |
import java.util.concurrent.ExecutorService; |
21 |
> |
import java.util.concurrent.Future; |
22 |
> |
import java.util.concurrent.FutureTask; |
23 |
> |
import java.util.concurrent.LinkedBlockingQueue; |
24 |
> |
import java.util.concurrent.RejectedExecutionException; |
25 |
> |
import java.util.concurrent.RejectedExecutionHandler; |
26 |
> |
import java.util.concurrent.RunnableFuture; |
27 |
> |
import java.util.concurrent.SynchronousQueue; |
28 |
> |
import java.util.concurrent.ThreadFactory; |
29 |
> |
import java.util.concurrent.ThreadPoolExecutor; |
30 |
> |
import java.util.concurrent.TimeoutException; |
31 |
> |
import java.util.concurrent.TimeUnit; |
32 |
> |
import java.util.concurrent.locks.Condition; |
33 |
> |
import java.util.concurrent.locks.ReentrantLock; |
34 |
> |
|
35 |
> |
import junit.framework.Test; |
36 |
> |
import junit.framework.TestSuite; |
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() ; } |
183 |
|
workQueue, threadFactory, handler); |
184 |
|
} |
185 |
|
|
186 |
< |
volatile boolean beforeCalled = false; |
187 |
< |
volatile boolean afterCalled = false; |
188 |
< |
volatile boolean terminatedCalled = false; |
186 |
> |
final CountDownLatch beforeCalled = new CountDownLatch(1); |
187 |
> |
final CountDownLatch afterCalled = new CountDownLatch(1); |
188 |
> |
final CountDownLatch terminatedCalled = new CountDownLatch(1); |
189 |
> |
|
190 |
|
public CustomTPE() { |
191 |
|
super(1, 1, LONG_DELAY_MS, MILLISECONDS, new SynchronousQueue<Runnable>()); |
192 |
|
} |
193 |
|
protected void beforeExecute(Thread t, Runnable r) { |
194 |
< |
beforeCalled = true; |
194 |
> |
beforeCalled.countDown(); |
195 |
|
} |
196 |
|
protected void afterExecute(Runnable r, Throwable t) { |
197 |
< |
afterCalled = true; |
197 |
> |
afterCalled.countDown(); |
198 |
|
} |
199 |
|
protected void terminated() { |
200 |
< |
terminatedCalled = true; |
200 |
> |
terminatedCalled.countDown(); |
201 |
|
} |
202 |
|
|
203 |
+ |
public boolean beforeCalled() { |
204 |
+ |
return beforeCalled.getCount() == 0; |
205 |
+ |
} |
206 |
+ |
public boolean afterCalled() { |
207 |
+ |
return afterCalled.getCount() == 0; |
208 |
+ |
} |
209 |
+ |
public boolean terminatedCalled() { |
210 |
+ |
return terminatedCalled.getCount() == 0; |
211 |
+ |
} |
212 |
|
} |
213 |
|
|
214 |
|
static class FailingThreadFactory implements ThreadFactory { |
316 |
|
threadProceed.await(); |
317 |
|
threadDone.countDown(); |
318 |
|
}}); |
319 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
319 |
> |
await(threadStarted); |
320 |
|
assertEquals(0, p.getCompletedTaskCount()); |
321 |
|
threadProceed.countDown(); |
322 |
|
threadDone.await(); |
323 |
< |
delay(SHORT_DELAY_MS); |
324 |
< |
assertEquals(1, p.getCompletedTaskCount()); |
323 |
> |
long startTime = System.nanoTime(); |
324 |
> |
while (p.getCompletedTaskCount() != 1) { |
325 |
> |
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
326 |
> |
fail("timed out"); |
327 |
> |
Thread.yield(); |
328 |
> |
} |
329 |
|
} finally { |
330 |
|
joinPool(p); |
331 |
|
} |
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, |
964 |
< |
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 { |
1144 |
– |
p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1230 |
|
p.execute(null); |
1231 |
|
shouldThrow(); |
1232 |
|
} catch (NullPointerException success) {} |
1308 |
|
public void testTerminated() { |
1309 |
|
CustomTPE p = new CustomTPE(); |
1310 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
1311 |
< |
assertTrue(p.terminatedCalled); |
1311 |
> |
assertTrue(p.terminatedCalled()); |
1312 |
|
joinPool(p); |
1313 |
|
} |
1314 |
|
|
1318 |
|
public void testBeforeAfter() throws InterruptedException { |
1319 |
|
CustomTPE p = new CustomTPE(); |
1320 |
|
try { |
1321 |
< |
TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
1322 |
< |
p.execute(r); |
1323 |
< |
delay(SHORT_DELAY_MS); |
1324 |
< |
assertTrue(r.done); |
1325 |
< |
assertTrue(p.beforeCalled); |
1326 |
< |
assertTrue(p.afterCalled); |
1321 |
> |
final CountDownLatch done = new CountDownLatch(1); |
1322 |
> |
p.execute(new CheckedRunnable() { |
1323 |
> |
public void realRun() { |
1324 |
> |
done.countDown(); |
1325 |
> |
}}); |
1326 |
> |
await(p.afterCalled); |
1327 |
> |
assertEquals(0, done.getCount()); |
1328 |
> |
assertTrue(p.afterCalled()); |
1329 |
> |
assertTrue(p.beforeCalled()); |
1330 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
1331 |
|
} finally { |
1332 |
|
joinPool(p); |
1743 |
|
l.add(new StringTask()); |
1744 |
|
List<Future<String>> futures = |
1745 |
|
e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); |
1746 |
< |
assertEquals(3, futures.size()); |
1747 |
< |
Iterator<Future<String>> it = futures.iterator(); |
1748 |
< |
Future<String> f1 = it.next(); |
1749 |
< |
Future<String> f2 = it.next(); |
1750 |
< |
Future<String> f3 = it.next(); |
1663 |
< |
assertTrue(f1.isDone()); |
1664 |
< |
assertTrue(f2.isDone()); |
1665 |
< |
assertTrue(f3.isDone()); |
1666 |
< |
assertFalse(f1.isCancelled()); |
1667 |
< |
assertTrue(f2.isCancelled()); |
1746 |
> |
assertEquals(l.size(), futures.size()); |
1747 |
> |
for (Future future : futures) |
1748 |
> |
assertTrue(future.isDone()); |
1749 |
> |
assertFalse(futures.get(0).isCancelled()); |
1750 |
> |
assertTrue(futures.get(1).isCancelled()); |
1751 |
|
} finally { |
1752 |
|
joinPool(e); |
1753 |
|
} |