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.121 by jsr166, Sat Jul 15 18:28:08 2017 UTC vs.
Revision 1.122 by jsr166, Sat Jul 15 18:42:01 2017 UTC

# Line 2085 | Line 2085 | public class ThreadPoolExecutorTest exte
2085          }
2086      }
2087  
2088 <    public void testAbortPolicy() {
2089 <        final RejectedExecutionHandler handler = new AbortPolicy();
2088 >    /** Directly test simple ThreadPoolExecutor RejectedExecutionHandlers. */
2089 >    public void testStandardRejectedExecutionHandlers() {
2090          final ThreadPoolExecutor p =
2091 <            new ThreadPoolExecutor(1, 1,
2092 <                                   LONG_DELAY_MS, MILLISECONDS,
2093 <                                   new ArrayBlockingQueue<Runnable>(10));
2094 <        final TrackedNoOpRunnable r = new TrackedNoOpRunnable();
2091 >            new ThreadPoolExecutor(1, 1, 1, SECONDS,
2092 >                                   new ArrayBlockingQueue<Runnable>(1));
2093 >        final AtomicReference<Thread> thread = new AtomicReference<>();
2094 >        final Runnable r = new Runnable() { public void run() {
2095 >            thread.set(Thread.currentThread()); }};
2096 >
2097          try {
2098 <            handler.rejectedExecution(r, p);
2098 >            new AbortPolicy().rejectedExecution(r, p);
2099              shouldThrow();
2100          } catch (RejectedExecutionException success) {}
2101 <        assertFalse(r.done);
2100 <        assertEquals(0, p.getTaskCount());
2101 <        assertTrue(p.getQueue().isEmpty());
2102 <    }
2101 >        assertNull(thread.get());
2102  
2103 <    public void testCallerRunsPolicy() {
2104 <        final RejectedExecutionHandler handler = new CallerRunsPolicy();
2105 <        final ThreadPoolExecutor p =
2106 <            new ThreadPoolExecutor(1, 1,
2108 <                                   LONG_DELAY_MS, MILLISECONDS,
2109 <                                   new ArrayBlockingQueue<Runnable>(10));
2110 <        final AtomicReference<Thread> thread = new AtomicReference<>();
2111 <        final Runnable r = new Runnable() { public void run() {
2112 <            thread.set(Thread.currentThread()); }};
2113 <        handler.rejectedExecution(r, p);
2103 >        new DiscardPolicy().rejectedExecution(r, p);
2104 >        assertNull(thread.get());
2105 >
2106 >        new CallerRunsPolicy().rejectedExecution(r, p);
2107          assertSame(Thread.currentThread(), thread.get());
2108 +
2109 +        // check that pool was not perturbed by handlers
2110          assertTrue(p.getRejectedExecutionHandler() instanceof AbortPolicy);
2111          assertEquals(0, p.getTaskCount());
2112          assertTrue(p.getQueue().isEmpty());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines