Search in sources :

Example 6 with Metadata

use of com.datastax.oss.driver.api.core.metadata.Metadata in project janusgraph by JanusGraph.

the class CQLStoreTest method testNewTableOpenDatabase.

@Test
public void testNewTableOpenDatabase() throws BackendException {
    // arrange
    String someTableName = "foo";
    Metadata metadata = mock(Metadata.class);
    KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class);
    when(keyspaceMetadata.getTable(someTableName)).thenReturn(Optional.empty());
    when(session.getMetadata()).thenReturn(metadata);
    when(metadata.getKeyspace(mockManager.getKeyspaceName())).thenReturn(Optional.of(keyspaceMetadata));
    // act
    mockManager.openDatabase(someTableName, null);
    // assert
    verify(session, times(1)).execute(any(Statement.class));
}
Also used : Statement(com.datastax.oss.driver.api.core.cql.Statement) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) KeyColumnValueStoreTest(org.janusgraph.diskstorage.KeyColumnValueStoreTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with Metadata

use of com.datastax.oss.driver.api.core.metadata.Metadata in project janusgraph by JanusGraph.

the class CQLStoreTest method testNewKeyspaceSession.

@Test
public void testNewKeyspaceSession() {
    Metadata metadata = mock(Metadata.class);
    Optional<KeyspaceMetadata> keyspaceMetadataOptional = Optional.empty();
    when(session.getMetadata()).thenReturn(metadata);
    when(metadata.getKeyspace(TEST_KEYSPACE_NAME)).thenReturn(keyspaceMetadataOptional);
    mockManager.initializeKeyspace();
    verify(session, times(1)).execute(any(Statement.class));
}
Also used : Statement(com.datastax.oss.driver.api.core.cql.Statement) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) KeyColumnValueStoreTest(org.janusgraph.diskstorage.KeyColumnValueStoreTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with Metadata

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

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

use of com.datastax.oss.driver.api.core.metadata.Metadata in project janusgraph by JanusGraph.

the class CQLStoreTest method testExistTableOpenDatabase.

@Test
public void testExistTableOpenDatabase() throws BackendException {
    // arrange
    String someTableName = "foo";
    Metadata metadata = mock(Metadata.class);
    KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class);
    TableMetadata tableMetadata = mock(TableMetadata.class);
    when(keyspaceMetadata.getTable(someTableName)).thenReturn(Optional.of(tableMetadata));
    when(session.getMetadata()).thenReturn(metadata);
    when(metadata.getKeyspace(mockManager.getKeyspaceName())).thenReturn(Optional.of(keyspaceMetadata));
    // act
    mockManager.openDatabase(someTableName, null);
    // assert
    verify(session, never()).execute(any(Statement.class));
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) Statement(com.datastax.oss.driver.api.core.cql.Statement) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) KeyColumnValueStoreTest(org.janusgraph.diskstorage.KeyColumnValueStoreTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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