Search in sources :

Example 16 with TableDefinition

use of com.palantir.atlasdb.table.description.TableDefinition in project atlasdb by palantir.

the class CassandraKeyValueServiceTableCreationIntegrationTest method testCreateTableCanRestoreLostMetadata.

@Test
public void testCreateTableCanRestoreLostMetadata() {
    // setup a basic table
    TableReference missingMetadataTable = TableReference.createFromFullyQualifiedName("test.metadata_missing");
    byte[] initialMetadata = new TableDefinition() {

        {
            rowName();
            rowComponent("blob", ValueType.BLOB);
            columns();
            column("bar", "b", ValueType.BLOB);
            conflictHandler(ConflictHandler.IGNORE_ALL);
            sweepStrategy(TableMetadataPersistence.SweepStrategy.NOTHING);
        }
    }.toTableMetadata().persistToBytes();
    kvs.createTable(missingMetadataTable, initialMetadata);
    // retrieve the metadata and see that it's the same as what we just put in
    byte[] existingMetadata = kvs.getMetadataForTable(missingMetadataTable);
    assertThat(initialMetadata, is(existingMetadata));
    // Directly get and delete the metadata (`get` necessary to get the fake timestamp putMetadataForTables used)
    Cell cell = Cell.create(missingMetadataTable.getQualifiedName().getBytes(StandardCharsets.UTF_8), "m".getBytes(StandardCharsets.UTF_8));
    Value persistedMetadata = Iterables.getLast(kvs.get(AtlasDbConstants.DEFAULT_METADATA_TABLE, ImmutableMap.of(cell, Long.MAX_VALUE)).values());
    kvs.delete(AtlasDbConstants.DEFAULT_METADATA_TABLE, ImmutableMultimap.of(cell, persistedMetadata.getTimestamp()));
    // pretend we started up again and did a createTable() for our existing table, that no longer has metadata
    kvs.createTable(missingMetadataTable, initialMetadata);
    // retrieve the metadata again and see that it's the same as what we just put in
    existingMetadata = kvs.getMetadataForTable(missingMetadataTable);
    assertThat(initialMetadata, is(existingMetadata));
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Value(com.palantir.atlasdb.keyvalue.api.Value) TableDefinition(com.palantir.atlasdb.table.description.TableDefinition) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 17 with TableDefinition

use of com.palantir.atlasdb.table.description.TableDefinition in project atlasdb by palantir.

the class CassandraKeyValueServiceTableCreationIntegrationTest method testGetMetadataCaseInsensitive.

@Test
public void testGetMetadataCaseInsensitive() {
    // Make two casewise-different references to the "same" table
    TableReference caseSensitiveTable = TableReference.createFromFullyQualifiedName("test.cased_table");
    TableReference wackyCasedTable = TableReference.createFromFullyQualifiedName("test.CaSeD_TaBlE");
    byte[] initialMetadata = new TableDefinition() {

        {
            rowName();
            rowComponent("blob", ValueType.BLOB);
            columns();
            column("bar", "b", ValueType.BLOB);
            conflictHandler(ConflictHandler.IGNORE_ALL);
            sweepStrategy(TableMetadataPersistence.SweepStrategy.NOTHING);
        }
    }.toTableMetadata().persistToBytes();
    kvs.createTable(caseSensitiveTable, initialMetadata);
    // retrieve the metadata and see that it's the same as what we just put in
    byte[] existingMetadata = kvs.getMetadataForTable(caseSensitiveTable);
    assertThat(initialMetadata, is(existingMetadata));
    // retrieve same metadata with a wacky cased version of the "same" name
    existingMetadata = kvs.getMetadataForTable(wackyCasedTable);
    assertThat(initialMetadata, is(existingMetadata));
    kvs.dropTable(caseSensitiveTable);
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) TableDefinition(com.palantir.atlasdb.table.description.TableDefinition) Test(org.junit.Test)

Aggregations

TableDefinition (com.palantir.atlasdb.table.description.TableDefinition)17 Schema (com.palantir.atlasdb.table.description.Schema)8 AtlasSchema (com.palantir.atlasdb.schema.AtlasSchema)7 Test (org.junit.Test)4 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)3 StreamStoreDefinitionBuilder (com.palantir.atlasdb.schema.stream.StreamStoreDefinitionBuilder)3 Cell (com.palantir.atlasdb.keyvalue.api.Cell)2 IndexDefinition (com.palantir.atlasdb.table.description.IndexDefinition)2 ClassName (com.squareup.javapoet.ClassName)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 AtlasDbTestCase (com.palantir.atlasdb.AtlasDbTestCase)1 PtBytes (com.palantir.atlasdb.encoding.PtBytes)1 Namespace (com.palantir.atlasdb.keyvalue.api.Namespace)1 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)1 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)1 Value (com.palantir.atlasdb.keyvalue.api.Value)1 InMemoryKeyValueService (com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService)1 TableMappingNotFoundException (com.palantir.atlasdb.keyvalue.impl.TableMappingNotFoundException)1