diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminCaseSensitivityIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminCaseSensitivityIntegrationTest.java new file mode 100644 index 0000000000..1dcc29cca4 --- /dev/null +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminCaseSensitivityIntegrationTest.java @@ -0,0 +1,20 @@ +package com.scalar.db.storage.cassandra; + +import com.scalar.db.api.DistributedStorageAdminCaseSensitivityIntegrationTestBase; +import com.scalar.db.config.DatabaseConfig; +import java.util.Properties; + +public class CassandraAdminCaseSensitivityIntegrationTest + extends DistributedStorageAdminCaseSensitivityIntegrationTestBase { + @Override + protected Properties getProperties(String testName) { + return CassandraEnv.getProperties(testName); + } + + @Override + protected String getSystemNamespaceName(Properties properties) { + return new CassandraConfig(new DatabaseConfig(properties)) + .getSystemNamespaceName() + .orElse(DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME); + } +} diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraCaseSensitivityIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraCaseSensitivityIntegrationTest.java new file mode 100644 index 0000000000..3632f6cb6e --- /dev/null +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraCaseSensitivityIntegrationTest.java @@ -0,0 +1,21 @@ +package com.scalar.db.storage.cassandra; + +import com.scalar.db.api.DistributedStorageCaseSensitivityIntegrationTestBase; +import java.util.Properties; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +public class CassandraCaseSensitivityIntegrationTest + extends DistributedStorageCaseSensitivityIntegrationTestBase { + @Override + protected Properties getProperties(String testName) { + return CassandraEnv.getProperties(testName); + } + + @Disabled( + "In Cassandra, if an IS NULL condition is specified for a column in a non-existing record, " + + "the condition is considered satisfied. This behavior differs from that of other adapters") + @Override + @Test + public void put_withPutIfIsNullWhenRecordDoesNotExist_shouldThrowNoMutationException() {} +} diff --git a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraWithReservedKeywordIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraWithReservedKeywordIntegrationTest.java index 9f2e323c1b..c380d1cdfa 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraWithReservedKeywordIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraWithReservedKeywordIntegrationTest.java @@ -2,6 +2,8 @@ import com.scalar.db.api.DistributedStorageWithReservedKeywordIntegrationTestBase; import java.util.Properties; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; public class CassandraWithReservedKeywordIntegrationTest extends DistributedStorageWithReservedKeywordIntegrationTestBase { @@ -52,4 +54,11 @@ protected String getColumnName5() { protected Properties getProperties(String testName) { return CassandraEnv.getProperties(testName); } + + @Disabled( + "In Cassandra, if an IS NULL condition is specified for a column in a non-existing record, " + + "the condition is considered satisfied. This behavior differs from that of other adapters") + @Override + @Test + public void put_withPutIfIsNullWhenRecordDoesNotExist_shouldThrowNoMutationException() {} } diff --git a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminCaseSensitivityIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminCaseSensitivityIntegrationTest.java new file mode 100644 index 0000000000..0ea6fca2c7 --- /dev/null +++ b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminCaseSensitivityIntegrationTest.java @@ -0,0 +1,27 @@ +package com.scalar.db.storage.cosmos; + +import com.scalar.db.api.DistributedStorageAdminCaseSensitivityIntegrationTestBase; +import com.scalar.db.config.DatabaseConfig; +import java.util.Map; +import java.util.Properties; + +public class CosmosAdminCaseSensitivityIntegrationTest + extends DistributedStorageAdminCaseSensitivityIntegrationTestBase { + + @Override + protected Properties getProperties(String testName) { + return CosmosEnv.getProperties(testName); + } + + @Override + protected Map getCreationOptions() { + return CosmosEnv.getCreationOptions(); + } + + @Override + protected String getSystemNamespaceName(Properties properties) { + return new CosmosConfig(new DatabaseConfig(properties)) + .getTableMetadataDatabase() + .orElse(DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME); + } +} diff --git a/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosCaseSensitivityIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosCaseSensitivityIntegrationTest.java new file mode 100644 index 0000000000..12fca00538 --- /dev/null +++ b/core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosCaseSensitivityIntegrationTest.java @@ -0,0 +1,19 @@ +package com.scalar.db.storage.cosmos; + +import com.scalar.db.api.DistributedStorageCaseSensitivityIntegrationTestBase; +import java.util.Map; +import java.util.Properties; + +public class CosmosCaseSensitivityIntegrationTest + extends DistributedStorageCaseSensitivityIntegrationTestBase { + + @Override + protected Properties getProperties(String testName) { + return CosmosEnv.getProperties(testName); + } + + @Override + protected Map getCreationOptions() { + return CosmosEnv.getCreationOptions(); + } +} diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoAdminCaseSensitivityIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoAdminCaseSensitivityIntegrationTest.java new file mode 100644 index 0000000000..2a6826d856 --- /dev/null +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoAdminCaseSensitivityIntegrationTest.java @@ -0,0 +1,82 @@ +package com.scalar.db.storage.dynamo; + +import com.scalar.db.api.DistributedStorageAdminCaseSensitivityIntegrationTestBase; +import com.scalar.db.config.DatabaseConfig; +import java.util.Map; +import java.util.Properties; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +public class DynamoAdminCaseSensitivityIntegrationTest + extends DistributedStorageAdminCaseSensitivityIntegrationTestBase { + + @Override + protected Properties getProperties(String testName) { + return DynamoEnv.getProperties(testName); + } + + @Override + protected Map getCreationOptions() { + return DynamoEnv.getCreationOptions(); + } + + @Override + protected boolean isIndexOnBooleanColumnSupported() { + return false; + } + + @Override + protected String getSystemNamespaceName(Properties properties) { + return new DynamoConfig(new DatabaseConfig(properties)) + .getTableMetadataNamespace() + .orElse(DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME); + } + + // Since DynamoDB doesn't have the namespace concept, some behaviors around the namespace are + // different from the other adapters. So disable several tests that check such behaviors + + @Disabled + @Test + @Override + public void createNamespace_ForNonExistingNamespace_ShouldCreateNamespaceProperly() {} + + @Disabled + @Test + @Override + public void createNamespace_ForExistingNamespace_ShouldThrowIllegalArgumentException() {} + + @Disabled + @Test + @Override + public void createNamespace_IfNotExists_ForExistingNamespace_ShouldNotThrowAnyException() {} + + @Disabled + @Test + @Override + public void dropNamespace_ForNonExistingNamespace_ShouldDropNamespaceProperly() {} + + @Disabled + @Test + @Override + public void dropNamespace_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() {} + + @Disabled + @Test + @Override + public void dropNamespace_ForNonEmptyNamespace_ShouldThrowIllegalArgumentException() {} + + @Disabled + @Test + @Override + public void dropNamespace_IfExists_ForNonExistingNamespace_ShouldNotThrowAnyException() {} + + @Disabled + @Test + @Override + public void namespaceExists_ShouldReturnCorrectResults() {} + + @Disabled + @Test + @Override + public void createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() {} +} diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoCaseSensitivityIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoCaseSensitivityIntegrationTest.java new file mode 100644 index 0000000000..954cbddbda --- /dev/null +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoCaseSensitivityIntegrationTest.java @@ -0,0 +1,24 @@ +package com.scalar.db.storage.dynamo; + +import com.scalar.db.api.DistributedStorageCaseSensitivityIntegrationTestBase; +import java.util.Map; +import java.util.Properties; +import org.junit.jupiter.api.Disabled; + +public class DynamoCaseSensitivityIntegrationTest + extends DistributedStorageCaseSensitivityIntegrationTestBase { + + @Override + protected Properties getProperties(String testName) { + return DynamoEnv.getProperties(testName); + } + + @Override + protected Map getCreationOptions() { + return DynamoEnv.getCreationOptions(); + } + + @Disabled("DynamoDB doesn't support putting a null value for a secondary index column") + @Override + public void put_PutGivenForIndexedColumnWithNullValue_ShouldPut() {} +} diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoIntegrationTest.java index a20c02fa40..ea40578509 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoIntegrationTest.java @@ -17,8 +17,7 @@ protected Map getCreationOptions() { return DynamoEnv.getCreationOptions(); } - // DynamoDB doesn't support putting a null value for a secondary index column - @Disabled + @Disabled("DynamoDB doesn't support putting a null value for a secondary index column") @Override public void put_PutGivenForIndexedColumnWithNullValue_ShouldPut() {} } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoWithReservedKeywordIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoWithReservedKeywordIntegrationTest.java index 491072758a..348bd988bb 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoWithReservedKeywordIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoWithReservedKeywordIntegrationTest.java @@ -3,6 +3,7 @@ import com.scalar.db.api.DistributedStorageWithReservedKeywordIntegrationTestBase; import java.util.Map; import java.util.Properties; +import org.junit.jupiter.api.Disabled; public class DynamoWithReservedKeywordIntegrationTest extends DistributedStorageWithReservedKeywordIntegrationTestBase { @@ -58,4 +59,8 @@ protected Properties getProperties(String testName) { protected Map getCreationOptions() { return DynamoEnv.getCreationOptions(); } + + @Disabled("DynamoDB doesn't support putting a null value for a secondary index column") + @Override + public void put_PutGivenForIndexedColumnWithNullValue_ShouldPut() {} } diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminCaseSensitivityIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminCaseSensitivityIntegrationTest.java new file mode 100644 index 0000000000..7d19aed743 --- /dev/null +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminCaseSensitivityIntegrationTest.java @@ -0,0 +1,98 @@ +package com.scalar.db.storage.jdbc; + +import com.scalar.db.api.DistributedStorageAdminCaseSensitivityIntegrationTestBase; +import com.scalar.db.config.DatabaseConfig; +import com.scalar.db.exception.storage.ExecutionException; +import java.util.Properties; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIf; + +public class JdbcAdminCaseSensitivityIntegrationTest + extends DistributedStorageAdminCaseSensitivityIntegrationTestBase { + + @Override + protected Properties getProperties(String testName) { + return JdbcEnv.getProperties(testName); + } + + @Override + protected String getSystemNamespaceName(Properties properties) { + return new JdbcConfig(new DatabaseConfig(properties)) + .getTableMetadataSchema() + .orElse(DatabaseConfig.DEFAULT_SYSTEM_NAMESPACE_NAME); + } + + // Since SQLite doesn't have persistent namespaces, some behaviors around the namespace are + // different from the other adapters. So disable several tests that check such behaviors. + + @SuppressWarnings("unused") + private boolean isSqlite() { + return JdbcEnv.isSqlite(); + } + + @Test + @Override + @DisabledIf("isSqlite") + public void createNamespace_ForNonExistingNamespace_ShouldCreateNamespaceProperly() + throws ExecutionException { + super.createNamespace_ForNonExistingNamespace_ShouldCreateNamespaceProperly(); + } + + @Test + @Override + @DisabledIf("isSqlite") + public void createNamespace_ForExistingNamespace_ShouldThrowIllegalArgumentException() { + super.createNamespace_ForExistingNamespace_ShouldThrowIllegalArgumentException(); + } + + @Test + @Override + @DisabledIf("isSqlite") + public void createNamespace_IfNotExists_ForExistingNamespace_ShouldNotThrowAnyException() { + super.createNamespace_IfNotExists_ForExistingNamespace_ShouldNotThrowAnyException(); + } + + @Test + @Override + @DisabledIf("isSqlite") + public void dropNamespace_ForNonExistingNamespace_ShouldDropNamespaceProperly() + throws ExecutionException { + super.dropNamespace_ForNonExistingNamespace_ShouldDropNamespaceProperly(); + } + + @Test + @Override + @DisabledIf("isSqlite") + public void dropNamespace_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() { + super.dropNamespace_ForNonExistingNamespace_ShouldThrowIllegalArgumentException(); + } + + @Test + @Override + @DisabledIf("isSqlite") + public void dropNamespace_ForNonEmptyNamespace_ShouldThrowIllegalArgumentException() + throws ExecutionException { + super.dropNamespace_ForNonEmptyNamespace_ShouldThrowIllegalArgumentException(); + } + + @Test + @Override + @DisabledIf("isSqlite") + public void dropNamespace_IfExists_ForNonExistingNamespace_ShouldNotThrowAnyException() { + super.dropNamespace_IfExists_ForNonExistingNamespace_ShouldNotThrowAnyException(); + } + + @Test + @Override + @DisabledIf("isSqlite") + public void namespaceExists_ShouldReturnCorrectResults() throws ExecutionException { + super.namespaceExists_ShouldReturnCorrectResults(); + } + + @Test + @Override + @DisabledIf("isSqlite") + public void createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentException() { + super.createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentException(); + } +} diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseCaseSensitivityIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseCaseSensitivityIntegrationTest.java new file mode 100644 index 0000000000..e2cb1a1aa5 --- /dev/null +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseCaseSensitivityIntegrationTest.java @@ -0,0 +1,29 @@ +package com.scalar.db.storage.jdbc; + +import com.scalar.db.api.DistributedStorageCaseSensitivityIntegrationTestBase; +import com.scalar.db.config.DatabaseConfig; +import java.util.Properties; + +public class JdbcDatabaseCaseSensitivityIntegrationTest + extends DistributedStorageCaseSensitivityIntegrationTestBase { + + private RdbEngineStrategy rdbEngine; + + @Override + protected Properties getProperties(String testName) { + Properties properties = JdbcEnv.getProperties(testName); + JdbcConfig config = new JdbcConfig(new DatabaseConfig(properties)); + rdbEngine = RdbEngineFactory.create(config); + return JdbcEnv.getProperties(testName); + } + + @Override + protected int getLargeDataSizeInBytes() { + if (JdbcTestUtils.isOracle(rdbEngine)) { + // For Oracle, the max data size for BLOB is 2000 bytes + return 2000; + } else { + return super.getLargeDataSizeInBytes(); + } + } +} diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseWithReservedKeywordIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseWithReservedKeywordIntegrationTest.java index 4f18348c33..3da319aa3e 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseWithReservedKeywordIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseWithReservedKeywordIntegrationTest.java @@ -1,11 +1,14 @@ package com.scalar.db.storage.jdbc; import com.scalar.db.api.DistributedStorageWithReservedKeywordIntegrationTestBase; +import com.scalar.db.config.DatabaseConfig; import java.util.Properties; public class JdbcDatabaseWithReservedKeywordIntegrationTest extends DistributedStorageWithReservedKeywordIntegrationTestBase { + private RdbEngineStrategy rdbEngine; + @Override protected String getNamespace() { // a reserved keyword in JDBC @@ -50,6 +53,19 @@ protected String getColumnName5() { @Override protected Properties getProperties(String testName) { + Properties properties = JdbcEnv.getProperties(testName); + JdbcConfig config = new JdbcConfig(new DatabaseConfig(properties)); + rdbEngine = RdbEngineFactory.create(config); return JdbcEnv.getProperties(testName); } + + @Override + protected int getLargeDataSizeInBytes() { + if (JdbcTestUtils.isOracle(rdbEngine)) { + // For Oracle, the max data size for BLOB is 2000 bytes + return 2000; + } else { + return super.getLargeDataSizeInBytes(); + } + } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminCaseSensitivityIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminCaseSensitivityIntegrationTestBase.java new file mode 100644 index 0000000000..14f7da5684 --- /dev/null +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminCaseSensitivityIntegrationTestBase.java @@ -0,0 +1,120 @@ +package com.scalar.db.api; + +public abstract class DistributedStorageAdminCaseSensitivityIntegrationTestBase + extends DistributedStorageAdminIntegrationTestBase { + + private static final String TEST_NAME = "storage_admin_case"; + private static final String NAMESPACE1 = "Int_test_" + TEST_NAME + "1"; + private static final String NAMESPACE2 = "Int_test_" + TEST_NAME + "2"; + private static final String NAMESPACE3 = "Int_test_" + TEST_NAME + "3"; + private static final String TABLE1 = "Test_table1"; + private static final String TABLE2 = "Test_table2"; + private static final String TABLE3 = "Test_table3"; + private static final String TABLE4 = "Test_table4"; + private static final String COL_NAME1 = "Column1"; + private static final String COL_NAME2 = "Column2"; + private static final String COL_NAME3 = "Column3"; + private static final String COL_NAME4 = "Column4"; + private static final String COL_NAME5 = "Column5"; + private static final String COL_NAME6 = "Column6"; + private static final String COL_NAME7 = "Column7"; + private static final String COL_NAME8 = "Column8"; + private static final String COL_NAME9 = "Column9"; + private static final String COL_NAME10 = "Column10"; + private static final String COL_NAME11 = "Column11"; + + @Override + protected String getTestName() { + return TEST_NAME; + } + + @Override + protected String getNamespace1() { + return NAMESPACE1; + } + + @Override + protected String getNamespace2() { + return NAMESPACE2; + } + + @Override + protected String getNamespace3() { + return NAMESPACE3; + } + + @Override + protected String getTable1() { + return TABLE1; + } + + @Override + protected String getTable2() { + return TABLE2; + } + + @Override + protected String getTable3() { + return TABLE3; + } + + @Override + protected String getTable4() { + return TABLE4; + } + + @Override + protected String getColumnName1() { + return COL_NAME1; + } + + @Override + protected String getColumnName2() { + return COL_NAME2; + } + + @Override + protected String getColumnName3() { + return COL_NAME3; + } + + @Override + protected String getColumnName4() { + return COL_NAME4; + } + + @Override + protected String getColumnName5() { + return COL_NAME5; + } + + @Override + protected String getColumnName6() { + return COL_NAME6; + } + + @Override + protected String getColumnName7() { + return COL_NAME7; + } + + @Override + protected String getColumnName8() { + return COL_NAME8; + } + + @Override + protected String getColumnName9() { + return COL_NAME9; + } + + @Override + protected String getColumnName10() { + return COL_NAME10; + } + + @Override + protected String getColumnName11() { + return COL_NAME11; + } +} diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java index 9f910ecd6d..335e727395 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminIntegrationTestBase.java @@ -49,26 +49,6 @@ public abstract class DistributedStorageAdminIntegrationTestBase { private static final String COL_NAME10 = "c10"; private static final String COL_NAME11 = "c11"; - private static final TableMetadata TABLE_METADATA = - TableMetadata.newBuilder() - .addColumn(COL_NAME1, DataType.INT) - .addColumn(COL_NAME2, DataType.TEXT) - .addColumn(COL_NAME3, DataType.TEXT) - .addColumn(COL_NAME4, DataType.INT) - .addColumn(COL_NAME5, DataType.INT) - .addColumn(COL_NAME6, DataType.TEXT) - .addColumn(COL_NAME7, DataType.BIGINT) - .addColumn(COL_NAME8, DataType.FLOAT) - .addColumn(COL_NAME9, DataType.DOUBLE) - .addColumn(COL_NAME10, DataType.BOOLEAN) - .addColumn(COL_NAME11, DataType.BLOB) - .addPartitionKey(COL_NAME2) - .addPartitionKey(COL_NAME1) - .addClusteringKey(COL_NAME4, Scan.Ordering.Order.ASC) - .addClusteringKey(COL_NAME3, Scan.Ordering.Order.DESC) - .addSecondaryIndex(COL_NAME5) - .addSecondaryIndex(COL_NAME6) - .build(); private StorageFactory storageFactory; private DistributedStorageAdmin admin; private String systemNamespaceName; @@ -78,8 +58,8 @@ public abstract class DistributedStorageAdminIntegrationTestBase { @BeforeAll public void beforeAll() throws Exception { - initialize(TEST_NAME); - Properties properties = getProperties(TEST_NAME); + initialize(getTestName()); + Properties properties = getProperties(getTestName()); storageFactory = StorageFactory.create(properties); admin = storageFactory.getAdmin(); systemNamespaceName = getSystemNamespaceName(properties); @@ -95,6 +75,10 @@ protected void initialize(String testName) throws Exception {} protected abstract String getSystemNamespaceName(Properties properties); + protected String getTestName() { + return TEST_NAME; + } + protected String getNamespace1() { return NAMESPACE1; } @@ -107,12 +91,94 @@ protected String getNamespace3() { return NAMESPACE3; } + protected String getTable1() { + return TABLE1; + } + + protected String getTable2() { + return TABLE2; + } + + protected String getTable3() { + return TABLE3; + } + + protected String getTable4() { + return TABLE4; + } + + protected String getColumnName1() { + return COL_NAME1; + } + + protected String getColumnName2() { + return COL_NAME2; + } + + protected String getColumnName3() { + return COL_NAME3; + } + + protected String getColumnName4() { + return COL_NAME4; + } + + protected String getColumnName5() { + return COL_NAME5; + } + + protected String getColumnName6() { + return COL_NAME6; + } + + protected String getColumnName7() { + return COL_NAME7; + } + + protected String getColumnName8() { + return COL_NAME8; + } + + protected String getColumnName9() { + return COL_NAME9; + } + + protected String getColumnName10() { + return COL_NAME10; + } + + protected String getColumnName11() { + return COL_NAME11; + } + + protected TableMetadata getTableMetadata() { + return TableMetadata.newBuilder() + .addColumn(getColumnName1(), DataType.INT) + .addColumn(getColumnName2(), DataType.TEXT) + .addColumn(getColumnName3(), DataType.TEXT) + .addColumn(getColumnName4(), DataType.INT) + .addColumn(getColumnName5(), DataType.INT) + .addColumn(getColumnName6(), DataType.TEXT) + .addColumn(getColumnName7(), DataType.BIGINT) + .addColumn(getColumnName8(), DataType.FLOAT) + .addColumn(getColumnName9(), DataType.DOUBLE) + .addColumn(getColumnName10(), DataType.BOOLEAN) + .addColumn(getColumnName11(), DataType.BLOB) + .addPartitionKey(getColumnName2()) + .addPartitionKey(getColumnName1()) + .addClusteringKey(getColumnName4(), Scan.Ordering.Order.ASC) + .addClusteringKey(getColumnName3(), Scan.Ordering.Order.DESC) + .addSecondaryIndex(getColumnName5()) + .addSecondaryIndex(getColumnName6()) + .build(); + } + private void createTables() throws ExecutionException { Map options = getCreationOptions(); for (String namespace : Arrays.asList(namespace1, namespace2)) { admin.createNamespace(namespace, true, options); - for (String table : Arrays.asList(TABLE1, TABLE2, TABLE3)) { - admin.createTable(namespace, table, TABLE_METADATA, true, options); + for (String table : Arrays.asList(getTable1(), getTable2(), getTable3())) { + admin.createTable(namespace, table, getTableMetadata(), true, options); } } } @@ -140,7 +206,7 @@ public void afterAll() throws Exception { private void dropTables() throws ExecutionException { for (String namespace : Arrays.asList(namespace1, namespace2)) { - for (String table : Arrays.asList(TABLE1, TABLE2, TABLE3)) { + for (String table : Arrays.asList(getTable1(), getTable2(), getTable3())) { admin.dropTable(namespace, table); } admin.dropNamespace(namespace); @@ -153,61 +219,63 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() // Arrange // Act - TableMetadata tableMetadata = admin.getTableMetadata(namespace1, TABLE1); + TableMetadata tableMetadata = admin.getTableMetadata(namespace1, getTable1()); // Assert assertThat(tableMetadata).isNotNull(); assertThat(tableMetadata.getPartitionKeyNames().size()).isEqualTo(2); Iterator iterator = tableMetadata.getPartitionKeyNames().iterator(); - assertThat(iterator.next()).isEqualTo(COL_NAME2); - assertThat(iterator.next()).isEqualTo(COL_NAME1); + assertThat(iterator.next()).isEqualTo(getColumnName2()); + assertThat(iterator.next()).isEqualTo(getColumnName1()); assertThat(tableMetadata.getClusteringKeyNames().size()).isEqualTo(2); iterator = tableMetadata.getClusteringKeyNames().iterator(); - assertThat(iterator.next()).isEqualTo(COL_NAME4); - assertThat(iterator.next()).isEqualTo(COL_NAME3); + assertThat(iterator.next()).isEqualTo(getColumnName4()); + assertThat(iterator.next()).isEqualTo(getColumnName3()); assertThat(tableMetadata.getColumnNames().size()).isEqualTo(11); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME1)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME2)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME3)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME4)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME5)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME6)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME7)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME8)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME9)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME10)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME11)).isTrue(); - - assertThat(tableMetadata.getColumnDataType(COL_NAME1)).isEqualTo(DataType.INT); - assertThat(tableMetadata.getColumnDataType(COL_NAME2)).isEqualTo(DataType.TEXT); - assertThat(tableMetadata.getColumnDataType(COL_NAME3)).isEqualTo(DataType.TEXT); - assertThat(tableMetadata.getColumnDataType(COL_NAME4)).isEqualTo(DataType.INT); - assertThat(tableMetadata.getColumnDataType(COL_NAME5)).isEqualTo(DataType.INT); - assertThat(tableMetadata.getColumnDataType(COL_NAME6)).isEqualTo(DataType.TEXT); - assertThat(tableMetadata.getColumnDataType(COL_NAME7)).isEqualTo(DataType.BIGINT); - assertThat(tableMetadata.getColumnDataType(COL_NAME8)).isEqualTo(DataType.FLOAT); - assertThat(tableMetadata.getColumnDataType(COL_NAME9)).isEqualTo(DataType.DOUBLE); - assertThat(tableMetadata.getColumnDataType(COL_NAME10)).isEqualTo(DataType.BOOLEAN); - assertThat(tableMetadata.getColumnDataType(COL_NAME11)).isEqualTo(DataType.BLOB); - - assertThat(tableMetadata.getClusteringOrder(COL_NAME1)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME2)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME3)).isEqualTo(Scan.Ordering.Order.DESC); - assertThat(tableMetadata.getClusteringOrder(COL_NAME4)).isEqualTo(Scan.Ordering.Order.ASC); - assertThat(tableMetadata.getClusteringOrder(COL_NAME5)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME6)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME7)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME8)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME9)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME10)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME11)).isNull(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName1())).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName2())).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName3())).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName4())).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName5())).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName6())).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName7())).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName8())).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName9())).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName10())).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName11())).isTrue(); + + assertThat(tableMetadata.getColumnDataType(getColumnName1())).isEqualTo(DataType.INT); + assertThat(tableMetadata.getColumnDataType(getColumnName2())).isEqualTo(DataType.TEXT); + assertThat(tableMetadata.getColumnDataType(getColumnName3())).isEqualTo(DataType.TEXT); + assertThat(tableMetadata.getColumnDataType(getColumnName4())).isEqualTo(DataType.INT); + assertThat(tableMetadata.getColumnDataType(getColumnName5())).isEqualTo(DataType.INT); + assertThat(tableMetadata.getColumnDataType(getColumnName6())).isEqualTo(DataType.TEXT); + assertThat(tableMetadata.getColumnDataType(getColumnName7())).isEqualTo(DataType.BIGINT); + assertThat(tableMetadata.getColumnDataType(getColumnName8())).isEqualTo(DataType.FLOAT); + assertThat(tableMetadata.getColumnDataType(getColumnName9())).isEqualTo(DataType.DOUBLE); + assertThat(tableMetadata.getColumnDataType(getColumnName10())).isEqualTo(DataType.BOOLEAN); + assertThat(tableMetadata.getColumnDataType(getColumnName11())).isEqualTo(DataType.BLOB); + + assertThat(tableMetadata.getClusteringOrder(getColumnName1())).isNull(); + assertThat(tableMetadata.getClusteringOrder(getColumnName2())).isNull(); + assertThat(tableMetadata.getClusteringOrder(getColumnName3())) + .isEqualTo(Scan.Ordering.Order.DESC); + assertThat(tableMetadata.getClusteringOrder(getColumnName4())) + .isEqualTo(Scan.Ordering.Order.ASC); + assertThat(tableMetadata.getClusteringOrder(getColumnName5())).isNull(); + assertThat(tableMetadata.getClusteringOrder(getColumnName6())).isNull(); + assertThat(tableMetadata.getClusteringOrder(getColumnName7())).isNull(); + assertThat(tableMetadata.getClusteringOrder(getColumnName8())).isNull(); + assertThat(tableMetadata.getClusteringOrder(getColumnName9())).isNull(); + assertThat(tableMetadata.getClusteringOrder(getColumnName10())).isNull(); + assertThat(tableMetadata.getClusteringOrder(getColumnName11())).isNull(); assertThat(tableMetadata.getSecondaryIndexNames().size()).isEqualTo(2); - assertThat(tableMetadata.getSecondaryIndexNames().contains(COL_NAME5)).isTrue(); - assertThat(tableMetadata.getSecondaryIndexNames().contains(COL_NAME6)).isTrue(); + assertThat(tableMetadata.getSecondaryIndexNames().contains(getColumnName5())).isTrue(); + assertThat(tableMetadata.getSecondaryIndexNames().contains(getColumnName6())).isTrue(); } @Test @@ -286,13 +354,13 @@ public void dropNamespace_ForNonEmptyNamespace_ShouldThrowIllegalArgumentExcepti try { // Arrange admin.createNamespace(namespace3); - admin.createTable(namespace3, TABLE1, TABLE_METADATA); + admin.createTable(namespace3, getTable1(), getTableMetadata()); // Act Assert assertThatThrownBy(() -> admin.dropNamespace(namespace3)) .isInstanceOf(IllegalArgumentException.class); } finally { - admin.dropTable(namespace3, TABLE1, true); + admin.dropTable(namespace3, getTable1(), true); admin.dropNamespace(namespace3, true); } } @@ -313,12 +381,12 @@ public void createTable_ForNonExistingTable_ShouldCreateTableProperly() Map options = getCreationOptions(); // Act - admin.createTable(namespace1, TABLE4, TABLE_METADATA, options); + admin.createTable(namespace1, getTable4(), getTableMetadata(), options); // Assert - assertThat(admin.tableExists(namespace1, TABLE4)).isTrue(); + assertThat(admin.tableExists(namespace1, getTable4())).isTrue(); } finally { - admin.dropTable(namespace1, TABLE4, true); + admin.dropTable(namespace1, getTable4(), true); } } @@ -327,7 +395,7 @@ public void createTable_ForExistingTable_ShouldThrowIllegalArgumentException() { // Arrange // Act Assert - assertThatThrownBy(() -> admin.createTable(namespace1, TABLE1, TABLE_METADATA)) + assertThatThrownBy(() -> admin.createTable(namespace1, getTable1(), getTableMetadata())) .isInstanceOf(IllegalArgumentException.class); } @@ -336,7 +404,7 @@ public void createTable_ForNonExistingNamespace_ShouldThrowIllegalArgumentExcept // Arrange // Act Assert - assertThatThrownBy(() -> admin.createTable(namespace3, TABLE1, TABLE_METADATA)) + assertThatThrownBy(() -> admin.createTable(namespace3, getTable1(), getTableMetadata())) .isInstanceOf(IllegalArgumentException.class); } @@ -345,7 +413,7 @@ public void createTable_IfNotExists_ForExistingNamespace_ShouldNotThrowAnyExcept // Arrange // Act Assert - assertThatCode(() -> admin.createTable(namespace1, TABLE1, TABLE_METADATA, true)) + assertThatCode(() -> admin.createTable(namespace1, getTable1(), getTableMetadata(), true)) .doesNotThrowAnyException(); } @@ -354,15 +422,15 @@ public void dropTable_ForExistingTable_ShouldDropTableProperly() throws Executio try { // Arrange Map options = getCreationOptions(); - admin.createTable(namespace1, TABLE4, TABLE_METADATA, options); + admin.createTable(namespace1, getTable4(), getTableMetadata(), options); // Act - admin.dropTable(namespace1, TABLE4); + admin.dropTable(namespace1, getTable4()); // Assert - assertThat(admin.tableExists(namespace1, TABLE4)).isFalse(); + assertThat(admin.tableExists(namespace1, getTable4())).isFalse(); } finally { - admin.dropTable(namespace1, TABLE4, true); + admin.dropTable(namespace1, getTable4(), true); } } @@ -371,7 +439,7 @@ public void dropTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() // Arrange // Act Assert - assertThatThrownBy(() -> admin.dropTable(namespace1, TABLE4)) + assertThatThrownBy(() -> admin.dropTable(namespace1, getTable4())) .isInstanceOf(IllegalArgumentException.class); } @@ -380,7 +448,7 @@ public void dropTable_IfExists_ForNonExistingTable_ShouldNotThrowAnyException() // Arrange // Act Assert - assertThatCode(() -> admin.dropTable(namespace1, TABLE4, true)).doesNotThrowAnyException(); + assertThatCode(() -> admin.dropTable(namespace1, getTable4(), true)).doesNotThrowAnyException(); } @Test @@ -388,27 +456,27 @@ public void truncateTable_ShouldTruncateProperly() throws ExecutionException, IO DistributedStorage storage = null; try { // Arrange - Key partitionKey = new Key(COL_NAME2, "aaa", COL_NAME1, 1); - Key clusteringKey = new Key(COL_NAME4, 2, COL_NAME3, "bbb"); + Key partitionKey = new Key(getColumnName2(), "aaa", getColumnName1(), 1); + Key clusteringKey = new Key(getColumnName4(), 2, getColumnName3(), "bbb"); storage = storageFactory.getStorage(); storage.put( new Put(partitionKey, clusteringKey) - .withValue(COL_NAME5, 3) - .withValue(COL_NAME6, "ccc") - .withValue(COL_NAME7, 4L) - .withValue(COL_NAME8, 1.0f) - .withValue(COL_NAME9, 1.0d) - .withValue(COL_NAME10, true) - .withValue(COL_NAME11, "ddd".getBytes(StandardCharsets.UTF_8)) + .withValue(getColumnName5(), 3) + .withValue(getColumnName6(), "ccc") + .withValue(getColumnName7(), 4L) + .withValue(getColumnName8(), 1.0f) + .withValue(getColumnName9(), 1.0d) + .withValue(getColumnName10(), true) + .withValue(getColumnName11(), "ddd".getBytes(StandardCharsets.UTF_8)) .forNamespace(namespace1) - .forTable(TABLE1)); + .forTable(getTable1())); // Act - admin.truncateTable(namespace1, TABLE1); + admin.truncateTable(namespace1, getTable1()); // Assert Scanner scanner = - storage.scan(new Scan(partitionKey).forNamespace(namespace1).forTable(TABLE1)); + storage.scan(new Scan(partitionKey).forNamespace(namespace1).forTable(getTable1())); assertThat(scanner.all()).isEmpty(); scanner.close(); } finally { @@ -423,7 +491,7 @@ public void truncateTable_ForNonExistingTable_ShouldThrowIllegalArgumentExceptio // Arrange // Act Assert - assertThatThrownBy(() -> admin.truncateTable(namespace1, TABLE4)) + assertThatThrownBy(() -> admin.truncateTable(namespace1, getTable4())) .isInstanceOf(IllegalArgumentException.class); } @@ -435,7 +503,8 @@ public void getNamespaceTableNames_ShouldReturnCorrectTables() throws ExecutionE Set actual = admin.getNamespaceTableNames(namespace1); // Assert - assertThat(actual).isEqualTo(new HashSet<>(Arrays.asList(TABLE1, TABLE2, TABLE3))); + assertThat(actual) + .isEqualTo(new HashSet<>(Arrays.asList(getTable1(), getTable2(), getTable3()))); } @Test @@ -453,10 +522,10 @@ public void tableExists_ShouldReturnCorrectResults() throws ExecutionException { // Arrange // Act Assert - assertThat(admin.tableExists(namespace1, TABLE1)).isTrue(); - assertThat(admin.tableExists(namespace1, TABLE2)).isTrue(); - assertThat(admin.tableExists(namespace1, TABLE3)).isTrue(); - assertThat(admin.tableExists(namespace1, TABLE4)).isFalse(); + assertThat(admin.tableExists(namespace1, getTable1())).isTrue(); + assertThat(admin.tableExists(namespace1, getTable2())).isTrue(); + assertThat(admin.tableExists(namespace1, getTable3())).isTrue(); + assertThat(admin.tableExists(namespace1, getTable4())).isFalse(); } @Test @@ -468,67 +537,79 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre Map options = getCreationOptions(); TableMetadata metadata = TableMetadata.newBuilder() - .addColumn(COL_NAME1, DataType.INT) - .addColumn(COL_NAME2, DataType.INT) - .addColumn(COL_NAME3, DataType.TEXT) - .addColumn(COL_NAME4, DataType.BIGINT) - .addColumn(COL_NAME5, DataType.FLOAT) - .addColumn(COL_NAME6, DataType.DOUBLE) - .addColumn(COL_NAME7, DataType.BOOLEAN) - .addColumn(COL_NAME8, DataType.BLOB) - .addColumn(COL_NAME9, DataType.TEXT) - .addPartitionKey(COL_NAME1) - .addSecondaryIndex(COL_NAME9) + .addColumn(getColumnName1(), DataType.INT) + .addColumn(getColumnName2(), DataType.INT) + .addColumn(getColumnName3(), DataType.TEXT) + .addColumn(getColumnName4(), DataType.BIGINT) + .addColumn(getColumnName5(), DataType.FLOAT) + .addColumn(getColumnName6(), DataType.DOUBLE) + .addColumn(getColumnName7(), DataType.BOOLEAN) + .addColumn(getColumnName8(), DataType.BLOB) + .addColumn(getColumnName9(), DataType.TEXT) + .addPartitionKey(getColumnName1()) + .addSecondaryIndex(getColumnName9()) .build(); - admin.createTable(namespace1, TABLE4, metadata, options); + admin.createTable(namespace1, getTable4(), metadata, options); storage = storageFactory.getStorage(); storage.put( Put.newBuilder() .namespace(namespace1) - .table(TABLE4) - .partitionKey(Key.ofInt(COL_NAME1, 1)) - .intValue(COL_NAME2, 2) - .textValue(COL_NAME3, "3") - .bigIntValue(COL_NAME4, 4) - .floatValue(COL_NAME5, 5) - .doubleValue(COL_NAME6, 6) - .booleanValue(COL_NAME7, true) - .blobValue(COL_NAME8, "8".getBytes(StandardCharsets.UTF_8)) - .textValue(COL_NAME9, "9") + .table(getTable4()) + .partitionKey(Key.ofInt(getColumnName1(), 1)) + .intValue(getColumnName2(), 2) + .textValue(getColumnName3(), "3") + .bigIntValue(getColumnName4(), 4) + .floatValue(getColumnName5(), 5) + .doubleValue(getColumnName6(), 6) + .booleanValue(getColumnName7(), true) + .blobValue(getColumnName8(), "8".getBytes(StandardCharsets.UTF_8)) + .textValue(getColumnName9(), "9") .build()); // Act - admin.createIndex(namespace1, TABLE4, COL_NAME2, options); - admin.createIndex(namespace1, TABLE4, COL_NAME3, options); - admin.createIndex(namespace1, TABLE4, COL_NAME4, options); - admin.createIndex(namespace1, TABLE4, COL_NAME5, options); - admin.createIndex(namespace1, TABLE4, COL_NAME6, options); + admin.createIndex(namespace1, getTable4(), getColumnName2(), options); + admin.createIndex(namespace1, getTable4(), getColumnName3(), options); + admin.createIndex(namespace1, getTable4(), getColumnName4(), options); + admin.createIndex(namespace1, getTable4(), getColumnName5(), options); + admin.createIndex(namespace1, getTable4(), getColumnName6(), options); if (isIndexOnBooleanColumnSupported()) { - admin.createIndex(namespace1, TABLE4, COL_NAME7, options); + admin.createIndex(namespace1, getTable4(), getColumnName7(), options); } - admin.createIndex(namespace1, TABLE4, COL_NAME8, options); + admin.createIndex(namespace1, getTable4(), getColumnName8(), options); // Assert - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME2)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME3)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME4)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME5)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME6)).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName2())).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName3())).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName4())).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName5())).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName6())).isTrue(); if (isIndexOnBooleanColumnSupported()) { - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME7)).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName7())).isTrue(); } - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME8)).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName8())).isTrue(); if (isIndexOnBooleanColumnSupported()) { - assertThat(admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames()) + assertThat(admin.getTableMetadata(namespace1, getTable4()).getSecondaryIndexNames()) .containsOnly( - COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME7, COL_NAME8, - COL_NAME9); + getColumnName2(), + getColumnName3(), + getColumnName4(), + getColumnName5(), + getColumnName6(), + getColumnName7(), + getColumnName8(), + getColumnName9()); } else { - assertThat(admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames()) + assertThat(admin.getTableMetadata(namespace1, getTable4()).getSecondaryIndexNames()) .containsOnly( - COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME8, COL_NAME9); + getColumnName2(), + getColumnName3(), + getColumnName4(), + getColumnName5(), + getColumnName6(), + getColumnName8(), + getColumnName9()); } } finally { - admin.dropTable(namespace1, TABLE4, true); + admin.dropTable(namespace1, getTable4(), true); if (storage != null) { storage.close(); } @@ -543,7 +624,7 @@ public void createIndex_ForNonExistingTable_ShouldThrowIllegalArgumentException( assertThatThrownBy( () -> admin.createIndex( - namespace1, "non-existing_table", COL_NAME2, getCreationOptions())) + namespace1, "non-existing_table", getColumnName2(), getCreationOptions())) .isInstanceOf(IllegalArgumentException.class); } @@ -554,7 +635,8 @@ public void createIndex_ForNonExistingColumn_ShouldThrowIllegalArgumentException // Act Assert assertThatThrownBy( () -> - admin.createIndex(namespace1, TABLE1, "non-existing_column", getCreationOptions())) + admin.createIndex( + namespace1, getTable1(), "non-existing_column", getCreationOptions())) .isInstanceOf(IllegalArgumentException.class); } @@ -566,19 +648,21 @@ public void createIndex_ForAlreadyExistingIndex_ShouldThrowIllegalArgumentExcept Map options = getCreationOptions(); TableMetadata metadata = TableMetadata.newBuilder() - .addColumn(COL_NAME1, DataType.INT) - .addColumn(COL_NAME2, DataType.INT) - .addPartitionKey(COL_NAME1) - .addSecondaryIndex(COL_NAME2) + .addColumn(getColumnName1(), DataType.INT) + .addColumn(getColumnName2(), DataType.INT) + .addPartitionKey(getColumnName1()) + .addSecondaryIndex(getColumnName2()) .build(); - admin.createTable(namespace1, TABLE4, metadata, options); + admin.createTable(namespace1, getTable4(), metadata, options); // Act Assert assertThatThrownBy( - () -> admin.createIndex(namespace1, TABLE4, COL_NAME2, getCreationOptions())) + () -> + admin.createIndex( + namespace1, getTable4(), getColumnName2(), getCreationOptions())) .isInstanceOf(IllegalArgumentException.class); } finally { - admin.dropTable(namespace1, TABLE4, true); + admin.dropTable(namespace1, getTable4(), true); } } @@ -590,19 +674,21 @@ public void createIndex_IfNotExists_ForAlreadyExistingIndex_ShouldNotThrowAnyExc Map options = getCreationOptions(); TableMetadata metadata = TableMetadata.newBuilder() - .addColumn(COL_NAME1, DataType.INT) - .addColumn(COL_NAME2, DataType.INT) - .addPartitionKey(COL_NAME1) - .addSecondaryIndex(COL_NAME2) + .addColumn(getColumnName1(), DataType.INT) + .addColumn(getColumnName2(), DataType.INT) + .addPartitionKey(getColumnName1()) + .addSecondaryIndex(getColumnName2()) .build(); - admin.createTable(namespace1, TABLE4, metadata, options); + admin.createTable(namespace1, getTable4(), metadata, options); // Act Assert assertThatCode( - () -> admin.createIndex(namespace1, TABLE4, COL_NAME2, true, getCreationOptions())) + () -> + admin.createIndex( + namespace1, getTable4(), getColumnName2(), true, getCreationOptions())) .doesNotThrowAnyException(); } finally { - admin.dropTable(namespace1, TABLE4, true); + admin.dropTable(namespace1, getTable4(), true); } } @@ -615,68 +701,68 @@ public void dropIndex_ForAllDataTypesWithExistingData_ShouldDropIndexCorrectly() Map options = getCreationOptions(); TableMetadata metadata = TableMetadata.newBuilder() - .addColumn(COL_NAME1, DataType.INT) - .addColumn(COL_NAME2, DataType.INT) - .addColumn(COL_NAME3, DataType.TEXT) - .addColumn(COL_NAME4, DataType.BIGINT) - .addColumn(COL_NAME5, DataType.FLOAT) - .addColumn(COL_NAME6, DataType.DOUBLE) - .addColumn(COL_NAME7, DataType.BOOLEAN) - .addColumn(COL_NAME8, DataType.BLOB) - .addColumn(COL_NAME9, DataType.TEXT) - .addPartitionKey(COL_NAME1) - .addSecondaryIndex(COL_NAME2) - .addSecondaryIndex(COL_NAME3) - .addSecondaryIndex(COL_NAME4) - .addSecondaryIndex(COL_NAME5) - .addSecondaryIndex(COL_NAME6) - .addSecondaryIndex(COL_NAME8) - .addSecondaryIndex(COL_NAME9) - .addSecondaryIndex(COL_NAME9) + .addColumn(getColumnName1(), DataType.INT) + .addColumn(getColumnName2(), DataType.INT) + .addColumn(getColumnName3(), DataType.TEXT) + .addColumn(getColumnName4(), DataType.BIGINT) + .addColumn(getColumnName5(), DataType.FLOAT) + .addColumn(getColumnName6(), DataType.DOUBLE) + .addColumn(getColumnName7(), DataType.BOOLEAN) + .addColumn(getColumnName8(), DataType.BLOB) + .addColumn(getColumnName9(), DataType.TEXT) + .addPartitionKey(getColumnName1()) + .addSecondaryIndex(getColumnName2()) + .addSecondaryIndex(getColumnName3()) + .addSecondaryIndex(getColumnName4()) + .addSecondaryIndex(getColumnName5()) + .addSecondaryIndex(getColumnName6()) + .addSecondaryIndex(getColumnName8()) + .addSecondaryIndex(getColumnName9()) + .addSecondaryIndex(getColumnName9()) .build(); if (isIndexOnBooleanColumnSupported()) { - metadata = TableMetadata.newBuilder(metadata).addSecondaryIndex(COL_NAME7).build(); + metadata = TableMetadata.newBuilder(metadata).addSecondaryIndex(getColumnName7()).build(); } - admin.createTable(namespace1, TABLE4, metadata, options); + admin.createTable(namespace1, getTable4(), metadata, options); storage = storageFactory.getStorage(); storage.put( Put.newBuilder() .namespace(namespace1) - .table(TABLE4) - .partitionKey(Key.ofInt(COL_NAME1, 1)) - .intValue(COL_NAME2, 2) - .textValue(COL_NAME3, "3") - .bigIntValue(COL_NAME4, 4) - .floatValue(COL_NAME5, 5) - .doubleValue(COL_NAME6, 6) - .booleanValue(COL_NAME7, true) - .blobValue(COL_NAME8, "8".getBytes(StandardCharsets.UTF_8)) - .textValue(COL_NAME9, "9") + .table(getTable4()) + .partitionKey(Key.ofInt(getColumnName1(), 1)) + .intValue(getColumnName2(), 2) + .textValue(getColumnName3(), "3") + .bigIntValue(getColumnName4(), 4) + .floatValue(getColumnName5(), 5) + .doubleValue(getColumnName6(), 6) + .booleanValue(getColumnName7(), true) + .blobValue(getColumnName8(), "8".getBytes(StandardCharsets.UTF_8)) + .textValue(getColumnName9(), "9") .build()); // Act - admin.dropIndex(namespace1, TABLE4, COL_NAME2); - admin.dropIndex(namespace1, TABLE4, COL_NAME3); - admin.dropIndex(namespace1, TABLE4, COL_NAME4); - admin.dropIndex(namespace1, TABLE4, COL_NAME5); - admin.dropIndex(namespace1, TABLE4, COL_NAME6); + admin.dropIndex(namespace1, getTable4(), getColumnName2()); + admin.dropIndex(namespace1, getTable4(), getColumnName3()); + admin.dropIndex(namespace1, getTable4(), getColumnName4()); + admin.dropIndex(namespace1, getTable4(), getColumnName5()); + admin.dropIndex(namespace1, getTable4(), getColumnName6()); if (isIndexOnBooleanColumnSupported()) { - admin.dropIndex(namespace1, TABLE4, COL_NAME7); + admin.dropIndex(namespace1, getTable4(), getColumnName7()); } - admin.dropIndex(namespace1, TABLE4, COL_NAME8); + admin.dropIndex(namespace1, getTable4(), getColumnName8()); // Assert - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME2)).isFalse(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME3)).isFalse(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME4)).isFalse(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME5)).isFalse(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME6)).isFalse(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME7)).isFalse(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME8)).isFalse(); - assertThat(admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames()) - .containsOnly(COL_NAME9); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName2())).isFalse(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName3())).isFalse(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName4())).isFalse(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName5())).isFalse(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName6())).isFalse(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName7())).isFalse(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName8())).isFalse(); + assertThat(admin.getTableMetadata(namespace1, getTable4()).getSecondaryIndexNames()) + .containsOnly(getColumnName9()); } finally { - admin.dropTable(namespace1, TABLE4, true); + admin.dropTable(namespace1, getTable4(), true); if (storage != null) { storage.close(); } @@ -688,7 +774,7 @@ public void dropIndex_ForNonExistingTable_ShouldThrowIllegalArgumentException() // Arrange // Act Assert - assertThatThrownBy(() -> admin.dropIndex(namespace1, "non-existing-table", COL_NAME2)) + assertThatThrownBy(() -> admin.dropIndex(namespace1, "non-existing-table", getColumnName2())) .isInstanceOf(IllegalArgumentException.class); } @@ -697,7 +783,7 @@ public void dropIndex_ForNonExistingIndex_ShouldThrowIllegalArgumentException() // Arrange // Act Assert - assertThatThrownBy(() -> admin.dropIndex(namespace1, TABLE1, COL_NAME2)) + assertThatThrownBy(() -> admin.dropIndex(namespace1, getTable1(), getColumnName2())) .isInstanceOf(IllegalArgumentException.class); } @@ -706,7 +792,7 @@ public void dropIndex_IfExists_ForNonExistingIndex_ShouldNotThrowAnyException() // Arrange // Act Assert - assertThatCode(() -> admin.dropIndex(namespace1, TABLE1, COL_NAME2, true)) + assertThatCode(() -> admin.dropIndex(namespace1, getTable1(), getColumnName2(), true)) .doesNotThrowAnyException(); } @@ -722,16 +808,16 @@ public void addNewColumnToTable_AddColumnForEachExistingDataType_ShouldAddNewCol .addColumn("pk1", DataType.TEXT) .addColumn("c1", DataType.TEXT) .build(); - admin.createTable(namespace1, TABLE4, currentTableMetadata, options); + admin.createTable(namespace1, getTable4(), currentTableMetadata, options); // Act - admin.addNewColumnToTable(namespace1, TABLE4, "c2", DataType.TEXT); - admin.addNewColumnToTable(namespace1, TABLE4, "c3", DataType.DOUBLE); - admin.addNewColumnToTable(namespace1, TABLE4, "c4", DataType.INT); - admin.addNewColumnToTable(namespace1, TABLE4, "c5", DataType.BIGINT); - admin.addNewColumnToTable(namespace1, TABLE4, "c6", DataType.BLOB); - admin.addNewColumnToTable(namespace1, TABLE4, "c7", DataType.BOOLEAN); - admin.addNewColumnToTable(namespace1, TABLE4, "c8", DataType.FLOAT); + admin.addNewColumnToTable(namespace1, getTable4(), "c2", DataType.TEXT); + admin.addNewColumnToTable(namespace1, getTable4(), "c3", DataType.DOUBLE); + admin.addNewColumnToTable(namespace1, getTable4(), "c4", DataType.INT); + admin.addNewColumnToTable(namespace1, getTable4(), "c5", DataType.BIGINT); + admin.addNewColumnToTable(namespace1, getTable4(), "c6", DataType.BLOB); + admin.addNewColumnToTable(namespace1, getTable4(), "c7", DataType.BOOLEAN); + admin.addNewColumnToTable(namespace1, getTable4(), "c8", DataType.FLOAT); // Assert TableMetadata expectedTableMetadata = @@ -744,9 +830,9 @@ public void addNewColumnToTable_AddColumnForEachExistingDataType_ShouldAddNewCol .addColumn("c7", DataType.BOOLEAN) .addColumn("c8", DataType.FLOAT) .build(); - assertThat(admin.getTableMetadata(namespace1, TABLE4)).isEqualTo(expectedTableMetadata); + assertThat(admin.getTableMetadata(namespace1, getTable4())).isEqualTo(expectedTableMetadata); } finally { - admin.dropTable(namespace1, TABLE4, true); + admin.dropTable(namespace1, getTable4(), true); } } @@ -756,7 +842,8 @@ public void addNewColumnToTable_ForNonExistingTable_ShouldThrowIllegalArgumentEx // Act Assert assertThatThrownBy( - () -> admin.addNewColumnToTable(namespace1, TABLE4, COL_NAME2, DataType.TEXT)) + () -> + admin.addNewColumnToTable(namespace1, getTable4(), getColumnName2(), DataType.TEXT)) .isInstanceOf(IllegalArgumentException.class); } @@ -766,7 +853,8 @@ public void addNewColumnToTable_ForAlreadyExistingColumn_ShouldThrowIllegalArgum // Act Assert assertThatThrownBy( - () -> admin.addNewColumnToTable(namespace1, TABLE1, COL_NAME2, DataType.TEXT)) + () -> + admin.addNewColumnToTable(namespace1, getTable1(), getColumnName2(), DataType.TEXT)) .isInstanceOf(IllegalArgumentException.class); } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCaseSensitivityIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCaseSensitivityIntegrationTestBase.java new file mode 100644 index 0000000000..2f853b48bb --- /dev/null +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageCaseSensitivityIntegrationTestBase.java @@ -0,0 +1,63 @@ +package com.scalar.db.api; + +import org.junit.jupiter.api.TestInstance; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public abstract class DistributedStorageCaseSensitivityIntegrationTestBase + extends DistributedStorageIntegrationTestBase { + + private static final String TEST_NAME = "storage_case"; + private static final String NAMESPACE = "Int_test_" + TEST_NAME; + private static final String TABLE = "Test_table"; + private static final String COL_NAME1 = "Column1"; + private static final String COL_NAME2 = "Column2"; + private static final String COL_NAME3 = "Column3"; + private static final String COL_NAME4 = "Column4"; + private static final String COL_NAME5 = "Column5"; + private static final String COL_NAME6 = "Column6"; + + @Override + protected String getTestName() { + return TEST_NAME; + } + + @Override + protected String getNamespace() { + return NAMESPACE; + } + + @Override + protected String getTableName() { + return TABLE; + } + + @Override + protected String getColumnName1() { + return COL_NAME1; + } + + @Override + protected String getColumnName2() { + return COL_NAME2; + } + + @Override + protected String getColumnName3() { + return COL_NAME3; + } + + @Override + protected String getColumnName4() { + return COL_NAME4; + } + + @Override + protected String getColumnName5() { + return COL_NAME5; + } + + @Override + protected String getColumnName6() { + return COL_NAME6; + } +} diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageIntegrationTestBase.java index 40c30fa45b..0b6f5cc95a 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageIntegrationTestBase.java @@ -65,8 +65,8 @@ public abstract class DistributedStorageIntegrationTestBase { @BeforeAll public void beforeAll() throws Exception { - initialize(TEST_NAME); - StorageFactory factory = StorageFactory.create(getProperties(TEST_NAME)); + initialize(getTestName()); + StorageFactory factory = StorageFactory.create(getProperties(getTestName())); admin = factory.getAdmin(); namespace = getNamespace(); createTable(); @@ -77,26 +77,66 @@ protected void initialize(String testName) throws Exception {} protected abstract Properties getProperties(String testName); + protected String getTestName() { + return TEST_NAME; + } + protected String getNamespace() { return NAMESPACE; } + protected String getTableName() { + return TABLE; + } + + protected String getColumnName1() { + return COL_NAME1; + } + + protected String getColumnName2() { + return COL_NAME2; + } + + protected String getColumnName3() { + return COL_NAME3; + } + + protected String getColumnName4() { + return COL_NAME4; + } + + protected String getColumnName5() { + return COL_NAME5; + } + + protected String getColumnName6() { + return COL_NAME6; + } + + protected DistributedStorage getStorage() { + return storage; + } + + protected DistributedStorageAdmin getAdmin() { + return admin; + } + private void createTable() throws ExecutionException { Map options = getCreationOptions(); admin.createNamespace(namespace, true, options); admin.createTable( namespace, - TABLE, + getTableName(), TableMetadata.newBuilder() - .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) - .addColumn(COL_NAME6, DataType.BLOB) - .addPartitionKey(COL_NAME1) - .addClusteringKey(COL_NAME4) - .addSecondaryIndex(COL_NAME3) + .addColumn(getColumnName1(), DataType.INT) + .addColumn(getColumnName2(), DataType.TEXT) + .addColumn(getColumnName3(), DataType.INT) + .addColumn(getColumnName4(), DataType.INT) + .addColumn(getColumnName5(), DataType.BOOLEAN) + .addColumn(getColumnName6(), DataType.BLOB) + .addPartitionKey(getColumnName1()) + .addClusteringKey(getColumnName4()) + .addSecondaryIndex(getColumnName3()) .build(), true, options); @@ -113,11 +153,11 @@ protected Map getCreationOptions() { @BeforeEach public void setUp() throws Exception { truncateTable(); - storage.with(namespace, TABLE); + storage.with(namespace, getTableName()); } private void truncateTable() throws ExecutionException { - admin.truncateTable(namespace, TABLE); + admin.truncateTable(namespace, getTableName()); } @AfterAll @@ -146,16 +186,16 @@ public void afterAll() throws Exception { } private void dropTable() throws ExecutionException { - admin.dropTable(namespace, TABLE); + admin.dropTable(namespace, getTableName()); admin.dropNamespace(namespace); } @Test public void operation_NoTargetGiven_ShouldThrowIllegalArgumentException() { // Arrange - storage.with(null, TABLE); - Key partitionKey = new Key(COL_NAME1, 0); - Key clusteringKey = new Key(COL_NAME4, 0); + storage.with(null, getTableName()); + Key partitionKey = new Key(getColumnName1(), 0); + Key clusteringKey = new Key(getColumnName4(), 0); Get get = new Get(partitionKey, clusteringKey); // Act Assert @@ -165,9 +205,9 @@ public void operation_NoTargetGiven_ShouldThrowIllegalArgumentException() { @Test public void operation_WrongNamespaceGiven_ShouldThrowIllegalArgumentException() { // Arrange - storage.with("wrong_" + namespace, TABLE); // a wrong namespace - Key partitionKey = new Key(COL_NAME1, 0); - Key clusteringKey = new Key(COL_NAME4, 0); + storage.with("wrong_" + namespace, getTableName()); // a wrong namespace + Key partitionKey = new Key(getColumnName1(), 0); + Key clusteringKey = new Key(getColumnName4(), 0); Get get = new Get(partitionKey, clusteringKey); // Act Assert @@ -177,9 +217,9 @@ public void operation_WrongNamespaceGiven_ShouldThrowIllegalArgumentException() @Test public void operation_WrongTableGiven_ShouldThrowIllegalArgumentException() { // Arrange - storage.with(namespace, "wrong_" + TABLE); // a wrong table - Key partitionKey = new Key(COL_NAME1, 0); - Key clusteringKey = new Key(COL_NAME4, 0); + storage.with(namespace, "wrong_" + getTableName()); // a wrong table + Key partitionKey = new Key(getColumnName1(), 0); + Key clusteringKey = new Key(getColumnName4(), 0); Get get = new Get(partitionKey, clusteringKey); // Act Assert @@ -188,7 +228,7 @@ public void operation_WrongTableGiven_ShouldThrowIllegalArgumentException() { @Test public void operation_DefaultNamespaceGiven_ShouldWorkProperly() { - Properties properties = getProperties(TEST_NAME); + Properties properties = getProperties(getTestName()); properties.put(DatabaseConfig.DEFAULT_NAMESPACE_NAME, getNamespace()); final DistributedStorage storageWithDefaultNamespace = StorageFactory.create(properties).getStorage(); @@ -197,36 +237,40 @@ public void operation_DefaultNamespaceGiven_ShouldWorkProperly() { populateRecords(); Get get = Get.newBuilder() - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 0)) - .clusteringKey(Key.ofInt(COL_NAME4, 0)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 0)) + .clusteringKey(Key.ofInt(getColumnName4(), 0)) + .build(); + Scan scan = + Scan.newBuilder() + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 0)) .build(); - Scan scan = Scan.newBuilder().table(TABLE).partitionKey(Key.ofInt(COL_NAME1, 0)).build(); Put put = Put.newBuilder() - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 1)) - .clusteringKey(Key.ofInt(COL_NAME4, 0)) - .textValue(COL_NAME2, "foo") + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 1)) + .clusteringKey(Key.ofInt(getColumnName4(), 0)) + .textValue(getColumnName2(), "foo") .build(); Delete delete = Delete.newBuilder() - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 2)) - .clusteringKey(Key.ofInt(COL_NAME4, 0)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 2)) + .clusteringKey(Key.ofInt(getColumnName4(), 0)) .build(); Mutation putAsMutation1 = Put.newBuilder() - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 3)) - .clusteringKey(Key.ofInt(COL_NAME4, 0)) - .textValue(COL_NAME2, "foo") + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 3)) + .clusteringKey(Key.ofInt(getColumnName4(), 0)) + .textValue(getColumnName2(), "foo") .build(); Mutation deleteAsMutation2 = Delete.newBuilder() - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 3)) - .clusteringKey(Key.ofInt(COL_NAME4, 1)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 3)) + .clusteringKey(Key.ofInt(getColumnName4(), 1)) .build(); // Act Assert @@ -260,9 +304,10 @@ public void get_GetWithPartitionKeyAndClusteringKeyGiven_ShouldRetrieveSingleRes // Assert assertThat(actual.isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME1)) - .isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey))); - assertThat(actual.get().getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, 0))); + assertThat(actual.get().getValue(getColumnName1())) + .isEqualTo(Optional.of(new IntValue(getColumnName1(), pKey))); + assertThat(actual.get().getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), 0))); } @Test @@ -272,7 +317,7 @@ public void get_GetWithoutPartitionKeyGiven_ShouldThrowInvalidUsageException() { int pKey = 0; // Act Assert - Key partitionKey = new Key(COL_NAME1, pKey); + Key partitionKey = new Key(getColumnName1(), pKey); Get get = new Get(partitionKey); assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class); } @@ -287,17 +332,18 @@ public void get_GetWithProjectionsGiven_ShouldRetrieveSpecifiedValues() // Act Get get = prepareGet(pKey, cKey); - get.withProjections(Arrays.asList(COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME6)); + get.withProjections( + Arrays.asList(getColumnName1(), getColumnName2(), getColumnName3(), getColumnName6())); Optional actual = storage.get(get); // Assert assertThat(actual).isNotEmpty(); assertThat(actual.get().getContainedColumnNames()) - .containsOnly(COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME6); - assertThat(actual.get().getInt(COL_NAME1)).isEqualTo(0); - assertThat(actual.get().getText(COL_NAME2)).isEqualTo("0"); - assertThat(actual.get().getInt(COL_NAME3)).isEqualTo(0); - assertThat(actual.get().isNull(COL_NAME6)).isTrue(); + .containsOnly(getColumnName1(), getColumnName2(), getColumnName3(), getColumnName6()); + assertThat(actual.get().getInt(getColumnName1())).isEqualTo(0); + assertThat(actual.get().getText(getColumnName2())).isEqualTo("0"); + assertThat(actual.get().getInt(getColumnName3())).isEqualTo(0); + assertThat(actual.get().isNull(getColumnName6())).isTrue(); } @Test @@ -311,17 +357,17 @@ public void get_GetWithMatchedConjunctionsGiven_ShouldRetrieveSingleResult() // Act Get get = Get.newBuilder(prepareGet(pKey, cKey)) - .where(ConditionBuilder.column(COL_NAME2).isEqualToText("3")) - .and(ConditionBuilder.column(COL_NAME3).isEqualToInt(3)) + .where(ConditionBuilder.column(getColumnName2()).isEqualToText("3")) + .and(ConditionBuilder.column(getColumnName3()).isEqualToInt(3)) .build(); Optional actual = storage.get(get); // Assert assertThat(actual.isPresent()).isTrue(); - assertThat(actual.get().getInt(COL_NAME1)).isEqualTo(pKey); - assertThat(actual.get().getInt(COL_NAME4)).isEqualTo(cKey); - assertThat(actual.get().getText(COL_NAME2)).isEqualTo("3"); - assertThat(actual.get().getInt(COL_NAME3)).isEqualTo(3); + assertThat(actual.get().getInt(getColumnName1())).isEqualTo(pKey); + assertThat(actual.get().getInt(getColumnName4())).isEqualTo(cKey); + assertThat(actual.get().getText(getColumnName2())).isEqualTo("3"); + assertThat(actual.get().getInt(getColumnName3())).isEqualTo(3); } @Test @@ -334,8 +380,8 @@ public void get_GetWithUnmatchedConjunctionsGiven_ShouldReturnEmpty() throws Exe // Act Get get = Get.newBuilder(prepareGet(pKey, cKey)) - .where(ConditionBuilder.column(COL_NAME2).isEqualToText("a")) - .and(ConditionBuilder.column(COL_NAME3).isEqualToInt(3)) + .where(ConditionBuilder.column(getColumnName2()).isEqualToText("a")) + .and(ConditionBuilder.column(getColumnName3()).isEqualToInt(3)) .build(); Optional actual = storage.get(get); @@ -352,28 +398,28 @@ public void scan_ScanWithProjectionsGiven_ShouldRetrieveSpecifiedValues() // Act Scan scan = - new Scan(Key.ofInt(COL_NAME1, pKey)) - .withProjection(COL_NAME1) - .withProjection(COL_NAME2) - .withProjection(COL_NAME3) - .withProjection(COL_NAME6); + new Scan(Key.ofInt(getColumnName1(), pKey)) + .withProjection(getColumnName1()) + .withProjection(getColumnName2()) + .withProjection(getColumnName3()) + .withProjection(getColumnName6()); List actual = scanAll(scan); // Assert actual.forEach( a -> { assertThat(a.getContainedColumnNames()) - .containsOnly(COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME6); - assertThat(a.getInt(COL_NAME1)).isEqualTo(0); - assertThat(a.isNull(COL_NAME6)).isTrue(); + .containsOnly(getColumnName1(), getColumnName2(), getColumnName3(), getColumnName6()); + assertThat(a.getInt(getColumnName1())).isEqualTo(0); + assertThat(a.isNull(getColumnName6())).isTrue(); }); assertThat(actual.size()).isEqualTo(3); - assertThat(actual.get(0).getText(COL_NAME2)).isEqualTo("0"); - assertThat(actual.get(1).getText(COL_NAME2)).isEqualTo("1"); - assertThat(actual.get(2).getText(COL_NAME2)).isEqualTo("2"); - assertThat(actual.get(0).getInt(COL_NAME3)).isEqualTo(0); - assertThat(actual.get(1).getInt(COL_NAME3)).isEqualTo(1); - assertThat(actual.get(2).getInt(COL_NAME3)).isEqualTo(2); + assertThat(actual.get(0).getText(getColumnName2())).isEqualTo("0"); + assertThat(actual.get(1).getText(getColumnName2())).isEqualTo("1"); + assertThat(actual.get(2).getText(getColumnName2())).isEqualTo("2"); + assertThat(actual.get(0).getInt(getColumnName3())).isEqualTo(0); + assertThat(actual.get(1).getInt(getColumnName3())).isEqualTo(1); + assertThat(actual.get(2).getInt(getColumnName3())).isEqualTo(2); } @Test @@ -384,7 +430,7 @@ public void scan_ScanWithPartitionKeyGivenAndResultsIteratedWithOne_ShouldReturn int pKey = 0; // Act - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = new Scan(new Key(getColumnName1(), pKey)); Scanner scanner = storage.scan(scan); // Assert @@ -406,18 +452,18 @@ public void scan_ScanWithPartitionKeyGivenAndResultsIteratedWithOne_ShouldReturn assertThat(result.isPresent()).isFalse(); assertThat(results.size()).isEqualTo(3); - assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(0).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); - assertThat(results.get(2).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(2).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); + assertThat(results.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(0).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName4()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(1).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName4()).get().getAsInt()).isEqualTo(1); + assertThat(results.get(2).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(2).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(2).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(2).getValue(getColumnName4()).get().getAsInt()).isEqualTo(2); scanner.close(); } @@ -430,7 +476,7 @@ public void scan_ScanWithPartitionGivenThreeTimes_ShouldRetrieveResultsProperlyE int pKey = 0; // Act - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = new Scan(new Key(getColumnName1(), pKey)); double t1 = System.currentTimeMillis(); List actual = scanAll(scan); double t2 = System.currentTimeMillis(); @@ -442,10 +488,10 @@ public void scan_ScanWithPartitionGivenThreeTimes_ShouldRetrieveResultsProperlyE double t4 = System.currentTimeMillis(); // Assert - assertThat(actual.get(0).getValue(COL_NAME1)) - .isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey))); - assertThat(actual.get(0).getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, 0))); + assertThat(actual.get(0).getValue(getColumnName1())) + .isEqualTo(Optional.of(new IntValue(getColumnName1(), pKey))); + assertThat(actual.get(0).getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), 0))); System.err.println("first: " + (t2 - t1) + " (ms)"); System.err.println("second: " + (t3 - t2) + " (ms)"); System.err.println("third: " + (t4 - t3) + " (ms)"); @@ -460,21 +506,21 @@ public void scan_ScanWithStartInclusiveRangeGiven_ShouldRetrieveResultsOfGivenRa // Act Scan scan = - new Scan(new Key(COL_NAME1, pKey)) - .withStart(new Key(COL_NAME4, 0), true) - .withEnd(new Key(COL_NAME4, 2), false); + new Scan(new Key(getColumnName1(), pKey)) + .withStart(new Key(getColumnName4(), 0), true) + .withEnd(new Key(getColumnName4(), 2), false); List actual = scanAll(scan); // verify assertThat(actual.size()).isEqualTo(2); - assertThat(actual.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(0).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(1).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); + assertThat(actual.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(0).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(0).getValue(getColumnName4()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(1).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(1).getValue(getColumnName4()).get().getAsInt()).isEqualTo(1); } @Test @@ -486,21 +532,21 @@ public void scan_ScanWithEndInclusiveRangeGiven_ShouldRetrieveResultsOfGivenRang // Act Scan scan = - new Scan(new Key(COL_NAME1, pKey)) - .withStart(new Key(COL_NAME4, 0), false) - .withEnd(new Key(COL_NAME4, 2), true); + new Scan(new Key(getColumnName1(), pKey)) + .withStart(new Key(getColumnName4(), 0), false) + .withEnd(new Key(getColumnName4(), 2), true); List actual = scanAll(scan); // verify assertThat(actual.size()).isEqualTo(2); - assertThat(actual.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(0).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); - assertThat(actual.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(1).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); + assertThat(actual.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(0).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(0).getValue(getColumnName4()).get().getAsInt()).isEqualTo(1); + assertThat(actual.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(1).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(1).getValue(getColumnName4()).get().getAsInt()).isEqualTo(2); } @Test @@ -510,20 +556,20 @@ public void scan_ScanWithOrderAscGiven_ShouldReturnAscendingOrderedResults() List puts = preparePuts(); storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2))); Scan scan = - new Scan(new Key(COL_NAME1, 0)) - .withOrdering(new Scan.Ordering(COL_NAME4, Scan.Ordering.Order.ASC)); + new Scan(new Key(getColumnName1(), 0)) + .withOrdering(new Scan.Ordering(getColumnName4(), Scan.Ordering.Order.ASC)); // Act List actual = scanAll(scan); // Assert assertThat(actual.size()).isEqualTo(3); - assertThat(actual.get(0).getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, 0))); - assertThat(actual.get(1).getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, 1))); - assertThat(actual.get(2).getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, 2))); + assertThat(actual.get(0).getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), 0))); + assertThat(actual.get(1).getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), 1))); + assertThat(actual.get(2).getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), 2))); } @Test @@ -533,20 +579,20 @@ public void scan_ScanWithOrderDescGiven_ShouldReturnDescendingOrderedResults() List puts = preparePuts(); storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2))); Scan scan = - new Scan(new Key(COL_NAME1, 0)) - .withOrdering(new Scan.Ordering(COL_NAME4, Scan.Ordering.Order.DESC)); + new Scan(new Key(getColumnName1(), 0)) + .withOrdering(new Scan.Ordering(getColumnName4(), Scan.Ordering.Order.DESC)); // Act List actual = scanAll(scan); // Assert assertThat(actual.size()).isEqualTo(3); - assertThat(actual.get(0).getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, 2))); - assertThat(actual.get(1).getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, 1))); - assertThat(actual.get(2).getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, 0))); + assertThat(actual.get(0).getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), 2))); + assertThat(actual.get(1).getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), 1))); + assertThat(actual.get(2).getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), 0))); } @Test @@ -557,8 +603,8 @@ public void scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults() storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2))); Scan scan = - new Scan(new Key(COL_NAME1, 0)) - .withOrdering(new Scan.Ordering(COL_NAME4, Scan.Ordering.Order.DESC)) + new Scan(new Key(getColumnName1(), 0)) + .withOrdering(new Scan.Ordering(getColumnName4(), Scan.Ordering.Order.DESC)) .withLimit(1); // exercise @@ -566,8 +612,8 @@ public void scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults() // verify assertThat(actual.size()).isEqualTo(1); - assertThat(actual.get(0).getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, 2))); + assertThat(actual.get(0).getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), 2))); } @Test @@ -581,24 +627,24 @@ public void scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults() Scan scan = Scan.newBuilder() .namespace(getNamespace()) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 0)) - .start(Key.ofInt(COL_NAME4, 0)) - .end(Key.ofInt(COL_NAME4, 2)) - .where(ConditionBuilder.column(COL_NAME5).isEqualToBoolean(true)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 0)) + .start(Key.ofInt(getColumnName4(), 0)) + .end(Key.ofInt(getColumnName4(), 2)) + .where(ConditionBuilder.column(getColumnName5()).isEqualToBoolean(true)) .build(); List actual = scanAll(scan); // verify assertThat(actual.size()).isEqualTo(2); - assertThat(actual.get(0).contains(COL_NAME1)).isTrue(); - assertThat(actual.get(0).getInt(COL_NAME1)).isEqualTo(0); - assertThat(actual.get(0).contains(COL_NAME4)).isTrue(); - assertThat(actual.get(0).getInt(COL_NAME4)).isEqualTo(0); - assertThat(actual.get(1).contains(COL_NAME1)).isTrue(); - assertThat(actual.get(1).getInt(COL_NAME1)).isEqualTo(0); - assertThat(actual.get(1).contains(COL_NAME4)).isTrue(); - assertThat(actual.get(1).getInt(COL_NAME4)).isEqualTo(2); + assertThat(actual.get(0).contains(getColumnName1())).isTrue(); + assertThat(actual.get(0).getInt(getColumnName1())).isEqualTo(0); + assertThat(actual.get(0).contains(getColumnName4())).isTrue(); + assertThat(actual.get(0).getInt(getColumnName4())).isEqualTo(0); + assertThat(actual.get(1).contains(getColumnName1())).isTrue(); + assertThat(actual.get(1).getInt(getColumnName1())).isEqualTo(0); + assertThat(actual.get(1).contains(getColumnName4())).isTrue(); + assertThat(actual.get(1).getInt(getColumnName4())).isEqualTo(2); } @Test @@ -609,7 +655,7 @@ public void scannerIterator_ScanWithPartitionKeyGiven_ShouldRetrieveCorrectResul int pKey = 0; // Act - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = new Scan(new Key(getColumnName1(), pKey)); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); scanner.forEach(actual::add); @@ -617,18 +663,18 @@ public void scannerIterator_ScanWithPartitionKeyGiven_ShouldRetrieveCorrectResul // Assert assertThat(actual.size()).isEqualTo(3); - assertThat(actual.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(0).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(1).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); - assertThat(actual.get(2).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(2).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); + assertThat(actual.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(0).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(0).getValue(getColumnName4()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(1).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(1).getValue(getColumnName4()).get().getAsInt()).isEqualTo(1); + assertThat(actual.get(2).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(2).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(2).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(2).getValue(getColumnName4()).get().getAsInt()).isEqualTo(2); } @Test @@ -639,7 +685,7 @@ public void scannerIterator_OneAndIteratorCalled_ShouldRetrieveCorrectResults() int pKey = 0; // Act - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = new Scan(new Key(getColumnName1(), pKey)); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); Optional result = scanner.one(); @@ -648,20 +694,20 @@ public void scannerIterator_OneAndIteratorCalled_ShouldRetrieveCorrectResults() // Assert assertThat(result.isPresent()).isTrue(); - assertThat(result.get().getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(result.get().getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(0); + assertThat(result.get().getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(result.get().getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(result.get().getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(result.get().getValue(getColumnName4()).get().getAsInt()).isEqualTo(0); assertThat(actual.size()).isEqualTo(2); - assertThat(actual.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(0).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); - assertThat(actual.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(1).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); + assertThat(actual.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(0).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(0).getValue(getColumnName4()).get().getAsInt()).isEqualTo(1); + assertThat(actual.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(1).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(1).getValue(getColumnName4()).get().getAsInt()).isEqualTo(2); } @Test @@ -672,7 +718,7 @@ public void scannerIterator_AllAndIteratorCalled_ShouldRetrieveCorrectResults() int pKey = 0; // Act - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = new Scan(new Key(getColumnName1(), pKey)); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); List all = scanner.all(); @@ -681,18 +727,18 @@ public void scannerIterator_AllAndIteratorCalled_ShouldRetrieveCorrectResults() // Assert assertThat(all.size()).isEqualTo(3); - assertThat(all.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(all.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(all.get(0).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(all.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(0); - assertThat(all.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(all.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(all.get(1).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(all.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); - assertThat(all.get(2).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(all.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(all.get(2).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(all.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); + assertThat(all.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(all.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(all.get(0).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(all.get(0).getValue(getColumnName4()).get().getAsInt()).isEqualTo(0); + assertThat(all.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(all.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(all.get(1).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(all.get(1).getValue(getColumnName4()).get().getAsInt()).isEqualTo(1); + assertThat(all.get(2).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(all.get(2).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(all.get(2).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(all.get(2).getValue(getColumnName4()).get().getAsInt()).isEqualTo(2); assertThat(actual).isEmpty(); } @@ -705,7 +751,7 @@ public void scannerIterator_IteratorCalledMultipleTimes_ShouldRetrieveCorrectRes int pKey = 0; // Act - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = new Scan(new Key(getColumnName1(), pKey)); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); actual.add(scanner.iterator().next()); @@ -715,18 +761,18 @@ public void scannerIterator_IteratorCalledMultipleTimes_ShouldRetrieveCorrectRes // Assert assertThat(actual.size()).isEqualTo(3); - assertThat(actual.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(0).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(1).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); - assertThat(actual.get(2).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(2).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); + assertThat(actual.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(0).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(0).getValue(getColumnName4()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(1).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(1).getValue(getColumnName4()).get().getAsInt()).isEqualTo(1); + assertThat(actual.get(2).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(2).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(2).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(2).getValue(getColumnName4()).get().getAsInt()).isEqualTo(2); } @Test @@ -735,8 +781,8 @@ public void put_SinglePutGiven_ShouldStoreProperly() throws ExecutionException { int pKey = 0; int cKey = 0; List puts = preparePuts(); - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); + Key partitionKey = new Key(getColumnName1(), pKey); + Key clusteringKey = new Key(getColumnName4(), cKey); Get get = new Get(partitionKey, clusteringKey); // Act @@ -745,16 +791,16 @@ public void put_SinglePutGiven_ShouldStoreProperly() throws ExecutionException { // Assert Optional actual = storage.get(get); assertThat(actual.isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME1)) - .isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey))); - assertThat(actual.get().getValue(COL_NAME2)) - .isEqualTo(Optional.of(new TextValue(COL_NAME2, Integer.toString(pKey + cKey)))); - assertThat(actual.get().getValue(COL_NAME3)) - .isEqualTo(Optional.of(new IntValue(COL_NAME3, pKey + cKey))); - assertThat(actual.get().getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, cKey))); - assertThat(actual.get().getValue(COL_NAME5)) - .isEqualTo(Optional.of(new BooleanValue(COL_NAME5, cKey % 2 == 0))); + assertThat(actual.get().getValue(getColumnName1())) + .isEqualTo(Optional.of(new IntValue(getColumnName1(), pKey))); + assertThat(actual.get().getValue(getColumnName2())) + .isEqualTo(Optional.of(new TextValue(getColumnName2(), Integer.toString(pKey + cKey)))); + assertThat(actual.get().getValue(getColumnName3())) + .isEqualTo(Optional.of(new IntValue(getColumnName3(), pKey + cKey))); + assertThat(actual.get().getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), cKey))); + assertThat(actual.get().getValue(getColumnName5())) + .isEqualTo(Optional.of(new BooleanValue(getColumnName5(), cKey % 2 == 0))); } @Test @@ -764,28 +810,28 @@ public void put_SinglePutWithIfNotExistsGiven_ShouldStoreProperly() throws Execu int cKey = 0; List puts = preparePuts(); puts.get(0).withCondition(new PutIfNotExists()); - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); + Key partitionKey = new Key(getColumnName1(), pKey); + Key clusteringKey = new Key(getColumnName4(), cKey); Get get = new Get(partitionKey, clusteringKey); // Act storage.put(puts.get(0)); - puts.get(0).withValue(COL_NAME3, Integer.MAX_VALUE); + puts.get(0).withValue(getColumnName3(), Integer.MAX_VALUE); assertThatThrownBy(() -> storage.put(puts.get(0))).isInstanceOf(NoMutationException.class); // Assert Optional actual = storage.get(get); assertThat(actual.isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME1)) - .isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey))); - assertThat(actual.get().getValue(COL_NAME2)) - .isEqualTo(Optional.of(new TextValue(COL_NAME2, Integer.toString(pKey + cKey)))); - assertThat(actual.get().getValue(COL_NAME3)) - .isEqualTo(Optional.of(new IntValue(COL_NAME3, pKey + cKey))); - assertThat(actual.get().getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, cKey))); - assertThat(actual.get().getValue(COL_NAME5)) - .isEqualTo(Optional.of(new BooleanValue(COL_NAME5, cKey % 2 == 0))); + assertThat(actual.get().getValue(getColumnName1())) + .isEqualTo(Optional.of(new IntValue(getColumnName1(), pKey))); + assertThat(actual.get().getValue(getColumnName2())) + .isEqualTo(Optional.of(new TextValue(getColumnName2(), Integer.toString(pKey + cKey)))); + assertThat(actual.get().getValue(getColumnName3())) + .isEqualTo(Optional.of(new IntValue(getColumnName3(), pKey + cKey))); + assertThat(actual.get().getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), cKey))); + assertThat(actual.get().getValue(getColumnName5())) + .isEqualTo(Optional.of(new BooleanValue(getColumnName5(), cKey % 2 == 0))); } @Test @@ -794,7 +840,7 @@ public void put_MultiplePutGiven_ShouldStoreProperly() throws IOException, Execu int pKey = 0; int cKey = 0; List puts = preparePuts(); - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = new Scan(new Key(getColumnName1(), pKey)); // Act assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) @@ -803,18 +849,20 @@ public void put_MultiplePutGiven_ShouldStoreProperly() throws IOException, Execu // Assert List results = scanAll(scan); assertThat(results.size()).isEqualTo(3); - assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(0).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey); - assertThat(results.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey + 1); - assertThat(results.get(2).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(2).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey + 2); + assertThat(results.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(0).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName4()).get().getAsInt()).isEqualTo(pKey + cKey); + assertThat(results.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(1).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName4()).get().getAsInt()) + .isEqualTo(pKey + cKey + 1); + assertThat(results.get(2).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(2).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(2).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(2).getValue(getColumnName4()).get().getAsInt()) + .isEqualTo(pKey + cKey + 2); } @Test @@ -827,7 +875,7 @@ public void put_MultiplePutWithIfNotExistsGiven_ShouldStoreProperly() puts.get(0).withCondition(new PutIfNotExists()); puts.get(1).withCondition(new PutIfNotExists()); puts.get(2).withCondition(new PutIfNotExists()); - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = new Scan(new Key(getColumnName1(), pKey)); // Act assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) @@ -836,25 +884,27 @@ public void put_MultiplePutWithIfNotExistsGiven_ShouldStoreProperly() // Assert List results = scanAll(scan); assertThat(results.size()).isEqualTo(3); - assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(0).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey); - assertThat(results.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey + 1); - assertThat(results.get(2).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(2).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey + 2); + assertThat(results.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(0).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName4()).get().getAsInt()).isEqualTo(pKey + cKey); + assertThat(results.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(1).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName4()).get().getAsInt()) + .isEqualTo(pKey + cKey + 1); + assertThat(results.get(2).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(2).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(2).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(2).getValue(getColumnName4()).get().getAsInt()) + .isEqualTo(pKey + cKey + 2); } @Test public void put_PutWithoutValuesGiven_ShouldStoreProperly() throws ExecutionException { // Arrange - Key partitionKey = new Key(COL_NAME1, 0); - Key clusteringKey = new Key(COL_NAME4, 0); + Key partitionKey = new Key(getColumnName1(), 0); + Key clusteringKey = new Key(getColumnName4(), 0); // Act assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))) @@ -868,8 +918,8 @@ public void put_PutWithoutValuesGiven_ShouldStoreProperly() throws ExecutionExce @Test public void put_PutWithoutValuesGivenTwice_ShouldStoreProperly() throws ExecutionException { // Arrange - Key partitionKey = new Key(COL_NAME1, 0); - Key clusteringKey = new Key(COL_NAME4, 0); + Key partitionKey = new Key(getColumnName1(), 0); + Key clusteringKey = new Key(getColumnName4(), 0); // Act assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))) @@ -893,7 +943,7 @@ public void put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutati puts.get(0).withCondition(new PutIfNotExists()); puts.get(1).withCondition(new PutIfNotExists()); puts.get(2).withCondition(new PutIfNotExists()); - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = new Scan(new Key(getColumnName1(), pKey)); // Act assertThatThrownBy(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) @@ -902,8 +952,8 @@ public void put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutati // Assert List results = scanAll(scan); assertThat(results.size()).isEqualTo(1); - assertThat(results.get(0).getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, pKey + cKey))); + assertThat(results.get(0).getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), pKey + cKey))); } @Test @@ -922,11 +972,11 @@ public void put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutati // Assert List results; - results = scanAll(new Scan(new Key(COL_NAME1, 0))); + results = scanAll(new Scan(new Key(getColumnName1(), 0))); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(COL_NAME1, 3))); + results = scanAll(new Scan(new Key(getColumnName1(), 3))); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(COL_NAME1, 6))); + results = scanAll(new Scan(new Key(getColumnName1(), 6))); assertThat(results.size()).isEqualTo(0); } @@ -942,11 +992,11 @@ public void put_MultiplePutWithDifferentPartitionsGiven_ShouldThrowIllegalArgume // Assert List results; - results = scanAll(new Scan(new Key(COL_NAME1, 0))); + results = scanAll(new Scan(new Key(getColumnName1(), 0))); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(COL_NAME1, 3))); + results = scanAll(new Scan(new Key(getColumnName1(), 3))); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(COL_NAME1, 6))); + results = scanAll(new Scan(new Key(getColumnName1(), 6))); assertThat(results.size()).isEqualTo(0); } @@ -961,23 +1011,23 @@ public void put_MultiplePutWithDifferentConditionsGiven_ShouldStoreProperly() .withCondition( new PutIf( new ConditionalExpression( - COL_NAME2, new TextValue("1"), ConditionalExpression.Operator.EQ))); + getColumnName2(), new TextValue("1"), ConditionalExpression.Operator.EQ))); // Act assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1)))) .doesNotThrowAnyException(); // Assert - List results = scanAll(new Scan(new Key(COL_NAME1, 0))); + List results = scanAll(new Scan(new Key(getColumnName1(), 0))); assertThat(results.size()).isEqualTo(2); - assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(0).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); + assertThat(results.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(0).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName4()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(1).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName4()).get().getAsInt()).isEqualTo(1); } @Test @@ -1010,17 +1060,19 @@ public void put_PutWithIfExistsGivenWhenSuchRecordExists_ShouldUpdateRecord() // Act Assert storage.put(puts.get(0)); puts.get(0).withCondition(new PutIfExists()); - puts.get(0).withValue(COL_NAME3, Integer.MAX_VALUE); + puts.get(0).withValue(getColumnName3(), Integer.MAX_VALUE); assertThatCode(() -> storage.put(puts.get(0))).doesNotThrowAnyException(); // Assert Optional actual = storage.get(get); assertThat(actual.isPresent()).isTrue(); Result result = actual.get(); - assertThat(result.getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey))); - assertThat(result.getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, cKey))); - assertThat(result.getValue(COL_NAME3)) - .isEqualTo(Optional.of(new IntValue(COL_NAME3, Integer.MAX_VALUE))); + assertThat(result.getValue(getColumnName1())) + .isEqualTo(Optional.of(new IntValue(getColumnName1(), pKey))); + assertThat(result.getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), cKey))); + assertThat(result.getValue(getColumnName3())) + .isEqualTo(Optional.of(new IntValue(getColumnName3(), Integer.MAX_VALUE))); } @Test @@ -1038,18 +1090,22 @@ public void put_PutWithIfGivenWhenSuchRecordExists_ShouldUpdateRecord() .withCondition( new PutIf( new ConditionalExpression( - COL_NAME3, new IntValue(pKey + cKey), ConditionalExpression.Operator.EQ))); - puts.get(0).withValue(COL_NAME3, Integer.MAX_VALUE); + getColumnName3(), + new IntValue(pKey + cKey), + ConditionalExpression.Operator.EQ))); + puts.get(0).withValue(getColumnName3(), Integer.MAX_VALUE); assertThatCode(() -> storage.put(puts.get(0))).doesNotThrowAnyException(); // Assert Optional actual = storage.get(get); assertThat(actual.isPresent()).isTrue(); Result result = actual.get(); - assertThat(result.getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey))); - assertThat(result.getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, cKey))); - assertThat(result.getValue(COL_NAME3)) - .isEqualTo(Optional.of(new IntValue(COL_NAME3, Integer.MAX_VALUE))); + assertThat(result.getValue(getColumnName1())) + .isEqualTo(Optional.of(new IntValue(getColumnName1(), pKey))); + assertThat(result.getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), cKey))); + assertThat(result.getValue(getColumnName3())) + .isEqualTo(Optional.of(new IntValue(getColumnName3(), Integer.MAX_VALUE))); } @Test @@ -1067,18 +1123,22 @@ public void put_PutWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationException() .withCondition( new PutIf( new ConditionalExpression( - COL_NAME3, new IntValue(pKey + cKey + 1), ConditionalExpression.Operator.EQ))); - puts.get(0).withValue(COL_NAME3, Integer.MAX_VALUE); + getColumnName3(), + new IntValue(pKey + cKey + 1), + ConditionalExpression.Operator.EQ))); + puts.get(0).withValue(getColumnName3(), Integer.MAX_VALUE); assertThatThrownBy(() -> storage.put(puts.get(0))).isInstanceOf(NoMutationException.class); // Assert Optional actual = storage.get(get); assertThat(actual.isPresent()).isTrue(); Result result = actual.get(); - assertThat(result.getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey))); - assertThat(result.getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, cKey))); - assertThat(result.getValue(COL_NAME3)) - .isEqualTo(Optional.of(new IntValue(COL_NAME3, pKey + cKey))); + assertThat(result.getValue(getColumnName1())) + .isEqualTo(Optional.of(new IntValue(getColumnName1(), pKey))); + assertThat(result.getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), cKey))); + assertThat(result.getValue(getColumnName3())) + .isEqualTo(Optional.of(new IntValue(getColumnName3(), pKey + cKey))); } @Test @@ -1087,8 +1147,8 @@ public void put_PutWithNullValue_ShouldPutProperly() throws ExecutionException { Put put = preparePuts().get(0); storage.put(put); - put.withTextValue(COL_NAME2, null); - put.withBooleanValue(COL_NAME5, null); + put.withTextValue(getColumnName2(), null); + put.withBooleanValue(getColumnName5(), null); // Act storage.put(put); @@ -1097,48 +1157,57 @@ public void put_PutWithNullValue_ShouldPutProperly() throws ExecutionException { Optional actual = storage.get(prepareGet(0, 0)); assertThat(actual.isPresent()).isTrue(); Result result = actual.get(); - assertThat(result.getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, 0))); - assertThat(result.getValue(COL_NAME4)).isEqualTo(Optional.of(new IntValue(COL_NAME4, 0))); - assertThat(result.getValue(COL_NAME2)) - .isEqualTo(Optional.of(new TextValue(COL_NAME2, (String) null))); - assertThat(result.getValue(COL_NAME3)).isEqualTo(Optional.of(new IntValue(COL_NAME3, 0))); - assertThat(result.getValue(COL_NAME5)) - .isEqualTo(Optional.of(new BooleanValue(COL_NAME5, false))); + assertThat(result.getValue(getColumnName1())) + .isEqualTo(Optional.of(new IntValue(getColumnName1(), 0))); + assertThat(result.getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), 0))); + assertThat(result.getValue(getColumnName2())) + .isEqualTo(Optional.of(new TextValue(getColumnName2(), (String) null))); + assertThat(result.getValue(getColumnName3())) + .isEqualTo(Optional.of(new IntValue(getColumnName3(), 0))); + assertThat(result.getValue(getColumnName5())) + .isEqualTo(Optional.of(new BooleanValue(getColumnName5(), false))); assertThat(result.getContainedColumnNames()) .isEqualTo( new HashSet<>( - Arrays.asList(COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6))); - - assertThat(result.contains(COL_NAME1)).isTrue(); - assertThat(result.isNull(COL_NAME1)).isFalse(); - assertThat(result.getInt(COL_NAME1)).isEqualTo(0); - assertThat(result.getAsObject(COL_NAME1)).isEqualTo(0); - - assertThat(result.contains(COL_NAME4)).isTrue(); - assertThat(result.isNull(COL_NAME4)).isFalse(); - assertThat(result.getInt(COL_NAME4)).isEqualTo(0); - assertThat(result.getAsObject(COL_NAME4)).isEqualTo(0); - - assertThat(result.contains(COL_NAME2)).isTrue(); - assertThat(result.isNull(COL_NAME2)).isTrue(); - assertThat(result.getText(COL_NAME2)).isNull(); - assertThat(result.getAsObject(COL_NAME2)).isNull(); - - assertThat(result.contains(COL_NAME3)).isTrue(); - assertThat(result.isNull(COL_NAME3)).isFalse(); - assertThat(result.getInt(COL_NAME3)).isEqualTo(0); - assertThat(result.getAsObject(COL_NAME3)).isEqualTo(0); - - assertThat(result.contains(COL_NAME5)).isTrue(); - assertThat(result.isNull(COL_NAME5)).isTrue(); - assertThat(result.getBoolean(COL_NAME5)).isFalse(); - assertThat(result.getAsObject(COL_NAME5)).isNull(); - - assertThat(result.contains(COL_NAME6)).isTrue(); - assertThat(result.isNull(COL_NAME6)).isTrue(); - assertThat(result.getBlob(COL_NAME6)).isNull(); - assertThat(result.getAsObject(COL_NAME6)).isNull(); + Arrays.asList( + getColumnName1(), + getColumnName2(), + getColumnName3(), + getColumnName4(), + getColumnName5(), + getColumnName6()))); + + assertThat(result.contains(getColumnName1())).isTrue(); + assertThat(result.isNull(getColumnName1())).isFalse(); + assertThat(result.getInt(getColumnName1())).isEqualTo(0); + assertThat(result.getAsObject(getColumnName1())).isEqualTo(0); + + assertThat(result.contains(getColumnName4())).isTrue(); + assertThat(result.isNull(getColumnName4())).isFalse(); + assertThat(result.getInt(getColumnName4())).isEqualTo(0); + assertThat(result.getAsObject(getColumnName4())).isEqualTo(0); + + assertThat(result.contains(getColumnName2())).isTrue(); + assertThat(result.isNull(getColumnName2())).isTrue(); + assertThat(result.getText(getColumnName2())).isNull(); + assertThat(result.getAsObject(getColumnName2())).isNull(); + + assertThat(result.contains(getColumnName3())).isTrue(); + assertThat(result.isNull(getColumnName3())).isFalse(); + assertThat(result.getInt(getColumnName3())).isEqualTo(0); + assertThat(result.getAsObject(getColumnName3())).isEqualTo(0); + + assertThat(result.contains(getColumnName5())).isTrue(); + assertThat(result.isNull(getColumnName5())).isTrue(); + assertThat(result.getBoolean(getColumnName5())).isFalse(); + assertThat(result.getAsObject(getColumnName5())).isNull(); + + assertThat(result.contains(getColumnName6())).isTrue(); + assertThat(result.isNull(getColumnName6())).isTrue(); + assertThat(result.getBlob(getColumnName6())).isNull(); + assertThat(result.getAsObject(getColumnName6())).isNull(); } @Test @@ -1147,9 +1216,10 @@ public void put_withPutIfIsNullWhenRecordDoesNotExist_shouldThrowNoMutationExcep // Arrange Put putIf = Put.newBuilder(preparePuts().get(0)) - .intValue(COL_NAME3, 100) + .intValue(getColumnName3(), 100) .condition( - ConditionBuilder.putIf(ConditionBuilder.column(COL_NAME3).isNullInt()).build()) + ConditionBuilder.putIf(ConditionBuilder.column(getColumnName3()).isNullInt()) + .build()) .enableImplicitPreRead() .build(); @@ -1167,7 +1237,7 @@ public void delete_DeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingl populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(COL_NAME1, pKey); + Key partitionKey = new Key(getColumnName1(), pKey); // Act Delete delete = prepareDelete(pKey, cKey); @@ -1176,14 +1246,14 @@ public void delete_DeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingl // Assert List results = scanAll(new Scan(partitionKey)); assertThat(results.size()).isEqualTo(2); - assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(0).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(cKey + 1); - assertThat(results.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(cKey + 2); + assertThat(results.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(0).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName4()).get().getAsInt()).isEqualTo(cKey + 1); + assertThat(results.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(1).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName4()).get().getAsInt()).isEqualTo(cKey + 2); } @Test @@ -1205,8 +1275,8 @@ public void delete_DeleteWithIfExistsGivenWhenSuchRecordExists_ShouldDeletePrope populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); + Key partitionKey = new Key(getColumnName1(), pKey); + Key clusteringKey = new Key(getColumnName4(), cKey); // Act Delete delete = prepareDelete(pKey, cKey); @@ -1225,15 +1295,15 @@ public void delete_DeleteWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationExcept populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); + Key partitionKey = new Key(getColumnName1(), pKey); + Key clusteringKey = new Key(getColumnName4(), cKey); // Act Delete delete = prepareDelete(pKey, cKey); delete.withCondition( new DeleteIf( new ConditionalExpression( - COL_NAME2, + getColumnName2(), new TextValue(Integer.toString(Integer.MAX_VALUE)), ConditionalExpression.Operator.EQ))); assertThatThrownBy(() -> storage.delete(delete)).isInstanceOf(NoMutationException.class); @@ -1250,15 +1320,15 @@ public void delete_DeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); + Key partitionKey = new Key(getColumnName1(), pKey); + Key clusteringKey = new Key(getColumnName4(), cKey); // Act Delete delete = prepareDelete(pKey, cKey); delete.withCondition( new DeleteIf( new ConditionalExpression( - COL_NAME2, + getColumnName2(), new TextValue(Integer.toString(pKey)), ConditionalExpression.Operator.EQ))); assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException(); @@ -1281,7 +1351,7 @@ public void delete_MultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProper .withCondition( new DeleteIf( new ConditionalExpression( - COL_NAME2, new TextValue("1"), ConditionalExpression.Operator.EQ))); + getColumnName2(), new TextValue("1"), ConditionalExpression.Operator.EQ))); // Act assertThatCode( @@ -1289,7 +1359,7 @@ public void delete_MultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProper .doesNotThrowAnyException(); // Assert - List results = scanAll(new Scan(new Key(COL_NAME1, 0))); + List results = scanAll(new Scan(new Key(getColumnName1(), 0))); assertThat(results.size()).isEqualTo(0); } @@ -1310,7 +1380,7 @@ public void mutate_MultiplePutGiven_ShouldStoreProperly() throws ExecutionExcept int pKey = 0; int cKey = 0; List puts = preparePuts(); - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = new Scan(new Key(getColumnName1(), pKey)); // Act assertThatCode(() -> storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) @@ -1319,18 +1389,20 @@ public void mutate_MultiplePutGiven_ShouldStoreProperly() throws ExecutionExcept // Assert List results = scanAll(scan); assertThat(results.size()).isEqualTo(3); - assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(0).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey); - assertThat(results.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey + 1); - assertThat(results.get(2).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(2).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(results.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(pKey + cKey + 2); + assertThat(results.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(0).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName4()).get().getAsInt()).isEqualTo(pKey + cKey); + assertThat(results.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(1).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName4()).get().getAsInt()) + .isEqualTo(pKey + cKey + 1); + assertThat(results.get(2).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(2).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(2).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(results.get(2).getValue(getColumnName4()).get().getAsInt()) + .isEqualTo(pKey + cKey + 2); } @Test @@ -1345,11 +1417,11 @@ public void mutate_MultiplePutWithDifferentPartitionsGiven_ShouldThrowIllegalArg // Assert List results; - results = scanAll(new Scan(new Key(COL_NAME1, 0))); + results = scanAll(new Scan(new Key(getColumnName1(), 0))); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(COL_NAME1, 3))); + results = scanAll(new Scan(new Key(getColumnName1(), 3))); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(COL_NAME1, 6))); + results = scanAll(new Scan(new Key(getColumnName1(), 6))); assertThat(results.size()).isEqualTo(0); } @@ -1359,14 +1431,14 @@ public void mutate_PutAndDeleteGiven_ShouldUpdateAndDeleteRecordsProperly() // Arrange populateRecords(); List puts = preparePuts(); - puts.get(1).withValue(COL_NAME3, Integer.MAX_VALUE); - puts.get(2).withValue(COL_NAME3, Integer.MIN_VALUE); + puts.get(1).withValue(getColumnName3(), Integer.MAX_VALUE); + puts.get(2).withValue(getColumnName3(), Integer.MIN_VALUE); int pKey = 0; int cKey = 0; Delete delete = prepareDelete(pKey, cKey); - Scan scan = new Scan(new Key(COL_NAME1, pKey)); + Scan scan = new Scan(new Key(getColumnName1(), pKey)); // Act assertThatCode(() -> storage.mutate(Arrays.asList(delete, puts.get(1), puts.get(2)))) @@ -1375,14 +1447,16 @@ public void mutate_PutAndDeleteGiven_ShouldUpdateAndDeleteRecordsProperly() // Assert List results = scanAll(scan); assertThat(results.size()).isEqualTo(2); - assertThat(results.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(0).getValue(COL_NAME3).isPresent()).isTrue(); - assertThat(results.get(0).getValue(COL_NAME3).get().getAsInt()).isEqualTo(Integer.MAX_VALUE); - assertThat(results.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(COL_NAME3).isPresent()).isTrue(); - assertThat(results.get(1).getValue(COL_NAME3).get().getAsInt()).isEqualTo(Integer.MIN_VALUE); + assertThat(results.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(0).getValue(getColumnName3()).isPresent()).isTrue(); + assertThat(results.get(0).getValue(getColumnName3()).get().getAsInt()) + .isEqualTo(Integer.MAX_VALUE); + assertThat(results.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(results.get(1).getValue(getColumnName3()).isPresent()).isTrue(); + assertThat(results.get(1).getValue(getColumnName3()).get().getAsInt()) + .isEqualTo(Integer.MIN_VALUE); } @Test @@ -1391,8 +1465,8 @@ public void mutate_SinglePutGiven_ShouldStoreProperly() throws ExecutionExceptio int pKey = 0; int cKey = 0; List puts = preparePuts(); - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); + Key partitionKey = new Key(getColumnName1(), pKey); + Key clusteringKey = new Key(getColumnName4(), cKey); Get get = new Get(partitionKey, clusteringKey); // Act @@ -1401,16 +1475,16 @@ public void mutate_SinglePutGiven_ShouldStoreProperly() throws ExecutionExceptio // Assert Optional actual = storage.get(get); assertThat(actual.isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME1)) - .isEqualTo(Optional.of(new IntValue(COL_NAME1, pKey))); - assertThat(actual.get().getValue(COL_NAME2)) - .isEqualTo(Optional.of(new TextValue(COL_NAME2, Integer.toString(pKey + cKey)))); - assertThat(actual.get().getValue(COL_NAME3)) - .isEqualTo(Optional.of(new IntValue(COL_NAME3, pKey + cKey))); - assertThat(actual.get().getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, cKey))); - assertThat(actual.get().getValue(COL_NAME5)) - .isEqualTo(Optional.of(new BooleanValue(COL_NAME5, cKey % 2 == 0))); + assertThat(actual.get().getValue(getColumnName1())) + .isEqualTo(Optional.of(new IntValue(getColumnName1(), pKey))); + assertThat(actual.get().getValue(getColumnName2())) + .isEqualTo(Optional.of(new TextValue(getColumnName2(), Integer.toString(pKey + cKey)))); + assertThat(actual.get().getValue(getColumnName3())) + .isEqualTo(Optional.of(new IntValue(getColumnName3(), pKey + cKey))); + assertThat(actual.get().getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), cKey))); + assertThat(actual.get().getValue(getColumnName5())) + .isEqualTo(Optional.of(new BooleanValue(getColumnName5(), cKey % 2 == 0))); } @Test @@ -1423,8 +1497,8 @@ public void mutate_SinglePutGiven_ShouldStoreProperly() throws ExecutionExceptio int cKey = 0; // Act - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); + Key partitionKey = new Key(getColumnName1(), pKey); + Key clusteringKey = new Key(getColumnName4(), cKey); Delete delete = new Delete(partitionKey, clusteringKey); assertThatCode(() -> storage.mutate(Collections.singletonList(delete))) .doesNotThrowAnyException(); @@ -1432,14 +1506,14 @@ public void mutate_SinglePutGiven_ShouldStoreProperly() throws ExecutionExceptio // Assert List actual = scanAll(new Scan(partitionKey)); assertThat(actual.size()).isEqualTo(2); - assertThat(actual.get(0).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(0).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(cKey + 1); - assertThat(actual.get(1).getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(actual.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(0); - assertThat(actual.get(1).getValue(COL_NAME4).isPresent()).isTrue(); - assertThat(actual.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(cKey + 2); + assertThat(actual.get(0).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(0).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(0).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(0).getValue(getColumnName4()).get().getAsInt()).isEqualTo(cKey + 1); + assertThat(actual.get(1).getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(actual.get(1).getValue(getColumnName1()).get().getAsInt()).isEqualTo(0); + assertThat(actual.get(1).getValue(getColumnName4()).isPresent()).isTrue(); + assertThat(actual.get(1).getValue(getColumnName4()).get().getAsInt()).isEqualTo(cKey + 2); } @Test @@ -1453,7 +1527,7 @@ public void mutate_EmptyListGiven_ShouldThrowIllegalArgumentException() { public void put_PutWithoutClusteringKeyGiven_ShouldThrowIllegalArgumentException() { // Arrange int pKey = 0; - Key partitionKey = new Key(COL_NAME1, pKey); + Key partitionKey = new Key(getColumnName1(), pKey); Put put = new Put(partitionKey); // Act Assert @@ -1465,8 +1539,8 @@ public void put_IncorrectPutGiven_ShouldThrowIllegalArgumentException() { // Arrange int pKey = 0; int cKey = 0; - Key partitionKey = new Key(COL_NAME1, pKey); - Put put = new Put(partitionKey).withValue(COL_NAME4, cKey); + Key partitionKey = new Key(getColumnName1(), pKey); + Put put = new Put(partitionKey).withValue(getColumnName4(), cKey); // Act Assert assertThatCode(() -> storage.put(put)).isInstanceOf(IllegalArgumentException.class); @@ -1475,7 +1549,7 @@ public void put_IncorrectPutGiven_ShouldThrowIllegalArgumentException() { @Test public void put_PutGivenForIndexedColumnWithNullValue_ShouldPut() throws ExecutionException { // Arrange - storage.put(preparePuts().get(0).withValue(IntColumn.ofNull(COL_NAME3))); // (0,0) + storage.put(preparePuts().get(0).withValue(IntColumn.ofNull(getColumnName3()))); // (0,0) Get get = new Get(prepareGet(0, 0)); // Act @@ -1483,9 +1557,12 @@ public void put_PutGivenForIndexedColumnWithNullValue_ShouldPut() throws Executi // Assert assertThat(actual.isPresent()).isTrue(); - assertThat(actual.get().getColumns().get(COL_NAME1)).isEqualTo(IntColumn.of(COL_NAME1, 0)); - assertThat(actual.get().getColumns().get(COL_NAME4)).isEqualTo(IntColumn.of(COL_NAME4, 0)); - assertThat(actual.get().getColumns().get(COL_NAME3)).isEqualTo(IntColumn.ofNull(COL_NAME3)); + assertThat(actual.get().getColumns().get(getColumnName1())) + .isEqualTo(IntColumn.of(getColumnName1(), 0)); + assertThat(actual.get().getColumns().get(getColumnName4())) + .isEqualTo(IntColumn.of(getColumnName4(), 0)); + assertThat(actual.get().getColumns().get(getColumnName3())) + .isEqualTo(IntColumn.ofNull(getColumnName3())); } @Test @@ -1493,12 +1570,12 @@ public void get_GetGivenForIndexedColumn_ShouldGet() throws ExecutionException { // Arrange storage.put(preparePuts().get(0)); // (0,0) int c3 = 0; - Get getBuiltByConstructor = new Get(new Key(COL_NAME3, c3)); + Get getBuiltByConstructor = new Get(new Key(getColumnName3(), c3)); Get getBuiltByBuilder = Get.newBuilder() .namespace(namespace) - .table(TABLE) - .indexKey(Key.ofInt(COL_NAME3, c3)) + .table(getTableName()) + .indexKey(Key.ofInt(getColumnName3(), c3)) .build(); // Act @@ -1507,10 +1584,10 @@ public void get_GetGivenForIndexedColumn_ShouldGet() throws ExecutionException { // Assert assertThat(actual1.isPresent()).isTrue(); - assertThat(actual1.get().getValue(COL_NAME1)) - .isEqualTo(Optional.of(new IntValue(COL_NAME1, 0))); - assertThat(actual1.get().getValue(COL_NAME4)) - .isEqualTo(Optional.of(new IntValue(COL_NAME4, 0))); + assertThat(actual1.get().getValue(getColumnName1())) + .isEqualTo(Optional.of(new IntValue(getColumnName1(), 0))); + assertThat(actual1.get().getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), 0))); assertThat(actual2).isEqualTo(actual1); } @@ -1524,10 +1601,10 @@ public void get_GetGivenForIndexedColumnWithMatchedConjunctions_ShouldGet() Get get = Get.newBuilder() .namespace(namespace) - .table(TABLE) - .indexKey(Key.ofInt(COL_NAME3, c3)) - .where(ConditionBuilder.column(COL_NAME2).isEqualToText("0")) - .and(ConditionBuilder.column(COL_NAME5).isEqualToBoolean(true)) + .table(getTableName()) + .indexKey(Key.ofInt(getColumnName3(), c3)) + .where(ConditionBuilder.column(getColumnName2()).isEqualToText("0")) + .and(ConditionBuilder.column(getColumnName5()).isEqualToBoolean(true)) .build(); // Act @@ -1535,10 +1612,10 @@ public void get_GetGivenForIndexedColumnWithMatchedConjunctions_ShouldGet() // Assert assertThat(actual.isPresent()).isTrue(); - assertThat(actual.get().getInt(COL_NAME1)).isEqualTo(0); - assertThat(actual.get().getInt(COL_NAME4)).isEqualTo(0); - assertThat(actual.get().getText(COL_NAME2)).isEqualTo("0"); - assertThat(actual.get().getBoolean(COL_NAME5)).isEqualTo(true); + assertThat(actual.get().getInt(getColumnName1())).isEqualTo(0); + assertThat(actual.get().getInt(getColumnName4())).isEqualTo(0); + assertThat(actual.get().getText(getColumnName2())).isEqualTo("0"); + assertThat(actual.get().getBoolean(getColumnName5())).isEqualTo(true); } @Test @@ -1550,10 +1627,10 @@ public void get_GetGivenForIndexedColumnWithUnmatchedConjunctions_ShouldReturnEm Get get = Get.newBuilder() .namespace(namespace) - .table(TABLE) - .indexKey(Key.ofInt(COL_NAME3, c3)) - .where(ConditionBuilder.column(COL_NAME2).isEqualToText("a")) - .and(ConditionBuilder.column(COL_NAME5).isEqualToBoolean(true)) + .table(getTableName()) + .indexKey(Key.ofInt(getColumnName3(), c3)) + .where(ConditionBuilder.column(getColumnName2()).isEqualToText("a")) + .and(ConditionBuilder.column(getColumnName5()).isEqualToBoolean(true)) .build(); // Act @@ -1569,7 +1646,7 @@ public void get_GetGivenForIndexedColumnWithUnmatchedConjunctions_ShouldReturnEm // Arrange populateRecords(); int c3 = 3; - Get get = new Get(new Key(COL_NAME3, c3)); + Get get = new Get(new Key(getColumnName3(), c3)); // Act Assert assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class); @@ -1580,12 +1657,12 @@ public void scan_ScanGivenForIndexedColumn_ShouldScan() throws ExecutionExceptio // Arrange populateRecords(); int c3 = 3; - Scan scanBuiltByConstructor = new Scan(new Key(COL_NAME3, c3)); + Scan scanBuiltByConstructor = new Scan(new Key(getColumnName3(), c3)); Scan scanBuiltByBuilder = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .indexKey(Key.ofInt(COL_NAME3, c3)) + .table(getTableName()) + .indexKey(Key.ofInt(getColumnName3(), c3)) .build(); // Act @@ -1598,11 +1675,11 @@ public void scan_ScanGivenForIndexedColumn_ShouldScan() throws ExecutionExceptio new ArrayList<>( Arrays.asList(Arrays.asList(1, 2), Arrays.asList(2, 1), Arrays.asList(3, 0))); for (Result result : actual1) { - assertThat(result.getValue(COL_NAME1).isPresent()).isTrue(); - assertThat(result.getValue(COL_NAME4).isPresent()).isTrue(); + assertThat(result.getValue(getColumnName1()).isPresent()).isTrue(); + assertThat(result.getValue(getColumnName4()).isPresent()).isTrue(); - int col1Val = result.getValue(COL_NAME1).get().getAsInt(); - int col4Val = result.getValue(COL_NAME4).get().getAsInt(); + int col1Val = result.getValue(getColumnName1()).get().getAsInt(); + int col4Val = result.getValue(getColumnName4()).get().getAsInt(); List col1AndCol4 = Arrays.asList(col1Val, col4Val); assertThat(expectedValues).contains(col1AndCol4); expectedValues.remove(col1AndCol4); @@ -1617,7 +1694,7 @@ public void scan_ScanGivenForNonIndexedColumn_ShouldThrowIllegalArgumentExceptio // Arrange populateRecords(); String c2 = "test"; - Scan scan = new Scan(new Key(COL_NAME2, c2)); + Scan scan = new Scan(new Key(getColumnName2(), c2)); // Act Assert assertThatThrownBy(() -> scanAll(scan)).isInstanceOf(IllegalArgumentException.class); @@ -1629,12 +1706,12 @@ public void scan_ScanLargeData_ShouldRetrieveExpectedValues() int recordCount = 345; // Arrange - Key partitionKey = new Key(COL_NAME1, 1); + Key partitionKey = new Key(getColumnName1(), 1); for (int i = 0; i < recordCount; i++) { - Key clusteringKey = new Key(COL_NAME4, i); + Key clusteringKey = new Key(getColumnName4(), i); storage.put( new Put(partitionKey, clusteringKey) - .withBlobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()])); + .withBlobValue(getColumnName6(), new byte[getLargeDataSizeInBytes()])); } Scan scan = new Scan(partitionKey); @@ -1645,8 +1722,8 @@ public void scan_ScanLargeData_ShouldRetrieveExpectedValues() // Assert assertThat(results.size()).isEqualTo(recordCount); for (int i = 0; i < recordCount; i++) { - assertThat(results.get(i).getInt(COL_NAME1)).isEqualTo(1); - assertThat(results.get(i).getInt(COL_NAME4)).isEqualTo(i); + assertThat(results.get(i).getInt(getColumnName1())).isEqualTo(1); + assertThat(results.get(i).getInt(getColumnName4())).isEqualTo(i); } } @@ -1657,16 +1734,16 @@ public void scan_ScanLargeDataWithOrdering_ShouldRetrieveExpectedValues() int fetchCount = 234; // Arrange - Key partitionKey = new Key(COL_NAME1, 1); + Key partitionKey = new Key(getColumnName1(), 1); for (int i = 0; i < recordCount; i++) { - Key clusteringKey = new Key(COL_NAME4, i); + Key clusteringKey = new Key(getColumnName4(), i); storage.put( new Put(partitionKey, clusteringKey) - .withBlobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()])); + .withBlobValue(getColumnName6(), new byte[getLargeDataSizeInBytes()])); } - Scan scanAsc = new Scan(partitionKey).withOrdering(new Ordering(COL_NAME4, Order.ASC)); - Scan scanDesc = new Scan(partitionKey).withOrdering(new Ordering(COL_NAME4, Order.DESC)); + Scan scanAsc = new Scan(partitionKey).withOrdering(new Ordering(getColumnName4(), Order.ASC)); + Scan scanDesc = new Scan(partitionKey).withOrdering(new Ordering(getColumnName4(), Order.DESC)); // Act List resultsAsc = new ArrayList<>(); @@ -1688,14 +1765,14 @@ public void scan_ScanLargeDataWithOrdering_ShouldRetrieveExpectedValues() // Assert assertThat(resultsAsc.size()).isEqualTo(fetchCount); for (int i = 0; i < fetchCount; i++) { - assertThat(resultsAsc.get(i).getInt(COL_NAME1)).isEqualTo(1); - assertThat(resultsAsc.get(i).getInt(COL_NAME4)).isEqualTo(i); + assertThat(resultsAsc.get(i).getInt(getColumnName1())).isEqualTo(1); + assertThat(resultsAsc.get(i).getInt(getColumnName4())).isEqualTo(i); } assertThat(resultsDesc.size()).isEqualTo(fetchCount); for (int i = 0; i < fetchCount; i++) { - assertThat(resultsDesc.get(i).getInt(COL_NAME1)).isEqualTo(1); - assertThat(resultsDesc.get(i).getInt(COL_NAME4)).isEqualTo(recordCount - i - 1); + assertThat(resultsDesc.get(i).getInt(getColumnName1())).isEqualTo(1); + assertThat(resultsDesc.get(i).getInt(getColumnName4())).isEqualTo(recordCount - i - 1); } } @@ -1705,12 +1782,12 @@ public void scan_ScanLargeDataWithLimit_ShouldRetrieveExpectedValues() throws Ex int recordCount = 345; int limit = 234; - Key partitionKey = new Key(COL_NAME1, 1); + Key partitionKey = new Key(getColumnName1(), 1); for (int i = 0; i < recordCount; i++) { - Key clusteringKey = new Key(COL_NAME4, i); + Key clusteringKey = new Key(getColumnName4(), i); storage.put( new Put(partitionKey, clusteringKey) - .withBlobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()])); + .withBlobValue(getColumnName6(), new byte[getLargeDataSizeInBytes()])); } Scan scan = new Scan(partitionKey).withLimit(limit); @@ -1720,8 +1797,8 @@ public void scan_ScanLargeDataWithLimit_ShouldRetrieveExpectedValues() throws Ex // Assert assertThat(results.size()).isEqualTo(limit); for (int i = 0; i < limit; i++) { - assertThat(results.get(i).getInt(COL_NAME1)).isEqualTo(1); - assertThat(results.get(i).getInt(COL_NAME4)).isEqualTo(i); + assertThat(results.get(i).getInt(getColumnName1())).isEqualTo(1); + assertThat(results.get(i).getInt(getColumnName4())).isEqualTo(i); } } @@ -1745,12 +1822,13 @@ public void scan_ScanAllWithNoLimitGiven_ShouldRetrieveAllRecords() j -> expectedResults.add( new ExpectedResultBuilder() - .column(IntColumn.of(COL_NAME1, i)) - .column(IntColumn.of(COL_NAME4, j)) - .column(TextColumn.of(COL_NAME2, Integer.toString(i + j))) - .column(IntColumn.of(COL_NAME3, i + j)) - .column(BooleanColumn.of(COL_NAME5, j % 2 == 0)) - .column(BlobColumn.ofNull(COL_NAME6)) + .column(IntColumn.of(getColumnName1(), i)) + .column(IntColumn.of(getColumnName4(), j)) + .column( + TextColumn.of(getColumnName2(), Integer.toString(i + j))) + .column(IntColumn.of(getColumnName3(), i + j)) + .column(BooleanColumn.of(getColumnName5(), j % 2 == 0)) + .column(BlobColumn.ofNull(getColumnName6())) .build()))); TestUtils.assertResultsContainsExactlyInAnyOrder(results, expectedResults); } @@ -1759,10 +1837,10 @@ public void scan_ScanAllWithNoLimitGiven_ShouldRetrieveAllRecords() public void scan_ScanAllWithLimitGiven_ShouldRetrieveExpectedRecords() throws ExecutionException, IOException { // Arrange - Put p1 = new Put(Key.ofInt(COL_NAME1, 1), Key.ofInt(COL_NAME4, 1)); - Put p2 = new Put(Key.ofInt(COL_NAME1, 1), Key.ofInt(COL_NAME4, 2)); - Put p3 = new Put(Key.ofInt(COL_NAME1, 2), Key.ofInt(COL_NAME4, 1)); - Put p4 = new Put(Key.ofInt(COL_NAME1, 3), Key.ofInt(COL_NAME4, 0)); + Put p1 = new Put(Key.ofInt(getColumnName1(), 1), Key.ofInt(getColumnName4(), 1)); + Put p2 = new Put(Key.ofInt(getColumnName1(), 1), Key.ofInt(getColumnName4(), 2)); + Put p3 = new Put(Key.ofInt(getColumnName1(), 2), Key.ofInt(getColumnName4(), 1)); + Put p4 = new Put(Key.ofInt(getColumnName1(), 3), Key.ofInt(getColumnName4(), 0)); storage.put(ImmutableList.of(p1, p2)); storage.put(p3); storage.put(p4); @@ -1776,36 +1854,36 @@ public void scan_ScanAllWithLimitGiven_ShouldRetrieveExpectedRecords() results, ImmutableList.of( new ExpectedResultBuilder() - .column(IntColumn.of(COL_NAME1, 1)) - .column(IntColumn.of(COL_NAME4, 1)) - .column(TextColumn.ofNull(COL_NAME2)) - .column(IntColumn.ofNull(COL_NAME3)) - .column(BooleanColumn.ofNull(COL_NAME5)) - .column(BlobColumn.ofNull(COL_NAME6)) + .column(IntColumn.of(getColumnName1(), 1)) + .column(IntColumn.of(getColumnName4(), 1)) + .column(TextColumn.ofNull(getColumnName2())) + .column(IntColumn.ofNull(getColumnName3())) + .column(BooleanColumn.ofNull(getColumnName5())) + .column(BlobColumn.ofNull(getColumnName6())) .build(), new ExpectedResultBuilder() - .column(IntColumn.of(COL_NAME1, 1)) - .column(IntColumn.of(COL_NAME4, 2)) - .column(TextColumn.ofNull(COL_NAME2)) - .column(IntColumn.ofNull(COL_NAME3)) - .column(BooleanColumn.ofNull(COL_NAME5)) - .column(BlobColumn.ofNull(COL_NAME6)) + .column(IntColumn.of(getColumnName1(), 1)) + .column(IntColumn.of(getColumnName4(), 2)) + .column(TextColumn.ofNull(getColumnName2())) + .column(IntColumn.ofNull(getColumnName3())) + .column(BooleanColumn.ofNull(getColumnName5())) + .column(BlobColumn.ofNull(getColumnName6())) .build(), new ExpectedResultBuilder() - .column(IntColumn.of(COL_NAME1, 2)) - .column(IntColumn.of(COL_NAME4, 1)) - .column(TextColumn.ofNull(COL_NAME2)) - .column(IntColumn.ofNull(COL_NAME3)) - .column(BooleanColumn.ofNull(COL_NAME5)) - .column(BlobColumn.ofNull(COL_NAME6)) + .column(IntColumn.of(getColumnName1(), 2)) + .column(IntColumn.of(getColumnName4(), 1)) + .column(TextColumn.ofNull(getColumnName2())) + .column(IntColumn.ofNull(getColumnName3())) + .column(BooleanColumn.ofNull(getColumnName5())) + .column(BlobColumn.ofNull(getColumnName6())) .build(), new ExpectedResultBuilder() - .column(IntColumn.of(COL_NAME1, 3)) - .column(IntColumn.of(COL_NAME4, 0)) - .column(TextColumn.ofNull(COL_NAME2)) - .column(IntColumn.ofNull(COL_NAME3)) - .column(BooleanColumn.ofNull(COL_NAME5)) - .column(BlobColumn.ofNull(COL_NAME6)) + .column(IntColumn.of(getColumnName1(), 3)) + .column(IntColumn.of(getColumnName4(), 0)) + .column(TextColumn.ofNull(getColumnName2())) + .column(IntColumn.ofNull(getColumnName3())) + .column(BooleanColumn.ofNull(getColumnName5())) + .column(BlobColumn.ofNull(getColumnName6())) .build())); assertThat(results).hasSize(2); } @@ -1818,7 +1896,10 @@ public void scan_ScanAllWithProjectionsGiven_ShouldRetrieveSpecifiedValues() // Act ScanAll scanAll = - new ScanAll().withProjections(Arrays.asList(COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME6)); + new ScanAll() + .withProjections( + Arrays.asList( + getColumnName1(), getColumnName2(), getColumnName3(), getColumnName6())); List actualResults = scanAll(scanAll); // Assert @@ -1831,16 +1912,18 @@ public void scan_ScanAllWithProjectionsGiven_ShouldRetrieveSpecifiedValues() j -> expectedResults.add( new ExpectedResultBuilder() - .column(IntColumn.of(COL_NAME1, i)) - .column(TextColumn.of(COL_NAME2, Integer.toString(i + j))) - .column(IntColumn.of(COL_NAME3, i + j)) - .column(BlobColumn.ofNull(COL_NAME6)) + .column(IntColumn.of(getColumnName1(), i)) + .column( + TextColumn.of(getColumnName2(), Integer.toString(i + j))) + .column(IntColumn.of(getColumnName3(), i + j)) + .column(BlobColumn.ofNull(getColumnName6())) .build()))); TestUtils.assertResultsContainsExactlyInAnyOrder(actualResults, expectedResults); actualResults.forEach( actualResult -> assertThat(actualResult.getContainedColumnNames()) - .containsOnly(COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME6)); + .containsOnly( + getColumnName1(), getColumnName2(), getColumnName3(), getColumnName6())); } @Test @@ -1848,11 +1931,11 @@ public void scan_ScanAllWithLargeData_ShouldRetrieveExpectedValues() throws ExecutionException, IOException { // Arrange for (int i = 0; i < 345; i++) { - Key partitionKey = new Key(COL_NAME1, i % 4); - Key clusteringKey = new Key(COL_NAME4, i); + Key partitionKey = new Key(getColumnName1(), i % 4); + Key clusteringKey = new Key(getColumnName4(), i); storage.put( new Put(partitionKey, clusteringKey) - .withBlobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()])); + .withBlobValue(getColumnName6(), new byte[getLargeDataSizeInBytes()])); } Scan scan = new ScanAll(); @@ -1864,12 +1947,12 @@ public void scan_ScanAllWithLargeData_ShouldRetrieveExpectedValues() for (int i = 0; i < 345; i++) { expectedResults.add( new ExpectedResultBuilder() - .column(IntColumn.of(COL_NAME1, i % 4)) - .column(IntColumn.of(COL_NAME4, i)) - .column(TextColumn.ofNull(COL_NAME2)) - .column(IntColumn.ofNull(COL_NAME3)) - .column(BooleanColumn.ofNull(COL_NAME5)) - .column(BlobColumn.of(COL_NAME6, new byte[getLargeDataSizeInBytes()])) + .column(IntColumn.of(getColumnName1(), i % 4)) + .column(IntColumn.of(getColumnName4(), i)) + .column(TextColumn.ofNull(getColumnName2())) + .column(IntColumn.ofNull(getColumnName3())) + .column(BooleanColumn.ofNull(getColumnName5())) + .column(BlobColumn.of(getColumnName6(), new byte[getLargeDataSizeInBytes()])) .build()); } TestUtils.assertResultsContainsExactlyInAnyOrder(results, expectedResults); @@ -1880,24 +1963,24 @@ public void get_GetWithProjectionsGivenOnNonPrimaryKey_ShouldRetrieveOnlyProject throws ExecutionException { // Arrange Put put = - new Put(Key.ofInt(COL_NAME1, 0), Key.ofInt(COL_NAME4, 0)) - .withTextValue(COL_NAME2, "foo") - .withIntValue(COL_NAME3, 0) - .withBooleanValue(COL_NAME5, true) + new Put(Key.ofInt(getColumnName1(), 0), Key.ofInt(getColumnName4(), 0)) + .withTextValue(getColumnName2(), "foo") + .withIntValue(getColumnName3(), 0) + .withBooleanValue(getColumnName5(), true) .forNamespace(namespace) - .forTable(TABLE); + .forTable(getTableName()); storage.put(put); // Act - Get get = prepareGet(0, 0).withProjection(COL_NAME3).withProjection(COL_NAME5); + Get get = prepareGet(0, 0).withProjection(getColumnName3()).withProjection(getColumnName5()); Optional actual = storage.get(get); // Assert assertThat(actual.isPresent()).isTrue(); Result result = actual.get(); - assertThat(result.getContainedColumnNames()).containsOnly(COL_NAME3, COL_NAME5); - assertThat(result.getInt(COL_NAME3)).isEqualTo(0); - assertThat(result.getBoolean(COL_NAME5)).isTrue(); + assertThat(result.getContainedColumnNames()).containsOnly(getColumnName3(), getColumnName5()); + assertThat(result.getInt(getColumnName3())).isEqualTo(0); + assertThat(result.getBoolean(getColumnName5())).isTrue(); } @Test @@ -1905,24 +1988,27 @@ public void scan_ScanWithProjectionsGivenOnNonPrimaryKey_ShouldRetrieveOnlyProje throws ExecutionException, IOException { // Arrange Put put = - new Put(Key.ofInt(COL_NAME1, 0), Key.ofInt(COL_NAME4, 0)) - .withTextValue(COL_NAME2, "foo") - .withIntValue(COL_NAME3, 0) - .withBooleanValue(COL_NAME5, true) + new Put(Key.ofInt(getColumnName1(), 0), Key.ofInt(getColumnName4(), 0)) + .withTextValue(getColumnName2(), "foo") + .withIntValue(getColumnName3(), 0) + .withBooleanValue(getColumnName5(), true) .forNamespace(namespace) - .forTable(TABLE); + .forTable(getTableName()); storage.put(put); // Act Scan scan = - new Scan(Key.ofInt(COL_NAME1, 0)).withProjection(COL_NAME3).withProjection(COL_NAME5); + new Scan(Key.ofInt(getColumnName1(), 0)) + .withProjection(getColumnName3()) + .withProjection(getColumnName5()); List results = scanAll(scan); // Assert assertThat(results.size()).isEqualTo(1); - assertThat(results.get(0).getContainedColumnNames()).containsOnly(COL_NAME3, COL_NAME5); - assertThat(results.get(0).getInt(COL_NAME3)).isEqualTo(0); - assertThat(results.get(0).getBoolean(COL_NAME5)).isTrue(); + assertThat(results.get(0).getContainedColumnNames()) + .containsOnly(getColumnName3(), getColumnName5()); + assertThat(results.get(0).getInt(getColumnName3())).isEqualTo(0); + assertThat(results.get(0).getBoolean(getColumnName5())).isTrue(); } @Test @@ -1930,23 +2016,25 @@ public void scan_ScanAllWithProjectionsGivenOnNonPrimaryKey_ShouldRetrieveOnlyPr throws ExecutionException, IOException { // Arrange Put put = - new Put(Key.ofInt(COL_NAME1, 0), Key.ofInt(COL_NAME4, 0)) - .withTextValue(COL_NAME2, "foo") - .withIntValue(COL_NAME3, 0) - .withBooleanValue(COL_NAME5, true) + new Put(Key.ofInt(getColumnName1(), 0), Key.ofInt(getColumnName4(), 0)) + .withTextValue(getColumnName2(), "foo") + .withIntValue(getColumnName3(), 0) + .withBooleanValue(getColumnName5(), true) .forNamespace(namespace) - .forTable(TABLE); + .forTable(getTableName()); storage.put(put); // Act - ScanAll scanAll = new ScanAll().withProjection(COL_NAME3).withProjection(COL_NAME5); + ScanAll scanAll = + new ScanAll().withProjection(getColumnName3()).withProjection(getColumnName5()); List results = scanAll(scanAll); // Assert assertThat(results.size()).isEqualTo(1); - assertThat(results.get(0).getContainedColumnNames()).containsOnly(COL_NAME3, COL_NAME5); - assertThat(results.get(0).getInt(COL_NAME3)).isEqualTo(0); - assertThat(results.get(0).getBoolean(COL_NAME5)).isTrue(); + assertThat(results.get(0).getContainedColumnNames()) + .containsOnly(getColumnName3(), getColumnName5()); + assertThat(results.get(0).getInt(getColumnName3())).isEqualTo(0); + assertThat(results.get(0).getBoolean(getColumnName5())).isTrue(); } @Test @@ -1955,12 +2043,12 @@ public void scan_ScanAllLargeData_ShouldRetrieveExpectedValues() int recordCount = 345; // Arrange - Key clusteringKey = new Key(COL_NAME4, 1); + Key clusteringKey = new Key(getColumnName4(), 1); for (int i = 0; i < recordCount; i++) { - Key partitionKey = new Key(COL_NAME1, i); + Key partitionKey = new Key(getColumnName1(), i); storage.put( new Put(partitionKey, clusteringKey) - .withBlobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()])); + .withBlobValue(getColumnName6(), new byte[getLargeDataSizeInBytes()])); } ScanAll scanAll = new ScanAll(); @@ -1973,8 +2061,8 @@ public void scan_ScanAllLargeData_ShouldRetrieveExpectedValues() Set partitionKeys = new HashSet<>(); for (int i = 0; i < recordCount; i++) { - partitionKeys.add(results.get(i).getInt(COL_NAME1)); - assertThat(results.get(i).getInt(COL_NAME4)).isEqualTo(1); + partitionKeys.add(results.get(i).getInt(getColumnName1())); + assertThat(results.get(i).getInt(getColumnName4())).isEqualTo(1); } assertThat(partitionKeys.size()).isEqualTo(recordCount); assertThat(partitionKeys).allMatch(i -> i >= 0 && i < recordCount); @@ -1987,12 +2075,12 @@ public void scan_ScanAllLargeDataWithLimit_ShouldRetrieveExpectedValues() int recordCount = 345; int limit = 234; - Key clusteringKey = new Key(COL_NAME4, 1); + Key clusteringKey = new Key(getColumnName4(), 1); for (int i = 0; i < recordCount; i++) { - Key partitionKey = new Key(COL_NAME1, i); + Key partitionKey = new Key(getColumnName1(), i); storage.put( new Put(partitionKey, clusteringKey) - .withBlobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()])); + .withBlobValue(getColumnName6(), new byte[getLargeDataSizeInBytes()])); } Scan scan = new ScanAll().withLimit(limit); @@ -2005,8 +2093,8 @@ public void scan_ScanAllLargeDataWithLimit_ShouldRetrieveExpectedValues() Set partitionKeys = new HashSet<>(); for (int i = 0; i < limit; i++) { - partitionKeys.add(results.get(i).getInt(COL_NAME1)); - assertThat(results.get(i).getInt(COL_NAME4)).isEqualTo(1); + partitionKeys.add(results.get(i).getInt(getColumnName1())); + assertThat(results.get(i).getInt(getColumnName4())).isEqualTo(1); } assertThat(partitionKeys.size()).isEqualTo(limit); assertThat(partitionKeys).allMatch(i -> i >= 0 && i < recordCount); @@ -2018,8 +2106,8 @@ private void populateRecords() { } private Get prepareGet(int pKey, int cKey) { - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); + Key partitionKey = new Key(getColumnName1(), pKey); + Key clusteringKey = new Key(getColumnName4(), cKey); return new Get(partitionKey, clusteringKey); } @@ -2032,13 +2120,13 @@ private List preparePuts() { IntStream.range(0, 3) .forEach( j -> { - Key partitionKey = new Key(COL_NAME1, i); - Key clusteringKey = new Key(COL_NAME4, j); + Key partitionKey = new Key(getColumnName1(), i); + Key clusteringKey = new Key(getColumnName4(), j); Put put = new Put(partitionKey, clusteringKey) - .withValue(COL_NAME2, Integer.toString(i + j)) - .withValue(COL_NAME3, i + j) - .withValue(COL_NAME5, j % 2 == 0); + .withValue(getColumnName2(), Integer.toString(i + j)) + .withValue(getColumnName3(), i + j) + .withValue(getColumnName5(), j % 2 == 0); puts.add(put); })); @@ -2046,8 +2134,8 @@ private List preparePuts() { } private Delete prepareDelete(int pKey, int cKey) { - Key partitionKey = new Key(COL_NAME1, pKey); - Key clusteringKey = new Key(COL_NAME4, cKey); + Key partitionKey = new Key(getColumnName1(), pKey); + Key clusteringKey = new Key(getColumnName4(), cKey); return new Delete(partitionKey, clusteringKey); } @@ -2060,8 +2148,8 @@ private List prepareDeletes() { IntStream.range(0, 3) .forEach( j -> { - Key partitionKey = new Key(COL_NAME1, i); - Key clusteringKey = new Key(COL_NAME4, j); + Key partitionKey = new Key(getColumnName1(), i); + Key clusteringKey = new Key(getColumnName4(), j); Delete delete = new Delete(partitionKey, clusteringKey); deletes.add(delete); })); diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageWithReservedKeywordIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageWithReservedKeywordIntegrationTestBase.java index 8fd2de48d0..e6acbb046b 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageWithReservedKeywordIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageWithReservedKeywordIntegrationTestBase.java @@ -1,605 +1,12 @@ package com.scalar.db.api; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; - -import com.google.common.collect.ImmutableList; -import com.scalar.db.api.Scan.Ordering; -import com.scalar.db.api.Scan.Ordering.Order; -import com.scalar.db.exception.storage.ExecutionException; -import com.scalar.db.io.BooleanValue; -import com.scalar.db.io.DataType; -import com.scalar.db.io.IntValue; -import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; -import com.scalar.db.service.StorageFactory; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Properties; -import java.util.stream.IntStream; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -public abstract class DistributedStorageWithReservedKeywordIntegrationTestBase { - private static final Logger logger = - LoggerFactory.getLogger(DistributedStorageWithReservedKeywordIntegrationTestBase.class); +public abstract class DistributedStorageWithReservedKeywordIntegrationTestBase + extends DistributedStorageIntegrationTestBase { private static final String TEST_NAME = "storage_reserved_kw"; - private DistributedStorage storage; - private DistributedStorageAdmin admin; - - private String namespace; - private String tableName; - private String columnName1; - private String columnName2; - private String columnName3; - private String columnName4; - private String columnName5; - - @BeforeAll - public void beforeAll() throws Exception { - initialize(TEST_NAME); - StorageFactory factory = StorageFactory.create(getProperties(TEST_NAME)); - admin = factory.getAdmin(); - namespace = getNamespace(); - tableName = getTableName(); - columnName1 = getColumnName1(); - columnName2 = getColumnName2(); - columnName3 = getColumnName3(); - columnName4 = getColumnName4(); - columnName5 = getColumnName5(); - createTable(); - storage = factory.getStorage(); - } - - protected void initialize(String testName) throws Exception {} - - protected abstract Properties getProperties(String testName); - - protected abstract String getNamespace(); - - protected abstract String getTableName(); - - protected abstract String getColumnName1(); - - protected abstract String getColumnName2(); - - protected abstract String getColumnName3(); - - protected abstract String getColumnName4(); - - protected abstract String getColumnName5(); - - private void createTable() throws ExecutionException { - Map options = getCreationOptions(); - admin.createNamespace(namespace, true, options); - admin.createTable( - namespace, - tableName, - TableMetadata.newBuilder() - .addColumn(columnName1, DataType.INT) - .addColumn(columnName2, DataType.TEXT) - .addColumn(columnName3, DataType.INT) - .addColumn(columnName4, DataType.INT) - .addColumn(columnName5, DataType.BOOLEAN) - .addPartitionKey(columnName1) - .addClusteringKey(columnName4) - .addSecondaryIndex(columnName3) - .build(), - true, - options); - } - - protected Map getCreationOptions() { - return Collections.emptyMap(); - } - - @BeforeEach - public void setUp() throws Exception { - truncateTable(); - storage.with(namespace, tableName); - } - - private void truncateTable() throws ExecutionException { - admin.truncateTable(namespace, tableName); - } - - @AfterAll - public void afterAll() throws Exception { - try { - dropTable(); - } catch (Exception e) { - logger.warn("Failed to drop tables", e); - } - - try { - if (admin != null) { - admin.close(); - } - } catch (Exception e) { - logger.warn("Failed to close admin", e); - } - - try { - if (storage != null) { - storage.close(); - } - } catch (Exception e) { - logger.warn("Failed to close storage", e); - } - } - - private void dropTable() throws ExecutionException { - admin.dropTable(namespace, tableName); - admin.dropNamespace(namespace); - } - - @Test - public void - get_GetWithReservedKeywordAndPartitionKeyAndClusteringKeyGiven_ShouldRetrieveSingleResult() - throws ExecutionException { - // Arrange - populateRecords(); - int pKey = 0; - - // Act - Get get = prepareGet(pKey, 0); - Optional actual = storage.get(get); - - // Assert - assertThat(actual.isPresent()).isTrue(); - assertThat(actual.get().getValue(columnName1)) - .isEqualTo(Optional.of(new IntValue(columnName1, pKey))); - assertThat(actual.get().getValue(columnName4)) - .isEqualTo(Optional.of(new IntValue(columnName4, 0))); - } - - @Test - public void get_GetWithReservedKeywordAndProjectionsGiven_ShouldRetrieveSpecifiedValues() - throws ExecutionException { - // Arrange - populateRecords(); - int pKey = 0; - int cKey = 0; - - // Act - Get get = prepareGet(pKey, cKey); - get.withProjection(columnName1).withProjection(columnName2).withProjection(columnName3); - Optional actual = storage.get(get); - - // Assert - assertThat(actual.isPresent()).isTrue(); - assertThat(actual.get().getValue(columnName1)) - .isEqualTo(Optional.of(new IntValue(columnName1, pKey))); - assertThat(actual.get().getValue(columnName2)) - .isEqualTo(Optional.of(new TextValue(columnName2, Integer.toString(pKey + cKey)))); - assertThat(actual.get().getValue(columnName3)) - .isEqualTo(Optional.of(new IntValue(columnName3, pKey + cKey))); - assertThat(actual.get().getValue(columnName4).isPresent()).isFalse(); - assertThat(actual.get().getValue(columnName5).isPresent()).isFalse(); - } - - @Test - public void scan_ScanWithReservedKeywordAndProjectionsGiven_ShouldRetrieveSpecifiedValues() - throws IOException, ExecutionException { - // Arrange - populateRecords(); - int pKey = 0; - - // Act - Scan scan = - new Scan(new Key(columnName1, pKey)) - .withProjection(columnName1) - .withProjection(columnName2) - .withProjection(columnName3); - List actual = scanAll(scan); - - // Assert - actual.forEach( - a -> - assertThat(a.getContainedColumnNames()) - .containsOnly(columnName1, columnName2, columnName3)); - assertThat(actual.size()).isEqualTo(3); - assertThat(actual.get(0).getInt(columnName1)).isEqualTo(0); - assertThat(actual.get(0).getInt(columnName3)).isEqualTo(0); - assertThat(actual.get(1).getInt(columnName1)).isEqualTo(0); - assertThat(actual.get(1).getInt(columnName3)).isEqualTo(1); - assertThat(actual.get(2).getInt(columnName1)).isEqualTo(0); - assertThat(actual.get(2).getInt(columnName3)).isEqualTo(2); - } - - @Test - public void - scan_ScanWithReservedKeywordAndPartitionKeyGivenAndResultsIteratedWithOne_ShouldReturnWhatsPut() - throws ExecutionException, IOException { - // Arrange - populateRecords(); - int pKey = 0; - - // Act - Scan scan = new Scan(new Key(columnName1, pKey)); - Scanner scanner = storage.scan(scan); - - // Assert - List results = new ArrayList<>(); - - Optional result = scanner.one(); - assertThat(result.isPresent()).isTrue(); - results.add(result.get()); - - result = scanner.one(); - assertThat(result.isPresent()).isTrue(); - results.add(result.get()); - - result = scanner.one(); - assertThat(result.isPresent()).isTrue(); - results.add(result.get()); - - result = scanner.one(); - assertThat(result.isPresent()).isFalse(); - - assertThat(results.size()).isEqualTo(3); - assertThat(results.get(0).getValue(columnName1).isPresent()).isTrue(); - assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(0).getValue(columnName4).isPresent()).isTrue(); - assertThat(results.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(columnName1).isPresent()).isTrue(); - assertThat(results.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(columnName4).isPresent()).isTrue(); - assertThat(results.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(1); - assertThat(results.get(2).getValue(columnName1).isPresent()).isTrue(); - assertThat(results.get(2).getValue(columnName1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(2).getValue(columnName4).isPresent()).isTrue(); - assertThat(results.get(2).getValue(columnName4).get().getAsInt()).isEqualTo(2); - - scanner.close(); - } - - @Test - public void put_WithReservedKeywordAndSinglePutGiven_ShouldStoreProperly() - throws ExecutionException { - // Arrange - int pKey = 0; - int cKey = 0; - List puts = preparePuts(); - Key partitionKey = new Key(columnName1, pKey); - Key clusteringKey = new Key(columnName4, cKey); - Get get = new Get(partitionKey, clusteringKey); - - // Act - storage.put(puts.get(pKey * 2 + cKey)); - - // Assert - Optional actual = storage.get(get); - assertThat(actual.isPresent()).isTrue(); - assertThat(actual.get().getValue(columnName1)) - .isEqualTo(Optional.of(new IntValue(columnName1, pKey))); - assertThat(actual.get().getValue(columnName2)) - .isEqualTo(Optional.of(new TextValue(columnName2, Integer.toString(pKey + cKey)))); - assertThat(actual.get().getValue(columnName3)) - .isEqualTo(Optional.of(new IntValue(columnName3, pKey + cKey))); - assertThat(actual.get().getValue(columnName4)) - .isEqualTo(Optional.of(new IntValue(columnName4, cKey))); - assertThat(actual.get().getValue(columnName5)) - .isEqualTo(Optional.of(new BooleanValue(columnName5, cKey % 2 == 0))); - } - - @Test - public void put_PutWithReservedKeywordAndIfGivenWhenSuchRecordExists_ShouldUpdateRecord() - throws ExecutionException { - // Arrange - int pKey = 0; - int cKey = 0; - List puts = preparePuts(); - Get get = prepareGet(pKey, cKey); - - // Act Assert - storage.put(puts.get(0)); - puts.get(0) - .withCondition( - new PutIf( - new ConditionalExpression( - columnName3, new IntValue(pKey + cKey), ConditionalExpression.Operator.EQ))); - puts.get(0).withValue(columnName3, Integer.MAX_VALUE); - assertThatCode(() -> storage.put(puts.get(0))).doesNotThrowAnyException(); - - // Assert - Optional actual = storage.get(get); - assertThat(actual.isPresent()).isTrue(); - Result result = actual.get(); - assertThat(result.getValue(columnName1)) - .isEqualTo(Optional.of(new IntValue(columnName1, pKey))); - assertThat(result.getValue(columnName4)) - .isEqualTo(Optional.of(new IntValue(columnName4, cKey))); - assertThat(result.getValue(columnName3)) - .isEqualTo(Optional.of(new IntValue(columnName3, Integer.MAX_VALUE))); - } - - @Test - public void put_WithReservedKeywordAndMultiplePutGiven_ShouldStoreProperly() - throws IOException, ExecutionException { - // Arrange - int pKey = 0; - int cKey = 0; - List puts = preparePuts(); - Scan scan = new Scan(new Key(columnName1, pKey)); - - // Act - assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) - .doesNotThrowAnyException(); - - // Assert - List results = scanAll(scan); - assertThat(results.size()).isEqualTo(3); - assertThat(results.get(0).getValue(columnName1).isPresent()).isTrue(); - assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(0).getValue(columnName4).isPresent()).isTrue(); - assertThat(results.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(pKey + cKey); - assertThat(results.get(1).getValue(columnName1).isPresent()).isTrue(); - assertThat(results.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(columnName4).isPresent()).isTrue(); - assertThat(results.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(pKey + cKey + 1); - assertThat(results.get(2).getValue(columnName1).isPresent()).isTrue(); - assertThat(results.get(2).getValue(columnName1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(2).getValue(columnName4).isPresent()).isTrue(); - assertThat(results.get(2).getValue(columnName4).get().getAsInt()).isEqualTo(pKey + cKey + 2); - } - - @Test - public void - put_WithReservedKeywordAndMultiplePutWithDifferentConditionsGiven_ShouldStoreProperly() - throws IOException, ExecutionException { - // Arrange - List puts = preparePuts(); - storage.put(puts.get(1)); - puts.get(0).withCondition(new PutIfNotExists()); - puts.get(1) - .withCondition( - new PutIf( - new ConditionalExpression( - columnName2, new TextValue("1"), ConditionalExpression.Operator.EQ))); - - // Act - assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1)))) - .doesNotThrowAnyException(); - - // Assert - List results = scanAll(new Scan(new Key(columnName1, 0))); - assertThat(results.size()).isEqualTo(2); - assertThat(results.get(0).getValue(columnName1).isPresent()).isTrue(); - assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(0).getValue(columnName4).isPresent()).isTrue(); - assertThat(results.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(columnName1).isPresent()).isTrue(); - assertThat(results.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(columnName4).isPresent()).isTrue(); - assertThat(results.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(1); - } - - @Test - public void - delete_WithReservedKeywordAndDeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingleRecordProperly() - throws IOException, ExecutionException { - // Arrange - populateRecords(); - int pKey = 0; - int cKey = 0; - Key partitionKey = new Key(columnName1, pKey); - - // Act - Delete delete = prepareDelete(pKey, cKey); - assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException(); - - // Assert - List results = scanAll(new Scan(partitionKey)); - assertThat(results.size()).isEqualTo(2); - assertThat(results.get(0).getValue(columnName1).isPresent()).isTrue(); - assertThat(results.get(0).getValue(columnName1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(0).getValue(columnName4).isPresent()).isTrue(); - assertThat(results.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(cKey + 1); - assertThat(results.get(1).getValue(columnName1).isPresent()).isTrue(); - assertThat(results.get(1).getValue(columnName1).get().getAsInt()).isEqualTo(0); - assertThat(results.get(1).getValue(columnName4).isPresent()).isTrue(); - assertThat(results.get(1).getValue(columnName4).get().getAsInt()).isEqualTo(cKey + 2); - } - - @Test - public void - delete_WithReservedKeywordAndMultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProperly() - throws IOException, ExecutionException { - // Arrange - List puts = preparePuts(); - List deletes = prepareDeletes(); - storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2))); - deletes.get(0).withCondition(new DeleteIfExists()); - deletes - .get(1) - .withCondition( - new DeleteIf( - new ConditionalExpression( - columnName2, new TextValue("1"), ConditionalExpression.Operator.EQ))); - - // Act - assertThatCode( - () -> storage.delete(Arrays.asList(deletes.get(0), deletes.get(1), deletes.get(2)))) - .doesNotThrowAnyException(); - - // Assert - List results = scanAll(new Scan(new Key(columnName1, 0))); - assertThat(results.size()).isEqualTo(0); - } - - @Test - public void - delete_WithReservedKeywordAndDeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() - throws ExecutionException { - // Arrange - populateRecords(); - int pKey = 0; - int cKey = 0; - Key partitionKey = new Key(columnName1, pKey); - Key clusteringKey = new Key(columnName4, cKey); - - // Act - Delete delete = prepareDelete(pKey, cKey); - delete.withCondition( - new DeleteIf( - new ConditionalExpression( - columnName2, - new TextValue(Integer.toString(pKey)), - ConditionalExpression.Operator.EQ))); - assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException(); - - // Assert - Optional actual = storage.get(new Get(partitionKey, clusteringKey)); - assertThat(actual.isPresent()).isFalse(); - } - - @Test - public void get_WithReservedKeywordAndGetGivenForIndexedColumn_ShouldGet() - throws ExecutionException { - // Arrange - storage.put(preparePuts().get(0)); // (0,0) - int c3 = 0; - Get get = new Get(new Key(columnName3, c3)); - - // Act - Optional actual = storage.get(get); - - // Assert - assertThat(actual.isPresent()).isTrue(); - assertThat(actual.get().getValue(columnName1)) - .isEqualTo(Optional.of(new IntValue(columnName1, 0))); - assertThat(actual.get().getValue(columnName4)) - .isEqualTo(Optional.of(new IntValue(columnName4, 0))); - } - - @Test - public void scan_WithReservedKeywordAndScanGivenForIndexedColumn_ShouldScan() - throws ExecutionException, IOException { - // Arrange - populateRecords(); - int c3 = 3; - Scan scan = new Scan(new Key(columnName3, c3)); - - // Act - List actual = scanAll(scan); - - // Assert - assertThat(actual.size()).isEqualTo(3); // (1,2), (2,1), (3,0) - List> expectedValues = - new ArrayList<>( - Arrays.asList(Arrays.asList(1, 2), Arrays.asList(2, 1), Arrays.asList(3, 0))); - for (Result result : actual) { - assertThat(result.getValue(columnName1).isPresent()).isTrue(); - assertThat(result.getValue(columnName4).isPresent()).isTrue(); - - int col1Val = result.getValue(columnName1).get().getAsInt(); - int col4Val = result.getValue(columnName4).get().getAsInt(); - List col1AndCol4 = Arrays.asList(col1Val, col4Val); - assertThat(expectedValues).contains(col1AndCol4); - expectedValues.remove(col1AndCol4); - } - - assertThat(expectedValues).isEmpty(); - } - - @Test - public void scan_WithReservedKeywordAndClusteringKeyRange_ShouldReturnProperResult() - throws ExecutionException, IOException { - // Arrange - populateRecords(); - Scan scan = - new Scan(new Key(columnName1, 1)) - .withStart(new Key(columnName4, 1), false) - .withEnd(new Key(columnName4, 3), false) - .withOrdering(new Ordering(columnName4, Order.DESC)) - .forNamespace(namespace) - .forTable(tableName); - - List expected = ImmutableList.of(2); - - // Act - List actual = scanAll(scan); - - // Assert - assertThat(actual.size()).isEqualTo(1); - assertThat(actual.get(0).getValue(columnName4).isPresent()).isTrue(); - assertThat(actual.get(0).getValue(columnName4).get().getAsInt()).isEqualTo(expected.get(0)); - } - - private void populateRecords() { - List puts = preparePuts(); - puts.forEach(p -> assertThatCode(() -> storage.put(p)).doesNotThrowAnyException()); - } - - private Get prepareGet(int pKey, int cKey) { - Key partitionKey = new Key(columnName1, pKey); - Key clusteringKey = new Key(columnName4, cKey); - return new Get(partitionKey, clusteringKey); - } - - private List preparePuts() { - List puts = new ArrayList<>(); - - IntStream.range(0, 5) - .forEach( - i -> - IntStream.range(0, 3) - .forEach( - j -> { - Key partitionKey = new Key(columnName1, i); - Key clusteringKey = new Key(columnName4, j); - Put put = - new Put(partitionKey, clusteringKey) - .withValue(columnName2, Integer.toString(i + j)) - .withValue(columnName3, i + j) - .withValue(columnName5, j % 2 == 0); - puts.add(put); - })); - - return puts; - } - - private Delete prepareDelete(int pKey, int cKey) { - Key partitionKey = new Key(columnName1, pKey); - Key clusteringKey = new Key(columnName4, cKey); - return new Delete(partitionKey, clusteringKey); - } - - private List prepareDeletes() { - List deletes = new ArrayList<>(); - - IntStream.range(0, 5) - .forEach( - i -> - IntStream.range(0, 3) - .forEach( - j -> { - Key partitionKey = new Key(columnName1, i); - Key clusteringKey = new Key(columnName4, j); - Delete delete = new Delete(partitionKey, clusteringKey); - deletes.add(delete); - })); - - return deletes; - } - - private List scanAll(Scan scan) throws ExecutionException, IOException { - try (Scanner scanner = storage.scan(scan)) { - return scanner.all(); - } + @Override + protected String getTestName() { + return TEST_NAME; } }