Search in sources :

Example 76 with Health

use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.

the class CassandraDriverHealthIndicatorTests method healthWithOneUnknownNodeShouldReturnDown.

@Test
void healthWithOneUnknownNodeShouldReturnDown() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.UNKNOWN);
    CassandraDriverHealthIndicator healthIndicator = new CassandraDriverHealthIndicator(session);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
}
Also used : Health(org.springframework.boot.actuate.health.Health) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Example 77 with Health

use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.

the class Neo4jHealthIndicatorTests method neo4jIsDown.

@Test
void neo4jIsDown() {
    Driver driver = mock(Driver.class);
    given(driver.session(any(SessionConfig.class))).willThrow(ServiceUnavailableException.class);
    Health health = new Neo4jHealthIndicator(driver).health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails()).containsKeys("error");
}
Also used : Health(org.springframework.boot.actuate.health.Health) Driver(org.neo4j.driver.Driver) SessionConfig(org.neo4j.driver.SessionConfig) Test(org.junit.jupiter.api.Test)

Example 78 with Health

use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.

the class Neo4jHealthIndicatorTests method neo4jIsUp.

@Test
void neo4jIsUp() {
    ResultSummary resultSummary = ResultSummaryMock.createResultSummary("My Home", "test");
    Driver driver = mockDriver(resultSummary, "4711", "ultimate collectors edition");
    Health health = new Neo4jHealthIndicator(driver).health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails()).containsEntry("server", "4711@My Home");
    assertThat(health.getDetails()).containsEntry("database", "test");
    assertThat(health.getDetails()).containsEntry("edition", "ultimate collectors edition");
}
Also used : Health(org.springframework.boot.actuate.health.Health) ResultSummary(org.neo4j.driver.summary.ResultSummary) Driver(org.neo4j.driver.Driver) Test(org.junit.jupiter.api.Test)

Example 79 with Health

use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.

the class RedisHealthIndicatorTests method healthWhenClusterStateIsAbsentShouldBeUp.

@Test
void healthWhenClusterStateIsAbsentShouldBeUp() {
    RedisConnectionFactory redisConnectionFactory = createClusterConnectionFactory(null);
    RedisHealthIndicator healthIndicator = new RedisHealthIndicator(redisConnectionFactory);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails().get("cluster_size")).isEqualTo(4L);
    assertThat(health.getDetails().get("slots_up")).isEqualTo(4L);
    assertThat(health.getDetails().get("slots_fail")).isEqualTo(0L);
    then(redisConnectionFactory).should(atLeastOnce()).getConnection();
}
Also used : Health(org.springframework.boot.actuate.health.Health) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 80 with Health

use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.

the class RedisHealthIndicatorTests method healthWhenClusterStateIsFailShouldBeDown.

@Test
void healthWhenClusterStateIsFailShouldBeDown() {
    RedisConnectionFactory redisConnectionFactory = createClusterConnectionFactory("fail");
    RedisHealthIndicator healthIndicator = new RedisHealthIndicator(redisConnectionFactory);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails().get("cluster_size")).isEqualTo(4L);
    assertThat(health.getDetails().get("slots_up")).isEqualTo(3L);
    assertThat(health.getDetails().get("slots_fail")).isEqualTo(1L);
    then(redisConnectionFactory).should(atLeastOnce()).getConnection();
}
Also used : Health(org.springframework.boot.actuate.health.Health) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Test(org.junit.jupiter.api.Test)

Aggregations

Health (org.springframework.boot.actuate.health.Health)116 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 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 Test (org.junit.Test)17 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