Search in sources :

Example 6 with Duration

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);
}
Also used : Duration(io.dropwizard.util.Duration)

Example 7 with Duration

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);
}
Also used : Duration(io.dropwizard.util.Duration)

Example 8 with Duration

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());
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) Duration(io.dropwizard.util.Duration) Test(org.junit.jupiter.api.Test)

Aggregations

Duration (io.dropwizard.util.Duration)8 MetricRegistry (com.codahale.metrics.MetricRegistry)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Test (org.junit.jupiter.api.Test)2 PartitionedTable (com.airbnb.airpal.presto.PartitionedTable)1 Table (com.airbnb.airpal.presto.Table)1 InstrumentedScheduledExecutorService (com.codahale.metrics.InstrumentedScheduledExecutorService)1 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)1 InstrumentedHttpClientConnectionManager (com.codahale.metrics.httpclient.InstrumentedHttpClientConnectionManager)1 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 ImmutableList (com.google.common.collect.ImmutableList)1 HealthResponseProvider (io.dropwizard.health.response.HealthResponseProvider)1 MinDuration (io.dropwizard.validation.MinDuration)1 ValidationMethod (io.dropwizard.validation.ValidationMethod)1 Connection (java.sql.Connection)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1