use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class ConsensusCommitAdminTest method getTableMetadata_ShouldCallJdbcAdminProperly.
@Test
public void getTableMetadata_ShouldCallJdbcAdminProperly() throws ExecutionException {
// 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).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();
TableMetadata expected = TableMetadata.newBuilder().addColumn(ACCOUNT_ID, DataType.INT).addColumn(ACCOUNT_TYPE, DataType.INT).addColumn(BALANCE, DataType.INT).addPartitionKey(ACCOUNT_ID).addClusteringKey(ACCOUNT_TYPE).build();
when(distributedStorageAdmin.getTableMetadata(any(), any())).thenReturn(tableMetadata);
// Act
TableMetadata actual = admin.getTableMetadata("ns", "tbl");
// Assert
verify(distributedStorageAdmin).getTableMetadata("ns", "tbl");
assertThat(actual).isEqualTo(expected);
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class ConsensusCommitUtilsTest method isTransactionalTableMetadata_transactionalTableMetadataWithoutMetaColumnGiven_shouldReturnFalse.
@Test
public void isTransactionalTableMetadata_transactionalTableMetadataWithoutMetaColumnGiven_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.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).isFalse();
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class ConsensusCommitUtilsTest method isTransactionalMetaColumn_TableMetadataGiven_shouldReturnProperResult.
@Test
public void isTransactionalMetaColumn_TableMetadataGiven_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();
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class ConsensusCommitUtilsTest method isBeforeImageColumn_ResultGiven_shouldReturnProperResult.
@Test
public void isBeforeImageColumn_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.isBeforeImageColumn(ACCOUNT_ID, metadata)).isFalse();
assertThat(ConsensusCommitUtils.isBeforeImageColumn(ACCOUNT_TYPE, metadata)).isFalse();
assertThat(ConsensusCommitUtils.isBeforeImageColumn(BALANCE, 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 + BALANCE, 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();
assertThat(ConsensusCommitUtils.isBeforeImageColumn("aaa", metadata)).isFalse();
}
use of com.scalar.db.api.TableMetadata in project scalardb by scalar-labs.
the class ConsensusCommitUtilsTest method isTransactionalTableMetadata_transactionalTableMetadataWithoutProperBeforeColumnGiven_shouldReturnFalse.
@Test
public void isTransactionalTableMetadata_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_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).isFalse();
}
Aggregations