Search in sources :

Example 71 with Health

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

the class CassandraDriverHealthIndicatorTests method healthWithcassandraDownShouldReturnDown.

@Test
void healthWithcassandraDownShouldReturnDown() {
    CqlSession session = mock(CqlSession.class);
    given(session.getMetadata()).willThrow(new DriverTimeoutException("Test Exception"));
    CassandraDriverHealthIndicator healthIndicator = new CassandraDriverHealthIndicator(session);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails().get("error")).isEqualTo(DriverTimeoutException.class.getName() + ": Test Exception");
}
Also used : 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)

Example 72 with Health

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

the class CassandraDriverHealthIndicatorTests method healthWithoutNodeVersionShouldNotAddVersionDetail.

@Test
void healthWithoutNodeVersionShouldNotAddVersionDetail() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.UP);
    CassandraDriverHealthIndicator healthIndicator = new CassandraDriverHealthIndicator(session);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails().get("version")).isNull();
}
Also used : Health(org.springframework.boot.actuate.health.Health) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Example 73 with Health

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

the class CassandraDriverHealthIndicatorTests method healthWithOneUnhealthyNodeShouldReturnDown.

@Test
void healthWithOneUnhealthyNodeShouldReturnDown() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.DOWN);
    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 74 with Health

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

the class CassandraDriverHealthIndicatorTests method healthWithNodeVersionShouldAddVersionDetail.

@Test
void healthWithNodeVersionShouldAddVersionDetail() {
    CqlSession session = mock(CqlSession.class);
    Metadata metadata = mock(Metadata.class);
    given(session.getMetadata()).willReturn(metadata);
    Node node = mock(Node.class);
    given(node.getState()).willReturn(NodeState.UP);
    given(node.getCassandraVersion()).willReturn(Version.V4_0_0);
    given(metadata.getNodes()).willReturn(createNodesWithRandomUUID(Collections.singletonList(node)));
    CassandraDriverHealthIndicator healthIndicator = new CassandraDriverHealthIndicator(session);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails().get("version")).isEqualTo(Version.V4_0_0);
}
Also used : Health(org.springframework.boot.actuate.health.Health) Node(com.datastax.oss.driver.api.core.metadata.Node) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Example 75 with Health

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

the class CassandraDriverHealthIndicatorTests method healthWithOneHealthyNodeAndOneUnhealthyNodeShouldReturnUp.

@Test
void healthWithOneHealthyNodeAndOneUnhealthyNodeShouldReturnUp() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.UP, NodeState.DOWN);
    CassandraDriverHealthIndicator healthIndicator = new CassandraDriverHealthIndicator(session);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
}
Also used : Health(org.springframework.boot.actuate.health.Health) CqlSession(com.datastax.oss.driver.api.core.CqlSession) 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