Search in sources :

Example 1 with CqlSession

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

the class CassandraMockConfiguration method cqlSession.

@Bean
CqlSession cqlSession() {
    DriverContext context = mock(DriverContext.class);
    given(context.getCodecRegistry()).willReturn(this.codecRegistry);
    CqlSession cqlSession = mock(CqlSession.class);
    given(cqlSession.getContext()).willReturn(context);
    return cqlSession;
}
Also used : DriverContext(com.datastax.oss.driver.api.core.context.DriverContext) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Bean(org.springframework.context.annotation.Bean)

Example 2 with CqlSession

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

the class CassandraDriverHealthIndicatorTests method healthWithOneForcedDownNodeShouldReturnDown.

@Test
void healthWithOneForcedDownNodeShouldReturnDown() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.FORCED_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 3 with CqlSession

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

the class CassandraDriverHealthIndicatorTests method healthWithOneHealthyNodeAndOneUnknownNodeShouldReturnUp.

@Test
void healthWithOneHealthyNodeAndOneUnknownNodeShouldReturnUp() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.UP, NodeState.UNKNOWN);
    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 4 with CqlSession

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

the class CassandraDriverHealthIndicatorTests method mockCqlSessionWithNodeState.

private CqlSession mockCqlSessionWithNodeState(NodeState... nodeStates) {
    CqlSession session = mock(CqlSession.class);
    Metadata metadata = mock(Metadata.class);
    List<Node> nodes = new ArrayList<>();
    for (NodeState nodeState : nodeStates) {
        Node node = mock(Node.class);
        given(node.getState()).willReturn(nodeState);
        nodes.add(node);
    }
    given(session.getMetadata()).willReturn(metadata);
    given(metadata.getNodes()).willReturn(createNodesWithRandomUUID(nodes));
    return session;
}
Also used : NodeState(com.datastax.oss.driver.api.core.metadata.NodeState) Node(com.datastax.oss.driver.api.core.metadata.Node) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) ArrayList(java.util.ArrayList) CqlSession(com.datastax.oss.driver.api.core.CqlSession)

Example 5 with CqlSession

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

the class CassandraDriverHealthIndicatorTests method healthWithOneHealthyNodeShouldReturnUp.

@Test
void healthWithOneHealthyNodeShouldReturnUp() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.UP);
    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

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