Search in sources :

Example 6 with SchemaRefresh

use of com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh in project java-driver by datastax.

the class GraphSchemaRefreshTest method should_detect_adding_and_renaming_and_removing_vertex_label.

@Test
public void should_detect_adding_and_renaming_and_removing_vertex_label() {
    DefaultDseTableMetadata newTable = newTable(KS_WITH_ENGINE.getName(), CqlIdentifier.fromInternal("tbl"), new DefaultDseVertexMetadata(CqlIdentifier.fromInternal("someLabel")), null);
    DefaultDseKeyspaceMetadata ks = newKeyspace(KS_WITH_ENGINE.getName(), "Core", ImmutableMap.of(CqlIdentifier.fromInternal("tbl"), newTable));
    SchemaRefresh refresh = new SchemaRefresh(ImmutableMap.of(KS_WITH_ENGINE.getName(), ks, OLD_KS1.getName(), OLD_KS1));
    MetadataRefresh.Result result = refresh.compute(oldMetadata, false, context);
    assertThat(result.newMetadata.getKeyspaces()).hasSize(2);
    assertThat(result.events).containsExactly(TableChangeEvent.updated(OLD_TABLE, newTable));
    assertThat(result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName())).isNotNull();
    assertThat(((DseGraphTableMetadata) result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName()).getTable("tbl").get()).getVertex()).isNotNull();
    assertThat(((DseGraphTableMetadata) result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName()).getTable("tbl").get()).getVertex().get().getLabelName().asInternal()).isEqualTo("someLabel");
    // now rename the vertex label
    newTable = newTable(KS_WITH_ENGINE.getName(), CqlIdentifier.fromInternal("tbl"), new DefaultDseVertexMetadata(CqlIdentifier.fromInternal("someNewLabel")), null);
    ks = newKeyspace(KS_WITH_ENGINE.getName(), "Core", ImmutableMap.of(CqlIdentifier.fromInternal("tbl"), newTable));
    refresh = new SchemaRefresh(ImmutableMap.of(KS_WITH_ENGINE.getName(), ks, OLD_KS1.getName(), OLD_KS1));
    result = refresh.compute(oldMetadata, false, context);
    assertThat(result.newMetadata.getKeyspaces()).hasSize(2);
    assertThat(result.events).containsExactly(TableChangeEvent.updated(OLD_TABLE, newTable));
    assertThat(((DseGraphTableMetadata) result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName()).getTable("tbl").get()).getVertex().get().getLabelName().asInternal()).isEqualTo("someNewLabel");
    // now remove the vertex label from the table
    DefaultMetadata metadataWithVertexLabel = result.newMetadata;
    DefaultDseTableMetadata tableWithRemovedLabel = newTable(KS_WITH_ENGINE.getName(), CqlIdentifier.fromInternal("tbl"), null, null);
    ks = newKeyspace(KS_WITH_ENGINE.getName(), "Core", ImmutableMap.of(CqlIdentifier.fromInternal("tbl"), tableWithRemovedLabel));
    refresh = new SchemaRefresh(ImmutableMap.of(KS_WITH_ENGINE.getName(), ks, OLD_KS1.getName(), OLD_KS1));
    result = refresh.compute(metadataWithVertexLabel, false, context);
    assertThat(result.newMetadata.getKeyspaces()).hasSize(2);
    assertThat(result.events).containsExactly(TableChangeEvent.updated(newTable, tableWithRemovedLabel));
    assertThat(((DseGraphTableMetadata) result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName()).getTable("tbl").get()).getVertex().isPresent()).isFalse();
}
Also used : DefaultDseKeyspaceMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata) DseGraphTableMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseGraphTableMetadata) DefaultMetadata(com.datastax.oss.driver.internal.core.metadata.DefaultMetadata) SchemaRefresh(com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh) DefaultDseTableMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseTableMetadata) MetadataRefresh(com.datastax.oss.driver.internal.core.metadata.MetadataRefresh) DefaultDseVertexMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseVertexMetadata) Test(org.junit.Test)

Example 7 with SchemaRefresh

use of com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh in project java-driver by datastax.

the class GraphSchemaRefreshTest method should_detect_created_keyspace_with_graph_engine.

@Test
public void should_detect_created_keyspace_with_graph_engine() {
    DefaultDseKeyspaceMetadata ks2 = newKeyspace("ks2", "Core");
    SchemaRefresh refresh = new SchemaRefresh(ImmutableMap.of(OLD_KS1.getName(), OLD_KS1, KS_WITH_ENGINE.getName(), KS_WITH_ENGINE, ks2.getName(), ks2));
    MetadataRefresh.Result result = refresh.compute(oldMetadata, false, context);
    assertThat(result.newMetadata.getKeyspaces()).hasSize(3);
    assertThat(result.events).containsExactly(KeyspaceChangeEvent.created(ks2));
}
Also used : DefaultDseKeyspaceMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata) SchemaRefresh(com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh) MetadataRefresh(com.datastax.oss.driver.internal.core.metadata.MetadataRefresh) Test(org.junit.Test)

Example 8 with SchemaRefresh

use of com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh in project java-driver by datastax.

the class GraphSchemaRefreshTest method should_detect_top_level_graph_engine_update_in_keyspace.

@Test
public void should_detect_top_level_graph_engine_update_in_keyspace() {
    // Change only one top-level option (graph_engine)
    DefaultDseKeyspaceMetadata newKs1 = newKeyspace("ks1", "Core");
    SchemaRefresh refresh = new SchemaRefresh(ImmutableMap.of(KS_WITH_ENGINE.getName(), KS_WITH_ENGINE, OLD_KS1.getName(), newKs1));
    MetadataRefresh.Result result = refresh.compute(oldMetadata, false, context);
    assertThat(result.newMetadata.getKeyspaces()).hasSize(2);
    assertThat(result.events).containsExactly(KeyspaceChangeEvent.updated(OLD_KS1, newKs1));
}
Also used : DefaultDseKeyspaceMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata) SchemaRefresh(com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh) MetadataRefresh(com.datastax.oss.driver.internal.core.metadata.MetadataRefresh) Test(org.junit.Test)

Example 9 with SchemaRefresh

use of com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh in project java-driver by datastax.

the class GraphSchemaRefreshTest method should_detect_adding_and_renaming_and_removing_edge_label.

@Test
public void should_detect_adding_and_renaming_and_removing_edge_label() {
    DefaultDseTableMetadata newTable = newTable(KS_WITH_ENGINE.getName(), CqlIdentifier.fromInternal("tbl"), null, newEdgeMetadata(CqlIdentifier.fromInternal("created"), CqlIdentifier.fromInternal("person"), CqlIdentifier.fromInternal("software")));
    DefaultDseKeyspaceMetadata ks = newKeyspace(KS_WITH_ENGINE.getName(), "Core", ImmutableMap.of(CqlIdentifier.fromInternal("tbl"), newTable));
    SchemaRefresh refresh = new SchemaRefresh(ImmutableMap.of(KS_WITH_ENGINE.getName(), ks, OLD_KS1.getName(), OLD_KS1));
    MetadataRefresh.Result result = refresh.compute(oldMetadata, false, context);
    assertThat(result.newMetadata.getKeyspaces()).hasSize(2);
    assertThat(result.events).containsExactly(TableChangeEvent.updated(OLD_TABLE, newTable));
    assertThat(result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName())).isNotNull();
    assertThat(((DseGraphTableMetadata) result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName()).getTable("tbl").get()).getVertex()).isNotNull();
    assertThat(((DseGraphTableMetadata) result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName()).getTable("tbl").get()).getEdge().get().getLabelName().asInternal()).isEqualTo("created");
    // now rename the edge label
    newTable = newTable(KS_WITH_ENGINE.getName(), CqlIdentifier.fromInternal("tbl"), null, newEdgeMetadata(CqlIdentifier.fromInternal("CHANGED"), CqlIdentifier.fromInternal("person"), CqlIdentifier.fromInternal("software")));
    ks = newKeyspace(KS_WITH_ENGINE.getName(), "Core", ImmutableMap.of(CqlIdentifier.fromInternal("tbl"), newTable));
    refresh = new SchemaRefresh(ImmutableMap.of(KS_WITH_ENGINE.getName(), ks, OLD_KS1.getName(), OLD_KS1));
    result = refresh.compute(oldMetadata, false, context);
    assertThat(result.newMetadata.getKeyspaces()).hasSize(2);
    assertThat(result.events).containsExactly(TableChangeEvent.updated(OLD_TABLE, newTable));
    assertThat(((DseGraphTableMetadata) result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName()).getTable("tbl").get()).getEdge().get().getLabelName().asInternal()).isEqualTo("CHANGED");
    // now remove the edge label from the table
    DefaultMetadata metadataWithEdgeLabel = result.newMetadata;
    DefaultDseTableMetadata tableWithRemovedLabel = newTable(KS_WITH_ENGINE.getName(), CqlIdentifier.fromInternal("tbl"), null, null);
    ks = newKeyspace(KS_WITH_ENGINE.getName(), "Core", ImmutableMap.of(CqlIdentifier.fromInternal("tbl"), tableWithRemovedLabel));
    refresh = new SchemaRefresh(ImmutableMap.of(KS_WITH_ENGINE.getName(), ks, OLD_KS1.getName(), OLD_KS1));
    result = refresh.compute(metadataWithEdgeLabel, false, context);
    assertThat(result.newMetadata.getKeyspaces()).hasSize(2);
    assertThat(result.events).containsExactly(TableChangeEvent.updated(newTable, tableWithRemovedLabel));
    assertThat(((DseGraphTableMetadata) result.newMetadata.getKeyspaces().get(KS_WITH_ENGINE.getName()).getTable("tbl").get()).getEdge().isPresent()).isFalse();
}
Also used : DefaultDseKeyspaceMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata) DseGraphTableMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseGraphTableMetadata) DefaultMetadata(com.datastax.oss.driver.internal.core.metadata.DefaultMetadata) SchemaRefresh(com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh) DefaultDseTableMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseTableMetadata) MetadataRefresh(com.datastax.oss.driver.internal.core.metadata.MetadataRefresh) Test(org.junit.Test)

Example 10 with SchemaRefresh

use of com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh in project java-driver by datastax.

the class SchemaParserTest method should_parse_modern_keyspace_row.

@Test
public void should_parse_modern_keyspace_row() {
    SchemaRefresh refresh = (SchemaRefresh) parse(rows -> rows.withKeyspaces(ImmutableList.of(mockModernKeyspaceRow("ks"))));
    assertThat(refresh.newKeyspaces).hasSize(1);
    KeyspaceMetadata keyspace = refresh.newKeyspaces.values().iterator().next();
    checkKeyspace(keyspace);
}
Also used : CodecRegistry(com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) SchemaRefresh(com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh) MetadataRefresh(com.datastax.oss.driver.internal.core.metadata.MetadataRefresh) ImmutableList(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList) CassandraSchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.CassandraSchemaRows) Consumer(java.util.function.Consumer) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) DataTypes(com.datastax.oss.driver.api.core.type.DataTypes) SchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows) FunctionSignature(com.datastax.oss.driver.api.core.metadata.schema.FunctionSignature) Map(java.util.Map) Assertions.assertThat(com.datastax.oss.driver.Assertions.assertThat) SchemaRefresh(com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) Test(org.junit.Test)

Aggregations

SchemaRefresh (com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh)11 MetadataRefresh (com.datastax.oss.driver.internal.core.metadata.MetadataRefresh)9 Test (org.junit.Test)9 DefaultDseKeyspaceMetadata (com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata)6 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)6 KeyspaceMetadata (com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)6 Assertions.assertThat (com.datastax.oss.driver.Assertions.assertThat)4 FunctionSignature (com.datastax.oss.driver.api.core.metadata.schema.FunctionSignature)4 DataTypes (com.datastax.oss.driver.api.core.type.DataTypes)4 CodecRegistry (com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry)4 CassandraSchemaRows (com.datastax.oss.driver.internal.core.metadata.schema.queries.CassandraSchemaRows)4 SchemaRows (com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows)4 ImmutableList (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList)4 Map (java.util.Map)4 Consumer (java.util.function.Consumer)4 Mockito.when (org.mockito.Mockito.when)4 DseGraphTableMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseGraphTableMetadata)2 DefaultDseTableMetadata (com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseTableMetadata)2 AdminRow (com.datastax.oss.driver.internal.core.adminrequest.AdminRow)2 DefaultMetadata (com.datastax.oss.driver.internal.core.metadata.DefaultMetadata)2