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.7 by jsr166, Fri Nov 20 16:02:10 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 1175 | Line 1178 | public class ThreadPoolExecutorSubclassT
1178          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1179          try {
1180              ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1181 <            l.add(new CheckedCallable<String>() {
1182 <                      public String realCall() throws InterruptedException {
1183 <                          latch.await();
1181 >            l.add(new Callable<String>() {
1182 >                      public String call() {
1183 >                          try {
1184 >                              latch.await();
1185 >                          } catch (InterruptedException ok) {}
1186                            return TEST_STRING;
1187                        }});
1188              l.add(null);
# Line 1276 | Line 1281 | public class ThreadPoolExecutorSubclassT
1281              l.add(new NPETask());
1282              List<Future<String>> result = e.invokeAll(l);
1283              assertEquals(1, result.size());
1284 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1285 <                it.next().get();
1284 >            for (Future<String> future : result)
1285 >                future.get();
1286              shouldThrow();
1287          } catch (ExecutionException success) {
1288          } finally {
# Line 1296 | Line 1301 | public class ThreadPoolExecutorSubclassT
1301              l.add(new StringTask());
1302              List<Future<String>> result = e.invokeAll(l);
1303              assertEquals(2, result.size());
1304 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1305 <                assertSame(TEST_STRING, it.next().get());
1301 <            shouldThrow();
1302 <        } catch (ExecutionException success) {
1304 >            for (Future<String> future : result)
1305 >                assertSame(TEST_STRING, future.get());
1306          } finally {
1307              joinPool(e);
1308          }
# Line 1395 | Line 1398 | public class ThreadPoolExecutorSubclassT
1398              l.add(new StringTask());
1399              String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1400              assertSame(TEST_STRING, result);
1398            shouldThrow();
1399        } catch (ExecutionException success) {
1401          } finally {
1402              joinPool(e);
1403          }
# Line 1472 | Line 1473 | public class ThreadPoolExecutorSubclassT
1473              l.add(new NPETask());
1474              List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1475              assertEquals(1, result.size());
1476 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1477 <                it.next().get();
1476 >            for (Future<String> future : result)
1477 >                future.get();
1478              shouldThrow();
1479          } catch (ExecutionException success) {
1480 +            assertTrue(success.getCause() instanceof NullPointerException);
1481          } finally {
1482              joinPool(e);
1483          }
# Line 1492 | Line 1494 | public class ThreadPoolExecutorSubclassT
1494              l.add(new StringTask());
1495              List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
1496              assertEquals(2, result.size());
1497 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1498 <                assertSame(TEST_STRING, it.next().get());
1497 <            shouldThrow();
1497 >            for (Future<String> future : result)
1498 >                assertSame(TEST_STRING, future.get());
1499          } catch (ExecutionException success) {
1500          } finally {
1501              joinPool(e);
# Line 1534 | Line 1535 | public class ThreadPoolExecutorSubclassT
1535      public void testFailingThreadFactory() throws InterruptedException {
1536          ExecutorService e = new CustomTPE(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1537          try {
1537            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1538              for (int k = 0; k < 100; ++k) {
1539                  e.execute(new NoOpRunnable());
1540              }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines