Search in sources :

Example 6 with Clock

use of com.codahale.metrics.Clock in project metrics by dropwizard.

the class HealthCheckServletTest method returnsA500IfAnyHealthChecksAreUnhealthy.

@Test
public void returnsA500IfAnyHealthChecksAreUnhealthy() throws Exception {
    registry.register("fun", new HealthCheck() {

        @Override
        protected Result check() {
            return healthyResultUsingFixedClockWithMessage("whee");
        }

        @Override
        protected Clock clock() {
            return FIXED_CLOCK;
        }
    });
    registry.register("notFun", new HealthCheck() {

        @Override
        protected Result check() {
            return Result.builder().usingClock(FIXED_CLOCK).unhealthy().withMessage("whee").build();
        }

        @Override
        protected Clock clock() {
            return FIXED_CLOCK;
        }
    });
    processRequest();
    assertThat(response.getStatus()).isEqualTo(500);
    assertThat(response.getContent()).contains("{\"fun\":{\"healthy\":true,\"message\":\"whee\",\"duration\":0,\"timestamp\":\"" + EXPECTED_TIMESTAMP + "\"}", ",\"notFun\":{\"healthy\":false,\"message\":\"whee\",\"duration\":0,\"timestamp\":\"" + EXPECTED_TIMESTAMP + "\"}}");
    assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualTo("application/json");
}
Also used : HealthCheck(com.codahale.metrics.health.HealthCheck) Clock(com.codahale.metrics.Clock) Test(org.junit.Test)

Example 7 with Clock

use of com.codahale.metrics.Clock in project metrics by dropwizard.

the class HealthCheckServletTest method optionallyPrettyPrintsTheJson.

@Test
public void optionallyPrettyPrintsTheJson() throws Exception {
    registry.register("fun", new HealthCheck() {

        @Override
        protected Result check() {
            return healthyResultUsingFixedClockWithMessage("foo bar 123");
        }

        @Override
        protected Clock clock() {
            return FIXED_CLOCK;
        }
    });
    request.setURI("/healthchecks?pretty=true");
    processRequest();
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContent()).isEqualTo(String.format("{%n" + "  \"fun\" : {%n" + "    \"healthy\" : true,%n" + "    \"message\" : \"foo bar 123\",%n" + "    \"duration\" : 0,%n" + "    \"timestamp\" : \"" + EXPECTED_TIMESTAMP + "\"" + "%n  }%n}"));
    assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualTo("application/json");
}
Also used : HealthCheck(com.codahale.metrics.health.HealthCheck) Clock(com.codahale.metrics.Clock) Test(org.junit.Test)

Example 8 with Clock

use of com.codahale.metrics.Clock in project metrics by dropwizard.

the class HealthCheckServletTest method returnsASubsetOfHealthChecksIfFiltered.

@Test
public void returnsASubsetOfHealthChecksIfFiltered() throws Exception {
    registry.register("fun", new HealthCheck() {

        @Override
        protected Result check() {
            return healthyResultUsingFixedClockWithMessage("whee");
        }

        @Override
        protected Clock clock() {
            return FIXED_CLOCK;
        }
    });
    registry.register("filtered", new HealthCheck() {

        @Override
        protected Result check() {
            return Result.unhealthy("whee");
        }

        @Override
        protected Clock clock() {
            return FIXED_CLOCK;
        }
    });
    processRequest();
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContent()).isEqualTo("{\"fun\":{\"healthy\":true,\"message\":\"whee\",\"duration\":0,\"timestamp\":\"" + EXPECTED_TIMESTAMP + "\"}}");
    assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualTo("application/json");
}
Also used : HealthCheck(com.codahale.metrics.health.HealthCheck) Clock(com.codahale.metrics.Clock) Test(org.junit.Test)

Example 9 with Clock

use of com.codahale.metrics.Clock in project metrics by dropwizard.

the class HealthCheckServletTest method returnsA200IfAllHealthChecksAreHealthy.

@Test
public void returnsA200IfAllHealthChecksAreHealthy() throws Exception {
    registry.register("fun", new HealthCheck() {

        @Override
        protected Result check() {
            return healthyResultUsingFixedClockWithMessage("whee");
        }

        @Override
        protected Clock clock() {
            return FIXED_CLOCK;
        }
    });
    processRequest();
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContent()).isEqualTo("{\"fun\":{\"healthy\":true,\"message\":\"whee\",\"duration\":0,\"timestamp\":\"" + EXPECTED_TIMESTAMP + "\"}}");
    assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualTo("application/json");
}
Also used : HealthCheck(com.codahale.metrics.health.HealthCheck) Clock(com.codahale.metrics.Clock) Test(org.junit.Test)

Aggregations

Clock (com.codahale.metrics.Clock)9 Test (org.junit.Test)7 HealthCheck (com.codahale.metrics.health.HealthCheck)4 ExponentiallyDecayingReservoir (com.codahale.metrics.ExponentiallyDecayingReservoir)2 Reservoir (com.codahale.metrics.Reservoir)2 SlidingTimeWindowReservoir (com.codahale.metrics.SlidingTimeWindowReservoir)2 UniformReservoir (com.codahale.metrics.UniformReservoir)2 ZonedDateTime (java.time.ZonedDateTime)2 SlidingWindowReservoir (com.codahale.metrics.SlidingWindowReservoir)1 NodeConfig (org.apache.solr.core.NodeConfig)1 PluginInfoInitialized (org.apache.solr.util.plugin.PluginInfoInitialized)1