Search in sources :

Example 26 with CqlSession

use of com.datastax.oss.driver.api.core.CqlSession 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)

Example 27 with CqlSession

use of com.datastax.oss.driver.api.core.CqlSession 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 28 with CqlSession

use of com.datastax.oss.driver.api.core.CqlSession in project spring-boot by spring-projects.

the class CassandraDriverReactiveHealthIndicatorTests 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)));
    CassandraDriverReactiveHealthIndicator healthIndicator = new CassandraDriverReactiveHealthIndicator(session);
    Mono<Health> health = healthIndicator.health();
    StepVerifier.create(health).consumeNextWith((h) -> {
        assertThat(h.getStatus()).isEqualTo(Status.UP);
        assertThat(h.getDetails()).containsOnlyKeys("version");
        assertThat(h.getDetails().get("version")).isEqualTo(Version.V4_0_0);
    }).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) 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 29 with CqlSession

use of com.datastax.oss.driver.api.core.CqlSession in project spring-boot by spring-projects.

the class CassandraDriverReactiveHealthIndicatorTests method healthWithoutNodeVersionShouldNotAddVersionDetail.

@Test
void healthWithoutNodeVersionShouldNotAddVersionDetail() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.UP);
    CassandraDriverReactiveHealthIndicator healthIndicator = new CassandraDriverReactiveHealthIndicator(session);
    Mono<Health> health = healthIndicator.health();
    StepVerifier.create(health).consumeNextWith((h) -> {
        assertThat(h.getStatus()).isEqualTo(Status.UP);
        assertThat(h.getDetails().get("version")).isNull();
    }).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) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Example 30 with CqlSession

use of com.datastax.oss.driver.api.core.CqlSession in project spring-boot by spring-projects.

the class CassandraDriverReactiveHealthIndicatorTests method healthWithOneHealthyNodeShouldReturnUp.

@Test
void healthWithOneHealthyNodeShouldReturnUp() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.UP);
    CassandraDriverReactiveHealthIndicator healthIndicator = new CassandraDriverReactiveHealthIndicator(session);
    Mono<Health> health = healthIndicator.health();
    StepVerifier.create(health).consumeNextWith((h) -> assertThat(h.getStatus()).isEqualTo(Status.UP)).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) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Aggregations

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