192 |
|
|
193 |
|
|
194 |
|
/** |
195 |
< |
* execute successfully executes a runnable |
195 |
> |
* execute successfully executes a runnable |
196 |
|
*/ |
197 |
|
public void testExecute() throws InterruptedException { |
198 |
|
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
205 |
|
} |
206 |
|
|
207 |
|
/** |
208 |
< |
* getActiveCount increases but doesn't overestimate, when a |
209 |
< |
* thread becomes active |
208 |
> |
* getActiveCount increases but doesn't overestimate, when a |
209 |
> |
* thread becomes active |
210 |
|
*/ |
211 |
|
public void testGetActiveCount() throws InterruptedException { |
212 |
|
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
218 |
|
} |
219 |
|
|
220 |
|
/** |
221 |
< |
* prestartCoreThread starts a thread if under corePoolSize, else doesn't |
221 |
> |
* prestartCoreThread starts a thread if under corePoolSize, else doesn't |
222 |
|
*/ |
223 |
|
public void testPrestartCoreThread() { |
224 |
|
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
233 |
|
} |
234 |
|
|
235 |
|
/** |
236 |
< |
* prestartAllCoreThreads starts all corePoolSize threads |
236 |
> |
* prestartAllCoreThreads starts all corePoolSize threads |
237 |
|
*/ |
238 |
|
public void testPrestartAllCoreThreads() { |
239 |
|
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
246 |
|
} |
247 |
|
|
248 |
|
/** |
249 |
< |
* getCompletedTaskCount increases, but doesn't overestimate, |
250 |
< |
* when tasks complete |
249 |
> |
* getCompletedTaskCount increases, but doesn't overestimate, |
250 |
> |
* when tasks complete |
251 |
|
*/ |
252 |
|
public void testGetCompletedTaskCount() throws InterruptedException { |
253 |
|
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
260 |
|
} |
261 |
|
|
262 |
|
/** |
263 |
< |
* getCorePoolSize returns size given in constructor if not otherwise set |
263 |
> |
* getCorePoolSize returns size given in constructor if not otherwise set |
264 |
|
*/ |
265 |
|
public void testGetCorePoolSize() { |
266 |
|
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
269 |
|
} |
270 |
|
|
271 |
|
/** |
272 |
< |
* getKeepAliveTime returns value given in constructor if not otherwise set |
272 |
> |
* getKeepAliveTime returns value given in constructor if not otherwise set |
273 |
|
*/ |
274 |
|
public void testGetKeepAliveTime() { |
275 |
|
ThreadPoolExecutor p2 = new CustomTPE(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
353 |
|
|
354 |
|
|
355 |
|
/** |
356 |
< |
* getLargestPoolSize increases, but doesn't overestimate, when |
357 |
< |
* multiple threads active |
356 |
> |
* getLargestPoolSize increases, but doesn't overestimate, when |
357 |
> |
* multiple threads active |
358 |
|
*/ |
359 |
|
public void testGetLargestPoolSize() throws InterruptedException { |
360 |
|
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
367 |
|
} |
368 |
|
|
369 |
|
/** |
370 |
< |
* getMaximumPoolSize returns value given in constructor if not |
371 |
< |
* otherwise set |
370 |
> |
* getMaximumPoolSize returns value given in constructor if not |
371 |
> |
* otherwise set |
372 |
|
*/ |
373 |
|
public void testGetMaximumPoolSize() { |
374 |
|
ThreadPoolExecutor p2 = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
377 |
|
} |
378 |
|
|
379 |
|
/** |
380 |
< |
* getPoolSize increases, but doesn't overestimate, when threads |
381 |
< |
* become active |
380 |
> |
* getPoolSize increases, but doesn't overestimate, when threads |
381 |
> |
* become active |
382 |
|
*/ |
383 |
|
public void testGetPoolSize() { |
384 |
|
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
389 |
|
} |
390 |
|
|
391 |
|
/** |
392 |
< |
* getTaskCount increases, but doesn't overestimate, when tasks submitted |
392 |
> |
* getTaskCount increases, but doesn't overestimate, when tasks submitted |
393 |
|
*/ |
394 |
|
public void testGetTaskCount() throws InterruptedException { |
395 |
|
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
401 |
|
} |
402 |
|
|
403 |
|
/** |
404 |
< |
* isShutDown is false before shutdown, true after |
404 |
> |
* isShutDown is false before shutdown, true after |
405 |
|
*/ |
406 |
|
public void testIsShutdown() { |
407 |
|
|
414 |
|
|
415 |
|
|
416 |
|
/** |
417 |
< |
* isTerminated is false before termination, true after |
417 |
> |
* isTerminated is false before termination, true after |
418 |
|
*/ |
419 |
|
public void testIsTerminated() throws InterruptedException { |
420 |
|
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
429 |
|
} |
430 |
|
|
431 |
|
/** |
432 |
< |
* isTerminating is not true when running or when terminated |
432 |
> |
* isTerminating is not true when running or when terminated |
433 |
|
*/ |
434 |
|
public void testIsTerminating() throws InterruptedException { |
435 |
|
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
498 |
|
} |
499 |
|
|
500 |
|
/** |
501 |
< |
* purge removes cancelled tasks from the queue |
501 |
> |
* purge removes cancelled tasks from the queue |
502 |
|
*/ |
503 |
|
public void testPurge() { |
504 |
|
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
516 |
|
} |
517 |
|
|
518 |
|
/** |
519 |
< |
* shutDownNow returns a list containing tasks that were not run |
519 |
> |
* shutDownNow returns a list containing tasks that were not run |
520 |
|
*/ |
521 |
|
public void testShutDownNow() { |
522 |
|
ThreadPoolExecutor p1 = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
529 |
|
try { |
530 |
|
l = p1.shutdownNow(); |
531 |
|
} catch (SecurityException ok) { return; } |
532 |
– |
|
532 |
|
} |
533 |
|
assertTrue(p1.isShutdown()); |
534 |
|
assertTrue(l.size() <= 4); |
794 |
|
} |
795 |
|
|
796 |
|
/** |
797 |
< |
* Constructor throws if workQueue is set to null |
797 |
> |
* Constructor throws if workQueue is null |
798 |
|
*/ |
799 |
|
public void testConstructorNullPointerException6() { |
800 |
|
try { |
804 |
|
} |
805 |
|
|
806 |
|
/** |
807 |
< |
* Constructor throws if handler is set to null |
807 |
> |
* Constructor throws if handler is null |
808 |
|
*/ |
809 |
|
public void testConstructorNullPointerException7() { |
810 |
|
try { |
815 |
|
} |
816 |
|
|
817 |
|
/** |
818 |
< |
* Constructor throws if ThreadFactory is set top null |
818 |
> |
* Constructor throws if ThreadFactory is null |
819 |
|
*/ |
820 |
|
public void testConstructorNullPointerException8() { |
821 |
|
try { |
827 |
|
|
828 |
|
|
829 |
|
/** |
830 |
< |
* execute throws RejectedExecutionException |
832 |
< |
* if saturated. |
830 |
> |
* execute throws RejectedExecutionException if saturated. |
831 |
|
*/ |
832 |
|
public void testSaturatedExecute() { |
833 |
|
ThreadPoolExecutor p = new CustomTPE(1,1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(1)); |
842 |
|
} |
843 |
|
|
844 |
|
/** |
845 |
< |
* executor using CallerRunsPolicy runs task if saturated. |
845 |
> |
* executor using CallerRunsPolicy runs task if saturated. |
846 |
|
*/ |
847 |
|
public void testSaturatedExecute2() { |
848 |
|
RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy(); |
868 |
|
} |
869 |
|
|
870 |
|
/** |
871 |
< |
* executor using DiscardPolicy drops task if saturated. |
871 |
> |
* executor using DiscardPolicy drops task if saturated. |
872 |
|
*/ |
873 |
|
public void testSaturatedExecute3() { |
874 |
|
RejectedExecutionHandler h = new CustomTPE.DiscardPolicy(); |
893 |
|
} |
894 |
|
|
895 |
|
/** |
896 |
< |
* executor using DiscardOldestPolicy drops oldest task if saturated. |
896 |
> |
* executor using DiscardOldestPolicy drops oldest task if saturated. |
897 |
|
*/ |
898 |
|
public void testSaturatedExecute4() { |
899 |
|
RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy(); |
914 |
|
} |
915 |
|
|
916 |
|
/** |
917 |
< |
* execute throws RejectedExecutionException if shutdown |
917 |
> |
* execute throws RejectedExecutionException if shutdown |
918 |
|
*/ |
919 |
|
public void testRejectedExecutionExceptionOnShutdown() { |
920 |
|
ThreadPoolExecutor tpe = |
929 |
|
} |
930 |
|
|
931 |
|
/** |
932 |
< |
* execute using CallerRunsPolicy drops task on shutdown |
932 |
> |
* execute using CallerRunsPolicy drops task on shutdown |
933 |
|
*/ |
934 |
|
public void testCallerRunsOnShutdown() { |
935 |
|
RejectedExecutionHandler h = new CustomTPE.CallerRunsPolicy(); |
946 |
|
} |
947 |
|
|
948 |
|
/** |
949 |
< |
* execute using DiscardPolicy drops task on shutdown |
949 |
> |
* execute using DiscardPolicy drops task on shutdown |
950 |
|
*/ |
951 |
|
public void testDiscardOnShutdown() { |
952 |
|
RejectedExecutionHandler h = new CustomTPE.DiscardPolicy(); |
964 |
|
|
965 |
|
|
966 |
|
/** |
967 |
< |
* execute using DiscardOldestPolicy drops task on shutdown |
967 |
> |
* execute using DiscardOldestPolicy drops task on shutdown |
968 |
|
*/ |
969 |
|
public void testDiscardOldestOnShutdown() { |
970 |
|
RejectedExecutionHandler h = new CustomTPE.DiscardOldestPolicy(); |
982 |
|
|
983 |
|
|
984 |
|
/** |
985 |
< |
* execute (null) throws NPE |
985 |
> |
* execute(null) throws NPE |
986 |
|
*/ |
987 |
|
public void testExecuteNull() { |
988 |
|
ThreadPoolExecutor tpe = null; |
996 |
|
} |
997 |
|
|
998 |
|
/** |
999 |
< |
* setCorePoolSize of negative value throws IllegalArgumentException |
999 |
> |
* setCorePoolSize of negative value throws IllegalArgumentException |
1000 |
|
*/ |
1001 |
|
public void testCorePoolSizeIllegalArgumentException() { |
1002 |
|
ThreadPoolExecutor tpe = |
1012 |
|
} |
1013 |
|
|
1014 |
|
/** |
1015 |
< |
* setMaximumPoolSize(int) throws IllegalArgumentException if |
1016 |
< |
* given a value less the core pool size |
1015 |
> |
* setMaximumPoolSize(int) throws IllegalArgumentException |
1016 |
> |
* if given a value less the core pool size |
1017 |
|
*/ |
1018 |
|
public void testMaximumPoolSizeIllegalArgumentException() { |
1019 |
|
ThreadPoolExecutor tpe = |
1029 |
|
} |
1030 |
|
|
1031 |
|
/** |
1032 |
< |
* setMaximumPoolSize throws IllegalArgumentException |
1033 |
< |
* if given a negative value |
1032 |
> |
* setMaximumPoolSize throws IllegalArgumentException |
1033 |
> |
* if given a negative value |
1034 |
|
*/ |
1035 |
|
public void testMaximumPoolSizeIllegalArgumentException2() { |
1036 |
|
ThreadPoolExecutor tpe = |
1047 |
|
|
1048 |
|
|
1049 |
|
/** |
1050 |
< |
* setKeepAliveTime throws IllegalArgumentException |
1051 |
< |
* when given a negative value |
1050 |
> |
* setKeepAliveTime throws IllegalArgumentException |
1051 |
> |
* when given a negative value |
1052 |
|
*/ |
1053 |
|
public void testKeepAliveTimeIllegalArgumentException() { |
1054 |
|
ThreadPoolExecutor tpe = |
1167 |
|
* invokeAny(c) throws NPE if c has null elements |
1168 |
|
*/ |
1169 |
|
public void testInvokeAny3() throws Exception { |
1170 |
< |
final CountDownLatch latch = new CountDownLatch(1); |
1170 |
> |
CountDownLatch latch = new CountDownLatch(1); |
1171 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1172 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1173 |
+ |
l.add(latchAwaitingStringTask(latch)); |
1174 |
+ |
l.add(null); |
1175 |
|
try { |
1175 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1176 |
– |
l.add(new Callable<String>() { |
1177 |
– |
public String call() { |
1178 |
– |
try { |
1179 |
– |
latch.await(); |
1180 |
– |
} catch (InterruptedException ok) {} |
1181 |
– |
return TEST_STRING; |
1182 |
– |
}}); |
1183 |
– |
l.add(null); |
1176 |
|
e.invokeAny(l); |
1177 |
|
shouldThrow(); |
1178 |
|
} catch (NullPointerException success) { |
1187 |
|
*/ |
1188 |
|
public void testInvokeAny4() throws Exception { |
1189 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1190 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1191 |
+ |
l.add(new NPETask()); |
1192 |
|
try { |
1199 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1200 |
– |
l.add(new NPETask()); |
1193 |
|
e.invokeAny(l); |
1194 |
|
shouldThrow(); |
1195 |
|
} catch (ExecutionException success) { |
1205 |
|
public void testInvokeAny5() throws Exception { |
1206 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1207 |
|
try { |
1208 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1208 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1209 |
|
l.add(new StringTask()); |
1210 |
|
l.add(new StringTask()); |
1211 |
|
String result = e.invokeAny(l); |
1247 |
|
*/ |
1248 |
|
public void testInvokeAll3() throws Exception { |
1249 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1250 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1251 |
+ |
l.add(new StringTask()); |
1252 |
+ |
l.add(null); |
1253 |
|
try { |
1259 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1260 |
– |
l.add(new StringTask()); |
1261 |
– |
l.add(null); |
1254 |
|
e.invokeAll(l); |
1255 |
|
shouldThrow(); |
1256 |
|
} catch (NullPointerException success) { |
1264 |
|
*/ |
1265 |
|
public void testInvokeAll4() throws Exception { |
1266 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1267 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1268 |
+ |
l.add(new NPETask()); |
1269 |
+ |
List<Future<String>> futures = e.invokeAll(l); |
1270 |
+ |
assertEquals(1, futures.size()); |
1271 |
|
try { |
1272 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1277 |
< |
l.add(new NPETask()); |
1278 |
< |
List<Future<String>> result = e.invokeAll(l); |
1279 |
< |
assertEquals(1, result.size()); |
1280 |
< |
for (Future<String> future : result) |
1281 |
< |
future.get(); |
1272 |
> |
futures.get(0).get(); |
1273 |
|
shouldThrow(); |
1274 |
|
} catch (ExecutionException success) { |
1275 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
1276 |
|
} finally { |
1277 |
|
joinPool(e); |
1278 |
|
} |
1284 |
|
public void testInvokeAll5() throws Exception { |
1285 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1286 |
|
try { |
1287 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1287 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1288 |
|
l.add(new StringTask()); |
1289 |
|
l.add(new StringTask()); |
1290 |
< |
List<Future<String>> result = e.invokeAll(l); |
1291 |
< |
assertEquals(2, result.size()); |
1292 |
< |
for (Future<String> future : result) |
1290 |
> |
List<Future<String>> futures = e.invokeAll(l); |
1291 |
> |
assertEquals(2, futures.size()); |
1292 |
> |
for (Future<String> future : futures) |
1293 |
|
assertSame(TEST_STRING, future.get()); |
1294 |
|
} finally { |
1295 |
|
joinPool(e); |
1317 |
|
*/ |
1318 |
|
public void testTimedInvokeAnyNullTimeUnit() throws Exception { |
1319 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1320 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1321 |
+ |
l.add(new StringTask()); |
1322 |
|
try { |
1329 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1330 |
– |
l.add(new StringTask()); |
1323 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
1324 |
|
shouldThrow(); |
1325 |
|
} catch (NullPointerException success) { |
1346 |
|
* timed invokeAny(c) throws NPE if c has null elements |
1347 |
|
*/ |
1348 |
|
public void testTimedInvokeAny3() throws Exception { |
1349 |
< |
final CountDownLatch latch = new CountDownLatch(1); |
1349 |
> |
CountDownLatch latch = new CountDownLatch(1); |
1350 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1351 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1352 |
+ |
l.add(latchAwaitingStringTask(latch)); |
1353 |
+ |
l.add(null); |
1354 |
|
try { |
1360 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1361 |
– |
l.add(new Callable<String>() { |
1362 |
– |
public String call() { |
1363 |
– |
try { |
1364 |
– |
latch.await(); |
1365 |
– |
} catch (InterruptedException ok) {} |
1366 |
– |
return TEST_STRING; |
1367 |
– |
}}); |
1368 |
– |
l.add(null); |
1355 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1356 |
|
shouldThrow(); |
1357 |
|
} catch (NullPointerException success) { |
1366 |
|
*/ |
1367 |
|
public void testTimedInvokeAny4() throws Exception { |
1368 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1369 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1370 |
+ |
l.add(new NPETask()); |
1371 |
|
try { |
1384 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1385 |
– |
l.add(new NPETask()); |
1372 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1373 |
|
shouldThrow(); |
1374 |
|
} catch (ExecutionException success) { |
1384 |
|
public void testTimedInvokeAny5() throws Exception { |
1385 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1386 |
|
try { |
1387 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1387 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1388 |
|
l.add(new StringTask()); |
1389 |
|
l.add(new StringTask()); |
1390 |
|
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1413 |
|
*/ |
1414 |
|
public void testTimedInvokeAllNullTimeUnit() throws Exception { |
1415 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1416 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1417 |
+ |
l.add(new StringTask()); |
1418 |
|
try { |
1431 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1432 |
– |
l.add(new StringTask()); |
1419 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
1420 |
|
shouldThrow(); |
1421 |
|
} catch (NullPointerException success) { |
1442 |
|
*/ |
1443 |
|
public void testTimedInvokeAll3() throws Exception { |
1444 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1445 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1446 |
+ |
l.add(new StringTask()); |
1447 |
+ |
l.add(null); |
1448 |
|
try { |
1460 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1461 |
– |
l.add(new StringTask()); |
1462 |
– |
l.add(null); |
1449 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1450 |
|
shouldThrow(); |
1451 |
|
} catch (NullPointerException success) { |
1459 |
|
*/ |
1460 |
|
public void testTimedInvokeAll4() throws Exception { |
1461 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1462 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1463 |
+ |
l.add(new NPETask()); |
1464 |
+ |
List<Future<String>> futures = |
1465 |
+ |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1466 |
+ |
assertEquals(1, futures.size()); |
1467 |
|
try { |
1468 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1478 |
< |
l.add(new NPETask()); |
1479 |
< |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1480 |
< |
assertEquals(1, result.size()); |
1481 |
< |
for (Future<String> future : result) |
1482 |
< |
future.get(); |
1468 |
> |
futures.get(0).get(); |
1469 |
|
shouldThrow(); |
1470 |
|
} catch (ExecutionException success) { |
1471 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
1480 |
|
public void testTimedInvokeAll5() throws Exception { |
1481 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1482 |
|
try { |
1483 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1483 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1484 |
|
l.add(new StringTask()); |
1485 |
|
l.add(new StringTask()); |
1486 |
< |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1487 |
< |
assertEquals(2, result.size()); |
1488 |
< |
for (Future<String> future : result) |
1486 |
> |
List<Future<String>> futures = |
1487 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1488 |
> |
assertEquals(2, futures.size()); |
1489 |
> |
for (Future<String> future : futures) |
1490 |
|
assertSame(TEST_STRING, future.get()); |
1491 |
|
} finally { |
1492 |
|
joinPool(e); |
1499 |
|
public void testTimedInvokeAll6() throws Exception { |
1500 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1501 |
|
try { |
1502 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1502 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1503 |
|
l.add(new StringTask()); |
1504 |
|
l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING)); |
1505 |
|
l.add(new StringTask()); |
1506 |
< |
List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); |
1507 |
< |
assertEquals(3, result.size()); |
1508 |
< |
Iterator<Future<String>> it = result.iterator(); |
1506 |
> |
List<Future<String>> futures = |
1507 |
> |
e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); |
1508 |
> |
assertEquals(3, futures.size()); |
1509 |
> |
Iterator<Future<String>> it = futures.iterator(); |
1510 |
|
Future<String> f1 = it.next(); |
1511 |
|
Future<String> f2 = it.next(); |
1512 |
|
Future<String> f3 = it.next(); |