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.80 by jsr166, Sun Oct 4 06:39:13 2015 UTC vs.
Revision 1.87 by jsr166, Mon Oct 5 22:19:00 2015 UTC

# Line 262 | Line 262 | public class ThreadPoolExecutorSubclassT
262                      assertEquals(1, p.getActiveCount());
263                      done.await();
264                  }});
265 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
265 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
266              assertEquals(1, p.getActiveCount());
267              done.countDown();
268          }
# Line 476 | Line 476 | public class ThreadPoolExecutorSubclassT
476       */
477      public void testGetLargestPoolSize() throws InterruptedException {
478          final int THREADS = 3;
479 +        final CountDownLatch done = new CountDownLatch(1);
480          final ThreadPoolExecutor p =
481              new CustomTPE(THREADS, THREADS,
482                            LONG_DELAY_MS, MILLISECONDS,
483                            new ArrayBlockingQueue<Runnable>(10));
484 <        try (PoolCleaner cleaner = cleaner(p)) {
484 <            final CountDownLatch threadsStarted = new CountDownLatch(THREADS);
485 <            final CountDownLatch done = new CountDownLatch(1);
484 >        try (PoolCleaner cleaner = cleaner(p, done)) {
485              assertEquals(0, p.getLargestPoolSize());
486 +            final CountDownLatch threadsStarted = new CountDownLatch(THREADS);
487              for (int i = 0; i < THREADS; i++)
488                  p.execute(new CheckedRunnable() {
489                      public void realRun() throws InterruptedException {
# Line 491 | Line 491 | public class ThreadPoolExecutorSubclassT
491                          done.await();
492                          assertEquals(THREADS, p.getLargestPoolSize());
493                      }});
494 <            assertTrue(threadsStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
494 >            assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS));
495              assertEquals(THREADS, p.getLargestPoolSize());
496            done.countDown();   // release pool
496          }
497          assertEquals(THREADS, p.getLargestPoolSize());
498      }
# Line 521 | Line 520 | public class ThreadPoolExecutorSubclassT
520       * become active
521       */
522      public void testGetPoolSize() throws InterruptedException {
523 +        final CountDownLatch done = new CountDownLatch(1);
524          final ThreadPoolExecutor p =
525              new CustomTPE(1, 1,
526                            LONG_DELAY_MS, MILLISECONDS,
527                            new ArrayBlockingQueue<Runnable>(10));
528 <        try (PoolCleaner cleaner = cleaner(p)) {
529 <            final CountDownLatch threadStarted = new CountDownLatch(1);
530 <            final CountDownLatch done = new CountDownLatch(1);
528 >        try (PoolCleaner cleaner = cleaner(p, done)) {
529              assertEquals(0, p.getPoolSize());
530 +            final CountDownLatch threadStarted = new CountDownLatch(1);
531              p.execute(new CheckedRunnable() {
532                  public void realRun() throws InterruptedException {
533                      threadStarted.countDown();
534                      assertEquals(1, p.getPoolSize());
535                      done.await();
536                  }});
537 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
537 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
538              assertEquals(1, p.getPoolSize());
540            done.countDown();   // release pool
539          }
540      }
541  
# Line 545 | Line 543 | public class ThreadPoolExecutorSubclassT
543       * getTaskCount increases, but doesn't overestimate, when tasks submitted
544       */
545      public void testGetTaskCount() throws InterruptedException {
546 +        final int TASKS = 3;
547 +        final CountDownLatch done = new CountDownLatch(1);
548          final ThreadPoolExecutor p =
549              new CustomTPE(1, 1,
550                            LONG_DELAY_MS, MILLISECONDS,
551                            new ArrayBlockingQueue<Runnable>(10));
552 <        try (PoolCleaner cleaner = cleaner(p)) {
552 >        try (PoolCleaner cleaner = cleaner(p, done)) {
553              final CountDownLatch threadStarted = new CountDownLatch(1);
554            final CountDownLatch done = new CountDownLatch(1);
554              assertEquals(0, p.getTaskCount());
555 +            assertEquals(0, p.getCompletedTaskCount());
556              p.execute(new CheckedRunnable() {
557                  public void realRun() throws InterruptedException {
558                      threadStarted.countDown();
559                    assertEquals(1, p.getTaskCount());
559                      done.await();
560                  }});
561 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
561 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
562              assertEquals(1, p.getTaskCount());
563 <            done.countDown();
563 >            assertEquals(0, p.getCompletedTaskCount());
564 >            for (int i = 0; i < TASKS; i++) {
565 >                assertEquals(1 + i, p.getTaskCount());
566 >                p.execute(new CheckedRunnable() {
567 >                    public void realRun() throws InterruptedException {
568 >                        threadStarted.countDown();
569 >                        assertEquals(1 + TASKS, p.getTaskCount());
570 >                        done.await();
571 >                    }});
572 >            }
573 >            assertEquals(1 + TASKS, p.getTaskCount());
574 >            assertEquals(0, p.getCompletedTaskCount());
575          }
576 +        assertEquals(1 + TASKS, p.getTaskCount());
577 +        assertEquals(1 + TASKS, p.getCompletedTaskCount());
578      }
579  
580      /**
# Line 598 | Line 610 | public class ThreadPoolExecutorSubclassT
610                      threadStarted.countDown();
611                      done.await();
612                  }});
613 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
613 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
614              assertFalse(p.isTerminating());
615              done.countDown();
616              try { p.shutdown(); } catch (SecurityException ok) { return; }
# Line 626 | Line 638 | public class ThreadPoolExecutorSubclassT
638                      threadStarted.countDown();
639                      done.await();
640                  }});
641 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
641 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
642              assertFalse(p.isTerminating());
643              done.countDown();
644              try { p.shutdown(); } catch (SecurityException ok) { return; }
# Line 660 | Line 672 | public class ThreadPoolExecutorSubclassT
672                  tasks[i] = new FutureTask(task);
673                  p.execute(tasks[i]);
674              }
675 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
675 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
676              assertSame(q, p.getQueue());
677              assertFalse(q.contains(tasks[0]));
678              assertTrue(q.contains(tasks[tasks.length - 1]));
# Line 690 | Line 702 | public class ThreadPoolExecutorSubclassT
702                      }};
703                  p.execute(tasks[i]);
704              }
705 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
705 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
706              assertFalse(p.remove(tasks[0]));
707              assertTrue(q.contains(tasks[4]));
708              assertTrue(q.contains(tasks[3]));
# Line 715 | Line 727 | public class ThreadPoolExecutorSubclassT
727              new CustomTPE(1, 1,
728                            LONG_DELAY_MS, MILLISECONDS,
729                            q);
730 <        try (PoolCleaner cleaner = cleaner(p)) {
730 >        try (PoolCleaner cleaner = cleaner(p, done)) {
731              FutureTask[] tasks = new FutureTask[5];
732              for (int i = 0; i < tasks.length; i++) {
733                  Callable task = new CheckedCallable<Boolean>() {
# Line 727 | Line 739 | public class ThreadPoolExecutorSubclassT
739                  tasks[i] = new FutureTask(task);
740                  p.execute(tasks[i]);
741              }
742 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
742 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
743              assertEquals(tasks.length, p.getTaskCount());
744              assertEquals(tasks.length - 1, q.size());
745              assertEquals(1L, p.getActiveCount());
# Line 740 | Line 752 | public class ThreadPoolExecutorSubclassT
752              p.purge();         // Nothing to do
753              assertEquals(tasks.length - 3, q.size());
754              assertEquals(tasks.length - 2, p.getTaskCount());
743            done.countDown();
755          }
756      }
757  
# Line 753 | Line 764 | public class ThreadPoolExecutorSubclassT
764          final int count = 5;
765          final AtomicInteger ran = new AtomicInteger(0);
766          final ThreadPoolExecutor p =
767 <            new CustomTPE(poolSize, poolSize, LONG_DELAY_MS, MILLISECONDS,
767 >            new CustomTPE(poolSize, poolSize,
768 >                          LONG_DELAY_MS, MILLISECONDS,
769                            new ArrayBlockingQueue<Runnable>(10));
770 <        CountDownLatch threadsStarted = new CountDownLatch(poolSize);
770 >        final CountDownLatch threadsStarted = new CountDownLatch(poolSize);
771          Runnable waiter = new CheckedRunnable() { public void realRun() {
772              threadsStarted.countDown();
773              try {
# Line 1322 | Line 1334 | public class ThreadPoolExecutorSubclassT
1334       */
1335      public void testCorePoolSizeIllegalArgumentException() {
1336          final ThreadPoolExecutor p =
1337 <            new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1338 <        try {
1339 <            p.setCorePoolSize(-1);
1340 <            shouldThrow();
1341 <        } catch (IllegalArgumentException success) {
1342 <        } finally {
1343 <            try { p.shutdown(); } catch (SecurityException ok) { return; }
1337 >            new CustomTPE(1, 2,
1338 >                          LONG_DELAY_MS, MILLISECONDS,
1339 >                          new ArrayBlockingQueue<Runnable>(10));
1340 >        try (PoolCleaner cleaner = cleaner(p)) {
1341 >            try {
1342 >                p.setCorePoolSize(-1);
1343 >                shouldThrow();
1344 >            } catch (IllegalArgumentException success) {}
1345          }
1333        joinPool(p);
1346      }
1347  
1348      /**
# Line 1339 | Line 1351 | public class ThreadPoolExecutorSubclassT
1351       */
1352      public void testMaximumPoolSizeIllegalArgumentException() {
1353          final ThreadPoolExecutor p =
1354 <            new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1355 <        try {
1356 <            p.setMaximumPoolSize(1);
1357 <            shouldThrow();
1358 <        } catch (IllegalArgumentException success) {
1359 <        } finally {
1360 <            try { p.shutdown(); } catch (SecurityException ok) { return; }
1354 >            new CustomTPE(2, 3,
1355 >                          LONG_DELAY_MS, MILLISECONDS,
1356 >                          new ArrayBlockingQueue<Runnable>(10));
1357 >        try (PoolCleaner cleaner = cleaner(p)) {
1358 >            try {
1359 >                p.setMaximumPoolSize(1);
1360 >                shouldThrow();
1361 >            } catch (IllegalArgumentException success) {}
1362          }
1350        joinPool(p);
1363      }
1364  
1365      /**
# Line 1356 | Line 1368 | public class ThreadPoolExecutorSubclassT
1368       */
1369      public void testMaximumPoolSizeIllegalArgumentException2() {
1370          final ThreadPoolExecutor p =
1371 <            new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1372 <        try {
1373 <            p.setMaximumPoolSize(-1);
1374 <            shouldThrow();
1375 <        } catch (IllegalArgumentException success) {
1376 <        } finally {
1377 <            try { p.shutdown(); } catch (SecurityException ok) { return; }
1371 >            new CustomTPE(2, 3,
1372 >                          LONG_DELAY_MS,
1373 >                          MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1374 >        try (PoolCleaner cleaner = cleaner(p)) {
1375 >            try {
1376 >                p.setMaximumPoolSize(-1);
1377 >                shouldThrow();
1378 >            } catch (IllegalArgumentException success) {}
1379          }
1367        joinPool(p);
1380      }
1381  
1382      /**
# Line 1373 | Line 1385 | public class ThreadPoolExecutorSubclassT
1385       */
1386      public void testKeepAliveTimeIllegalArgumentException() {
1387          final ThreadPoolExecutor p =
1388 <            new CustomTPE(2,3,LONG_DELAY_MS, MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1389 <
1390 <        try {
1391 <            p.setKeepAliveTime(-1,MILLISECONDS);
1392 <            shouldThrow();
1393 <        } catch (IllegalArgumentException success) {
1394 <        } finally {
1395 <            try { p.shutdown(); } catch (SecurityException ok) { return; }
1388 >            new CustomTPE(2, 3,
1389 >                          LONG_DELAY_MS, MILLISECONDS,
1390 >                          new ArrayBlockingQueue<Runnable>(10));
1391 >        try (PoolCleaner cleaner = cleaner(p)) {
1392 >            try {
1393 >                p.setKeepAliveTime(-1, MILLISECONDS);
1394 >                shouldThrow();
1395 >            } catch (IllegalArgumentException success) {}
1396          }
1385        joinPool(p);
1397      }
1398  
1399      /**
# Line 1390 | Line 1401 | public class ThreadPoolExecutorSubclassT
1401       */
1402      public void testTerminated() {
1403          CustomTPE p = new CustomTPE();
1404 <        try { p.shutdown(); } catch (SecurityException ok) { return; }
1405 <        assertTrue(p.terminatedCalled());
1406 <        joinPool(p);
1404 >        try (PoolCleaner cleaner = cleaner(p)) {
1405 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
1406 >            assertTrue(p.terminatedCalled());
1407 >            assertTrue(p.isShutdown());
1408 >        }
1409      }
1410  
1411      /**
# Line 1400 | Line 1413 | public class ThreadPoolExecutorSubclassT
1413       */
1414      public void testBeforeAfter() throws InterruptedException {
1415          CustomTPE p = new CustomTPE();
1416 <        try {
1416 >        try (PoolCleaner cleaner = cleaner(p)) {
1417              final CountDownLatch done = new CountDownLatch(1);
1418              p.execute(new CheckedRunnable() {
1419                  public void realRun() {
# Line 1410 | Line 1423 | public class ThreadPoolExecutorSubclassT
1423              assertEquals(0, done.getCount());
1424              assertTrue(p.afterCalled());
1425              assertTrue(p.beforeCalled());
1413            try { p.shutdown(); } catch (SecurityException ok) { return; }
1414        } finally {
1415            joinPool(p);
1426          }
1427      }
1428  
# Line 1424 | Line 1434 | public class ThreadPoolExecutorSubclassT
1434              new CustomTPE(2, 2,
1435                            LONG_DELAY_MS, MILLISECONDS,
1436                            new ArrayBlockingQueue<Runnable>(10));
1437 <        try {
1437 >        try (PoolCleaner cleaner = cleaner(e)) {
1438              Future<String> future = e.submit(new StringTask());
1439              String result = future.get();
1440              assertSame(TEST_STRING, result);
1431        } finally {
1432            joinPool(e);
1441          }
1442      }
1443  
# Line 1441 | Line 1449 | public class ThreadPoolExecutorSubclassT
1449              new CustomTPE(2, 2,
1450                            LONG_DELAY_MS, MILLISECONDS,
1451                            new ArrayBlockingQueue<Runnable>(10));
1452 <        try {
1452 >        try (PoolCleaner cleaner = cleaner(e)) {
1453              Future<?> future = e.submit(new NoOpRunnable());
1454              future.get();
1455              assertTrue(future.isDone());
1448        } finally {
1449            joinPool(e);
1456          }
1457      }
1458  
# Line 1458 | Line 1464 | public class ThreadPoolExecutorSubclassT
1464              new CustomTPE(2, 2,
1465                            LONG_DELAY_MS, MILLISECONDS,
1466                            new ArrayBlockingQueue<Runnable>(10));
1467 <        try {
1467 >        try (PoolCleaner cleaner = cleaner(e)) {
1468              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
1469              String result = future.get();
1470              assertSame(TEST_STRING, result);
1465        } finally {
1466            joinPool(e);
1471          }
1472      }
1473  
# Line 1475 | Line 1479 | public class ThreadPoolExecutorSubclassT
1479              new CustomTPE(2, 2,
1480                            LONG_DELAY_MS, MILLISECONDS,
1481                            new ArrayBlockingQueue<Runnable>(10));
1482 <        try {
1483 <            e.invokeAny(null);
1484 <            shouldThrow();
1485 <        } catch (NullPointerException success) {
1486 <        } finally {
1483 <            joinPool(e);
1482 >        try (PoolCleaner cleaner = cleaner(e)) {
1483 >            try {
1484 >                e.invokeAny(null);
1485 >                shouldThrow();
1486 >            } catch (NullPointerException success) {}
1487          }
1488      }
1489  
# Line 1492 | Line 1495 | public class ThreadPoolExecutorSubclassT
1495              new CustomTPE(2, 2,
1496                            LONG_DELAY_MS, MILLISECONDS,
1497                            new ArrayBlockingQueue<Runnable>(10));
1498 <        try {
1499 <            e.invokeAny(new ArrayList<Callable<String>>());
1500 <            shouldThrow();
1501 <        } catch (IllegalArgumentException success) {
1502 <        } finally {
1500 <            joinPool(e);
1498 >        try (PoolCleaner cleaner = cleaner(e)) {
1499 >            try {
1500 >                e.invokeAny(new ArrayList<Callable<String>>());
1501 >                shouldThrow();
1502 >            } catch (IllegalArgumentException success) {}
1503          }
1504      }
1505  
# Line 1510 | Line 1512 | public class ThreadPoolExecutorSubclassT
1512              new CustomTPE(2, 2,
1513                            LONG_DELAY_MS, MILLISECONDS,
1514                            new ArrayBlockingQueue<Runnable>(10));
1515 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1516 <        l.add(latchAwaitingStringTask(latch));
1517 <        l.add(null);
1518 <        try {
1519 <            e.invokeAny(l);
1520 <            shouldThrow();
1521 <        } catch (NullPointerException success) {
1522 <        } finally {
1515 >        try (PoolCleaner cleaner = cleaner(e)) {
1516 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1517 >            l.add(latchAwaitingStringTask(latch));
1518 >            l.add(null);
1519 >            try {
1520 >                e.invokeAny(l);
1521 >                shouldThrow();
1522 >            } catch (NullPointerException success) {}
1523              latch.countDown();
1522            joinPool(e);
1524          }
1525      }
1526  
# Line 1531 | Line 1532 | public class ThreadPoolExecutorSubclassT
1532              new CustomTPE(2, 2,
1533                            LONG_DELAY_MS, MILLISECONDS,
1534                            new ArrayBlockingQueue<Runnable>(10));
1535 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1536 <        l.add(new NPETask());
1537 <        try {
1538 <            e.invokeAny(l);
1539 <            shouldThrow();
1540 <        } catch (ExecutionException success) {
1541 <            assertTrue(success.getCause() instanceof NullPointerException);
1542 <        } finally {
1543 <            joinPool(e);
1535 >        try (PoolCleaner cleaner = cleaner(e)) {
1536 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1537 >            l.add(new NPETask());
1538 >            try {
1539 >                e.invokeAny(l);
1540 >                shouldThrow();
1541 >            } catch (ExecutionException success) {
1542 >                assertTrue(success.getCause() instanceof NullPointerException);
1543 >            }
1544          }
1545      }
1546  
# Line 1551 | Line 1552 | public class ThreadPoolExecutorSubclassT
1552              new CustomTPE(2, 2,
1553                            LONG_DELAY_MS, MILLISECONDS,
1554                            new ArrayBlockingQueue<Runnable>(10));
1555 <        try {
1555 >        try (PoolCleaner cleaner = cleaner(e)) {
1556              List<Callable<String>> l = new ArrayList<Callable<String>>();
1557              l.add(new StringTask());
1558              l.add(new StringTask());
1559              String result = e.invokeAny(l);
1560              assertSame(TEST_STRING, result);
1560        } finally {
1561            joinPool(e);
1561          }
1562      }
1563  
# Line 1570 | Line 1569 | public class ThreadPoolExecutorSubclassT
1569              new CustomTPE(2, 2,
1570                            LONG_DELAY_MS, MILLISECONDS,
1571                            new ArrayBlockingQueue<Runnable>(10));
1572 <        try {
1573 <            e.invokeAll(null);
1574 <            shouldThrow();
1575 <        } catch (NullPointerException success) {
1576 <        } finally {
1578 <            joinPool(e);
1572 >        try (PoolCleaner cleaner = cleaner(e)) {
1573 >            try {
1574 >                e.invokeAll(null);
1575 >                shouldThrow();
1576 >            } catch (NullPointerException success) {}
1577          }
1578      }
1579  
# Line 1587 | Line 1585 | public class ThreadPoolExecutorSubclassT
1585              new CustomTPE(2, 2,
1586                            LONG_DELAY_MS, MILLISECONDS,
1587                            new ArrayBlockingQueue<Runnable>(10));
1588 <        try {
1588 >        try (PoolCleaner cleaner = cleaner(e)) {
1589              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
1590              assertTrue(r.isEmpty());
1593        } finally {
1594            joinPool(e);
1591          }
1592      }
1593  
# Line 1603 | Line 1599 | public class ThreadPoolExecutorSubclassT
1599              new CustomTPE(2, 2,
1600                            LONG_DELAY_MS, MILLISECONDS,
1601                            new ArrayBlockingQueue<Runnable>(10));
1602 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1603 <        l.add(new StringTask());
1604 <        l.add(null);
1605 <        try {
1606 <            e.invokeAll(l);
1607 <            shouldThrow();
1608 <        } catch (NullPointerException success) {
1609 <        } finally {
1614 <            joinPool(e);
1602 >        try (PoolCleaner cleaner = cleaner(e)) {
1603 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1604 >            l.add(new StringTask());
1605 >            l.add(null);
1606 >            try {
1607 >                e.invokeAll(l);
1608 >                shouldThrow();
1609 >            } catch (NullPointerException success) {}
1610          }
1611      }
1612  
# Line 1623 | Line 1618 | public class ThreadPoolExecutorSubclassT
1618              new CustomTPE(2, 2,
1619                            LONG_DELAY_MS, MILLISECONDS,
1620                            new ArrayBlockingQueue<Runnable>(10));
1621 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1622 <        l.add(new NPETask());
1623 <        List<Future<String>> futures = e.invokeAll(l);
1624 <        assertEquals(1, futures.size());
1625 <        try {
1626 <            futures.get(0).get();
1627 <            shouldThrow();
1628 <        } catch (ExecutionException success) {
1629 <            assertTrue(success.getCause() instanceof NullPointerException);
1630 <        } finally {
1631 <            joinPool(e);
1621 >        try (PoolCleaner cleaner = cleaner(e)) {
1622 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1623 >            l.add(new NPETask());
1624 >            List<Future<String>> futures = e.invokeAll(l);
1625 >            assertEquals(1, futures.size());
1626 >            try {
1627 >                futures.get(0).get();
1628 >                shouldThrow();
1629 >            } catch (ExecutionException success) {
1630 >                assertTrue(success.getCause() instanceof NullPointerException);
1631 >            }
1632          }
1633      }
1634  
# Line 1645 | Line 1640 | public class ThreadPoolExecutorSubclassT
1640              new CustomTPE(2, 2,
1641                            LONG_DELAY_MS, MILLISECONDS,
1642                            new ArrayBlockingQueue<Runnable>(10));
1643 <        try {
1643 >        try (PoolCleaner cleaner = cleaner(e)) {
1644              List<Callable<String>> l = new ArrayList<Callable<String>>();
1645              l.add(new StringTask());
1646              l.add(new StringTask());
# Line 1653 | Line 1648 | public class ThreadPoolExecutorSubclassT
1648              assertEquals(2, futures.size());
1649              for (Future<String> future : futures)
1650                  assertSame(TEST_STRING, future.get());
1656        } finally {
1657            joinPool(e);
1651          }
1652      }
1653  
# Line 1666 | Line 1659 | public class ThreadPoolExecutorSubclassT
1659              new CustomTPE(2, 2,
1660                            LONG_DELAY_MS, MILLISECONDS,
1661                            new ArrayBlockingQueue<Runnable>(10));
1662 <        try {
1663 <            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
1664 <            shouldThrow();
1665 <        } catch (NullPointerException success) {
1666 <        } finally {
1674 <            joinPool(e);
1662 >        try (PoolCleaner cleaner = cleaner(e)) {
1663 >            try {
1664 >                e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
1665 >                shouldThrow();
1666 >            } catch (NullPointerException success) {}
1667          }
1668      }
1669  
# Line 1683 | Line 1675 | public class ThreadPoolExecutorSubclassT
1675              new CustomTPE(2, 2,
1676                            LONG_DELAY_MS, MILLISECONDS,
1677                            new ArrayBlockingQueue<Runnable>(10));
1678 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1679 <        l.add(new StringTask());
1680 <        try {
1681 <            e.invokeAny(l, MEDIUM_DELAY_MS, null);
1682 <            shouldThrow();
1683 <        } catch (NullPointerException success) {
1684 <        } finally {
1693 <            joinPool(e);
1678 >        try (PoolCleaner cleaner = cleaner(e)) {
1679 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1680 >            l.add(new StringTask());
1681 >            try {
1682 >                e.invokeAny(l, MEDIUM_DELAY_MS, null);
1683 >                shouldThrow();
1684 >            } catch (NullPointerException success) {}
1685          }
1686      }
1687  
# Line 1702 | Line 1693 | public class ThreadPoolExecutorSubclassT
1693              new CustomTPE(2, 2,
1694                            LONG_DELAY_MS, MILLISECONDS,
1695                            new ArrayBlockingQueue<Runnable>(10));
1696 <        try {
1697 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1698 <            shouldThrow();
1699 <        } catch (IllegalArgumentException success) {
1700 <        } finally {
1701 <            joinPool(e);
1696 >        try (PoolCleaner cleaner = cleaner(e)) {
1697 >            try {
1698 >                e.invokeAny(new ArrayList<Callable<String>>(),
1699 >                            MEDIUM_DELAY_MS, MILLISECONDS);
1700 >                shouldThrow();
1701 >            } catch (IllegalArgumentException success) {}
1702          }
1703      }
1704  
# Line 1720 | Line 1711 | public class ThreadPoolExecutorSubclassT
1711              new CustomTPE(2, 2,
1712                            LONG_DELAY_MS, MILLISECONDS,
1713                            new ArrayBlockingQueue<Runnable>(10));
1714 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1715 <        l.add(latchAwaitingStringTask(latch));
1716 <        l.add(null);
1717 <        try {
1718 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1719 <            shouldThrow();
1720 <        } catch (NullPointerException success) {
1721 <        } finally {
1714 >        try (PoolCleaner cleaner = cleaner(e)) {
1715 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1716 >            l.add(latchAwaitingStringTask(latch));
1717 >            l.add(null);
1718 >            try {
1719 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1720 >                shouldThrow();
1721 >            } catch (NullPointerException success) {}
1722              latch.countDown();
1732            joinPool(e);
1723          }
1724      }
1725  
# Line 1741 | Line 1731 | public class ThreadPoolExecutorSubclassT
1731              new CustomTPE(2, 2,
1732                            LONG_DELAY_MS, MILLISECONDS,
1733                            new ArrayBlockingQueue<Runnable>(10));
1734 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1735 <        l.add(new NPETask());
1736 <        try {
1737 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1738 <            shouldThrow();
1739 <        } catch (ExecutionException success) {
1740 <            assertTrue(success.getCause() instanceof NullPointerException);
1741 <        } finally {
1742 <            joinPool(e);
1734 >        try (PoolCleaner cleaner = cleaner(e)) {
1735 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1736 >            l.add(new NPETask());
1737 >            try {
1738 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1739 >                shouldThrow();
1740 >            } catch (ExecutionException success) {
1741 >                assertTrue(success.getCause() instanceof NullPointerException);
1742 >            }
1743          }
1744      }
1745  
# Line 1761 | Line 1751 | public class ThreadPoolExecutorSubclassT
1751              new CustomTPE(2, 2,
1752                            LONG_DELAY_MS, MILLISECONDS,
1753                            new ArrayBlockingQueue<Runnable>(10));
1754 <        try {
1754 >        try (PoolCleaner cleaner = cleaner(e)) {
1755              List<Callable<String>> l = new ArrayList<Callable<String>>();
1756              l.add(new StringTask());
1757              l.add(new StringTask());
1758              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1759              assertSame(TEST_STRING, result);
1770        } finally {
1771            joinPool(e);
1760          }
1761      }
1762  
# Line 1780 | Line 1768 | public class ThreadPoolExecutorSubclassT
1768              new CustomTPE(2, 2,
1769                            LONG_DELAY_MS, MILLISECONDS,
1770                            new ArrayBlockingQueue<Runnable>(10));
1771 <        try {
1772 <            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
1773 <            shouldThrow();
1774 <        } catch (NullPointerException success) {
1775 <        } finally {
1788 <            joinPool(e);
1771 >        try (PoolCleaner cleaner = cleaner(e)) {
1772 >            try {
1773 >                e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
1774 >                shouldThrow();
1775 >            } catch (NullPointerException success) {}
1776          }
1777      }
1778  
# Line 1797 | Line 1784 | public class ThreadPoolExecutorSubclassT
1784              new CustomTPE(2, 2,
1785                            LONG_DELAY_MS, MILLISECONDS,
1786                            new ArrayBlockingQueue<Runnable>(10));
1787 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1788 <        l.add(new StringTask());
1789 <        try {
1790 <            e.invokeAll(l, MEDIUM_DELAY_MS, null);
1791 <            shouldThrow();
1792 <        } catch (NullPointerException success) {
1793 <        } finally {
1807 <            joinPool(e);
1787 >        try (PoolCleaner cleaner = cleaner(e)) {
1788 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1789 >            l.add(new StringTask());
1790 >            try {
1791 >                e.invokeAll(l, MEDIUM_DELAY_MS, null);
1792 >                shouldThrow();
1793 >            } catch (NullPointerException success) {}
1794          }
1795      }
1796  
# Line 1816 | Line 1802 | public class ThreadPoolExecutorSubclassT
1802              new CustomTPE(2, 2,
1803                            LONG_DELAY_MS, MILLISECONDS,
1804                            new ArrayBlockingQueue<Runnable>(10));
1805 <        try {
1806 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1805 >        try (PoolCleaner cleaner = cleaner(e)) {
1806 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(),
1807 >                                                 MEDIUM_DELAY_MS, MILLISECONDS);
1808              assertTrue(r.isEmpty());
1822        } finally {
1823            joinPool(e);
1809          }
1810      }
1811  
# Line 1832 | Line 1817 | public class ThreadPoolExecutorSubclassT
1817              new CustomTPE(2, 2,
1818                            LONG_DELAY_MS, MILLISECONDS,
1819                            new ArrayBlockingQueue<Runnable>(10));
1820 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1821 <        l.add(new StringTask());
1822 <        l.add(null);
1823 <        try {
1824 <            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1825 <            shouldThrow();
1826 <        } catch (NullPointerException success) {
1827 <        } finally {
1843 <            joinPool(e);
1820 >        try (PoolCleaner cleaner = cleaner(e)) {
1821 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1822 >            l.add(new StringTask());
1823 >            l.add(null);
1824 >            try {
1825 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1826 >                shouldThrow();
1827 >            } catch (NullPointerException success) {}
1828          }
1829      }
1830  
# Line 1852 | Line 1836 | public class ThreadPoolExecutorSubclassT
1836              new CustomTPE(2, 2,
1837                            LONG_DELAY_MS, MILLISECONDS,
1838                            new ArrayBlockingQueue<Runnable>(10));
1839 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1840 <        l.add(new NPETask());
1841 <        List<Future<String>> futures =
1842 <            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1843 <        assertEquals(1, futures.size());
1844 <        try {
1845 <            futures.get(0).get();
1846 <            shouldThrow();
1847 <        } catch (ExecutionException success) {
1848 <            assertTrue(success.getCause() instanceof NullPointerException);
1849 <        } finally {
1850 <            joinPool(e);
1839 >        try (PoolCleaner cleaner = cleaner(e)) {
1840 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1841 >            l.add(new NPETask());
1842 >            List<Future<String>> futures =
1843 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1844 >            assertEquals(1, futures.size());
1845 >            try {
1846 >                futures.get(0).get();
1847 >                shouldThrow();
1848 >            } catch (ExecutionException success) {
1849 >                assertTrue(success.getCause() instanceof NullPointerException);
1850 >            }
1851          }
1852      }
1853  
# Line 1875 | Line 1859 | public class ThreadPoolExecutorSubclassT
1859              new CustomTPE(2, 2,
1860                            LONG_DELAY_MS, MILLISECONDS,
1861                            new ArrayBlockingQueue<Runnable>(10));
1862 <        try {
1862 >        try (PoolCleaner cleaner = cleaner(e)) {
1863              List<Callable<String>> l = new ArrayList<Callable<String>>();
1864              l.add(new StringTask());
1865              l.add(new StringTask());
# Line 1884 | Line 1868 | public class ThreadPoolExecutorSubclassT
1868              assertEquals(2, futures.size());
1869              for (Future<String> future : futures)
1870                  assertSame(TEST_STRING, future.get());
1887        } finally {
1888            joinPool(e);
1871          }
1872      }
1873  
# Line 1897 | Line 1879 | public class ThreadPoolExecutorSubclassT
1879              new CustomTPE(2, 2,
1880                            LONG_DELAY_MS, MILLISECONDS,
1881                            new ArrayBlockingQueue<Runnable>(10));
1882 <        try {
1882 >        try (PoolCleaner cleaner = cleaner(e)) {
1883              for (long timeout = timeoutMillis();;) {
1884                  List<Callable<String>> tasks = new ArrayList<>();
1885                  tasks.add(new StringTask("0"));
# Line 1921 | Line 1903 | public class ThreadPoolExecutorSubclassT
1903                          fail("expected exactly one task to be cancelled");
1904                  }
1905              }
1924        } finally {
1925            joinPool(e);
1906          }
1907      }
1908  
# Line 1936 | Line 1916 | public class ThreadPoolExecutorSubclassT
1916                            LONG_DELAY_MS, MILLISECONDS,
1917                            new LinkedBlockingQueue<Runnable>(),
1918                            new FailingThreadFactory());
1919 <        try {
1919 >        try (PoolCleaner cleaner = cleaner(e)) {
1920              final int TASKS = 100;
1921              final CountDownLatch done = new CountDownLatch(TASKS);
1922              for (int k = 0; k < TASKS; ++k)
# Line 1945 | Line 1925 | public class ThreadPoolExecutorSubclassT
1925                          done.countDown();
1926                      }});
1927              assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
1948        } finally {
1949            joinPool(e);
1928          }
1929      }
1930  
# Line 1958 | Line 1936 | public class ThreadPoolExecutorSubclassT
1936              new CustomTPE(2, 2,
1937                            1000, MILLISECONDS,
1938                            new ArrayBlockingQueue<Runnable>(10));
1939 <        assertFalse(p.allowsCoreThreadTimeOut());
1940 <        joinPool(p);
1939 >        try (PoolCleaner cleaner = cleaner(p)) {
1940 >            assertFalse(p.allowsCoreThreadTimeOut());
1941 >        }
1942      }
1943  
1944      /**
# Line 1971 | Line 1950 | public class ThreadPoolExecutorSubclassT
1950              new CustomTPE(2, 10,
1951                            keepAliveTime, MILLISECONDS,
1952                            new ArrayBlockingQueue<Runnable>(10));
1953 <        final CountDownLatch threadStarted = new CountDownLatch(1);
1954 <        try {
1953 >        try (PoolCleaner cleaner = cleaner(p)) {
1954 >            final CountDownLatch threadStarted = new CountDownLatch(1);
1955              p.allowCoreThreadTimeOut(true);
1956              p.execute(new CheckedRunnable() {
1957                  public void realRun() {
# Line 1987 | Line 1966 | public class ThreadPoolExecutorSubclassT
1966                  Thread.yield();
1967              assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1968              assertEquals(0, p.getPoolSize());
1990        } finally {
1991            joinPool(p);
1969          }
1970      }
1971  
# Line 2001 | Line 1978 | public class ThreadPoolExecutorSubclassT
1978              new CustomTPE(2, 10,
1979                            keepAliveTime, MILLISECONDS,
1980                            new ArrayBlockingQueue<Runnable>(10));
1981 <        final CountDownLatch threadStarted = new CountDownLatch(1);
1982 <        try {
1981 >        try (PoolCleaner cleaner = cleaner(p)) {
1982 >            final CountDownLatch threadStarted = new CountDownLatch(1);
1983              p.allowCoreThreadTimeOut(false);
1984              p.execute(new CheckedRunnable() {
1985                  public void realRun() throws InterruptedException {
# Line 2011 | Line 1988 | public class ThreadPoolExecutorSubclassT
1988                  }});
1989              delay(2 * keepAliveTime);
1990              assertTrue(p.getPoolSize() >= 1);
2014        } finally {
2015            joinPool(p);
1991          }
1992      }
1993  
# Line 2025 | Line 2000 | public class ThreadPoolExecutorSubclassT
2000              new CustomTPE(1, 1,
2001                            LONG_DELAY_MS, MILLISECONDS,
2002                            new LinkedBlockingQueue<Runnable>());
2003 <        try {
2003 >        try (PoolCleaner cleaner = cleaner(e)) {
2004              final CountDownLatch blockerStarted = new CountDownLatch(1);
2005              final CountDownLatch done = new CountDownLatch(1);
2006              final List<Future<?>> futures = new ArrayList<>();
# Line 2052 | Line 2027 | public class ThreadPoolExecutorSubclassT
2027                  assertTrue(future.isDone());
2028              }
2029              done.countDown();
2055        } finally {
2056            joinPool(e);
2030          }
2031      }
2032  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines