1168 |
|
* invokeAny(c) throws NPE if c has null elements |
1169 |
|
*/ |
1170 |
|
public void testInvokeAny3() throws Exception { |
1171 |
< |
final CountDownLatch latch = new CountDownLatch(1); |
1171 |
> |
CountDownLatch latch = new CountDownLatch(1); |
1172 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1173 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1174 |
+ |
l.add(latchAwaitingStringTask(latch)); |
1175 |
+ |
l.add(null); |
1176 |
|
try { |
1174 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1175 |
– |
l.add(new Callable<String>() { |
1176 |
– |
public String call() { |
1177 |
– |
try { |
1178 |
– |
latch.await(); |
1179 |
– |
} catch (InterruptedException ok) {} |
1180 |
– |
return TEST_STRING; |
1181 |
– |
}}); |
1182 |
– |
l.add(null); |
1177 |
|
e.invokeAny(l); |
1178 |
|
shouldThrow(); |
1179 |
|
} catch (NullPointerException success) { |
1188 |
|
*/ |
1189 |
|
public void testInvokeAny4() throws Exception { |
1190 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1191 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1192 |
+ |
l.add(new NPETask()); |
1193 |
|
try { |
1198 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1199 |
– |
l.add(new NPETask()); |
1194 |
|
e.invokeAny(l); |
1195 |
|
shouldThrow(); |
1196 |
|
} catch (ExecutionException success) { |
1206 |
|
public void testInvokeAny5() throws Exception { |
1207 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1208 |
|
try { |
1209 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1209 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1210 |
|
l.add(new StringTask()); |
1211 |
|
l.add(new StringTask()); |
1212 |
|
String result = e.invokeAny(l); |
1248 |
|
*/ |
1249 |
|
public void testInvokeAll3() throws Exception { |
1250 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1251 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1252 |
+ |
l.add(new StringTask()); |
1253 |
+ |
l.add(null); |
1254 |
|
try { |
1258 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1259 |
– |
l.add(new StringTask()); |
1260 |
– |
l.add(null); |
1255 |
|
e.invokeAll(l); |
1256 |
|
shouldThrow(); |
1257 |
|
} catch (NullPointerException success) { |
1265 |
|
*/ |
1266 |
|
public void testInvokeAll4() throws Exception { |
1267 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1268 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1269 |
+ |
l.add(new NPETask()); |
1270 |
+ |
List<Future<String>> futures = e.invokeAll(l); |
1271 |
+ |
assertEquals(1, futures.size()); |
1272 |
|
try { |
1273 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1276 |
< |
l.add(new NPETask()); |
1277 |
< |
List<Future<String>> result = e.invokeAll(l); |
1278 |
< |
assertEquals(1, result.size()); |
1279 |
< |
for (Future<String> future : result) |
1280 |
< |
future.get(); |
1273 |
> |
futures.get(0).get(); |
1274 |
|
shouldThrow(); |
1275 |
|
} catch (ExecutionException success) { |
1276 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
1285 |
|
public void testInvokeAll5() throws Exception { |
1286 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1287 |
|
try { |
1288 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1288 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1289 |
|
l.add(new StringTask()); |
1290 |
|
l.add(new StringTask()); |
1291 |
< |
List<Future<String>> result = e.invokeAll(l); |
1292 |
< |
assertEquals(2, result.size()); |
1293 |
< |
for (Future<String> future : result) |
1291 |
> |
List<Future<String>> futures = e.invokeAll(l); |
1292 |
> |
assertEquals(2, futures.size()); |
1293 |
> |
for (Future<String> future : futures) |
1294 |
|
assertSame(TEST_STRING, future.get()); |
1295 |
|
} finally { |
1296 |
|
joinPool(e); |
1318 |
|
*/ |
1319 |
|
public void testTimedInvokeAnyNullTimeUnit() throws Exception { |
1320 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1321 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1322 |
+ |
l.add(new StringTask()); |
1323 |
|
try { |
1329 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1330 |
– |
l.add(new StringTask()); |
1324 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
1325 |
|
shouldThrow(); |
1326 |
|
} catch (NullPointerException success) { |
1347 |
|
* timed invokeAny(c) throws NPE if c has null elements |
1348 |
|
*/ |
1349 |
|
public void testTimedInvokeAny3() throws Exception { |
1350 |
< |
final CountDownLatch latch = new CountDownLatch(1); |
1350 |
> |
CountDownLatch latch = new CountDownLatch(1); |
1351 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1352 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1353 |
+ |
l.add(latchAwaitingStringTask(latch)); |
1354 |
+ |
l.add(null); |
1355 |
|
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); |
1356 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1357 |
|
shouldThrow(); |
1358 |
|
} catch (NullPointerException success) { |
1367 |
|
*/ |
1368 |
|
public void testTimedInvokeAny4() throws Exception { |
1369 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1370 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1371 |
+ |
l.add(new NPETask()); |
1372 |
|
try { |
1384 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1385 |
– |
l.add(new NPETask()); |
1373 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1374 |
|
shouldThrow(); |
1375 |
|
} catch (ExecutionException success) { |
1385 |
|
public void testTimedInvokeAny5() throws Exception { |
1386 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1387 |
|
try { |
1388 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1388 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1389 |
|
l.add(new StringTask()); |
1390 |
|
l.add(new StringTask()); |
1391 |
|
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1414 |
|
*/ |
1415 |
|
public void testTimedInvokeAllNullTimeUnit() throws Exception { |
1416 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1417 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1418 |
+ |
l.add(new StringTask()); |
1419 |
|
try { |
1431 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1432 |
– |
l.add(new StringTask()); |
1420 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
1421 |
|
shouldThrow(); |
1422 |
|
} catch (NullPointerException success) { |
1443 |
|
*/ |
1444 |
|
public void testTimedInvokeAll3() throws Exception { |
1445 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1446 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1447 |
+ |
l.add(new StringTask()); |
1448 |
+ |
l.add(null); |
1449 |
|
try { |
1460 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1461 |
– |
l.add(new StringTask()); |
1462 |
– |
l.add(null); |
1450 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1451 |
|
shouldThrow(); |
1452 |
|
} catch (NullPointerException success) { |
1460 |
|
*/ |
1461 |
|
public void testTimedInvokeAll4() throws Exception { |
1462 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1463 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1464 |
+ |
l.add(new NPETask()); |
1465 |
+ |
List<Future<String>> futures = |
1466 |
+ |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1467 |
+ |
assertEquals(1, futures.size()); |
1468 |
|
try { |
1469 |
< |
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(); |
1469 |
> |
futures.get(0).get(); |
1470 |
|
shouldThrow(); |
1471 |
|
} catch (ExecutionException success) { |
1472 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
1481 |
|
public void testTimedInvokeAll5() throws Exception { |
1482 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1483 |
|
try { |
1484 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1484 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1485 |
|
l.add(new StringTask()); |
1486 |
|
l.add(new StringTask()); |
1487 |
< |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1488 |
< |
assertEquals(2, result.size()); |
1489 |
< |
for (Future<String> future : result) |
1487 |
> |
List<Future<String>> futures = |
1488 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1489 |
> |
assertEquals(2, futures.size()); |
1490 |
> |
for (Future<String> future : futures) |
1491 |
|
assertSame(TEST_STRING, future.get()); |
1492 |
|
} finally { |
1493 |
|
joinPool(e); |
1500 |
|
public void testTimedInvokeAll6() throws Exception { |
1501 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1502 |
|
try { |
1503 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1503 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1504 |
|
l.add(new StringTask()); |
1505 |
|
l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING)); |
1506 |
|
l.add(new StringTask()); |
1507 |
< |
List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); |
1508 |
< |
assertEquals(3, result.size()); |
1509 |
< |
Iterator<Future<String>> it = result.iterator(); |
1507 |
> |
List<Future<String>> futures = |
1508 |
> |
e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); |
1509 |
> |
assertEquals(3, futures.size()); |
1510 |
> |
Iterator<Future<String>> it = futures.iterator(); |
1511 |
|
Future<String> f1 = it.next(); |
1512 |
|
Future<String> f2 = it.next(); |
1513 |
|
Future<String> f3 = it.next(); |