Search in sources :

Example 1 with Metadata

use of com.datastax.oss.driver.api.core.metadata.Metadata 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 2 with Metadata

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

the class CassandraDriverReactiveHealthIndicatorTests 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 3 with Metadata

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

the class InternalForTests method mockSession.

static CqlSession mockSession() {
    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.9"));
    KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class);
    when(session.getMetadata()).thenReturn(metadata);
    when(metadata.getKeyspace("zipkin2")).thenReturn(Optional.of(keyspaceMetadata));
    when(keyspaceMetadata.getTable(TABLE_SERVICE_REMOTE_SERVICES)).thenReturn(Optional.of(mock(TableMetadata.class)));
    return session;
}
Also used : Node(com.datastax.oss.driver.api.core.metadata.Node) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) 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) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)

Example 4 with Metadata

use of com.datastax.oss.driver.api.core.metadata.Metadata 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 5 with Metadata

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

Aggregations

Metadata (com.datastax.oss.driver.api.core.metadata.Metadata)14 CqlSession (com.datastax.oss.driver.api.core.CqlSession)10 Node (com.datastax.oss.driver.api.core.metadata.Node)10 KeyspaceMetadata (com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)10 Test (org.junit.jupiter.api.Test)6 TableMetadata (com.datastax.oss.driver.api.core.metadata.schema.TableMetadata)5 Test (org.junit.Test)5 Statement (com.datastax.oss.driver.api.core.cql.Statement)4 KeyColumnValueStoreTest (org.janusgraph.diskstorage.KeyColumnValueStoreTest)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 NodeState (com.datastax.oss.driver.api.core.metadata.NodeState)3 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)2 Health (org.springframework.boot.actuate.health.Health)2 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)1 Version (com.datastax.oss.driver.api.core.Version)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1