Search in sources :

Example 1 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_without_graph_engine.

@Test
public void should_detect_created_keyspace_without_graph_engine() {
    DefaultDseKeyspaceMetadata ks2 = newKeyspace("ks2", null);
    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 2 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_keyspace_with_all_children.

@Test
public void should_parse_keyspace_with_all_children() {
    // Needed to parse the aggregate
    when(context.getCodecRegistry()).thenReturn(CodecRegistry.DEFAULT);
    SchemaRefresh refresh = (SchemaRefresh) parse(rows -> rows.withKeyspaces(ImmutableList.of(mockModernKeyspaceRow("ks"))).withTypes(ImmutableList.of(mockTypeRow("ks", "t", ImmutableList.of("i"), ImmutableList.of("int")))).withTables(ImmutableList.of(TableParserTest.TABLE_ROW_3_0)).withColumns(TableParserTest.COLUMN_ROWS_3_0).withIndexes(TableParserTest.INDEX_ROWS_3_0).withViews(ImmutableList.of(ViewParserTest.VIEW_ROW_3_0)).withColumns(ViewParserTest.COLUMN_ROWS_3_0).withFunctions(ImmutableList.of(FunctionParserTest.ID_ROW_3_0)).withAggregates(ImmutableList.of(AggregateParserTest.SUM_AND_TO_STRING_ROW_3_0)));
    assertThat(refresh.newKeyspaces).hasSize(1);
    KeyspaceMetadata keyspace = refresh.newKeyspaces.values().iterator().next();
    checkKeyspace(keyspace);
    assertThat(keyspace.getUserDefinedTypes()).hasSize(1).containsKey(CqlIdentifier.fromInternal("t"));
    assertThat(keyspace.getTables()).hasSize(1).containsKey(CqlIdentifier.fromInternal("foo"));
    assertThat(keyspace.getViews()).hasSize(1).containsKey(CqlIdentifier.fromInternal("alltimehigh"));
    assertThat(keyspace.getFunctions()).hasSize(1).containsKey(new FunctionSignature(CqlIdentifier.fromInternal("id"), DataTypes.INT));
    assertThat(keyspace.getAggregates()).hasSize(1).containsKey(new FunctionSignature(CqlIdentifier.fromInternal("sum_and_to_string"), DataTypes.INT));
}
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) FunctionSignature(com.datastax.oss.driver.api.core.metadata.schema.FunctionSignature) Test(org.junit.Test)

Example 3 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_legacy_keyspace_row.

@Test
public void should_parse_legacy_keyspace_row() {
    SchemaRefresh refresh = (SchemaRefresh) parse(rows -> rows.withKeyspaces(ImmutableList.of(mockLegacyKeyspaceRow("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)

Example 4 with SchemaRefresh

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

the class CassandraSchemaParser method parse.

@Override
public SchemaRefresh parse() {
    ImmutableMap.Builder<CqlIdentifier, KeyspaceMetadata> keyspacesBuilder = ImmutableMap.builder();
    for (AdminRow row : rows.keyspaces()) {
        KeyspaceMetadata keyspace = parseKeyspace(row);
        keyspacesBuilder.put(keyspace.getName(), keyspace);
    }
    for (AdminRow row : rows.virtualKeyspaces()) {
        KeyspaceMetadata keyspace = parseVirtualKeyspace(row);
        keyspacesBuilder.put(keyspace.getName(), keyspace);
    }
    SchemaRefresh refresh = new SchemaRefresh(keyspacesBuilder.build());
    LOG.debug("[{}] Schema parsing took {}", logPrefix, NanoTime.formatTimeSince(startTimeNs));
    return refresh;
}
Also used : SchemaRefresh(com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) DefaultKeyspaceMetadata(com.datastax.oss.driver.internal.core.metadata.schema.DefaultKeyspaceMetadata) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)

Example 5 with SchemaRefresh

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

the class DseSchemaParser method parse.

@Override
public SchemaRefresh parse() {
    ImmutableMap.Builder<CqlIdentifier, KeyspaceMetadata> keyspacesBuilder = ImmutableMap.builder();
    for (AdminRow row : rows.keyspaces()) {
        DseKeyspaceMetadata keyspace = parseKeyspace(row);
        keyspacesBuilder.put(keyspace.getName(), keyspace);
    }
    for (AdminRow row : rows.virtualKeyspaces()) {
        DseKeyspaceMetadata keyspace = parseVirtualKeyspace(row);
        keyspacesBuilder.put(keyspace.getName(), keyspace);
    }
    SchemaRefresh refresh = new SchemaRefresh(keyspacesBuilder.build());
    LOG.debug("[{}] Schema parsing took {}", logPrefix, NanoTime.formatTimeSince(startTimeNs));
    return refresh;
}
Also used : DseKeyspaceMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseKeyspaceMetadata) DefaultDseKeyspaceMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata) SchemaRefresh(com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) DseKeyspaceMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseKeyspaceMetadata) DefaultDseKeyspaceMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)

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