@Test public void should_wait_on_runtime_exception() { Assertions.assertTimeoutPreemptively(Duration.ofSeconds(1), () -> { runnable.setAction(() -> { throw new RuntimeException(); }); runUntilShutdown.run(); assertThat(countingWaiter.counter, is(2)); }); }
@Override public void run() { while (!schedulerState.isShuttingDown()) { try { toRun.run(); } catch (Throwable e) { LOG.error("Unhandled exception. Will keep running.", e); statsRegistry.register(StatsRegistry.SchedulerStatsEvent.UNEXPECTED_ERROR); } try { waitBetweenRuns.doWait(); } catch (InterruptedException interruptedException) { if (schedulerState.isShuttingDown()) { LOG.debug("Thread '{}' interrupted due to shutdown.", Thread.currentThread().getName()); } else { LOG.error("Unexpected interruption of thread. Will keep running.", interruptedException); statsRegistry.register(StatsRegistry.SchedulerStatsEvent.UNEXPECTED_ERROR); } } } }
RunUntilShutdown implements Runnable { @Override public void run() { while (!schedulerState.isShuttingDown()) { try { toRun.run(); } catch (Throwable e) { LOG.error("Unhandled exception. Will keep running.", e); statsRegistry.register(StatsRegistry.SchedulerStatsEvent.UNEXPECTED_ERROR); } try { waitBetweenRuns.doWait(); } catch (InterruptedException interruptedException) { if (schedulerState.isShuttingDown()) { LOG.debug("Thread '{}' interrupted due to shutdown.", Thread.currentThread().getName()); } else { LOG.error("Unexpected interruption of thread. Will keep running.", interruptedException); statsRegistry.register(StatsRegistry.SchedulerStatsEvent.UNEXPECTED_ERROR); } } } } }
RunUntilShutdown implements Runnable { @Override public void run() { while (!schedulerState.isShuttingDown()) { try { toRun.run(); } catch (Throwable e) { LOG.error("Unhandled exception. Will keep running.", e); statsRegistry.register(StatsRegistry.SchedulerStatsEvent.UNEXPECTED_ERROR); } try { waitBetweenRuns.doWait(); } catch (InterruptedException interruptedException) { if (schedulerState.isShuttingDown()) { LOG.debug("Thread '{}' interrupted due to shutdown.", Thread.currentThread().getName()); } else { LOG.error("Unexpected interruption of thread. Will keep running.", interruptedException); statsRegistry.register(StatsRegistry.SchedulerStatsEvent.UNEXPECTED_ERROR); } } } } RunUntilShutdown(Runnable toRun, Waiter waitBetweenRuns, SchedulerState schedulerState, StatsRegistry statsRegistry); }
RunUntilShutdown implements Runnable { @Override public void run() { while (!schedulerState.isShuttingDown()) { try { toRun.run(); } catch (Throwable e) { LOG.error("Unhandled exception. Will keep running.", e); statsRegistry.register(StatsRegistry.SchedulerStatsEvent.UNEXPECTED_ERROR); } try { waitBetweenRuns.doWait(); } catch (InterruptedException interruptedException) { if (schedulerState.isShuttingDown()) { LOG.debug("Thread '{}' interrupted due to shutdown.", Thread.currentThread().getName()); } else { LOG.error("Unexpected interruption of thread. Will keep running.", interruptedException); statsRegistry.register(StatsRegistry.SchedulerStatsEvent.UNEXPECTED_ERROR); } } } } RunUntilShutdown(Runnable toRun, Waiter waitBetweenRuns, SchedulerState schedulerState, StatsRegistry statsRegistry); @Override void run(); }
RunUntilShutdown implements Runnable { @Override public void run() { while (!schedulerState.isShuttingDown()) { try { toRun.run(); } catch (Throwable e) { LOG.error("Unhandled exception. Will keep running.", e); statsRegistry.register(StatsRegistry.SchedulerStatsEvent.UNEXPECTED_ERROR); } try { waitBetweenRuns.doWait(); } catch (InterruptedException interruptedException) { if (schedulerState.isShuttingDown()) { LOG.debug("Thread '{}' interrupted due to shutdown.", Thread.currentThread().getName()); } else { LOG.error("Unexpected interruption of thread. Will keep running.", interruptedException); statsRegistry.register(StatsRegistry.SchedulerStatsEvent.UNEXPECTED_ERROR); } } } } RunUntilShutdown(Runnable toRun, Waiter waitBetweenRuns, SchedulerState schedulerState, StatsRegistry statsRegistry); @Override void run();  }