1984 |
|
assertTrue(p.getQueue().isEmpty()); |
1985 |
|
} |
1986 |
|
|
1987 |
+ |
public void testThreadFactoryReturnsTerminatedThread_shouldThrow() { |
1988 |
+ |
if (!testImplementationDetails) |
1989 |
+ |
return; |
1990 |
+ |
|
1991 |
+ |
ThreadFactory returnsTerminatedThread = runnableIgnored -> { |
1992 |
+ |
Thread thread = new Thread(() -> {}); |
1993 |
+ |
thread.start(); |
1994 |
+ |
try { thread.join(); } |
1995 |
+ |
catch (InterruptedException ex) { throw new Error(ex); } |
1996 |
+ |
return thread; |
1997 |
+ |
}; |
1998 |
+ |
ThreadPoolExecutor p = |
1999 |
+ |
new ThreadPoolExecutor(1, 1, 1, SECONDS, |
2000 |
+ |
new ArrayBlockingQueue<Runnable>(1), |
2001 |
+ |
returnsTerminatedThread); |
2002 |
+ |
try (PoolCleaner cleaner = cleaner(p)) { |
2003 |
+ |
assertThrows(IllegalThreadStateException.class, |
2004 |
+ |
() -> p.execute(() -> {})); |
2005 |
+ |
} |
2006 |
+ |
} |
2007 |
+ |
|
2008 |
+ |
public void testThreadFactoryReturnsStartedThread_shouldThrow() { |
2009 |
+ |
if (!testImplementationDetails) |
2010 |
+ |
return; |
2011 |
+ |
|
2012 |
+ |
CountDownLatch latch = new CountDownLatch(1); |
2013 |
+ |
Runnable awaitLatch = () -> { |
2014 |
+ |
try { latch.await(); } |
2015 |
+ |
catch (InterruptedException ex) { throw new Error(ex); }}; |
2016 |
+ |
ThreadFactory returnsStartedThread = runnable -> { |
2017 |
+ |
Thread thread = new Thread(awaitLatch); |
2018 |
+ |
thread.start(); |
2019 |
+ |
return thread; |
2020 |
+ |
}; |
2021 |
+ |
ThreadPoolExecutor p = |
2022 |
+ |
new ThreadPoolExecutor(1, 1, 1, SECONDS, |
2023 |
+ |
new ArrayBlockingQueue<Runnable>(1), |
2024 |
+ |
returnsStartedThread); |
2025 |
+ |
try (PoolCleaner cleaner = cleaner(p)) { |
2026 |
+ |
assertThrows(IllegalThreadStateException.class, |
2027 |
+ |
() -> p.execute(() -> {})); |
2028 |
+ |
latch.countDown(); |
2029 |
+ |
} |
2030 |
+ |
} |
2031 |
+ |
|
2032 |
|
} |