void () { TestTimeOut t = TestTimeOut.setTimeout(20, TimeUnit.SECONDS); while (!t.isTimedOut()) { BoundedScheduledExecutorService executor = createBoundedScheduledExecutor(AppExecutorUtil.getAppExecutorService(), 1); AtomicBoolean shutdownCalled = new AtomicBoolean(); Future<?> future1 = executor.scheduleWithFixedDelay(() -> { boolean isShutdown = executor.isShutdown(); assertTrue(shutdownCalled.get() || !isShutdown); }, 10, 10, TimeUnit.DAYS); Future<?> future2 = executor.schedule(() -> { boolean isShutdown = executor.isShutdown(); assertTrue(shutdownCalled.get() || !isShutdown); }, 10, TimeUnit.DAYS); shutdownCalled.set(true); List<Runnable> runnables = executor.shutdownNow(); assertEquals(2, runnables.size()); assertTrue(executor.isShutdown()); assertTrue(executor.isTerminated()); assertTrue(future1.isCancelled()); // all scheduled tasks should be canceled automatically by design of SchedulingWrapper assertTrue(future2.isCancelled()); // all scheduled tasks should be canceled automatically by design of SchedulingWrapper } }