use of io.dropwizard.util.Duration in project dropwizard by dropwizard.
the class HealthCheckScheduler method schedule.
public void schedule(final ScheduledHealthCheck check, final boolean healthy) {
unschedule(check.getName());
final Duration interval;
if (healthy) {
interval = check.getSchedule().getCheckInterval();
} else {
interval = check.getSchedule().getDowntimeInterval();
}
schedule(check, interval, interval);
}
use of io.dropwizard.util.Duration in project dropwizard by dropwizard.
the class HealthCheckScheduler method scheduleInitial.
void scheduleInitial(final ScheduledHealthCheck check) {
final Duration interval;
if (check.isHealthy()) {
interval = check.getSchedule().getCheckInterval();
} else {
interval = check.getSchedule().getDowntimeInterval();
}
schedule(check, check.getSchedule().getInitialDelay(), interval);
}
use of io.dropwizard.util.Duration in project dropwizard by dropwizard.
the class TimeBoundHealthCheckTest method testCheck.
@Test
@SuppressWarnings("unchecked")
void testCheck() throws InterruptedException, ExecutionException, TimeoutException {
final ExecutorService executorService = mock(ExecutorService.class);
final Duration duration = mock(Duration.class);
when(duration.getQuantity()).thenReturn(5L);
when(duration.getUnit()).thenReturn(TimeUnit.SECONDS);
final Callable<HealthCheck.Result> callable = mock(Callable.class);
final Future<HealthCheck.Result> future = mock(Future.class);
when(executorService.submit(callable)).thenReturn(future);
new TimeBoundHealthCheck(executorService, duration).check(callable);
verify(executorService, times(1)).submit(callable);
verify(future, times(1)).get(duration.getQuantity(), duration.getUnit());
}
Aggregations