Search in sources :

Example 31 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class ConsensusCommitUtilsTest method isBeforeImageColumn_PartitionKeyAndClusteringKeyWithBeforePrefixGiven_shouldReturnProperResult.

@Test
public void isBeforeImageColumn_PartitionKeyAndClusteringKeyWithBeforePrefixGiven_shouldReturnProperResult() {
    // Arrange
    TableMetadata metadata = TableMetadata.newBuilder().addColumn("partitionKey", DataType.INT).addColumn("before_partitionKey", DataType.INT).addColumn("clusteringKey", DataType.INT).addColumn("before_clusteringKey", DataType.INT).addColumn("col", DataType.INT).addColumn(Attribute.ID, DataType.TEXT).addColumn(Attribute.STATE, DataType.INT).addColumn(Attribute.VERSION, DataType.INT).addColumn(Attribute.PREPARED_AT, DataType.BIGINT).addColumn(Attribute.COMMITTED_AT, DataType.BIGINT).addColumn(Attribute.BEFORE_PREFIX + "col", DataType.INT).addColumn(Attribute.BEFORE_ID, DataType.TEXT).addColumn(Attribute.BEFORE_STATE, DataType.INT).addColumn(Attribute.BEFORE_VERSION, DataType.INT).addColumn(Attribute.BEFORE_PREPARED_AT, DataType.BIGINT).addColumn(Attribute.BEFORE_COMMITTED_AT, DataType.BIGINT).addPartitionKey("partitionKey").addPartitionKey("before_partitionKey").addClusteringKey("clusteringKey").addClusteringKey("before_clusteringKey").build();
    // Act Assert
    assertThat(ConsensusCommitUtils.isBeforeImageColumn("partitionKey", metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn("before_partitionKey", metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn("clusteringKey", metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn("before_clusteringKey", metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn("col", metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn(Attribute.ID, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn(Attribute.STATE, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn(Attribute.VERSION, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn(Attribute.PREPARED_AT, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn(Attribute.COMMITTED_AT, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn(Attribute.BEFORE_PREFIX + "col", metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn(Attribute.BEFORE_ID, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn(Attribute.BEFORE_STATE, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn(Attribute.BEFORE_VERSION, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn(Attribute.BEFORE_PREPARED_AT, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isBeforeImageColumn(Attribute.BEFORE_COMMITTED_AT, metadata)).isTrue();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.jupiter.api.Test)

Example 32 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class TwoPhaseConsensusCommitSpecificIntegrationTestBase method createTables.

private void createTables() throws ExecutionException {
    Map<String, String> options = getCreateOptions();
    TableMetadata tableMetadata = TableMetadata.newBuilder().addColumn(ACCOUNT_ID, DataType.INT).addColumn(ACCOUNT_TYPE, DataType.INT).addColumn(BALANCE, DataType.INT).addPartitionKey(ACCOUNT_ID).addClusteringKey(ACCOUNT_TYPE).build();
    admin.createNamespace(namespace, true, options);
    consensusCommitAdmin.createTable(namespace, TABLE_1, tableMetadata, true, options);
    consensusCommitAdmin.createTable(namespace, TABLE_2, tableMetadata, true, options);
    consensusCommitAdmin.createCoordinatorTables(true, options);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata)

Example 33 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class MultiStorageAdminIntegrationTest method getTableMetadata_ForWrongTable_ShouldReturnNull.

@Test
public void getTableMetadata_ForWrongTable_ShouldReturnNull() throws ExecutionException {
    // Arrange
    String namespace = "wrong_ns";
    String table = "wrong_table";
    // Act
    TableMetadata tableMetadata = multiStorageAdmin.getTableMetadata(namespace, table);
    // Assert
    assertThat(tableMetadata).isNull();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.jupiter.api.Test)

Example 34 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class MultiStorageAdminIntegrationTest method initAdmin1.

private void initAdmin1() throws ExecutionException {
    StorageFactory factory = StorageFactory.create(MultiStorageEnv.getPropertiesForStorage1());
    admin1 = factory.getAdmin();
    // create tables
    admin1.createNamespace(NAMESPACE1, true);
    TableMetadata tableMetadata = TableMetadata.newBuilder().addPartitionKey(COL_NAME1).addClusteringKey(COL_NAME4).addColumn(COL_NAME1, DataType.INT).addColumn(COL_NAME2, DataType.TEXT).addColumn(COL_NAME3, DataType.INT).addColumn(COL_NAME4, DataType.INT).addColumn(COL_NAME5, DataType.BOOLEAN).build();
    for (String table : Arrays.asList(TABLE1, TABLE2, TABLE3)) {
        admin1.createTable(NAMESPACE1, table, tableMetadata, true);
    }
    admin1.createNamespace(NAMESPACE2, true);
    admin1.createTable(NAMESPACE2, TABLE1, tableMetadata, true);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) StorageFactory(com.scalar.db.service.StorageFactory)

Example 35 with TableMetadata

use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.

the class MultiStorageAdminIntegrationTest method initAdmin2.

private void initAdmin2() throws ExecutionException {
    StorageFactory factory = StorageFactory.create(MultiStorageEnv.getPropertiesForStorage2());
    admin2 = factory.getAdmin();
    // create tables
    admin2.createNamespace(NAMESPACE1, true);
    TableMetadata tableMetadata = TableMetadata.newBuilder().addColumn(COL_NAME1, DataType.TEXT).addColumn(COL_NAME2, DataType.INT).addColumn(COL_NAME3, DataType.BOOLEAN).addPartitionKey(COL_NAME1).build();
    for (String table : Arrays.asList(TABLE1, TABLE2, TABLE3)) {
        admin2.createTable(NAMESPACE1, table, tableMetadata, true);
    }
    admin2.createNamespace(NAMESPACE2, true);
    admin2.createTable(NAMESPACE2, TABLE1, tableMetadata, true);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) StorageFactory(com.scalar.db.service.StorageFactory)

Aggregations

TableMetadata (com.scalar.db.api.TableMetadata)101 Test (org.junit.jupiter.api.Test)39 Get (com.scalar.db.api.Get)11 PreparedStatement (java.sql.PreparedStatement)10 ExecutionException (com.scalar.db.exception.storage.ExecutionException)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Key (com.scalar.db.io.Key)6 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)6 Mutation (com.scalar.db.api.Mutation)5 Result (com.scalar.db.api.Result)5 GetTableMetadataResponse (com.scalar.db.rpc.GetTableMetadataResponse)5 ResultSet (java.sql.ResultSet)5 Nonnull (javax.annotation.Nonnull)5 HashMap (java.util.HashMap)4 Options (com.datastax.driver.core.schemabuilder.Create.Options)3 KeyspaceOptions (com.datastax.driver.core.schemabuilder.KeyspaceOptions)3 TableOptions (com.datastax.driver.core.schemabuilder.TableOptions)3 ScanAll (com.scalar.db.api.ScanAll)3 NoMutationException (com.scalar.db.exception.storage.NoMutationException)3