2009 assertTrue(p.getRejectedExecutionHandler() instanceof AbortPolicy); |
2009 assertTrue(p.getRejectedExecutionHandler() instanceof AbortPolicy); |
2010 assertEquals(0, p.getTaskCount()); |
2010 assertEquals(0, p.getTaskCount()); |
2011 assertTrue(p.getQueue().isEmpty()); |
2011 assertTrue(p.getQueue().isEmpty()); |
2012 } |
2012 } |
2013 |
2013 |
|
2014 public void testThreadFactoryReturnsTerminatedThread_shouldThrow() { |
|
2015 if (!testImplementationDetails) |
|
2016 return; |
|
2017 |
|
2018 ThreadFactory returnsTerminatedThread = runnableIgnored -> { |
|
2019 Thread thread = new Thread(() -> {}); |
|
2020 thread.start(); |
|
2021 try { thread.join(); } |
|
2022 catch (InterruptedException ex) { throw new Error(ex); } |
|
2023 return thread; |
|
2024 }; |
|
2025 ThreadPoolExecutor p = |
|
2026 new ThreadPoolExecutor(1, 1, 1, SECONDS, |
|
2027 new ArrayBlockingQueue<Runnable>(1), |
|
2028 returnsTerminatedThread); |
|
2029 try (PoolCleaner cleaner = cleaner(p)) { |
|
2030 assertThrows(IllegalThreadStateException.class, |
|
2031 () -> p.execute(() -> {})); |
|
2032 } |
|
2033 } |
|
2034 |
|
2035 public void testThreadFactoryReturnsStartedThread_shouldThrow() { |
|
2036 if (!testImplementationDetails) |
|
2037 return; |
|
2038 |
|
2039 CountDownLatch latch = new CountDownLatch(1); |
|
2040 Runnable awaitLatch = () -> { |
|
2041 try { latch.await(); } |
|
2042 catch (InterruptedException ex) { throw new Error(ex); }}; |
|
2043 ThreadFactory returnsStartedThread = runnable -> { |
|
2044 Thread thread = new Thread(awaitLatch); |
|
2045 thread.start(); |
|
2046 return thread; |
|
2047 }; |
|
2048 ThreadPoolExecutor p = |
|
2049 new ThreadPoolExecutor(1, 1, 1, SECONDS, |
|
2050 new ArrayBlockingQueue<Runnable>(1), |
|
2051 returnsStartedThread); |
|
2052 try (PoolCleaner cleaner = cleaner(p)) { |
|
2053 assertThrows(IllegalThreadStateException.class, |
|
2054 () -> p.execute(() -> {})); |
|
2055 latch.countDown(); |
|
2056 } |
|
2057 } |
|
2058 |
2014 } |
2059 } |