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.81 by jsr166, Sun Oct 4 06:45:29 2015 UTC vs.
Revision 1.86 by jsr166, Mon Oct 5 22:09:02 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 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
497          }
# Line 535 | Line 535 | public class ThreadPoolExecutorSubclassT
535                      assertEquals(1, p.getPoolSize());
536                      done.await();
537                  }});
538 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
538 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
539              assertEquals(1, p.getPoolSize());
540              done.countDown();   // release pool
541          }
# Line 545 | Line 545 | public class ThreadPoolExecutorSubclassT
545       * getTaskCount increases, but doesn't overestimate, when tasks submitted
546       */
547      public void testGetTaskCount() throws InterruptedException {
548 +        final int TASKS = 3;
549 +        final CountDownLatch done = new CountDownLatch(1);
550          final ThreadPoolExecutor p =
551              new CustomTPE(1, 1,
552                            LONG_DELAY_MS, MILLISECONDS,
553                            new ArrayBlockingQueue<Runnable>(10));
554 <        try (PoolCleaner cleaner = cleaner(p)) {
554 >        try (PoolCleaner cleaner = cleaner(p, done)) {
555              final CountDownLatch threadStarted = new CountDownLatch(1);
554            final CountDownLatch done = new CountDownLatch(1);
556              assertEquals(0, p.getTaskCount());
557 +            assertEquals(0, p.getCompletedTaskCount());
558              p.execute(new CheckedRunnable() {
559                  public void realRun() throws InterruptedException {
560                      threadStarted.countDown();
559                    assertEquals(1, p.getTaskCount());
561                      done.await();
562                  }});
563 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
563 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
564              assertEquals(1, p.getTaskCount());
565 <            done.countDown();
565 >            assertEquals(0, p.getCompletedTaskCount());
566 >            for (int i = 0; i < TASKS; i++) {
567 >                assertEquals(1 + i, p.getTaskCount());
568 >                p.execute(new CheckedRunnable() {
569 >                    public void realRun() throws InterruptedException {
570 >                        threadStarted.countDown();
571 >                        assertEquals(1 + TASKS, p.getTaskCount());
572 >                        done.await();
573 >                    }});
574 >            }
575 >            assertEquals(1 + TASKS, p.getTaskCount());
576 >            assertEquals(0, p.getCompletedTaskCount());
577          }
578 +        assertEquals(1 + TASKS, p.getTaskCount());
579 +        assertEquals(1 + TASKS, p.getCompletedTaskCount());
580      }
581  
582      /**
# Line 598 | Line 612 | public class ThreadPoolExecutorSubclassT
612                      threadStarted.countDown();
613                      done.await();
614                  }});
615 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
615 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
616              assertFalse(p.isTerminating());
617              done.countDown();
618              try { p.shutdown(); } catch (SecurityException ok) { return; }
# Line 626 | Line 640 | public class ThreadPoolExecutorSubclassT
640                      threadStarted.countDown();
641                      done.await();
642                  }});
643 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
643 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
644              assertFalse(p.isTerminating());
645              done.countDown();
646              try { p.shutdown(); } catch (SecurityException ok) { return; }
# Line 660 | Line 674 | public class ThreadPoolExecutorSubclassT
674                  tasks[i] = new FutureTask(task);
675                  p.execute(tasks[i]);
676              }
677 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
677 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
678              assertSame(q, p.getQueue());
679              assertFalse(q.contains(tasks[0]));
680              assertTrue(q.contains(tasks[tasks.length - 1]));
# Line 690 | Line 704 | public class ThreadPoolExecutorSubclassT
704                      }};
705                  p.execute(tasks[i]);
706              }
707 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
707 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
708              assertFalse(p.remove(tasks[0]));
709              assertTrue(q.contains(tasks[4]));
710              assertTrue(q.contains(tasks[3]));
# Line 715 | Line 729 | public class ThreadPoolExecutorSubclassT
729              new CustomTPE(1, 1,
730                            LONG_DELAY_MS, MILLISECONDS,
731                            q);
732 <        try (PoolCleaner cleaner = cleaner(p)) {
732 >        try (PoolCleaner cleaner = cleaner(p, done)) {
733              FutureTask[] tasks = new FutureTask[5];
734              for (int i = 0; i < tasks.length; i++) {
735                  Callable task = new CheckedCallable<Boolean>() {
# Line 727 | Line 741 | public class ThreadPoolExecutorSubclassT
741                  tasks[i] = new FutureTask(task);
742                  p.execute(tasks[i]);
743              }
744 <            assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS));
744 >            assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS));
745              assertEquals(tasks.length, p.getTaskCount());
746              assertEquals(tasks.length - 1, q.size());
747              assertEquals(1L, p.getActiveCount());
# Line 740 | Line 754 | public class ThreadPoolExecutorSubclassT
754              p.purge();         // Nothing to do
755              assertEquals(tasks.length - 3, q.size());
756              assertEquals(tasks.length - 2, p.getTaskCount());
743            done.countDown();
757          }
758      }
759  
# Line 756 | Line 769 | public class ThreadPoolExecutorSubclassT
769              new CustomTPE(poolSize, poolSize,
770                            LONG_DELAY_MS, MILLISECONDS,
771                            new ArrayBlockingQueue<Runnable>(10));
772 <        CountDownLatch threadsStarted = new CountDownLatch(poolSize);
772 >        final CountDownLatch threadsStarted = new CountDownLatch(poolSize);
773          Runnable waiter = new CheckedRunnable() { public void realRun() {
774              threadsStarted.countDown();
775              try {
# Line 1343 | Line 1356 | public class ThreadPoolExecutorSubclassT
1356              new CustomTPE(2, 3,
1357                            LONG_DELAY_MS, MILLISECONDS,
1358                            new ArrayBlockingQueue<Runnable>(10));
1359 <        try {
1360 <            p.setMaximumPoolSize(1);
1361 <            shouldThrow();
1362 <        } catch (IllegalArgumentException success) {
1363 <        } finally {
1351 <            try { p.shutdown(); } catch (SecurityException ok) { return; }
1359 >        try (PoolCleaner cleaner = cleaner(p)) {
1360 >            try {
1361 >                p.setMaximumPoolSize(1);
1362 >                shouldThrow();
1363 >            } catch (IllegalArgumentException success) {}
1364          }
1353        joinPool(p);
1365      }
1366  
1367      /**
# Line 1362 | Line 1373 | public class ThreadPoolExecutorSubclassT
1373              new CustomTPE(2, 3,
1374                            LONG_DELAY_MS,
1375                            MILLISECONDS,new ArrayBlockingQueue<Runnable>(10));
1376 <        try {
1377 <            p.setMaximumPoolSize(-1);
1378 <            shouldThrow();
1379 <        } catch (IllegalArgumentException success) {
1380 <        } finally {
1370 <            try { p.shutdown(); } catch (SecurityException ok) { return; }
1376 >        try (PoolCleaner cleaner = cleaner(p)) {
1377 >            try {
1378 >                p.setMaximumPoolSize(-1);
1379 >                shouldThrow();
1380 >            } catch (IllegalArgumentException success) {}
1381          }
1372        joinPool(p);
1382      }
1383  
1384      /**
# Line 1381 | Line 1390 | public class ThreadPoolExecutorSubclassT
1390              new CustomTPE(2, 3,
1391                            LONG_DELAY_MS, MILLISECONDS,
1392                            new ArrayBlockingQueue<Runnable>(10));
1393 <
1394 <        try {
1395 <            p.setKeepAliveTime(-1,MILLISECONDS);
1396 <            shouldThrow();
1397 <        } catch (IllegalArgumentException success) {
1389 <        } finally {
1390 <            try { p.shutdown(); } catch (SecurityException ok) { return; }
1393 >        try (PoolCleaner cleaner = cleaner(p)) {
1394 >            try {
1395 >                p.setKeepAliveTime(-1, MILLISECONDS);
1396 >                shouldThrow();
1397 >            } catch (IllegalArgumentException success) {}
1398          }
1392        joinPool(p);
1399      }
1400  
1401      /**
# Line 1397 | Line 1403 | public class ThreadPoolExecutorSubclassT
1403       */
1404      public void testTerminated() {
1405          CustomTPE p = new CustomTPE();
1406 <        try { p.shutdown(); } catch (SecurityException ok) { return; }
1407 <        assertTrue(p.terminatedCalled());
1408 <        joinPool(p);
1406 >        try (PoolCleaner cleaner = cleaner(p)) {
1407 >            try { p.shutdown(); } catch (SecurityException ok) { return; }
1408 >            assertTrue(p.terminatedCalled());
1409 >            assertTrue(p.isShutdown());
1410 >        }
1411      }
1412  
1413      /**
# Line 1407 | Line 1415 | public class ThreadPoolExecutorSubclassT
1415       */
1416      public void testBeforeAfter() throws InterruptedException {
1417          CustomTPE p = new CustomTPE();
1418 <        try {
1418 >        try (PoolCleaner cleaner = cleaner(p)) {
1419              final CountDownLatch done = new CountDownLatch(1);
1420              p.execute(new CheckedRunnable() {
1421                  public void realRun() {
# Line 1417 | Line 1425 | public class ThreadPoolExecutorSubclassT
1425              assertEquals(0, done.getCount());
1426              assertTrue(p.afterCalled());
1427              assertTrue(p.beforeCalled());
1420            try { p.shutdown(); } catch (SecurityException ok) { return; }
1421        } finally {
1422            joinPool(p);
1428          }
1429      }
1430  
# Line 1431 | Line 1436 | public class ThreadPoolExecutorSubclassT
1436              new CustomTPE(2, 2,
1437                            LONG_DELAY_MS, MILLISECONDS,
1438                            new ArrayBlockingQueue<Runnable>(10));
1439 <        try {
1439 >        try (PoolCleaner cleaner = cleaner(e)) {
1440              Future<String> future = e.submit(new StringTask());
1441              String result = future.get();
1442              assertSame(TEST_STRING, result);
1438        } finally {
1439            joinPool(e);
1443          }
1444      }
1445  
# Line 1448 | Line 1451 | public class ThreadPoolExecutorSubclassT
1451              new CustomTPE(2, 2,
1452                            LONG_DELAY_MS, MILLISECONDS,
1453                            new ArrayBlockingQueue<Runnable>(10));
1454 <        try {
1454 >        try (PoolCleaner cleaner = cleaner(e)) {
1455              Future<?> future = e.submit(new NoOpRunnable());
1456              future.get();
1457              assertTrue(future.isDone());
1455        } finally {
1456            joinPool(e);
1458          }
1459      }
1460  
# Line 1465 | Line 1466 | public class ThreadPoolExecutorSubclassT
1466              new CustomTPE(2, 2,
1467                            LONG_DELAY_MS, MILLISECONDS,
1468                            new ArrayBlockingQueue<Runnable>(10));
1469 <        try {
1469 >        try (PoolCleaner cleaner = cleaner(e)) {
1470              Future<String> future = e.submit(new NoOpRunnable(), TEST_STRING);
1471              String result = future.get();
1472              assertSame(TEST_STRING, result);
1472        } finally {
1473            joinPool(e);
1473          }
1474      }
1475  
# Line 1482 | Line 1481 | public class ThreadPoolExecutorSubclassT
1481              new CustomTPE(2, 2,
1482                            LONG_DELAY_MS, MILLISECONDS,
1483                            new ArrayBlockingQueue<Runnable>(10));
1484 <        try {
1485 <            e.invokeAny(null);
1486 <            shouldThrow();
1487 <        } catch (NullPointerException success) {
1488 <        } finally {
1490 <            joinPool(e);
1484 >        try (PoolCleaner cleaner = cleaner(e)) {
1485 >            try {
1486 >                e.invokeAny(null);
1487 >                shouldThrow();
1488 >            } catch (NullPointerException success) {}
1489          }
1490      }
1491  
# Line 1499 | Line 1497 | public class ThreadPoolExecutorSubclassT
1497              new CustomTPE(2, 2,
1498                            LONG_DELAY_MS, MILLISECONDS,
1499                            new ArrayBlockingQueue<Runnable>(10));
1500 <        try {
1501 <            e.invokeAny(new ArrayList<Callable<String>>());
1502 <            shouldThrow();
1503 <        } catch (IllegalArgumentException success) {
1504 <        } finally {
1507 <            joinPool(e);
1500 >        try (PoolCleaner cleaner = cleaner(e)) {
1501 >            try {
1502 >                e.invokeAny(new ArrayList<Callable<String>>());
1503 >                shouldThrow();
1504 >            } catch (IllegalArgumentException success) {}
1505          }
1506      }
1507  
# Line 1517 | Line 1514 | public class ThreadPoolExecutorSubclassT
1514              new CustomTPE(2, 2,
1515                            LONG_DELAY_MS, MILLISECONDS,
1516                            new ArrayBlockingQueue<Runnable>(10));
1517 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1518 <        l.add(latchAwaitingStringTask(latch));
1519 <        l.add(null);
1520 <        try {
1521 <            e.invokeAny(l);
1522 <            shouldThrow();
1523 <        } catch (NullPointerException success) {
1524 <        } finally {
1517 >        try (PoolCleaner cleaner = cleaner(e)) {
1518 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1519 >            l.add(latchAwaitingStringTask(latch));
1520 >            l.add(null);
1521 >            try {
1522 >                e.invokeAny(l);
1523 >                shouldThrow();
1524 >            } catch (NullPointerException success) {}
1525              latch.countDown();
1529            joinPool(e);
1526          }
1527      }
1528  
# Line 1538 | Line 1534 | public class ThreadPoolExecutorSubclassT
1534              new CustomTPE(2, 2,
1535                            LONG_DELAY_MS, MILLISECONDS,
1536                            new ArrayBlockingQueue<Runnable>(10));
1537 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1538 <        l.add(new NPETask());
1539 <        try {
1540 <            e.invokeAny(l);
1541 <            shouldThrow();
1542 <        } catch (ExecutionException success) {
1543 <            assertTrue(success.getCause() instanceof NullPointerException);
1544 <        } finally {
1545 <            joinPool(e);
1537 >        try (PoolCleaner cleaner = cleaner(e)) {
1538 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1539 >            l.add(new NPETask());
1540 >            try {
1541 >                e.invokeAny(l);
1542 >                shouldThrow();
1543 >            } catch (ExecutionException success) {
1544 >                assertTrue(success.getCause() instanceof NullPointerException);
1545 >            }
1546          }
1547      }
1548  
# Line 1558 | Line 1554 | public class ThreadPoolExecutorSubclassT
1554              new CustomTPE(2, 2,
1555                            LONG_DELAY_MS, MILLISECONDS,
1556                            new ArrayBlockingQueue<Runnable>(10));
1557 <        try {
1557 >        try (PoolCleaner cleaner = cleaner(e)) {
1558              List<Callable<String>> l = new ArrayList<Callable<String>>();
1559              l.add(new StringTask());
1560              l.add(new StringTask());
1561              String result = e.invokeAny(l);
1562              assertSame(TEST_STRING, result);
1567        } finally {
1568            joinPool(e);
1563          }
1564      }
1565  
# Line 1577 | Line 1571 | public class ThreadPoolExecutorSubclassT
1571              new CustomTPE(2, 2,
1572                            LONG_DELAY_MS, MILLISECONDS,
1573                            new ArrayBlockingQueue<Runnable>(10));
1574 <        try {
1575 <            e.invokeAll(null);
1576 <            shouldThrow();
1577 <        } catch (NullPointerException success) {
1578 <        } finally {
1585 <            joinPool(e);
1574 >        try (PoolCleaner cleaner = cleaner(e)) {
1575 >            try {
1576 >                e.invokeAll(null);
1577 >                shouldThrow();
1578 >            } catch (NullPointerException success) {}
1579          }
1580      }
1581  
# Line 1594 | Line 1587 | public class ThreadPoolExecutorSubclassT
1587              new CustomTPE(2, 2,
1588                            LONG_DELAY_MS, MILLISECONDS,
1589                            new ArrayBlockingQueue<Runnable>(10));
1590 <        try {
1590 >        try (PoolCleaner cleaner = cleaner(e)) {
1591              List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
1592              assertTrue(r.isEmpty());
1600        } finally {
1601            joinPool(e);
1593          }
1594      }
1595  
# Line 1610 | Line 1601 | public class ThreadPoolExecutorSubclassT
1601              new CustomTPE(2, 2,
1602                            LONG_DELAY_MS, MILLISECONDS,
1603                            new ArrayBlockingQueue<Runnable>(10));
1604 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1605 <        l.add(new StringTask());
1606 <        l.add(null);
1607 <        try {
1608 <            e.invokeAll(l);
1609 <            shouldThrow();
1610 <        } catch (NullPointerException success) {
1611 <        } finally {
1621 <            joinPool(e);
1604 >        try (PoolCleaner cleaner = cleaner(e)) {
1605 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1606 >            l.add(new StringTask());
1607 >            l.add(null);
1608 >            try {
1609 >                e.invokeAll(l);
1610 >                shouldThrow();
1611 >            } catch (NullPointerException success) {}
1612          }
1613      }
1614  
# Line 1630 | Line 1620 | public class ThreadPoolExecutorSubclassT
1620              new CustomTPE(2, 2,
1621                            LONG_DELAY_MS, MILLISECONDS,
1622                            new ArrayBlockingQueue<Runnable>(10));
1623 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1624 <        l.add(new NPETask());
1625 <        List<Future<String>> futures = e.invokeAll(l);
1626 <        assertEquals(1, futures.size());
1627 <        try {
1628 <            futures.get(0).get();
1629 <            shouldThrow();
1630 <        } catch (ExecutionException success) {
1631 <            assertTrue(success.getCause() instanceof NullPointerException);
1632 <        } finally {
1633 <            joinPool(e);
1623 >        try (PoolCleaner cleaner = cleaner(e)) {
1624 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1625 >            l.add(new NPETask());
1626 >            List<Future<String>> futures = e.invokeAll(l);
1627 >            assertEquals(1, futures.size());
1628 >            try {
1629 >                futures.get(0).get();
1630 >                shouldThrow();
1631 >            } catch (ExecutionException success) {
1632 >                assertTrue(success.getCause() instanceof NullPointerException);
1633 >            }
1634          }
1635      }
1636  
# Line 1652 | Line 1642 | public class ThreadPoolExecutorSubclassT
1642              new CustomTPE(2, 2,
1643                            LONG_DELAY_MS, MILLISECONDS,
1644                            new ArrayBlockingQueue<Runnable>(10));
1645 <        try {
1645 >        try (PoolCleaner cleaner = cleaner(e)) {
1646              List<Callable<String>> l = new ArrayList<Callable<String>>();
1647              l.add(new StringTask());
1648              l.add(new StringTask());
# Line 1660 | Line 1650 | public class ThreadPoolExecutorSubclassT
1650              assertEquals(2, futures.size());
1651              for (Future<String> future : futures)
1652                  assertSame(TEST_STRING, future.get());
1663        } finally {
1664            joinPool(e);
1653          }
1654      }
1655  
# Line 1673 | Line 1661 | public class ThreadPoolExecutorSubclassT
1661              new CustomTPE(2, 2,
1662                            LONG_DELAY_MS, MILLISECONDS,
1663                            new ArrayBlockingQueue<Runnable>(10));
1664 <        try {
1665 <            e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
1666 <            shouldThrow();
1667 <        } catch (NullPointerException success) {
1668 <        } finally {
1681 <            joinPool(e);
1664 >        try (PoolCleaner cleaner = cleaner(e)) {
1665 >            try {
1666 >                e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
1667 >                shouldThrow();
1668 >            } catch (NullPointerException success) {}
1669          }
1670      }
1671  
# Line 1690 | Line 1677 | public class ThreadPoolExecutorSubclassT
1677              new CustomTPE(2, 2,
1678                            LONG_DELAY_MS, MILLISECONDS,
1679                            new ArrayBlockingQueue<Runnable>(10));
1680 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1681 <        l.add(new StringTask());
1682 <        try {
1683 <            e.invokeAny(l, MEDIUM_DELAY_MS, null);
1684 <            shouldThrow();
1685 <        } catch (NullPointerException success) {
1686 <        } finally {
1700 <            joinPool(e);
1680 >        try (PoolCleaner cleaner = cleaner(e)) {
1681 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1682 >            l.add(new StringTask());
1683 >            try {
1684 >                e.invokeAny(l, MEDIUM_DELAY_MS, null);
1685 >                shouldThrow();
1686 >            } catch (NullPointerException success) {}
1687          }
1688      }
1689  
# Line 1709 | Line 1695 | public class ThreadPoolExecutorSubclassT
1695              new CustomTPE(2, 2,
1696                            LONG_DELAY_MS, MILLISECONDS,
1697                            new ArrayBlockingQueue<Runnable>(10));
1698 <        try {
1699 <            e.invokeAny(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1700 <            shouldThrow();
1701 <        } catch (IllegalArgumentException success) {
1702 <        } finally {
1703 <            joinPool(e);
1698 >        try (PoolCleaner cleaner = cleaner(e)) {
1699 >            try {
1700 >                e.invokeAny(new ArrayList<Callable<String>>(),
1701 >                            MEDIUM_DELAY_MS, MILLISECONDS);
1702 >                shouldThrow();
1703 >            } catch (IllegalArgumentException success) {}
1704          }
1705      }
1706  
# Line 1727 | Line 1713 | public class ThreadPoolExecutorSubclassT
1713              new CustomTPE(2, 2,
1714                            LONG_DELAY_MS, MILLISECONDS,
1715                            new ArrayBlockingQueue<Runnable>(10));
1716 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1717 <        l.add(latchAwaitingStringTask(latch));
1718 <        l.add(null);
1719 <        try {
1720 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1721 <            shouldThrow();
1722 <        } catch (NullPointerException success) {
1723 <        } finally {
1716 >        try (PoolCleaner cleaner = cleaner(e)) {
1717 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1718 >            l.add(latchAwaitingStringTask(latch));
1719 >            l.add(null);
1720 >            try {
1721 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1722 >                shouldThrow();
1723 >            } catch (NullPointerException success) {}
1724              latch.countDown();
1739            joinPool(e);
1725          }
1726      }
1727  
# Line 1748 | Line 1733 | public class ThreadPoolExecutorSubclassT
1733              new CustomTPE(2, 2,
1734                            LONG_DELAY_MS, MILLISECONDS,
1735                            new ArrayBlockingQueue<Runnable>(10));
1736 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1737 <        l.add(new NPETask());
1738 <        try {
1739 <            e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1740 <            shouldThrow();
1741 <        } catch (ExecutionException success) {
1742 <            assertTrue(success.getCause() instanceof NullPointerException);
1743 <        } finally {
1744 <            joinPool(e);
1736 >        try (PoolCleaner cleaner = cleaner(e)) {
1737 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1738 >            l.add(new NPETask());
1739 >            try {
1740 >                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1741 >                shouldThrow();
1742 >            } catch (ExecutionException success) {
1743 >                assertTrue(success.getCause() instanceof NullPointerException);
1744 >            }
1745          }
1746      }
1747  
# Line 1768 | Line 1753 | public class ThreadPoolExecutorSubclassT
1753              new CustomTPE(2, 2,
1754                            LONG_DELAY_MS, MILLISECONDS,
1755                            new ArrayBlockingQueue<Runnable>(10));
1756 <        try {
1756 >        try (PoolCleaner cleaner = cleaner(e)) {
1757              List<Callable<String>> l = new ArrayList<Callable<String>>();
1758              l.add(new StringTask());
1759              l.add(new StringTask());
1760              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1761              assertSame(TEST_STRING, result);
1777        } finally {
1778            joinPool(e);
1762          }
1763      }
1764  
# Line 1787 | Line 1770 | public class ThreadPoolExecutorSubclassT
1770              new CustomTPE(2, 2,
1771                            LONG_DELAY_MS, MILLISECONDS,
1772                            new ArrayBlockingQueue<Runnable>(10));
1773 <        try {
1774 <            e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
1775 <            shouldThrow();
1776 <        } catch (NullPointerException success) {
1777 <        } finally {
1795 <            joinPool(e);
1773 >        try (PoolCleaner cleaner = cleaner(e)) {
1774 >            try {
1775 >                e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
1776 >                shouldThrow();
1777 >            } catch (NullPointerException success) {}
1778          }
1779      }
1780  
# Line 1804 | Line 1786 | public class ThreadPoolExecutorSubclassT
1786              new CustomTPE(2, 2,
1787                            LONG_DELAY_MS, MILLISECONDS,
1788                            new ArrayBlockingQueue<Runnable>(10));
1789 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1790 <        l.add(new StringTask());
1791 <        try {
1792 <            e.invokeAll(l, MEDIUM_DELAY_MS, null);
1793 <            shouldThrow();
1794 <        } catch (NullPointerException success) {
1795 <        } finally {
1814 <            joinPool(e);
1789 >        try (PoolCleaner cleaner = cleaner(e)) {
1790 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1791 >            l.add(new StringTask());
1792 >            try {
1793 >                e.invokeAll(l, MEDIUM_DELAY_MS, null);
1794 >                shouldThrow();
1795 >            } catch (NullPointerException success) {}
1796          }
1797      }
1798  
# Line 1823 | Line 1804 | public class ThreadPoolExecutorSubclassT
1804              new CustomTPE(2, 2,
1805                            LONG_DELAY_MS, MILLISECONDS,
1806                            new ArrayBlockingQueue<Runnable>(10));
1807 <        try {
1808 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
1807 >        try (PoolCleaner cleaner = cleaner(e)) {
1808 >            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(),
1809 >                                                 MEDIUM_DELAY_MS, MILLISECONDS);
1810              assertTrue(r.isEmpty());
1829        } finally {
1830            joinPool(e);
1811          }
1812      }
1813  
# Line 1839 | Line 1819 | public class ThreadPoolExecutorSubclassT
1819              new CustomTPE(2, 2,
1820                            LONG_DELAY_MS, MILLISECONDS,
1821                            new ArrayBlockingQueue<Runnable>(10));
1822 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1823 <        l.add(new StringTask());
1824 <        l.add(null);
1825 <        try {
1826 <            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1827 <            shouldThrow();
1828 <        } catch (NullPointerException success) {
1829 <        } finally {
1850 <            joinPool(e);
1822 >        try (PoolCleaner cleaner = cleaner(e)) {
1823 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1824 >            l.add(new StringTask());
1825 >            l.add(null);
1826 >            try {
1827 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1828 >                shouldThrow();
1829 >            } catch (NullPointerException success) {}
1830          }
1831      }
1832  
# Line 1859 | Line 1838 | public class ThreadPoolExecutorSubclassT
1838              new CustomTPE(2, 2,
1839                            LONG_DELAY_MS, MILLISECONDS,
1840                            new ArrayBlockingQueue<Runnable>(10));
1841 <        List<Callable<String>> l = new ArrayList<Callable<String>>();
1842 <        l.add(new NPETask());
1843 <        List<Future<String>> futures =
1844 <            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1845 <        assertEquals(1, futures.size());
1846 <        try {
1847 <            futures.get(0).get();
1848 <            shouldThrow();
1849 <        } catch (ExecutionException success) {
1850 <            assertTrue(success.getCause() instanceof NullPointerException);
1851 <        } finally {
1852 <            joinPool(e);
1841 >        try (PoolCleaner cleaner = cleaner(e)) {
1842 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1843 >            l.add(new NPETask());
1844 >            List<Future<String>> futures =
1845 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1846 >            assertEquals(1, futures.size());
1847 >            try {
1848 >                futures.get(0).get();
1849 >                shouldThrow();
1850 >            } catch (ExecutionException success) {
1851 >                assertTrue(success.getCause() instanceof NullPointerException);
1852 >            }
1853          }
1854      }
1855  
# Line 1882 | Line 1861 | public class ThreadPoolExecutorSubclassT
1861              new CustomTPE(2, 2,
1862                            LONG_DELAY_MS, MILLISECONDS,
1863                            new ArrayBlockingQueue<Runnable>(10));
1864 <        try {
1864 >        try (PoolCleaner cleaner = cleaner(e)) {
1865              List<Callable<String>> l = new ArrayList<Callable<String>>();
1866              l.add(new StringTask());
1867              l.add(new StringTask());
# Line 1891 | Line 1870 | public class ThreadPoolExecutorSubclassT
1870              assertEquals(2, futures.size());
1871              for (Future<String> future : futures)
1872                  assertSame(TEST_STRING, future.get());
1894        } finally {
1895            joinPool(e);
1873          }
1874      }
1875  
# Line 1904 | Line 1881 | public class ThreadPoolExecutorSubclassT
1881              new CustomTPE(2, 2,
1882                            LONG_DELAY_MS, MILLISECONDS,
1883                            new ArrayBlockingQueue<Runnable>(10));
1884 <        try {
1884 >        try (PoolCleaner cleaner = cleaner(e)) {
1885              for (long timeout = timeoutMillis();;) {
1886                  List<Callable<String>> tasks = new ArrayList<>();
1887                  tasks.add(new StringTask("0"));
# Line 1928 | Line 1905 | public class ThreadPoolExecutorSubclassT
1905                          fail("expected exactly one task to be cancelled");
1906                  }
1907              }
1931        } finally {
1932            joinPool(e);
1908          }
1909      }
1910  
# Line 1943 | Line 1918 | public class ThreadPoolExecutorSubclassT
1918                            LONG_DELAY_MS, MILLISECONDS,
1919                            new LinkedBlockingQueue<Runnable>(),
1920                            new FailingThreadFactory());
1921 <        try {
1921 >        try (PoolCleaner cleaner = cleaner(e)) {
1922              final int TASKS = 100;
1923              final CountDownLatch done = new CountDownLatch(TASKS);
1924              for (int k = 0; k < TASKS; ++k)
# Line 1952 | Line 1927 | public class ThreadPoolExecutorSubclassT
1927                          done.countDown();
1928                      }});
1929              assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS));
1955        } finally {
1956            joinPool(e);
1930          }
1931      }
1932  
# Line 1965 | Line 1938 | public class ThreadPoolExecutorSubclassT
1938              new CustomTPE(2, 2,
1939                            1000, MILLISECONDS,
1940                            new ArrayBlockingQueue<Runnable>(10));
1941 <        assertFalse(p.allowsCoreThreadTimeOut());
1942 <        joinPool(p);
1941 >        try (PoolCleaner cleaner = cleaner(p)) {
1942 >            assertFalse(p.allowsCoreThreadTimeOut());
1943 >        }
1944      }
1945  
1946      /**
# Line 1978 | Line 1952 | public class ThreadPoolExecutorSubclassT
1952              new CustomTPE(2, 10,
1953                            keepAliveTime, MILLISECONDS,
1954                            new ArrayBlockingQueue<Runnable>(10));
1955 <        final CountDownLatch threadStarted = new CountDownLatch(1);
1956 <        try {
1955 >        try (PoolCleaner cleaner = cleaner(p)) {
1956 >            final CountDownLatch threadStarted = new CountDownLatch(1);
1957              p.allowCoreThreadTimeOut(true);
1958              p.execute(new CheckedRunnable() {
1959                  public void realRun() {
# Line 1994 | Line 1968 | public class ThreadPoolExecutorSubclassT
1968                  Thread.yield();
1969              assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1970              assertEquals(0, p.getPoolSize());
1997        } finally {
1998            joinPool(p);
1971          }
1972      }
1973  
# Line 2008 | Line 1980 | public class ThreadPoolExecutorSubclassT
1980              new CustomTPE(2, 10,
1981                            keepAliveTime, MILLISECONDS,
1982                            new ArrayBlockingQueue<Runnable>(10));
1983 <        final CountDownLatch threadStarted = new CountDownLatch(1);
1984 <        try {
1983 >        try (PoolCleaner cleaner = cleaner(p)) {
1984 >            final CountDownLatch threadStarted = new CountDownLatch(1);
1985              p.allowCoreThreadTimeOut(false);
1986              p.execute(new CheckedRunnable() {
1987                  public void realRun() throws InterruptedException {
# Line 2018 | Line 1990 | public class ThreadPoolExecutorSubclassT
1990                  }});
1991              delay(2 * keepAliveTime);
1992              assertTrue(p.getPoolSize() >= 1);
2021        } finally {
2022            joinPool(p);
1993          }
1994      }
1995  
# Line 2032 | Line 2002 | public class ThreadPoolExecutorSubclassT
2002              new CustomTPE(1, 1,
2003                            LONG_DELAY_MS, MILLISECONDS,
2004                            new LinkedBlockingQueue<Runnable>());
2005 <        try {
2005 >        try (PoolCleaner cleaner = cleaner(e)) {
2006              final CountDownLatch blockerStarted = new CountDownLatch(1);
2007              final CountDownLatch done = new CountDownLatch(1);
2008              final List<Future<?>> futures = new ArrayList<>();
# Line 2059 | Line 2029 | public class ThreadPoolExecutorSubclassT
2029                  assertTrue(future.isDone());
2030              }
2031              done.countDown();
2062        } finally {
2063            joinPool(e);
2032          }
2033      }
2034  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines