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.92 by jsr166, Tue Oct 6 05:56:01 2015 UTC vs.
Revision 1.96 by jsr166, Wed Aug 24 22:22:39 2016 UTC

# Line 17 | Line 17 | import java.util.concurrent.Callable;
17   import java.util.concurrent.CancellationException;
18   import java.util.concurrent.CountDownLatch;
19   import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.Executors;
20   import java.util.concurrent.ExecutorService;
21   import java.util.concurrent.Future;
22   import java.util.concurrent.FutureTask;
# Line 1725 | Line 1724 | public class ThreadPoolExecutorSubclassT
1724                            LONG_DELAY_MS, MILLISECONDS,
1725                            new ArrayBlockingQueue<Runnable>(10));
1726          try (PoolCleaner cleaner = cleaner(e)) {
1727 +            long startTime = System.nanoTime();
1728              List<Callable<String>> l = new ArrayList<Callable<String>>();
1729              l.add(new NPETask());
1730              try {
1731 <                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1731 >                e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
1732                  shouldThrow();
1733              } catch (ExecutionException success) {
1734                  assertTrue(success.getCause() instanceof NullPointerException);
1735              }
1736 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1737          }
1738      }
1739  
# Line 1745 | Line 1746 | public class ThreadPoolExecutorSubclassT
1746                            LONG_DELAY_MS, MILLISECONDS,
1747                            new ArrayBlockingQueue<Runnable>(10));
1748          try (PoolCleaner cleaner = cleaner(e)) {
1749 +            long startTime = System.nanoTime();
1750              List<Callable<String>> l = new ArrayList<Callable<String>>();
1751              l.add(new StringTask());
1752              l.add(new StringTask());
1753 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1753 >            String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
1754              assertSame(TEST_STRING, result);
1755 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1756          }
1757      }
1758  
# Line 1868 | Line 1871 | public class ThreadPoolExecutorSubclassT
1871       * timed invokeAll(c) cancels tasks not completed by timeout
1872       */
1873      public void testTimedInvokeAll6() throws Exception {
1874 <        final ExecutorService e =
1875 <            new CustomTPE(2, 2,
1876 <                          LONG_DELAY_MS, MILLISECONDS,
1877 <                          new ArrayBlockingQueue<Runnable>(10));
1878 <        try (PoolCleaner cleaner = cleaner(e)) {
1879 <            for (long timeout = timeoutMillis();;) {
1874 >        for (long timeout = timeoutMillis();;) {
1875 >            final CountDownLatch done = new CountDownLatch(1);
1876 >            final Callable<String> waiter = new CheckedCallable<String>() {
1877 >                public String realCall() {
1878 >                    try { done.await(LONG_DELAY_MS, MILLISECONDS); }
1879 >                    catch (InterruptedException ok) {}
1880 >                    return "1"; }};
1881 >            final ExecutorService p =
1882 >                new CustomTPE(2, 2,
1883 >                              LONG_DELAY_MS, MILLISECONDS,
1884 >                              new ArrayBlockingQueue<Runnable>(10));
1885 >            try (PoolCleaner cleaner = cleaner(p, done)) {
1886                  List<Callable<String>> tasks = new ArrayList<>();
1887                  tasks.add(new StringTask("0"));
1888 <                tasks.add(Executors.callable(new LongPossiblyInterruptedRunnable(), TEST_STRING));
1888 >                tasks.add(waiter);
1889                  tasks.add(new StringTask("2"));
1890                  long startTime = System.nanoTime();
1891                  List<Future<String>> futures =
1892 <                    e.invokeAll(tasks, timeout, MILLISECONDS);
1892 >                    p.invokeAll(tasks, timeout, MILLISECONDS);
1893                  assertEquals(tasks.size(), futures.size());
1894                  assertTrue(millisElapsedSince(startTime) >= timeout);
1895                  for (Future future : futures)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines