use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class ElasticsearchReactiveHealthIndicatorTests method elasticsearchIsDownByResponseCode.
@Test
void elasticsearchIsDownByResponseCode() {
// first enqueue an OK response since the HostChecker first sends a HEAD request
// to "/"
this.server.enqueue(new MockResponse().setResponseCode(HttpStatus.OK.value()));
this.server.enqueue(new MockResponse().setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR.value()));
Health health = this.healthIndicator.health().block();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("statusCode")).asString().isEqualTo("500");
assertThat(health.getDetails().get("reasonPhrase")).asString().isEqualTo("Internal Server Error");
}
use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class ElasticsearchReactiveHealthIndicatorTests method elasticsearchIsDown.
@Test
void elasticsearchIsDown() throws Exception {
this.server.shutdown();
Health health = this.healthIndicator.health().block();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails().get("error")).asString().contains("org.springframework.data.elasticsearch.client.NoReachableHostException");
}
use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class RedisHealthIndicatorTests method redisIsUp.
@Test
void redisIsUp() {
Properties info = new Properties();
info.put("redis_version", "2.8.9");
RedisConnection redisConnection = mock(RedisConnection.class);
given(redisConnection.info("server")).willReturn(info);
RedisHealthIndicator healthIndicator = createHealthIndicator(redisConnection);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("version")).isEqualTo("2.8.9");
}
use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class MongoHealthIndicatorTests method mongoIsDown.
@Test
void mongoIsDown() {
MongoTemplate mongoTemplate = mock(MongoTemplate.class);
given(mongoTemplate.executeCommand("{ buildInfo: 1 }")).willThrow(new MongoException("Connection failed"));
MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat((String) health.getDetails().get("error")).contains("Connection failed");
then(mongoTemplate).should().executeCommand("{ buildInfo: 1 }");
}
use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.
the class CassandraDriverReactiveHealthIndicatorTests method healthWithCassandraDownShouldReturnDown.
@Test
void healthWithCassandraDownShouldReturnDown() {
CqlSession session = mock(CqlSession.class);
given(session.getMetadata()).willThrow(new DriverTimeoutException("Test Exception"));
CassandraDriverReactiveHealthIndicator cassandraReactiveHealthIndicator = new CassandraDriverReactiveHealthIndicator(session);
Mono<Health> health = cassandraReactiveHealthIndicator.health();
StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.DOWN);
assertThat(h.getDetails()).containsOnlyKeys("error");
assertThat(h.getDetails().get("error")).isEqualTo(DriverTimeoutException.class.getName() + ": Test Exception");
}).verifyComplete();
}
Aggregations