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

Comparing jsr166/src/test/tck/ThreadPoolExecutorTest.java (file contents):
Revision 1.63 by jsr166, Mon Sep 28 08:23:49 2015 UTC vs.
Revision 1.66 by jsr166, Sun Oct 4 01:18:25 2015 UTC

# Line 132 | Line 132 | public class ThreadPoolExecutorTest exte
132       */
133      public void testPrestartCoreThread() {
134          final ThreadPoolExecutor p =
135 <            new ThreadPoolExecutor(2, 2,
135 >            new ThreadPoolExecutor(2, 6,
136                                     LONG_DELAY_MS, MILLISECONDS,
137                                     new ArrayBlockingQueue<Runnable>(10));
138 <        assertEquals(0, p.getPoolSize());
139 <        assertTrue(p.prestartCoreThread());
140 <        assertEquals(1, p.getPoolSize());
141 <        assertTrue(p.prestartCoreThread());
142 <        assertEquals(2, p.getPoolSize());
143 <        assertFalse(p.prestartCoreThread());
144 <        assertEquals(2, p.getPoolSize());
145 <        joinPool(p);
138 >        try (PoolCleaner cleaner = cleaner(p)) {
139 >            assertEquals(0, p.getPoolSize());
140 >            assertTrue(p.prestartCoreThread());
141 >            assertEquals(1, p.getPoolSize());
142 >            assertTrue(p.prestartCoreThread());
143 >            assertEquals(2, p.getPoolSize());
144 >            assertFalse(p.prestartCoreThread());
145 >            assertEquals(2, p.getPoolSize());
146 >            p.setCorePoolSize(4);
147 >            assertTrue(p.prestartCoreThread());
148 >            assertEquals(3, p.getPoolSize());
149 >            assertTrue(p.prestartCoreThread());
150 >            assertEquals(4, p.getPoolSize());
151 >            assertFalse(p.prestartCoreThread());
152 >            assertEquals(4, p.getPoolSize());
153 >        }
154      }
155  
156      /**
# Line 1894 | Line 1902 | public class ThreadPoolExecutorTest exte
1902              l.add(new StringTask());
1903              l.add(new StringTask());
1904              List<Future<String>> futures =
1905 <                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1905 >                e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
1906              assertEquals(2, futures.size());
1907              for (Future<String> future : futures)
1908                  assertSame(TEST_STRING, future.get());
# Line 2062 | Line 2070 | public class ThreadPoolExecutorTest exte
2070          }
2071      }
2072  
2073 +    /**
2074 +     * get(cancelled task) throws CancellationException
2075 +     */
2076 +    public void testGet_cancelled() throws Exception {
2077 +        final ExecutorService e =
2078 +            new ThreadPoolExecutor(1, 1,
2079 +                                   LONG_DELAY_MS, MILLISECONDS,
2080 +                                   new LinkedBlockingQueue<Runnable>());
2081 +        try {
2082 +            final CountDownLatch blockerStarted = new CountDownLatch(1);
2083 +            final CountDownLatch done = new CountDownLatch(1);
2084 +            final List<Future<?>> futures = new ArrayList<>();
2085 +            for (int i = 0; i < 2; i++) {
2086 +                Runnable r = new CheckedRunnable() { public void realRun()
2087 +                                                         throws Throwable {
2088 +                    blockerStarted.countDown();
2089 +                    assertTrue(done.await(2 * LONG_DELAY_MS, MILLISECONDS));
2090 +                }};
2091 +                futures.add(e.submit(r));
2092 +            }
2093 +            assertTrue(blockerStarted.await(LONG_DELAY_MS, MILLISECONDS));
2094 +            for (Future<?> future : futures) future.cancel(false);
2095 +            for (Future<?> future : futures) {
2096 +                try {
2097 +                    future.get();
2098 +                    shouldThrow();
2099 +                } catch (CancellationException success) {}
2100 +                try {
2101 +                    future.get(LONG_DELAY_MS, MILLISECONDS);
2102 +                    shouldThrow();
2103 +                } catch (CancellationException success) {}
2104 +                assertTrue(future.isCancelled());
2105 +                assertTrue(future.isDone());
2106 +            }
2107 +            done.countDown();
2108 +        } finally {
2109 +            joinPool(e);
2110 +        }
2111 +    }
2112 +
2113   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines