529 |
|
try { |
530 |
|
l = p1.shutdownNow(); |
531 |
|
} catch (SecurityException ok) { return; } |
532 |
– |
|
532 |
|
} |
533 |
|
assertTrue(p1.isShutdown()); |
534 |
|
assertTrue(l.size() <= 4); |
1017 |
|
* given a value less the core pool size |
1018 |
|
*/ |
1019 |
|
public void testMaximumPoolSizeIllegalArgumentException() { |
1020 |
< |
ThreadPoolExecutor tpe = null; |
1021 |
< |
try { |
1023 |
< |
tpe = new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1024 |
< |
} catch (Exception e) {} |
1020 |
> |
ThreadPoolExecutor tpe = |
1021 |
> |
new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1022 |
|
try { |
1023 |
|
tpe.setMaximumPoolSize(1); |
1024 |
|
shouldThrow(); |
1034 |
|
* if given a negative value |
1035 |
|
*/ |
1036 |
|
public void testMaximumPoolSizeIllegalArgumentException2() { |
1037 |
< |
ThreadPoolExecutor tpe = null; |
1038 |
< |
try { |
1042 |
< |
tpe = new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1043 |
< |
} catch (Exception e) {} |
1037 |
> |
ThreadPoolExecutor tpe = |
1038 |
> |
new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1039 |
|
try { |
1040 |
|
tpe.setMaximumPoolSize(-1); |
1041 |
|
shouldThrow(); |
1052 |
|
* when given a negative value |
1053 |
|
*/ |
1054 |
|
public void testKeepAliveTimeIllegalArgumentException() { |
1055 |
< |
ThreadPoolExecutor tpe = null; |
1056 |
< |
try { |
1062 |
< |
tpe = new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1063 |
< |
} catch (Exception e) {} |
1055 |
> |
ThreadPoolExecutor tpe = |
1056 |
> |
new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1057 |
|
|
1058 |
|
try { |
1059 |
|
tpe.setKeepAliveTime(-1,MILLISECONDS); |
1200 |
|
e.invokeAny(l); |
1201 |
|
shouldThrow(); |
1202 |
|
} catch (ExecutionException success) { |
1203 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
1204 |
|
} finally { |
1205 |
|
joinPool(e); |
1206 |
|
} |
1280 |
|
future.get(); |
1281 |
|
shouldThrow(); |
1282 |
|
} catch (ExecutionException success) { |
1283 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
1284 |
|
} finally { |
1285 |
|
joinPool(e); |
1286 |
|
} |
1354 |
|
* timed invokeAny(c) throws NPE if c has null elements |
1355 |
|
*/ |
1356 |
|
public void testTimedInvokeAny3() throws Exception { |
1357 |
+ |
final CountDownLatch latch = new CountDownLatch(1); |
1358 |
|
ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1359 |
|
try { |
1360 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1361 |
< |
l.add(new StringTask()); |
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); |
1369 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1370 |
|
shouldThrow(); |
1371 |
|
} catch (NullPointerException success) { |
1372 |
|
} finally { |
1373 |
+ |
latch.countDown(); |
1374 |
|
joinPool(e); |
1375 |
|
} |
1376 |
|
} |
1386 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1387 |
|
shouldThrow(); |
1388 |
|
} catch (ExecutionException success) { |
1389 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
1390 |
|
} finally { |
1391 |
|
joinPool(e); |
1392 |
|
} |
1501 |
|
assertEquals(2, result.size()); |
1502 |
|
for (Future<String> future : result) |
1503 |
|
assertSame(TEST_STRING, future.get()); |
1500 |
– |
} catch (ExecutionException success) { |
1504 |
|
} finally { |
1505 |
|
joinPool(e); |
1506 |
|
} |