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()); |