ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java (file contents):
Revision 1.5 by jsr166, Wed Nov 18 16:51:26 2009 UTC vs.
Revision 1.6 by jsr166, Fri Nov 20 06:33:25 2009 UTC

# Line 14 | Line 14 | import java.util.*;
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> {
# Line 29 | Line 29 | public class ThreadPoolExecutorSubclassT
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() {
# Line 995 | Line 1000 | public class ThreadPoolExecutorSubclassT
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();
# Line 1276 | Line 1279 | public class ThreadPoolExecutorSubclassT
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 {
# Line 1296 | Line 1299 | public class ThreadPoolExecutorSubclassT
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          }
# Line 1395 | Line 1396 | public class ThreadPoolExecutorSubclassT
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          }
# Line 1472 | Line 1471 | public class ThreadPoolExecutorSubclassT
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          }
# Line 1492 | Line 1492 | public class ThreadPoolExecutorSubclassT
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);
# Line 1534 | Line 1533 | public class ThreadPoolExecutorSubclassT
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              }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines