AsyncJobLauncherImpl implements AsyncJobLauncher,
                                  InitializingBean { @Override public void shutdown() { ThreadPoolExecutor threadPoolExecutor = threadPoolTaskExecutor.getThreadPoolExecutor(); threadPoolExecutor.shutdown(); while (!terminated(threadPoolExecutor)) { LOGGER.info(LogId.IAL025020); } } AsyncJobLauncherImpl(ThreadPoolTaskExecutor threadPoolTaskExecutor,
            AsyncJobWorker asyncJobWorker); void setFair(boolean fair); @Override void executeJob(final String jobSequenceId); @Override void shutdown(); @Override void afterPropertiesSet();  }
@Test public void testShutdown01() throws Exception { ThreadPoolExecutor mockThreadPoolExecutor = mock(ThreadPoolExecutor.class); doReturn(true).when(mockThreadPoolExecutor).awaitTermination( anyLong(), eq(TimeUnit.MILLISECONDS)); doReturn(mockThreadPoolExecutor).when(threadPoolTaskExecutor) .getThreadPoolExecutor(); doNothing().when(threadPoolTaskExecutor).shutdown(); AsyncJobLauncherImpl asyncJobLauncher = new AsyncJobLauncherImpl( threadPoolTaskExecutor, asyncJobWorker); asyncJobLauncher.executorJobTerminateWaitIntervalTime = 1L; asyncJobLauncher.shutdown(); assertEquals(0, logger.getLoggingEvents().size()); }
@Test public void testShutdown02() throws Exception { ThreadPoolExecutor mockThreadPoolExecutor = mock(ThreadPoolExecutor.class); doReturn(false).doReturn(true).when( mockThreadPoolExecutor).awaitTermination(anyLong(), eq(TimeUnit.MILLISECONDS)); doReturn(mockThreadPoolExecutor).when(threadPoolTaskExecutor) .getThreadPoolExecutor(); doNothing().when(threadPoolTaskExecutor).shutdown(); AsyncJobLauncherImpl asyncJobLauncher = new AsyncJobLauncherImpl( threadPoolTaskExecutor, asyncJobWorker); asyncJobLauncher.executorJobTerminateWaitIntervalTime = 1L; asyncJobLauncher.shutdown(); assertThat(logger.getLoggingEvents().size(), is(1)); assertThat(logger.getLoggingEvents(), is(asList(info( "[IAL025020] Waiting to shutdown all tasks in ThreadPoolTaskExecutor.")))); }
@Test public void testShutdown03() throws Exception { ThreadPoolExecutor mockThreadPoolExecutor = mock(ThreadPoolExecutor.class); doThrow(new InterruptedException()).doReturn(true).when( mockThreadPoolExecutor).awaitTermination(anyLong(), eq(TimeUnit.MILLISECONDS)); doReturn(mockThreadPoolExecutor).when(threadPoolTaskExecutor) .getThreadPoolExecutor(); doNothing().when(threadPoolTaskExecutor).shutdown(); AsyncJobLauncherImpl asyncJobLauncher = new AsyncJobLauncherImpl( threadPoolTaskExecutor, asyncJobWorker); asyncJobLauncher.executorJobTerminateWaitIntervalTime = 1L; asyncJobLauncher.shutdown(); assertFalse(Thread.currentThread().isInterrupted()); assertThat(logger.getLoggingEvents().size(), is(1)); assertThat(logger.getLoggingEvents(), is(asList(info( "[IAL025020] Waiting to shutdown all tasks in ThreadPoolTaskExecutor.")))); }