Maintainer implements Runnable, AutoCloseable { @Override public void run() { try { if (jobControl.isActive(name())) { lockAndMaintain(); } } catch (UncheckedTimeoutException ignored) { } catch (Throwable e) { log.log(Level.WARNING, this + " failed. Will retry in " + interval.toMinutes() + " minutes", e); } } Maintainer(String name, Duration interval, Instant startedAt, JobControl jobControl, JobMetrics jobMetrics, List<String> clusterHostnames);  Maintainer(String name, Duration interval, Duration initialDelay, JobControl jobControl, JobMetrics jobMetrics); @Override void run(); @Override void close(); @Override final String toString(); @SuppressWarnings("unused") final void lockAndMaintain(); final String name();  }
@Test public void success_metric() { AtomicLong consecutiveFailures = new AtomicLong(); JobMetrics jobMetrics = new JobMetrics((job, count) -> consecutiveFailures.set(count)); TestMaintainer maintainer = new TestMaintainer(jobMetrics); maintainer.successOnNextRun(false).run(); assertEquals(1, consecutiveFailures.get()); maintainer.successOnNextRun(false).run(); assertEquals(2, consecutiveFailures.get()); maintainer.successOnNextRun(true).run(); assertEquals(0, consecutiveFailures.get()); maintainer.run(); assertEquals(0, consecutiveFailures.get()); maintainer.throwOnNextRun(true).run(); assertEquals(1, consecutiveFailures.get()); maintainer.throwOnNextRun(false).run(); assertEquals(0, consecutiveFailures.get()); }