Search in sources :

Example 26 with Health

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");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Health(org.springframework.boot.actuate.health.Health) Test(org.junit.jupiter.api.Test)

Example 27 with Health

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");
}
Also used : Health(org.springframework.boot.actuate.health.Health) Test(org.junit.jupiter.api.Test)

Example 28 with Health

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");
}
Also used : Health(org.springframework.boot.actuate.health.Health) Properties(java.util.Properties) RedisConnection(org.springframework.data.redis.connection.RedisConnection) Test(org.junit.jupiter.api.Test)

Example 29 with Health

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 }");
}
Also used : MongoException(com.mongodb.MongoException) Health(org.springframework.boot.actuate.health.Health) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Test(org.junit.jupiter.api.Test)

Example 30 with Health

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();
}
Also used : Node(com.datastax.oss.driver.api.core.metadata.Node) Status(org.springframework.boot.actuate.health.Status) NodeState(com.datastax.oss.driver.api.core.metadata.NodeState) StepVerifier(reactor.test.StepVerifier) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) Health(org.springframework.boot.actuate.health.Health) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Version(com.datastax.oss.driver.api.core.Version) List(java.util.List) CqlSession(com.datastax.oss.driver.api.core.CqlSession) BDDMockito.given(org.mockito.BDDMockito.given) Map(java.util.Map) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Health(org.springframework.boot.actuate.health.Health) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Aggregations

Health (org.springframework.boot.actuate.health.Health)118 Test (org.junit.jupiter.api.Test)89 Status (org.springframework.boot.actuate.health.Status)23 CqlSession (com.datastax.oss.driver.api.core.CqlSession)20 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)18 Test (org.junit.Test)18 BDDMockito.given (org.mockito.BDDMockito.given)18 Mockito.mock (org.mockito.Mockito.mock)18 Mono (reactor.core.publisher.Mono)18 StepVerifier (reactor.test.StepVerifier)18 List (java.util.List)14 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)11 Metadata (com.datastax.oss.driver.api.core.metadata.Metadata)11 Node (com.datastax.oss.driver.api.core.metadata.Node)11 HashMap (java.util.HashMap)11 Version (com.datastax.oss.driver.api.core.Version)10 NodeState (com.datastax.oss.driver.api.core.metadata.NodeState)10 ArrayList (java.util.ArrayList)10 Collections (java.util.Collections)10 Map (java.util.Map)10