/** * {@inheritDoc} */ @Override public void shutdown(boolean awaitShutdown) { ExecutorServiceUtils.shutdownExecutor(diagnosisServiceExecutor, SHUTDOWN_TIMEOUT, TimeUnit.SECONDS); }
/** * Shutting down the used executor service. */ @PreDestroy protected void shutDownExecutorService() { ExecutorServiceUtils.shutdownExecutor(scheduledExecutorService, 5L, TimeUnit.SECONDS); }
/** * {@inheritDoc} */ @PreDestroy public void stop() { if (shutdown) { return; } // mark shutdown started shutdown = true; // shutdown disruptor stopDisruptor(); // kill executor service ExecutorServiceUtils.shutdownExecutor(executorService, 5L, TimeUnit.SECONDS); }
@Test public void shutdownInterrupted() throws InterruptedException { ExecutorService executorService = mock(ExecutorService.class); doThrow(new InterruptedException()).when(executorService).awaitTermination(1, TimeUnit.MINUTES); ExecutorServiceUtils.shutdownExecutor(executorService, 1, TimeUnit.MINUTES); verify(executorService).shutdown(); verify(executorService, times(1)).awaitTermination(1, TimeUnit.MINUTES); verify(executorService).shutdownNow(); verifyNoMoreInteractions(executorService); } }
@Test public void successfulShutdown() throws InterruptedException { ExecutorService executorService = mock(ExecutorService.class); when(executorService.awaitTermination(1, TimeUnit.MINUTES)).thenReturn(true); ExecutorServiceUtils.shutdownExecutor(executorService, 1, TimeUnit.MINUTES); verify(executorService).shutdown(); verify(executorService).awaitTermination(1, TimeUnit.MINUTES); verifyNoMoreInteractions(executorService); }
@Test public void failingShutdown() throws InterruptedException { ExecutorService executorService = mock(ExecutorService.class); when(executorService.awaitTermination(1, TimeUnit.MINUTES)).thenReturn(false, false); ExecutorServiceUtils.shutdownExecutor(executorService, 1, TimeUnit.MINUTES); verify(executorService).shutdown(); verify(executorService, times(2)).awaitTermination(1, TimeUnit.MINUTES); verify(executorService).shutdownNow(); verifyNoMoreInteractions(executorService); }
@Test public void shutdownAfterTimeout() throws InterruptedException { ExecutorService executorService = mock(ExecutorService.class); when(executorService.awaitTermination(1, TimeUnit.MINUTES)).thenReturn(false, true); ExecutorServiceUtils.shutdownExecutor(executorService, 1, TimeUnit.MINUTES); verify(executorService).shutdown(); verify(executorService, times(2)).awaitTermination(1, TimeUnit.MINUTES); verify(executorService).shutdownNow(); verifyNoMoreInteractions(executorService); }