public void testShutdownAndAwaitTermination_nonTerminationInternal() throws Exception { ExecutorService service = mock(ExecutorService.class); when(service.awaitTermination(HALF_SECOND_NANOS, NANOSECONDS)) .thenReturn(false) .thenReturn(false); assertFalse(shutdownAndAwaitTermination(service, 1L, SECONDS)); verify(service).shutdown(); verify(service, times(2)).awaitTermination(HALF_SECOND_NANOS, NANOSECONDS); verify(service).shutdownNow(); }
public void testShutdownAndAwaitTermination_interruptedInternal() throws Exception { final ExecutorService service = mock(ExecutorService.class); when(service.awaitTermination(HALF_SECOND_NANOS, NANOSECONDS)) .thenThrow(new InterruptedException()); final AtomicBoolean terminated = new AtomicBoolean(); // we need to keep this in a flag because t.isInterrupted() returns false after t.join() final AtomicBoolean interrupted = new AtomicBoolean(); // we need to use another thread because it will be interrupted and thus using // the current one, owned by JUnit, would make the test fail Thread thread = new Thread( new Runnable() { @Override public void run() { terminated.set(shutdownAndAwaitTermination(service, 1L, SECONDS)); interrupted.set(Thread.currentThread().isInterrupted()); } }); thread.start(); thread.join(); verify(service).shutdown(); verify(service).awaitTermination(HALF_SECOND_NANOS, NANOSECONDS); verify(service).shutdownNow(); assertTrue(interrupted.get()); assertFalse(terminated.get()); } }
assertFalse(executor.isShutdown()); assertFalse(executor.isTerminated()); assertFalse(executor.isTerminated()); assertFalse(executor.awaitTermination(20, TimeUnit.MILLISECONDS));
public void testShutdownAndAwaitTermination_nonTerminationInternal() throws Exception { ExecutorService service = mock(ExecutorService.class); when(service.awaitTermination(HALF_SECOND_NANOS, NANOSECONDS)) .thenReturn(false).thenReturn(false); assertFalse(shutdownAndAwaitTermination(service, 1L, SECONDS)); verify(service).shutdown(); verify(service, times(2)).awaitTermination(HALF_SECOND_NANOS, NANOSECONDS); verify(service).shutdownNow(); }
public void testShutdownAndAwaitTermination_interruptedInternal() throws Exception { final ExecutorService service = mock(ExecutorService.class); when(service.awaitTermination(HALF_SECOND_NANOS, NANOSECONDS)) .thenThrow(new InterruptedException()); final AtomicBoolean terminated = new AtomicBoolean(); // we need to keep this in a flag because t.isInterrupted() returns false after t.join() final AtomicBoolean interrupted = new AtomicBoolean(); // we need to use another thread because it will be interrupted and thus using // the current one, owned by JUnit, would make the test fail Thread thread = new Thread(new Runnable() { @Override public void run() { terminated.set(shutdownAndAwaitTermination(service, 1L, SECONDS)); interrupted.set(Thread.currentThread().isInterrupted()); } }); thread.start(); thread.join(); verify(service).shutdown(); verify(service).awaitTermination(HALF_SECOND_NANOS, NANOSECONDS); verify(service).shutdownNow(); assertTrue(interrupted.get()); assertFalse(terminated.get()); } }
assertFalse(executor.isShutdown()); assertFalse(executor.isTerminated()); assertFalse(executor.isTerminated()); assertFalse(executor.awaitTermination(20, TimeUnit.MILLISECONDS));