Search in sources :

Example 21 with CqlSession

use of com.datastax.oss.driver.api.core.CqlSession in project zipkin by openzipkin.

the class SchemaTest method ensureKeyspaceMetadata_failsWhenKeyspaceMetadataIsNotNull.

@Test
public void ensureKeyspaceMetadata_failsWhenKeyspaceMetadataIsNotNull() {
    CqlSession session = mock(CqlSession.class);
    Metadata metadata = mock(Metadata.class);
    Node node = mock(Node.class);
    when(session.getMetadata()).thenReturn(metadata);
    when(metadata.getNodes()).thenReturn(Collections.singletonMap(UUID.fromString("11111111-1111-1111-1111-111111111111"), node));
    when(node.getCassandraVersion()).thenReturn(Version.parse("3.11.3"));
    assertThatThrownBy(() -> Schema.ensureKeyspaceMetadata(session, "zipkin2")).isInstanceOf(RuntimeException.class).hasMessageStartingWith("Cannot read keyspace metadata for keyspace");
}
Also used : Node(com.datastax.oss.driver.api.core.metadata.Node) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 22 with CqlSession

use of com.datastax.oss.driver.api.core.CqlSession in project zipkin by openzipkin.

the class SchemaTest method ensureKeyspaceMetadata_failsWhenVersionLessThan3_11_3.

@Test
public void ensureKeyspaceMetadata_failsWhenVersionLessThan3_11_3() {
    CqlSession session = mock(CqlSession.class);
    Metadata metadata = mock(Metadata.class);
    Node node = mock(Node.class);
    when(session.getMetadata()).thenReturn(metadata);
    when(metadata.getNodes()).thenReturn(Collections.singletonMap(UUID.fromString("11111111-1111-1111-1111-111111111111"), node));
    when(node.getCassandraVersion()).thenReturn(Version.parse("3.11.2"));
    assertThatThrownBy(() -> Schema.ensureKeyspaceMetadata(session, "zipkin2")).isInstanceOf(RuntimeException.class).hasMessage("Node 11111111-1111-1111-1111-111111111111 is running Cassandra 3.11.2, but minimum version is 3.11.3");
}
Also used : Node(com.datastax.oss.driver.api.core.metadata.Node) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 23 with CqlSession

use of com.datastax.oss.driver.api.core.CqlSession in project zipkin by openzipkin.

the class LazySession method close.

void close() {
    CqlSession maybeSession = session;
    if (maybeSession != null) {
        session.close();
        session = null;
    }
}
Also used : CqlSession(com.datastax.oss.driver.api.core.CqlSession)

Example 24 with CqlSession

use of com.datastax.oss.driver.api.core.CqlSession in project thingsboard by thingsboard.

the class CustomCassandraCQLUnit method after.

@Override
protected void after() {
    super.after();
    try (CqlSession s = session) {
        session = null;
    }
    System.setSecurityManager(null);
}
Also used : CqlSession(com.datastax.oss.driver.api.core.CqlSession)

Example 25 with CqlSession

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

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