Search in sources :

Example 26 with TableMetadata

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

the class ConsensusCommitUtilsTest method buildTransactionalTableMetadata_tableMetadataGiven_shouldCreateTransactionalTableProperly.

@Test
public void buildTransactionalTableMetadata_tableMetadataGiven_shouldCreateTransactionalTableProperly() {
    // Arrange
    final String ACCOUNT_ID = "account_id";
    final String ACCOUNT_TYPE = "account_type";
    final String BALANCE = "balance";
    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();
    TableMetadata expected = TableMetadata.newBuilder().addColumn(ACCOUNT_ID, DataType.INT).addColumn(ACCOUNT_TYPE, DataType.INT).addColumn(BALANCE, 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 + BALANCE, 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(ACCOUNT_ID).addClusteringKey(ACCOUNT_TYPE).build();
    // Act
    TableMetadata actual = ConsensusCommitUtils.buildTransactionalTableMetadata(tableMetadata);
    // Assert
    assertThat(actual).isEqualTo(expected);
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.jupiter.api.Test)

Example 27 with TableMetadata

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

the class ConsensusCommitUtilsTest method isTransactionalTableMetadata_properTransactionalTableMetadataGiven_shouldReturnTrue.

@Test
public void isTransactionalTableMetadata_properTransactionalTableMetadataGiven_shouldReturnTrue() {
    // Arrange
    final String ACCOUNT_ID = "account_id";
    final String ACCOUNT_TYPE = "account_type";
    final String BALANCE = "balance";
    TableMetadata metadata = TableMetadata.newBuilder().addColumn(ACCOUNT_ID, DataType.INT).addColumn(ACCOUNT_TYPE, DataType.INT).addColumn(BALANCE, 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 + BALANCE, 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(ACCOUNT_ID).addClusteringKey(ACCOUNT_TYPE).build();
    // Act
    boolean actual = ConsensusCommitUtils.isTransactionalTableMetadata(metadata);
    // Assert
    assertThat(actual).isTrue();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.jupiter.api.Test)

Example 28 with TableMetadata

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

the class ConsensusCommitUtilsTest method removeTransactionalMetaColumns_transactionalTableMetadataWithoutProperBeforeColumnGiven_shouldReturnFalse.

@Test
public void removeTransactionalMetaColumns_transactionalTableMetadataWithoutProperBeforeColumnGiven_shouldReturnFalse() {
    // Arrange
    final String ACCOUNT_ID = "account_id";
    final String ACCOUNT_TYPE = "account_type";
    final String BALANCE = "balance";
    TableMetadata metadata = TableMetadata.newBuilder().addColumn(ACCOUNT_ID, DataType.INT).addColumn(ACCOUNT_TYPE, DataType.INT).addColumn(BALANCE, 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 + BALANCE, 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(ACCOUNT_ID).addClusteringKey(ACCOUNT_TYPE).build();
    // Act
    TableMetadata actual = ConsensusCommitUtils.removeTransactionalMetaColumns(metadata);
    // Assert
    assertThat(actual).isEqualTo(TableMetadata.newBuilder().addColumn(ACCOUNT_ID, DataType.INT).addColumn(ACCOUNT_TYPE, DataType.INT).addColumn(BALANCE, DataType.INT).addPartitionKey(ACCOUNT_ID).addClusteringKey(ACCOUNT_TYPE).build());
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.jupiter.api.Test)

Example 29 with TableMetadata

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

the class ConsensusCommitUtilsTest method isAfterImageColumn_ResultGiven_shouldReturnProperResult.

@Test
public void isAfterImageColumn_ResultGiven_shouldReturnProperResult() {
    // Arrange
    final String ACCOUNT_ID = "account_id";
    final String ACCOUNT_TYPE = "account_type";
    final String BALANCE = "balance";
    TableMetadata metadata = TableMetadata.newBuilder().addColumn(ACCOUNT_ID, DataType.INT).addColumn(ACCOUNT_TYPE, DataType.INT).addColumn(BALANCE, 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 + BALANCE, 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(ACCOUNT_ID).addClusteringKey(ACCOUNT_TYPE).build();
    // Act Assert
    assertThat(ConsensusCommitUtils.isAfterImageColumn(ACCOUNT_ID, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isAfterImageColumn(ACCOUNT_TYPE, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isAfterImageColumn(BALANCE, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isAfterImageColumn(Attribute.ID, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isAfterImageColumn(Attribute.STATE, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isAfterImageColumn(Attribute.VERSION, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isAfterImageColumn(Attribute.PREPARED_AT, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isAfterImageColumn(Attribute.COMMITTED_AT, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isAfterImageColumn(Attribute.BEFORE_PREFIX + BALANCE, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isAfterImageColumn(Attribute.BEFORE_ID, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isAfterImageColumn(Attribute.BEFORE_STATE, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isAfterImageColumn(Attribute.BEFORE_VERSION, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isAfterImageColumn(Attribute.BEFORE_PREPARED_AT, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isAfterImageColumn(Attribute.BEFORE_COMMITTED_AT, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isAfterImageColumn("aaa", metadata)).isFalse();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.jupiter.api.Test)

Example 30 with TableMetadata

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

the class ConsensusCommitUtilsTest method isTransactionalMetaColumn_ResultGiven_shouldReturnProperResult.

@Test
public void isTransactionalMetaColumn_ResultGiven_shouldReturnProperResult() {
    // Arrange
    final String ACCOUNT_ID = "account_id";
    final String ACCOUNT_TYPE = "account_type";
    final String BALANCE = "balance";
    TableMetadata metadata = TableMetadata.newBuilder().addColumn(ACCOUNT_ID, DataType.INT).addColumn(ACCOUNT_TYPE, DataType.INT).addColumn(BALANCE, 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 + BALANCE, 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(ACCOUNT_ID).addClusteringKey(ACCOUNT_TYPE).build();
    // Act Assert
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(ACCOUNT_ID, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(ACCOUNT_TYPE, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(BALANCE, metadata)).isFalse();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(Attribute.ID, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(Attribute.STATE, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(Attribute.VERSION, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(Attribute.PREPARED_AT, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(Attribute.COMMITTED_AT, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(Attribute.BEFORE_PREFIX + BALANCE, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(Attribute.BEFORE_ID, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(Attribute.BEFORE_STATE, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(Attribute.BEFORE_VERSION, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(Attribute.BEFORE_PREPARED_AT, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn(Attribute.BEFORE_COMMITTED_AT, metadata)).isTrue();
    assertThat(ConsensusCommitUtils.isTransactionalMetaColumn("aaa", metadata)).isFalse();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Test(org.junit.jupiter.api.Test)

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