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");
}
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");
}
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");
}
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");
}
Aggregations