14 |
|
|
15 |
|
public class ThreadPoolExecutorSubclassTest extends JSR166TestCase { |
16 |
|
public static void main(String[] args) { |
17 |
< |
junit.textui.TestRunner.run (suite()); |
17 |
> |
junit.textui.TestRunner.run(suite()); |
18 |
|
} |
19 |
|
public static Test suite() { |
20 |
< |
return new TestSuite(ThreadPoolExecutorTest.class); |
20 |
> |
return new TestSuite(ThreadPoolExecutorSubclassTest.class); |
21 |
|
} |
22 |
|
|
23 |
|
static class CustomTask<V> implements RunnableFuture<V> { |
29 |
|
V result; |
30 |
|
Thread thread; |
31 |
|
Exception exception; |
32 |
< |
CustomTask(Callable<V> c) { callable = c; } |
33 |
< |
CustomTask(final Runnable r, final V res) { callable = new Callable<V>() { |
32 |
> |
CustomTask(Callable<V> c) { |
33 |
> |
if (c == null) throw new NullPointerException(); |
34 |
> |
callable = c; |
35 |
> |
} |
36 |
> |
CustomTask(final Runnable r, final V res) { |
37 |
> |
if (r == null) throw new NullPointerException(); |
38 |
> |
callable = new Callable<V>() { |
39 |
|
public V call() throws Exception { r.run(); return res; }}; |
40 |
|
} |
41 |
|
public boolean isDone() { |
1000 |
|
* setCorePoolSize of negative value throws IllegalArgumentException |
1001 |
|
*/ |
1002 |
|
public void testCorePoolSizeIllegalArgumentException() { |
1003 |
< |
ThreadPoolExecutor tpe = null; |
1004 |
< |
try { |
1000 |
< |
tpe = new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1001 |
< |
} catch (Exception e) {} |
1003 |
> |
ThreadPoolExecutor tpe = |
1004 |
> |
new CustomTPE(1,2,LONG_DELAY_MS, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(10)); |
1005 |
|
try { |
1006 |
|
tpe.setCorePoolSize(-1); |
1007 |
|
shouldThrow(); |
1279 |
|
l.add(new NPETask()); |
1280 |
|
List<Future<String>> result = e.invokeAll(l); |
1281 |
|
assertEquals(1, result.size()); |
1282 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1283 |
< |
it.next().get(); |
1282 |
> |
for (Future<String> future : result) |
1283 |
> |
future.get(); |
1284 |
|
shouldThrow(); |
1285 |
|
} catch (ExecutionException success) { |
1286 |
|
} finally { |
1299 |
|
l.add(new StringTask()); |
1300 |
|
List<Future<String>> result = e.invokeAll(l); |
1301 |
|
assertEquals(2, result.size()); |
1302 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1303 |
< |
assertSame(TEST_STRING, it.next().get()); |
1301 |
< |
shouldThrow(); |
1302 |
< |
} catch (ExecutionException success) { |
1302 |
> |
for (Future<String> future : result) |
1303 |
> |
assertSame(TEST_STRING, future.get()); |
1304 |
|
} finally { |
1305 |
|
joinPool(e); |
1306 |
|
} |
1396 |
|
l.add(new StringTask()); |
1397 |
|
String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1398 |
|
assertSame(TEST_STRING, result); |
1398 |
– |
shouldThrow(); |
1399 |
– |
} catch (ExecutionException success) { |
1399 |
|
} finally { |
1400 |
|
joinPool(e); |
1401 |
|
} |
1471 |
|
l.add(new NPETask()); |
1472 |
|
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1473 |
|
assertEquals(1, result.size()); |
1474 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1475 |
< |
it.next().get(); |
1474 |
> |
for (Future<String> future : result) |
1475 |
> |
future.get(); |
1476 |
|
shouldThrow(); |
1477 |
|
} catch (ExecutionException success) { |
1478 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
1479 |
|
} finally { |
1480 |
|
joinPool(e); |
1481 |
|
} |
1492 |
|
l.add(new StringTask()); |
1493 |
|
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
1494 |
|
assertEquals(2, result.size()); |
1495 |
< |
for (Iterator<Future<String>> it = result.iterator(); it.hasNext();) |
1496 |
< |
assertSame(TEST_STRING, it.next().get()); |
1497 |
< |
shouldThrow(); |
1495 |
> |
for (Future<String> future : result) |
1496 |
> |
assertSame(TEST_STRING, future.get()); |
1497 |
|
} catch (ExecutionException success) { |
1498 |
|
} finally { |
1499 |
|
joinPool(e); |
1533 |
|
public void testFailingThreadFactory() throws InterruptedException { |
1534 |
|
ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory()); |
1535 |
|
try { |
1537 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1536 |
|
for (int k = 0; k < 100; ++k) { |
1537 |
|
e.execute(new NoOpRunnable()); |
1538 |
|
} |