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.64 by jsr166, Mon Sep 28 21:15:44 2015 UTC

# Line 2062 | Line 2062 | public class ThreadPoolExecutorTest exte
2062          }
2063      }
2064  
2065 +    /**
2066 +     * get(cancelled task) throws CancellationException
2067 +     */
2068 +    public void testGet_cancelled() throws Exception {
2069 +        final ExecutorService e =
2070 +            new ThreadPoolExecutor(1, 1,
2071 +                                   LONG_DELAY_MS, MILLISECONDS,
2072 +                                   new LinkedBlockingQueue<Runnable>());
2073 +        try {
2074 +            final CountDownLatch blockerStarted = new CountDownLatch(1);
2075 +            final CountDownLatch done = new CountDownLatch(1);
2076 +            final List<Future<?>> futures = new ArrayList<>();
2077 +            for (int i = 0; i < 2; i++) {
2078 +                Runnable r = new CheckedRunnable() { public void realRun()
2079 +                                                         throws Throwable {
2080 +                    blockerStarted.countDown();
2081 +                    assertTrue(done.await(2 * LONG_DELAY_MS, MILLISECONDS));
2082 +                }};
2083 +                futures.add(e.submit(r));
2084 +            }
2085 +            assertTrue(blockerStarted.await(LONG_DELAY_MS, MILLISECONDS));
2086 +            for (Future<?> future : futures) future.cancel(false);
2087 +            for (Future<?> future : futures) {
2088 +                try {
2089 +                    future.get();
2090 +                    shouldThrow();
2091 +                } catch (CancellationException success) {}
2092 +                try {
2093 +                    future.get(LONG_DELAY_MS, MILLISECONDS);
2094 +                    shouldThrow();
2095 +                } catch (CancellationException success) {}
2096 +                assertTrue(future.isCancelled());
2097 +                assertTrue(future.isDone());
2098 +            }
2099 +            done.countDown();
2100 +        } finally {
2101 +            joinPool(e);
2102 +        }
2103 +    }
2104 +
2105   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines