From 4263155d64e1282cf3aa4f12947cb2f8df7365a2 Mon Sep 17 00:00:00 2001 From: Kodai Doki <52027276+KodaiD@users.noreply.github.com> Date: Fri, 1 Aug 2025 04:01:06 +0000 Subject: [PATCH 1/2] Empty commit [skip ci] From 358385ca4f12fdf013d4062e9c74a10fe3d78773 Mon Sep 17 00:00:00 2001 From: Kodai Doki <52027276+KodaiD@users.noreply.github.com> Date: Fri, 1 Aug 2025 13:00:49 +0900 Subject: [PATCH 2/2] Resolve conflicts --- ...raAdminCaseSensitivityIntegrationTest.java | 25 + ...ssandraCaseSensitivityIntegrationTest.java | 28 + ...draWithReservedKeywordIntegrationTest.java | 9 + ...osAdminCaseSensitivityIntegrationTest.java | 27 + .../CosmosCaseSensitivityIntegrationTest.java | 19 + ...moAdminCaseSensitivityIntegrationTest.java | 82 + .../DynamoCaseSensitivityIntegrationTest.java | 24 + .../storage/dynamo/DynamoIntegrationTest.java | 3 +- ...amoWithReservedKeywordIntegrationTest.java | 5 + ...bcAdminCaseSensitivityIntegrationTest.java | 109 ++ ...atabaseCaseSensitivityIntegrationTest.java | 153 ++ .../jdbc/JdbcDatabaseIntegrationTest.java | 68 +- ...aseWithReservedKeywordIntegrationTest.java | 142 +- ...minCaseSensitivityIntegrationTestBase.java | 144 ++ ...ibutedStorageAdminIntegrationTestBase.java | 638 ++++---- ...ageCaseSensitivityIntegrationTestBase.java | 63 + ...DistributedStorageIntegrationTestBase.java | 1360 +++++++++-------- ...ithReservedKeywordIntegrationTestBase.java | 677 +------- 18 files changed, 1971 insertions(+), 1605 deletions(-) create mode 100644 core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminCaseSensitivityIntegrationTest.java create mode 100644 core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraCaseSensitivityIntegrationTest.java create mode 100644 core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosAdminCaseSensitivityIntegrationTest.java create mode 100644 core/src/integration-test/java/com/scalar/db/storage/cosmos/CosmosCaseSensitivityIntegrationTest.java create mode 100644 core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoAdminCaseSensitivityIntegrationTest.java create mode 100644 core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoCaseSensitivityIntegrationTest.java create mode 100644 core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminCaseSensitivityIntegrationTest.java create mode 100644 core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseCaseSensitivityIntegrationTest.java create mode 100644 integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminCaseSensitivityIntegrationTestBase.java create mode 100644 integration-test/src/main/java/com/scalar/db/api/DistributedStorageCaseSensitivityIntegrationTestBase.java 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..8def2e329b --- /dev/null +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraAdminCaseSensitivityIntegrationTest.java @@ -0,0 +1,25 @@ +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); + } + + @Override + protected boolean isTimestampTypeSupported() { + return false; + } +} 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..10a3f684a0 --- /dev/null +++ b/core/src/integration-test/java/com/scalar/db/storage/cassandra/CassandraCaseSensitivityIntegrationTest.java @@ -0,0 +1,28 @@ +package com.scalar.db.storage.cassandra; + +import com.scalar.db.api.DistributedStorageCaseSensitivityIntegrationTestBase; +import java.util.Collections; +import java.util.Map; +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); + } + + @Override + protected Map getCreationOptions() { + return Collections.singletonMap(CassandraAdmin.REPLICATION_FACTOR, "1"); + } + + @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..60a7fd6ed7 --- /dev/null +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminCaseSensitivityIntegrationTest.java @@ -0,0 +1,109 @@ +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 { + private RdbEngineStrategy rdbEngine; + + @Override + protected Properties getProperties(String testName) { + Properties properties = JdbcEnv.getProperties(testName); + rdbEngine = RdbEngineFactory.create(new JdbcConfig(new DatabaseConfig(properties))); + return properties; + } + + @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(); + } + + @Override + protected boolean isCreateIndexOnTextAndBlobColumnsEnabled() { + // "admin.createIndex()" for TEXT and BLOB columns fails (the "create index" query runs + // indefinitely) on Db2 community edition version but works on Db2 hosted on IBM Cloud. + // So we disable these tests until the issue is resolved. + return !JdbcTestUtils.isDb2(rdbEngine); + } +} 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..fec281f106 --- /dev/null +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseCaseSensitivityIntegrationTest.java @@ -0,0 +1,153 @@ +package com.scalar.db.storage.jdbc; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.scalar.db.api.DistributedStorage; +import com.scalar.db.api.DistributedStorageCaseSensitivityIntegrationTestBase; +import com.scalar.db.api.Get; +import com.scalar.db.api.Put; +import com.scalar.db.api.Result; +import com.scalar.db.api.Scan; +import com.scalar.db.api.Scanner; +import com.scalar.db.config.DatabaseConfig; +import com.scalar.db.exception.storage.ExecutionException; +import com.scalar.db.io.Key; +import com.scalar.db.service.StorageFactory; +import java.io.IOException; +import java.util.List; +import java.util.Optional; +import java.util.Properties; +import org.junit.jupiter.api.Test; + +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 properties; + } + + @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(); + } + } + + @Test + public void get_InStreamingMode_ShouldRetrieveSingleResult() throws ExecutionException { + if (!JdbcTestUtils.isMysql(rdbEngine) || JdbcTestUtils.isMariaDB(rdbEngine)) { + // MySQL is the only RDB engine that supports streaming mode + return; + } + + try (DistributedStorage storage = getStorageInStreamingMode()) { + // Arrange + int pKey = 0; + int cKey = 1; + int value = 2; + + storage.put( + Put.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), cKey)) + .intValue(getColumnName3(), value) + .build()); + + // Act + Optional result = + storage.get( + Get.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), cKey)) + .build()); + + // Assert + assertThat(result.isPresent()).isTrue(); + assertThat(result.get().getInt(getColumnName1())).isEqualTo(pKey); + assertThat(result.get().getInt(getColumnName4())).isEqualTo(cKey); + assertThat(result.get().getInt(getColumnName3())).isEqualTo(value); + } + } + + @Test + public void scan_InStreamingMode_ShouldRetrieveResults() throws IOException, ExecutionException { + if (!JdbcTestUtils.isMysql(rdbEngine) || JdbcTestUtils.isMariaDB(rdbEngine)) { + // MySQL is the only RDB engine that supports streaming mode + return; + } + + try (DistributedStorage storage = getStorageInStreamingMode()) { + // Arrange + int pKey = 0; + + storage.put( + Put.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), 0)) + .intValue(getColumnName3(), 1) + .build()); + storage.put( + Put.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), 1)) + .intValue(getColumnName3(), 2) + .build()); + storage.put( + Put.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), 2)) + .intValue(getColumnName3(), 3) + .build()); + + // Act + Scanner scanner = + storage.scan( + Scan.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .build()); + List results = scanner.all(); + scanner.close(); + + // Assert + assertThat(results).hasSize(3); + assertThat(results.get(0).getInt(getColumnName1())).isEqualTo(pKey); + assertThat(results.get(0).getInt(getColumnName4())).isEqualTo(0); + assertThat(results.get(0).getInt(getColumnName3())).isEqualTo(1); + + assertThat(results.get(1).getInt(getColumnName1())).isEqualTo(pKey); + assertThat(results.get(1).getInt(getColumnName4())).isEqualTo(1); + assertThat(results.get(1).getInt(getColumnName3())).isEqualTo(2); + + assertThat(results.get(2).getInt(getColumnName1())).isEqualTo(pKey); + assertThat(results.get(2).getInt(getColumnName4())).isEqualTo(2); + assertThat(results.get(2).getInt(getColumnName3())).isEqualTo(3); + } + } + + private DistributedStorage getStorageInStreamingMode() { + Properties properties = JdbcEnv.getProperties(getTestName()); + properties.setProperty(DatabaseConfig.SCAN_FETCH_SIZE, Integer.toString(Integer.MIN_VALUE)); + return StorageFactory.create(properties).getStorage(); + } +} diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseIntegrationTest.java index 070baf8c18..95454a05b3 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcDatabaseIntegrationTest.java @@ -57,10 +57,10 @@ public void get_InStreamingMode_ShouldRetrieveSingleResult() throws ExecutionExc storage.put( Put.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) - .clusteringKey(Key.ofInt(COL_NAME4, cKey)) - .intValue(COL_NAME3, value) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), cKey)) + .intValue(getColumnName3(), value) .build()); // Act @@ -68,16 +68,16 @@ public void get_InStreamingMode_ShouldRetrieveSingleResult() throws ExecutionExc storage.get( Get.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) - .clusteringKey(Key.ofInt(COL_NAME4, cKey)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), cKey)) .build()); // Assert assertThat(result.isPresent()).isTrue(); - assertThat(result.get().getInt(COL_NAME1)).isEqualTo(pKey); - assertThat(result.get().getInt(COL_NAME4)).isEqualTo(cKey); - assertThat(result.get().getInt(COL_NAME3)).isEqualTo(value); + assertThat(result.get().getInt(getColumnName1())).isEqualTo(pKey); + assertThat(result.get().getInt(getColumnName4())).isEqualTo(cKey); + assertThat(result.get().getInt(getColumnName3())).isEqualTo(value); } } @@ -95,26 +95,26 @@ public void scan_InStreamingMode_ShouldRetrieveResults() throws IOException, Exe storage.put( Put.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) - .clusteringKey(Key.ofInt(COL_NAME4, 0)) - .intValue(COL_NAME3, 1) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), 0)) + .intValue(getColumnName3(), 1) .build()); storage.put( Put.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) - .clusteringKey(Key.ofInt(COL_NAME4, 1)) - .intValue(COL_NAME3, 2) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), 1)) + .intValue(getColumnName3(), 2) .build()); storage.put( Put.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) - .clusteringKey(Key.ofInt(COL_NAME4, 2)) - .intValue(COL_NAME3, 3) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), 2)) + .intValue(getColumnName3(), 3) .build()); // Act @@ -122,30 +122,30 @@ public void scan_InStreamingMode_ShouldRetrieveResults() throws IOException, Exe storage.scan( Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) .build()); List results = scanner.all(); scanner.close(); // Assert assertThat(results).hasSize(3); - assertThat(results.get(0).getInt(COL_NAME1)).isEqualTo(pKey); - assertThat(results.get(0).getInt(COL_NAME4)).isEqualTo(0); - assertThat(results.get(0).getInt(COL_NAME3)).isEqualTo(1); + assertThat(results.get(0).getInt(getColumnName1())).isEqualTo(pKey); + assertThat(results.get(0).getInt(getColumnName4())).isEqualTo(0); + assertThat(results.get(0).getInt(getColumnName3())).isEqualTo(1); - assertThat(results.get(1).getInt(COL_NAME1)).isEqualTo(pKey); - assertThat(results.get(1).getInt(COL_NAME4)).isEqualTo(1); - assertThat(results.get(1).getInt(COL_NAME3)).isEqualTo(2); + assertThat(results.get(1).getInt(getColumnName1())).isEqualTo(pKey); + assertThat(results.get(1).getInt(getColumnName4())).isEqualTo(1); + assertThat(results.get(1).getInt(getColumnName3())).isEqualTo(2); - assertThat(results.get(2).getInt(COL_NAME1)).isEqualTo(pKey); - assertThat(results.get(2).getInt(COL_NAME4)).isEqualTo(2); - assertThat(results.get(2).getInt(COL_NAME3)).isEqualTo(3); + assertThat(results.get(2).getInt(getColumnName1())).isEqualTo(pKey); + assertThat(results.get(2).getInt(getColumnName4())).isEqualTo(2); + assertThat(results.get(2).getInt(getColumnName3())).isEqualTo(3); } } private DistributedStorage getStorageInStreamingMode() { - Properties properties = JdbcEnv.getProperties(TEST_NAME); + Properties properties = JdbcEnv.getProperties(getTestName()); properties.setProperty(DatabaseConfig.SCAN_FETCH_SIZE, Integer.toString(Integer.MIN_VALUE)); return StorageFactory.create(properties).getStorage(); } 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..58f863ffa5 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,29 @@ package com.scalar.db.storage.jdbc; +import static org.assertj.core.api.Assertions.assertThat; + +import com.scalar.db.api.DistributedStorage; import com.scalar.db.api.DistributedStorageWithReservedKeywordIntegrationTestBase; +import com.scalar.db.api.Get; +import com.scalar.db.api.Put; +import com.scalar.db.api.Result; +import com.scalar.db.api.Scan; +import com.scalar.db.api.Scanner; +import com.scalar.db.config.DatabaseConfig; +import com.scalar.db.exception.storage.ExecutionException; +import com.scalar.db.io.Key; +import com.scalar.db.service.StorageFactory; +import java.io.IOException; +import java.util.List; +import java.util.Optional; import java.util.Properties; +import org.junit.jupiter.api.Test; public class JdbcDatabaseWithReservedKeywordIntegrationTest extends DistributedStorageWithReservedKeywordIntegrationTestBase { + private RdbEngineStrategy rdbEngine; + @Override protected String getNamespace() { // a reserved keyword in JDBC @@ -50,6 +68,128 @@ protected String getColumnName5() { @Override protected Properties getProperties(String testName) { - return JdbcEnv.getProperties(testName); + Properties properties = JdbcEnv.getProperties(testName); + JdbcConfig config = new JdbcConfig(new DatabaseConfig(properties)); + rdbEngine = RdbEngineFactory.create(config); + return properties; + } + + @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(); + } + } + + @Test + public void get_InStreamingMode_ShouldRetrieveSingleResult() throws ExecutionException { + if (!JdbcTestUtils.isMysql(rdbEngine) || JdbcTestUtils.isMariaDB(rdbEngine)) { + // MySQL is the only RDB engine that supports streaming mode + return; + } + + try (DistributedStorage storage = getStorageInStreamingMode()) { + // Arrange + int pKey = 0; + int cKey = 1; + int value = 2; + + storage.put( + Put.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), cKey)) + .intValue(getColumnName3(), value) + .build()); + + // Act + Optional result = + storage.get( + Get.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), cKey)) + .build()); + + // Assert + assertThat(result.isPresent()).isTrue(); + assertThat(result.get().getInt(getColumnName1())).isEqualTo(pKey); + assertThat(result.get().getInt(getColumnName4())).isEqualTo(cKey); + assertThat(result.get().getInt(getColumnName3())).isEqualTo(value); + } + } + + @Test + public void scan_InStreamingMode_ShouldRetrieveResults() throws IOException, ExecutionException { + if (!JdbcTestUtils.isMysql(rdbEngine) || JdbcTestUtils.isMariaDB(rdbEngine)) { + // MySQL is the only RDB engine that supports streaming mode + return; + } + + try (DistributedStorage storage = getStorageInStreamingMode()) { + // Arrange + int pKey = 0; + + storage.put( + Put.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), 0)) + .intValue(getColumnName3(), 1) + .build()); + storage.put( + Put.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), 1)) + .intValue(getColumnName3(), 2) + .build()); + storage.put( + Put.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .clusteringKey(Key.ofInt(getColumnName4(), 2)) + .intValue(getColumnName3(), 3) + .build()); + + // Act + Scanner scanner = + storage.scan( + Scan.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .build()); + List results = scanner.all(); + scanner.close(); + + // Assert + assertThat(results).hasSize(3); + assertThat(results.get(0).getInt(getColumnName1())).isEqualTo(pKey); + assertThat(results.get(0).getInt(getColumnName4())).isEqualTo(0); + assertThat(results.get(0).getInt(getColumnName3())).isEqualTo(1); + + assertThat(results.get(1).getInt(getColumnName1())).isEqualTo(pKey); + assertThat(results.get(1).getInt(getColumnName4())).isEqualTo(1); + assertThat(results.get(1).getInt(getColumnName3())).isEqualTo(2); + + assertThat(results.get(2).getInt(getColumnName1())).isEqualTo(pKey); + assertThat(results.get(2).getInt(getColumnName4())).isEqualTo(2); + assertThat(results.get(2).getInt(getColumnName3())).isEqualTo(3); + } + } + + private DistributedStorage getStorageInStreamingMode() { + Properties properties = JdbcEnv.getProperties(getTestName()); + properties.setProperty(DatabaseConfig.SCAN_FETCH_SIZE, Integer.toString(Integer.MIN_VALUE)); + return StorageFactory.create(properties).getStorage(); } } 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..7cc6d43e58 --- /dev/null +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminCaseSensitivityIntegrationTestBase.java @@ -0,0 +1,144 @@ +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"; + private static final String COL_NAME12 = "Column12"; + private static final String COL_NAME13 = "Column13"; + private static final String COL_NAME14 = "Column14"; + private static final String COL_NAME15 = "Column15"; + + @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; + } + + @Override + protected String getColumnName12() { + return COL_NAME12; + } + + @Override + protected String getColumnName13() { + return COL_NAME13; + } + + @Override + protected String getColumnName14() { + return COL_NAME14; + } + + @Override + protected String getColumnName15() { + return COL_NAME15; + } +} 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 de30919c0e..59c5f407e5 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 @@ -56,30 +56,6 @@ public abstract class DistributedStorageAdminIntegrationTestBase { private static final String COL_NAME13 = "c13"; private static final String COL_NAME14 = "c14"; private static final String COL_NAME15 = "c15"; - - 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) - .addColumn(COL_NAME12, DataType.DATE) - .addColumn(COL_NAME13, DataType.TIME) - .addColumn(COL_NAME14, DataType.TIMESTAMPTZ) - .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; @@ -89,8 +65,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); @@ -106,6 +82,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; } @@ -118,12 +98,113 @@ 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 String getColumnName12() { + return COL_NAME12; + } + + protected String getColumnName13() { + return COL_NAME13; + } + + protected String getColumnName14() { + return COL_NAME14; + } + + protected String getColumnName15() { + return COL_NAME15; + } + + 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) + .addColumn(getColumnName12(), DataType.DATE) + .addColumn(getColumnName13(), DataType.TIME) + .addColumn(getColumnName14(), DataType.TIMESTAMPTZ) + .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); } } } @@ -151,7 +232,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); @@ -163,24 +244,24 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() throws ExecutionException { // Arrange if (isTimestampTypeSupported()) { - admin.addNewColumnToTable(namespace1, TABLE1, COL_NAME15, DataType.TIMESTAMP); + admin.addNewColumnToTable(namespace1, getTable1(), getColumnName15(), DataType.TIMESTAMP); } // 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()); if (isTimestampTypeSupported()) { assertThat(tableMetadata.getColumnNames().size()).isEqualTo(15); @@ -188,61 +269,63 @@ public void getTableMetadata_CorrectTableGiven_ShouldReturnCorrectMetadata() assertThat(tableMetadata.getColumnNames().size()).isEqualTo(14); } - 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.getColumnNames().contains(COL_NAME12)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME13)).isTrue(); - assertThat(tableMetadata.getColumnNames().contains(COL_NAME14)).isTrue(); + 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.getColumnNames().contains(getColumnName12())).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName13())).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName14())).isTrue(); if (isTimestampTypeSupported()) { - assertThat(tableMetadata.getColumnNames().contains(COL_NAME15)).isTrue(); + assertThat(tableMetadata.getColumnNames().contains(getColumnName15())).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.getColumnDataType(COL_NAME12)).isEqualTo(DataType.DATE); - assertThat(tableMetadata.getColumnDataType(COL_NAME13)).isEqualTo(DataType.TIME); - assertThat(tableMetadata.getColumnDataType(COL_NAME14)).isEqualTo(DataType.TIMESTAMPTZ); + 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.getColumnDataType(getColumnName12())).isEqualTo(DataType.DATE); + assertThat(tableMetadata.getColumnDataType(getColumnName13())).isEqualTo(DataType.TIME); + assertThat(tableMetadata.getColumnDataType(getColumnName14())).isEqualTo(DataType.TIMESTAMPTZ); if (isTimestampTypeSupported()) { - assertThat(tableMetadata.getColumnDataType(COL_NAME15)).isEqualTo(DataType.TIMESTAMP); + assertThat(tableMetadata.getColumnDataType(getColumnName15())).isEqualTo(DataType.TIMESTAMP); } - 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.getClusteringOrder(COL_NAME12)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME13)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME14)).isNull(); - assertThat(tableMetadata.getClusteringOrder(COL_NAME15)).isNull(); + 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.getClusteringOrder(getColumnName12())).isNull(); + assertThat(tableMetadata.getClusteringOrder(getColumnName13())).isNull(); + assertThat(tableMetadata.getClusteringOrder(getColumnName14())).isNull(); + assertThat(tableMetadata.getClusteringOrder(getColumnName15())).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 @@ -321,13 +404,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); } } @@ -348,12 +431,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); } } @@ -362,7 +445,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); } @@ -371,7 +454,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); } @@ -380,7 +463,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(); } @@ -389,15 +472,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); } } @@ -406,7 +489,7 @@ public void dropTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() // Arrange // Act Assert - assertThatThrownBy(() -> admin.dropTable(namespace1, TABLE4)) + assertThatThrownBy(() -> admin.dropTable(namespace1, getTable4())) .isInstanceOf(IllegalArgumentException.class); } @@ -415,7 +498,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 @@ -423,27 +506,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 { @@ -458,7 +541,7 @@ public void truncateTable_ForNonExistingTable_ShouldThrowIllegalArgumentExceptio // Arrange // Act Assert - assertThatThrownBy(() -> admin.truncateTable(namespace1, TABLE4)) + assertThatThrownBy(() -> admin.truncateTable(namespace1, getTable4())) .isInstanceOf(IllegalArgumentException.class); } @@ -470,7 +553,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 @@ -488,10 +572,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 @@ -503,112 +587,119 @@ public void createIndex_ForAllDataTypesWithExistingData_ShouldCreateIndexesCorre Map options = getCreationOptions(); TableMetadata.Builder metadataBuilder = 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) - .addColumn(COL_NAME10, DataType.DATE) - .addColumn(COL_NAME11, DataType.TIME) - .addColumn(COL_NAME12, DataType.TIMESTAMPTZ) - .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) + .addColumn(getColumnName10(), DataType.DATE) + .addColumn(getColumnName11(), DataType.TIME) + .addColumn(getColumnName12(), DataType.TIMESTAMPTZ) + .addPartitionKey(getColumnName1()) + .addSecondaryIndex(getColumnName9()); if (isTimestampTypeSupported()) { - metadataBuilder = metadataBuilder.addColumn(COL_NAME13, DataType.TIMESTAMP); + metadataBuilder = metadataBuilder.addColumn(getColumnName13(), DataType.TIMESTAMP); } TableMetadata metadata = metadataBuilder.build(); - admin.createTable(namespace1, TABLE4, metadata, options); + admin.createTable(namespace1, getTable4(), metadata, options); storage = storageFactory.getStorage(); PutBuilder.Buildable 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") - .dateValue(COL_NAME10, LocalDate.of(2020, 6, 2)) - .timeValue(COL_NAME11, LocalTime.of(12, 2, 6, 123_456_000)) + .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") + .dateValue(getColumnName10(), LocalDate.of(2020, 6, 2)) + .timeValue(getColumnName11(), LocalTime.of(12, 2, 6, 123_456_000)) .timestampTZValue( - COL_NAME12, + getColumnName12(), LocalDateTime.of(LocalDate.of(2020, 6, 2), LocalTime.of(12, 2, 6, 123_000_000)) .toInstant(ZoneOffset.UTC)); if (isTimestampTypeSupported()) { put.timestampValue( - COL_NAME13, + getColumnName13(), LocalDateTime.of(LocalDate.of(2020, 6, 2), LocalTime.of(12, 2, 6, 123_000_000))); } storage.put(put.build()); // Act - admin.createIndex(namespace1, TABLE4, COL_NAME2, 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(), 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_NAME10, options); - admin.createIndex(namespace1, TABLE4, COL_NAME11, options); - admin.createIndex(namespace1, TABLE4, COL_NAME12, options); + admin.createIndex(namespace1, getTable4(), getColumnName10(), options); + admin.createIndex(namespace1, getTable4(), getColumnName11(), options); + admin.createIndex(namespace1, getTable4(), getColumnName12(), options); if (isTimestampTypeSupported()) { - admin.createIndex(namespace1, TABLE4, COL_NAME13, options); + admin.createIndex(namespace1, getTable4(), getColumnName13(), options); } if (isCreateIndexOnTextAndBlobColumnsEnabled()) { - admin.createIndex(namespace1, TABLE4, COL_NAME3, options); - admin.createIndex(namespace1, TABLE4, COL_NAME8, options); + admin.createIndex(namespace1, getTable4(), getColumnName3(), options); + admin.createIndex(namespace1, getTable4(), getColumnName8(), options); } // Assert - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME2)).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(), 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_NAME9)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME10)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME11)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME12)).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName9())).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName10())).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName11())).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName12())).isTrue(); if (isTimestampTypeSupported()) { - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME13)).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName13())).isTrue(); } if (isCreateIndexOnTextAndBlobColumnsEnabled()) { - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME3)).isTrue(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME8)).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName3())).isTrue(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName8())).isTrue(); } Set actualSecondaryIndexNames = - admin.getTableMetadata(namespace1, TABLE4).getSecondaryIndexNames(); + admin.getTableMetadata(namespace1, getTable4()).getSecondaryIndexNames(); assertThat(actualSecondaryIndexNames) - .contains(COL_NAME2, COL_NAME4, COL_NAME5, COL_NAME9, COL_NAME10, COL_NAME11, COL_NAME12); + .contains( + getColumnName2(), + getColumnName4(), + getColumnName5(), + getColumnName9(), + getColumnName10(), + getColumnName11(), + getColumnName12()); int indexCount = 8; if (isIndexOnBooleanColumnSupported()) { - assertThat(actualSecondaryIndexNames).contains(COL_NAME7); + assertThat(actualSecondaryIndexNames).contains(getColumnName7()); indexCount++; } if (isTimestampTypeSupported()) { - assertThat(actualSecondaryIndexNames).contains(COL_NAME13); + assertThat(actualSecondaryIndexNames).contains(getColumnName13()); indexCount++; } if (isCreateIndexOnTextAndBlobColumnsEnabled()) { - assertThat(actualSecondaryIndexNames).contains(COL_NAME3, COL_NAME8); + assertThat(actualSecondaryIndexNames).contains(getColumnName3(), getColumnName8()); indexCount += 2; } assertThat(actualSecondaryIndexNames).hasSize(indexCount); } finally { - admin.dropTable(namespace1, TABLE4, true); + admin.dropTable(namespace1, getTable4(), true); if (storage != null) { storage.close(); } @@ -623,7 +714,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); } @@ -634,7 +725,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); } @@ -646,19 +738,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); } } @@ -670,19 +764,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); } } @@ -695,99 +791,99 @@ public void dropIndex_ForAllDataTypesWithExistingData_ShouldDropIndexCorrectly() Map options = getCreationOptions(); TableMetadata.Builder metadataBuilder = 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) - .addColumn(COL_NAME10, DataType.DATE) - .addColumn(COL_NAME11, DataType.TIME) - .addColumn(COL_NAME12, DataType.TIMESTAMPTZ) - .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_NAME10) - .addSecondaryIndex(COL_NAME11) - .addSecondaryIndex(COL_NAME12); + .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) + .addColumn(getColumnName10(), DataType.DATE) + .addColumn(getColumnName11(), DataType.TIME) + .addColumn(getColumnName12(), DataType.TIMESTAMPTZ) + .addPartitionKey(getColumnName1()) + .addSecondaryIndex(getColumnName2()) + .addSecondaryIndex(getColumnName3()) + .addSecondaryIndex(getColumnName4()) + .addSecondaryIndex(getColumnName5()) + .addSecondaryIndex(getColumnName6()) + .addSecondaryIndex(getColumnName8()) + .addSecondaryIndex(getColumnName9()) + .addSecondaryIndex(getColumnName10()) + .addSecondaryIndex(getColumnName11()) + .addSecondaryIndex(getColumnName12()); if (isIndexOnBooleanColumnSupported()) { - metadataBuilder.addSecondaryIndex(COL_NAME7).build(); + metadataBuilder.addSecondaryIndex(getColumnName7()).build(); } if (isTimestampTypeSupported()) { - metadataBuilder.addColumn(COL_NAME13, DataType.TIMESTAMP); - metadataBuilder.addSecondaryIndex(COL_NAME13); + metadataBuilder.addColumn(getColumnName13(), DataType.TIMESTAMP); + metadataBuilder.addSecondaryIndex(getColumnName13()); } - admin.createTable(namespace1, TABLE4, metadataBuilder.build(), options); + admin.createTable(namespace1, getTable4(), metadataBuilder.build(), options); storage = storageFactory.getStorage(); PutBuilder.Buildable 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") - .dateValue(COL_NAME10, LocalDate.of(2020, 6, 2)) - .timeValue(COL_NAME11, LocalTime.of(12, 2, 6, 123_456_000)) + .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") + .dateValue(getColumnName10(), LocalDate.of(2020, 6, 2)) + .timeValue(getColumnName11(), LocalTime.of(12, 2, 6, 123_456_000)) .timestampTZValue( - COL_NAME12, + getColumnName12(), LocalDateTime.of(LocalDate.of(2020, 6, 2), LocalTime.of(12, 2, 6, 123_000_000)) .toInstant(ZoneOffset.UTC)); if (isTimestampTypeSupported()) { put.timestampValue( - COL_NAME13, + getColumnName13(), LocalDateTime.of(LocalDate.of(2020, 6, 2), LocalTime.of(12, 2, 6, 123_000_000))); } storage.put(put.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, TABLE4, COL_NAME10); - admin.dropIndex(namespace1, TABLE4, COL_NAME11); - admin.dropIndex(namespace1, TABLE4, COL_NAME12); + admin.dropIndex(namespace1, getTable4(), getColumnName8()); + admin.dropIndex(namespace1, getTable4(), getColumnName10()); + admin.dropIndex(namespace1, getTable4(), getColumnName11()); + admin.dropIndex(namespace1, getTable4(), getColumnName12()); if (isTimestampTypeSupported()) { - admin.dropIndex(namespace1, TABLE4, COL_NAME13); + admin.dropIndex(namespace1, getTable4(), getColumnName13()); } // 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, TABLE4, COL_NAME10)).isFalse(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME11)).isFalse(); - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME12)).isFalse(); + 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()); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName10())).isFalse(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName11())).isFalse(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName12())).isFalse(); if (isTimestampTypeSupported()) { - assertThat(admin.indexExists(namespace1, TABLE4, COL_NAME13)).isFalse(); + assertThat(admin.indexExists(namespace1, getTable4(), getColumnName13())).isFalse(); } } finally { - admin.dropTable(namespace1, TABLE4, true); + admin.dropTable(namespace1, getTable4(), true); if (storage != null) { storage.close(); } @@ -799,7 +895,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); } @@ -808,7 +904,7 @@ public void dropIndex_ForNonExistingIndex_ShouldThrowIllegalArgumentException() // Arrange // Act Assert - assertThatThrownBy(() -> admin.dropIndex(namespace1, TABLE1, COL_NAME2)) + assertThatThrownBy(() -> admin.dropIndex(namespace1, TABLE1, getColumnName2())) .isInstanceOf(IllegalArgumentException.class); } @@ -817,7 +913,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(); } @@ -833,16 +929,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 = @@ -855,9 +951,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); } } @@ -867,7 +963,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); } @@ -877,7 +974,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 0c7aa07b58..d513ff744e 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 @@ -47,15 +47,15 @@ public abstract class DistributedStorageIntegrationTestBase { private static final Logger logger = LoggerFactory.getLogger(DistributedStorageIntegrationTestBase.class); - protected static final String TEST_NAME = "storage"; - protected static final String NAMESPACE = "int_test_" + TEST_NAME; - protected static final String TABLE = "test_table"; - protected static final String COL_NAME1 = "c1"; - protected static final String COL_NAME2 = "c2"; - protected static final String COL_NAME3 = "c3"; - protected static final String COL_NAME4 = "c4"; - protected static final String COL_NAME5 = "c5"; - protected static final String COL_NAME6 = "c6"; + private static final String TEST_NAME = "storage"; + private static final String NAMESPACE = "int_test_" + TEST_NAME; + private static final String TABLE = "test_table"; + private static final String COL_NAME1 = "c1"; + private static final String COL_NAME2 = "c2"; + private static final String COL_NAME3 = "c3"; + private static final String COL_NAME4 = "c4"; + private static final String COL_NAME5 = "c5"; + private static final String COL_NAME6 = "c6"; protected DistributedStorage storage; protected DistributedStorageAdmin admin; @@ -63,8 +63,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(); @@ -75,26 +75,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); @@ -114,7 +154,7 @@ public void setUp() throws Exception { } private void truncateTable() throws ExecutionException { - admin.truncateTable(namespace, TABLE); + admin.truncateTable(namespace, getTableName()); } @AfterAll @@ -143,18 +183,18 @@ 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 - Key partitionKey = Key.ofInt(COL_NAME1, 0); - Key clusteringKey = Key.ofInt(COL_NAME4, 0); + Key partitionKey = Key.ofInt(getColumnName1(), 0); + Key clusteringKey = Key.ofInt(getColumnName4(), 0); Get get = Get.newBuilder() - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build(); @@ -166,12 +206,12 @@ public void operation_NoTargetGiven_ShouldThrowIllegalArgumentException() { @Test public void operation_WrongNamespaceGiven_ShouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = Key.ofInt(COL_NAME1, 0); - Key clusteringKey = Key.ofInt(COL_NAME4, 0); + Key partitionKey = Key.ofInt(getColumnName1(), 0); + Key clusteringKey = Key.ofInt(getColumnName4(), 0); Get get = Get.newBuilder() .namespace("wrong_" + namespace) // a wrong namespace - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build(); @@ -182,12 +222,12 @@ public void operation_WrongNamespaceGiven_ShouldThrowIllegalArgumentException() @Test public void operation_WrongTableGiven_ShouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = Key.ofInt(COL_NAME1, 0); - Key clusteringKey = Key.ofInt(COL_NAME4, 0); + Key partitionKey = Key.ofInt(getColumnName1(), 0); + Key clusteringKey = Key.ofInt(getColumnName4(), 0); Get get = Get.newBuilder() .namespace(namespace) - .table("wrong_" + TABLE) // a wrong table + .table("wrong_" + getTableName()) // a wrong table .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build(); @@ -198,7 +238,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, namespace); final DistributedStorage storageWithDefaultNamespace = StorageFactory.create(properties).getStorage(); @@ -207,36 +247,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 @@ -270,9 +314,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 @@ -282,8 +327,13 @@ public void get_GetWithoutPartitionKeyGiven_ShouldThrowInvalidUsageException() { int pKey = 0; // Act Assert - Key partitionKey = Key.ofInt(COL_NAME1, pKey); - Get get = Get.newBuilder().namespace(namespace).table(TABLE).partitionKey(partitionKey).build(); + Key partitionKey = Key.ofInt(getColumnName1(), pKey); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(partitionKey) + .build(); assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class); } @@ -297,17 +347,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 @@ -321,17 +372,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 @@ -344,8 +395,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); @@ -364,12 +415,12 @@ public void scan_ScanWithProjectionsGiven_ShouldRetrieveSpecifiedValues() Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) - .projection(COL_NAME1) - .projection(COL_NAME2) - .projection(COL_NAME3) - .projection(COL_NAME6) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .projection(getColumnName1()) + .projection(getColumnName2()) + .projection(getColumnName3()) + .projection(getColumnName6()) .build(); List actual = scanAll(scan); @@ -377,17 +428,17 @@ public void scan_ScanWithProjectionsGiven_ShouldRetrieveSpecifiedValues() 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 @@ -401,8 +452,8 @@ public void scan_ScanWithPartitionKeyGivenAndResultsIteratedWithOne_ShouldReturn Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) .build(); Scanner scanner = storage.scan(scan); @@ -425,18 +476,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(); } @@ -452,8 +503,8 @@ public void scan_ScanWithPartitionGivenThreeTimes_ShouldRetrieveResultsProperlyE Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) .build(); double t1 = System.currentTimeMillis(); List actual = scanAll(scan); @@ -466,10 +517,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)"); @@ -486,23 +537,23 @@ public void scan_ScanWithStartInclusiveRangeGiven_ShouldRetrieveResultsOfGivenRa Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) - .start(Key.ofInt(COL_NAME4, 0)) - .end(Key.ofInt(COL_NAME4, 2), false) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .start(Key.ofInt(getColumnName4(), 0)) + .end(Key.ofInt(getColumnName4(), 2), false) .build(); 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 @@ -516,23 +567,23 @@ public void scan_ScanWithEndInclusiveRangeGiven_ShouldRetrieveResultsOfGivenRang Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) - .start(Key.ofInt(COL_NAME4, 0), false) - .end(Key.ofInt(COL_NAME4, 2)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) + .start(Key.ofInt(getColumnName4(), 0), false) + .end(Key.ofInt(getColumnName4(), 2)) .build(); 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 @@ -544,11 +595,11 @@ public void scan_ScanWithOrderAscGiven_ShouldReturnAscendingOrderedResults() Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 0)) - .start(Key.ofInt(COL_NAME4, 0)) - .end(Key.ofInt(COL_NAME4, 2)) - .ordering(Scan.Ordering.asc(COL_NAME4)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 0)) + .start(Key.ofInt(getColumnName4(), 0)) + .end(Key.ofInt(getColumnName4(), 2)) + .ordering(Scan.Ordering.asc(getColumnName4())) .build(); // Act @@ -556,12 +607,12 @@ public void scan_ScanWithOrderAscGiven_ShouldReturnAscendingOrderedResults() // 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 @@ -573,26 +624,26 @@ public void scan_ScanWithOrderDescGiven_ShouldReturnDescendingOrderedResults() Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 0)) - .start(Key.ofInt(COL_NAME4, 0)) - .end(Key.ofInt(COL_NAME4, 2)) - .ordering(Scan.Ordering.desc(COL_NAME4)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 0)) + .start(Key.ofInt(getColumnName4(), 0)) + .end(Key.ofInt(getColumnName4(), 2)) + .ordering(Scan.Ordering.desc(getColumnName4())) .build(); - new Scan(Key.ofInt(COL_NAME1, 0)) - .withOrdering(new Scan.Ordering(COL_NAME4, Scan.Ordering.Order.DESC)); + new Scan(Key.ofInt(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 @@ -605,9 +656,9 @@ public void scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults() Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 0)) - .ordering(Scan.Ordering.desc(COL_NAME4)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 0)) + .ordering(Scan.Ordering.desc(getColumnName4())) .limit(1) .build(); @@ -616,8 +667,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 @@ -631,24 +682,24 @@ public void scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults() Scan scan = Scan.newBuilder() .namespace(namespace) - .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 @@ -662,8 +713,8 @@ public void scannerIterator_ScanWithPartitionKeyGiven_ShouldRetrieveCorrectResul Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) .build(); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); @@ -672,18 +723,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 @@ -697,8 +748,8 @@ public void scannerIterator_OneAndIteratorCalled_ShouldRetrieveCorrectResults() Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) .build(); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); @@ -708,20 +759,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 @@ -735,8 +786,8 @@ public void scannerIterator_AllAndIteratorCalled_ShouldRetrieveCorrectResults() Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) .build(); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); @@ -746,18 +797,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(); } @@ -773,8 +824,8 @@ public void scannerIterator_IteratorCalledMultipleTimes_ShouldRetrieveCorrectRes Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) .build(); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); @@ -785,18 +836,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 @@ -805,12 +856,12 @@ public void put_SinglePutGiven_ShouldStoreProperly() throws ExecutionException { int pKey = 0; int cKey = 0; List puts = preparePuts(); - Key partitionKey = Key.ofInt(COL_NAME1, pKey); - Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + Key partitionKey = Key.ofInt(getColumnName1(), pKey); + Key clusteringKey = Key.ofInt(getColumnName4(), cKey); Get get = Get.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build(); @@ -821,16 +872,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 @@ -840,34 +891,34 @@ public void put_SinglePutWithIfNotExistsGiven_ShouldStoreProperly() throws Execu int cKey = 0; List puts = preparePuts(); puts.get(0).withCondition(new PutIfNotExists()); - Key partitionKey = Key.ofInt(COL_NAME1, pKey); - Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + Key partitionKey = Key.ofInt(getColumnName1(), pKey); + Key clusteringKey = Key.ofInt(getColumnName4(), cKey); Get get = Get.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build(); // 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 @@ -879,8 +930,8 @@ public void put_MultiplePutGiven_ShouldStoreProperly() throws IOException, Execu Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) .build(); // Act @@ -890,18 +941,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 @@ -917,8 +970,8 @@ public void put_MultiplePutWithIfNotExistsGiven_ShouldStoreProperly() Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) .build(); // Act @@ -928,25 +981,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 = Key.ofInt(COL_NAME1, 0); - Key clusteringKey = Key.ofInt(COL_NAME4, 0); + Key partitionKey = Key.ofInt(getColumnName1(), 0); + Key clusteringKey = Key.ofInt(getColumnName4(), 0); // Act assertThatCode( @@ -954,7 +1009,7 @@ public void put_PutWithoutValuesGiven_ShouldStoreProperly() throws ExecutionExce storage.put( Put.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build())) @@ -965,7 +1020,7 @@ public void put_PutWithoutValuesGiven_ShouldStoreProperly() throws ExecutionExce storage.get( Get.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build()); @@ -975,8 +1030,8 @@ public void put_PutWithoutValuesGiven_ShouldStoreProperly() throws ExecutionExce @Test public void put_PutWithoutValuesGivenTwice_ShouldStoreProperly() throws ExecutionException { // Arrange - Key partitionKey = Key.ofInt(COL_NAME1, 0); - Key clusteringKey = Key.ofInt(COL_NAME4, 0); + Key partitionKey = Key.ofInt(getColumnName1(), 0); + Key clusteringKey = Key.ofInt(getColumnName4(), 0); // Act assertThatCode( @@ -984,7 +1039,7 @@ public void put_PutWithoutValuesGivenTwice_ShouldStoreProperly() throws Executio storage.put( Put.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build())) @@ -994,7 +1049,7 @@ public void put_PutWithoutValuesGivenTwice_ShouldStoreProperly() throws Executio storage.put( Put.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build())) @@ -1005,7 +1060,7 @@ public void put_PutWithoutValuesGivenTwice_ShouldStoreProperly() throws Executio storage.get( Get.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build()); @@ -1026,8 +1081,8 @@ public void put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutati Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) .build(); // Act @@ -1037,8 +1092,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 @@ -1052,7 +1107,7 @@ 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)))) @@ -1063,18 +1118,18 @@ public void put_MultiplePutWithDifferentConditionsGiven_ShouldStoreProperly() scanAll( Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 0)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 0)) .build()); 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 @@ -1107,17 +1162,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 @@ -1135,18 +1192,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 @@ -1164,18 +1225,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 @@ -1184,8 +1249,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); @@ -1194,48 +1259,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 @@ -1244,9 +1318,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(); @@ -1264,7 +1339,7 @@ public void delete_DeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingl populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Key partitionKey = Key.ofInt(getColumnName1(), pKey); // Act Delete delete = prepareDelete(pKey, cKey); @@ -1273,16 +1348,20 @@ public void delete_DeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingl // Assert List results = scanAll( - Scan.newBuilder().namespace(namespace).table(TABLE).partitionKey(partitionKey).build()); + Scan.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(partitionKey) + .build()); 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 @@ -1304,8 +1383,8 @@ public void delete_DeleteWithIfExistsGivenWhenSuchRecordExists_ShouldDeletePrope populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = Key.ofInt(COL_NAME1, pKey); - Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + Key partitionKey = Key.ofInt(getColumnName1(), pKey); + Key clusteringKey = Key.ofInt(getColumnName4(), cKey); // Act Delete delete = prepareDelete(pKey, cKey); @@ -1317,7 +1396,7 @@ public void delete_DeleteWithIfExistsGivenWhenSuchRecordExists_ShouldDeletePrope storage.get( Get.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build()); @@ -1331,15 +1410,15 @@ public void delete_DeleteWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationExcept populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = Key.ofInt(COL_NAME1, pKey); - Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + Key partitionKey = Key.ofInt(getColumnName1(), pKey); + Key clusteringKey = Key.ofInt(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); @@ -1349,7 +1428,7 @@ public void delete_DeleteWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationExcept storage.get( Get.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build()); @@ -1363,15 +1442,15 @@ public void delete_DeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = Key.ofInt(COL_NAME1, pKey); - Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + Key partitionKey = Key.ofInt(getColumnName1(), pKey); + Key clusteringKey = Key.ofInt(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(); @@ -1381,7 +1460,7 @@ public void delete_DeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() storage.get( Get.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build()); @@ -1401,7 +1480,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( @@ -1413,8 +1492,8 @@ public void delete_MultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProper scanAll( Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 0)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 0)) .build()); assertThat(results.size()).isEqualTo(0); } @@ -1439,8 +1518,8 @@ public void mutate_MultiplePutGiven_ShouldStoreProperly() throws ExecutionExcept Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) .build(); // Act @@ -1450,18 +1529,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 @@ -1470,8 +1551,8 @@ 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; @@ -1480,8 +1561,8 @@ public void mutate_PutAndDeleteGiven_ShouldUpdateAndDeleteRecordsProperly() Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, pKey)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), pKey)) .build(); // Act @@ -1491,14 +1572,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 @@ -1507,12 +1590,12 @@ public void mutate_SinglePutGiven_ShouldStoreProperly() throws ExecutionExceptio int pKey = 0; int cKey = 0; List puts = preparePuts(); - Key partitionKey = Key.ofInt(COL_NAME1, pKey); - Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + Key partitionKey = Key.ofInt(getColumnName1(), pKey); + Key clusteringKey = Key.ofInt(getColumnName4(), cKey); Get get = Get.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build(); @@ -1523,16 +1606,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 @@ -1545,12 +1628,12 @@ public void mutate_SinglePutGiven_ShouldStoreProperly() throws ExecutionExceptio int cKey = 0; // Act - Key partitionKey = Key.ofInt(COL_NAME1, pKey); - Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + Key partitionKey = Key.ofInt(getColumnName1(), pKey); + Key clusteringKey = Key.ofInt(getColumnName4(), cKey); Delete delete = Delete.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build(); @@ -1560,16 +1643,20 @@ public void mutate_SinglePutGiven_ShouldStoreProperly() throws ExecutionExceptio // Assert List actual = scanAll( - Scan.newBuilder().namespace(namespace).table(TABLE).partitionKey(partitionKey).build()); + Scan.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(partitionKey) + .build()); 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 @@ -1583,8 +1670,13 @@ public void mutate_EmptyListGiven_ShouldThrowIllegalArgumentException() { public void put_PutWithoutClusteringKeyGiven_ShouldThrowIllegalArgumentException() { // Arrange int pKey = 0; - Key partitionKey = Key.ofInt(COL_NAME1, pKey); - Put put = Put.newBuilder().namespace(namespace).table(TABLE).partitionKey(partitionKey).build(); + Key partitionKey = Key.ofInt(getColumnName1(), pKey); + Put put = + Put.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(partitionKey) + .build(); // Act Assert assertThatCode(() -> storage.put(put)).isInstanceOf(IllegalArgumentException.class); @@ -1595,13 +1687,13 @@ public void put_IncorrectPutGiven_ShouldThrowIllegalArgumentException() { // Arrange int pKey = 0; int cKey = 0; - Key partitionKey = Key.ofInt(COL_NAME1, pKey); + Key partitionKey = Key.ofInt(getColumnName1(), pKey); Put put = Put.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) - .intValue(COL_NAME4, cKey) + .intValue(getColumnName4(), cKey) .build(); // Act Assert @@ -1611,7 +1703,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 @@ -1619,9 +1711,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 @@ -1632,8 +1727,8 @@ public void get_GetGivenForIndexedColumn_ShouldGet() throws ExecutionException { Get get = Get.newBuilder() .namespace(namespace) - .table(TABLE) - .indexKey(Key.ofInt(COL_NAME3, c3)) + .table(getTableName()) + .indexKey(Key.ofInt(getColumnName3(), c3)) .build(); // Act @@ -1641,8 +1736,10 @@ public void get_GetGivenForIndexedColumn_ShouldGet() throws ExecutionException { // Assert assertThat(actual.isPresent()).isTrue(); - assertThat(actual.get().getValue(COL_NAME1)).isEqualTo(Optional.of(new IntValue(COL_NAME1, 0))); - 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(), 0))); + assertThat(actual.get().getValue(getColumnName4())) + .isEqualTo(Optional.of(new IntValue(getColumnName4(), 0))); } @Test @@ -1654,10 +1751,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 @@ -1665,10 +1762,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 @@ -1680,10 +1777,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 @@ -1702,8 +1799,8 @@ public void get_GetGivenForIndexedColumnWithUnmatchedConjunctions_ShouldReturnEm Get get = Get.newBuilder() .namespace(namespace) - .table(TABLE) - .indexKey(Key.ofInt(COL_NAME3, c3)) + .table(getTableName()) + .indexKey(Key.ofInt(getColumnName3(), c3)) .build(); // Act Assert @@ -1718,8 +1815,8 @@ public void scan_ScanGivenForIndexedColumn_ShouldScan() throws ExecutionExceptio Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .indexKey(Key.ofInt(COL_NAME3, c3)) + .table(getTableName()) + .indexKey(Key.ofInt(getColumnName3(), c3)) .build(); // Act @@ -1731,11 +1828,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 : actual) { - 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); @@ -1751,8 +1848,8 @@ public void scan_ScanGivenForNonIndexedColumn_ShouldThrowIllegalArgumentExceptio Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .indexKey(Key.ofText(COL_NAME2, c2)) + .table(getTableName()) + .indexKey(Key.ofText(getColumnName2(), c2)) .build(); // Act Assert @@ -1765,21 +1862,25 @@ public void scan_ScanLargeData_ShouldRetrieveExpectedValues() int recordCount = 345; // Arrange - Key partitionKey = Key.ofInt(COL_NAME1, 1); + Key partitionKey = Key.ofInt(getColumnName1(), 1); for (int i = 0; i < recordCount; i++) { - Key clusteringKey = Key.ofInt(COL_NAME4, i); + Key clusteringKey = Key.ofInt(getColumnName4(), i); storage.put( Put.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) - .blobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()]) + .blobValue(getColumnName6(), new byte[getLargeDataSizeInBytes()]) .build()); } Scan scan = - Scan.newBuilder().namespace(namespace).table(TABLE).partitionKey(partitionKey).build(); + Scan.newBuilder() + .namespace(namespace) + .table(getTableName()) + .partitionKey(partitionKey) + .build(); // Act List results = scanAll(scan); @@ -1787,8 +1888,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); } } @@ -1799,32 +1900,32 @@ public void scan_ScanLargeDataWithOrdering_ShouldRetrieveExpectedValues() int fetchCount = 234; // Arrange - Key partitionKey = Key.ofInt(COL_NAME1, 1); + Key partitionKey = Key.ofInt(getColumnName1(), 1); for (int i = 0; i < recordCount; i++) { - Key clusteringKey = Key.ofInt(COL_NAME4, i); + Key clusteringKey = Key.ofInt(getColumnName4(), i); storage.put( Put.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) - .blobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()]) + .blobValue(getColumnName6(), new byte[getLargeDataSizeInBytes()]) .build()); } Scan scanAsc = Scan.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) - .ordering(Scan.Ordering.asc(COL_NAME4)) + .ordering(Scan.Ordering.asc(getColumnName4())) .build(); Scan scanDesc = Scan.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) - .ordering(Scan.Ordering.desc(COL_NAME4)) + .ordering(Scan.Ordering.desc(getColumnName4())) .build(); // Act @@ -1847,14 +1948,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); } } @@ -1865,22 +1966,22 @@ public void scan_ScanLargeDataWithLimit_ShouldRetrieveExpectedValues() int recordCount = 345; int limit = 234; - Key partitionKey = Key.ofInt(COL_NAME1, 1); + Key partitionKey = Key.ofInt(getColumnName1(), 1); for (int i = 0; i < recordCount; i++) { - Key clusteringKey = Key.ofInt(COL_NAME4, i); + Key clusteringKey = Key.ofInt(getColumnName4(), i); storage.put( Put.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) - .blobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()]) + .blobValue(getColumnName6(), new byte[getLargeDataSizeInBytes()]) .build()); } Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .limit(limit) .build(); @@ -1891,8 +1992,8 @@ public void scan_ScanLargeDataWithLimit_ShouldRetrieveExpectedValues() // 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); } } @@ -1901,7 +2002,7 @@ public void scan_ScanAllWithNoLimitGiven_ShouldRetrieveAllRecords() throws ExecutionException, IOException { // Arrange populateRecords(); - Scan scanAll = Scan.newBuilder().namespace(namespace).table(TABLE).all().build(); + Scan scanAll = Scan.newBuilder().namespace(namespace).table(getTableName()).all().build(); // Act List results = scanAll(scanAll); @@ -1916,12 +2017,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); } @@ -1933,35 +2035,36 @@ public void scan_ScanAllWithLimitGiven_ShouldRetrieveExpectedRecords() Put p1 = Put.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 1)) - .clusteringKey(Key.ofInt(COL_NAME4, 1)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 1)) + .clusteringKey(Key.ofInt(getColumnName4(), 1)) .build(); Put p2 = Put.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 1)) - .clusteringKey(Key.ofInt(COL_NAME4, 2)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 1)) + .clusteringKey(Key.ofInt(getColumnName4(), 2)) .build(); Put p3 = Put.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 2)) - .clusteringKey(Key.ofInt(COL_NAME4, 1)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 2)) + .clusteringKey(Key.ofInt(getColumnName4(), 1)) .build(); Put p4 = Put.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 3)) - .clusteringKey(Key.ofInt(COL_NAME4, 0)) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 3)) + .clusteringKey(Key.ofInt(getColumnName4(), 0)) .build(); storage.put(ImmutableList.of(p1, p2)); storage.put(p3); storage.put(p4); - Scan scanAll = Scan.newBuilder().namespace(namespace).table(TABLE).all().limit(2).build(); + Scan scanAll = + Scan.newBuilder().namespace(namespace).table(getTableName()).all().limit(2).build(); // Act List results = scanAll(scanAll); @@ -1971,36 +2074,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); } @@ -2015,9 +2118,9 @@ public void scan_ScanAllWithProjectionsGiven_ShouldRetrieveSpecifiedValues() Scan scanAll = Scan.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .all() - .projections(COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME6) + .projections(getColumnName1(), getColumnName2(), getColumnName3(), getColumnName6()) .build(); List actualResults = scanAll(scanAll); @@ -2031,16 +2134,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 @@ -2048,18 +2153,18 @@ public void scan_ScanAllWithLargeData_ShouldRetrieveExpectedValues() throws ExecutionException, IOException { // Arrange for (int i = 0; i < 345; i++) { - Key partitionKey = Key.ofInt(COL_NAME1, i % 4); - Key clusteringKey = Key.ofInt(COL_NAME4, i); + Key partitionKey = Key.ofInt(getColumnName1(), i % 4); + Key clusteringKey = Key.ofInt(getColumnName4(), i); storage.put( Put.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) - .blobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()]) + .blobValue(getColumnName6(), new byte[getLargeDataSizeInBytes()]) .build()); } - Scan scan = Scan.newBuilder().namespace(namespace).table(TABLE).all().build(); + Scan scan = Scan.newBuilder().namespace(namespace).table(getTableName()).all().build(); // Act List results = scanAll(scan); @@ -2069,12 +2174,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); @@ -2085,24 +2190,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 @@ -2112,12 +2217,12 @@ public void scan_ScanWithProjectionsGivenOnNonPrimaryKey_ShouldRetrieveOnlyProje Put put = Put.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 0)) - .clusteringKey(Key.ofInt(COL_NAME4, 0)) - .textValue(COL_NAME2, "foo") - .intValue(COL_NAME3, 0) - .booleanValue(COL_NAME5, true) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 0)) + .clusteringKey(Key.ofInt(getColumnName4(), 0)) + .textValue(getColumnName2(), "foo") + .intValue(getColumnName3(), 0) + .booleanValue(getColumnName5(), true) .build(); storage.put(put); @@ -2125,18 +2230,19 @@ public void scan_ScanWithProjectionsGivenOnNonPrimaryKey_ShouldRetrieveOnlyProje Scan scan = Scan.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 0)) - .projection(COL_NAME3) - .projection(COL_NAME5) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 0)) + .projection(getColumnName3()) + .projection(getColumnName5()) .build(); 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 @@ -2146,12 +2252,12 @@ public void scan_ScanAllWithProjectionsGivenOnNonPrimaryKey_ShouldRetrieveOnlyPr Put put = Put.newBuilder() .namespace(namespace) - .table(TABLE) - .partitionKey(Key.ofInt(COL_NAME1, 0)) - .clusteringKey(Key.ofInt(COL_NAME4, 0)) - .textValue(COL_NAME2, "foo") - .intValue(COL_NAME3, 0) - .booleanValue(COL_NAME5, true) + .table(getTableName()) + .partitionKey(Key.ofInt(getColumnName1(), 0)) + .clusteringKey(Key.ofInt(getColumnName4(), 0)) + .textValue(getColumnName2(), "foo") + .intValue(getColumnName3(), 0) + .booleanValue(getColumnName5(), true) .build(); storage.put(put); @@ -2159,18 +2265,19 @@ public void scan_ScanAllWithProjectionsGivenOnNonPrimaryKey_ShouldRetrieveOnlyPr Scan scanAll = Scan.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .all() - .projection(COL_NAME3) - .projection(COL_NAME5) + .projection(getColumnName3()) + .projection(getColumnName5()) .build(); 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 @@ -2179,20 +2286,20 @@ public void scan_ScanAllLargeData_ShouldRetrieveExpectedValues() int recordCount = 345; // Arrange - Key clusteringKey = Key.ofInt(COL_NAME4, 1); + Key clusteringKey = Key.ofInt(getColumnName4(), 1); for (int i = 0; i < recordCount; i++) { - Key partitionKey = Key.ofInt(COL_NAME1, i); + Key partitionKey = Key.ofInt(getColumnName1(), i); storage.put( Put.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) - .blobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()]) + .blobValue(getColumnName6(), new byte[getLargeDataSizeInBytes()]) .build()); } - Scan scanAll = Scan.newBuilder().namespace(namespace).table(TABLE).all().build(); + Scan scanAll = Scan.newBuilder().namespace(namespace).table(getTableName()).all().build(); // Act List results = scanAll(scanAll); @@ -2202,8 +2309,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); @@ -2216,20 +2323,21 @@ public void scan_ScanAllLargeDataWithLimit_ShouldRetrieveExpectedValues() int recordCount = 345; int limit = 234; - Key clusteringKey = Key.ofInt(COL_NAME4, 1); + Key clusteringKey = Key.ofInt(getColumnName4(), 1); for (int i = 0; i < recordCount; i++) { - Key partitionKey = Key.ofInt(COL_NAME1, i); + Key partitionKey = Key.ofInt(getColumnName1(), i); storage.put( Put.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) - .blobValue(COL_NAME6, new byte[getLargeDataSizeInBytes()]) + .blobValue(getColumnName6(), new byte[getLargeDataSizeInBytes()]) .build()); } - Scan scan = Scan.newBuilder().namespace(namespace).table(TABLE).all().limit(limit).build(); + Scan scan = + Scan.newBuilder().namespace(namespace).table(getTableName()).all().limit(limit).build(); // Act List results = scanAll(scan); @@ -2239,8 +2347,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); @@ -2252,11 +2360,11 @@ private void populateRecords() { } private Get prepareGet(int pKey, int cKey) { - Key partitionKey = Key.ofInt(COL_NAME1, pKey); - Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + Key partitionKey = Key.ofInt(getColumnName1(), pKey); + Key clusteringKey = Key.ofInt(getColumnName4(), cKey); return Get.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build(); @@ -2271,17 +2379,17 @@ private List preparePuts() { IntStream.range(0, 3) .forEach( j -> { - Key partitionKey = Key.ofInt(COL_NAME1, i); - Key clusteringKey = Key.ofInt(COL_NAME4, j); + Key partitionKey = Key.ofInt(getColumnName1(), i); + Key clusteringKey = Key.ofInt(getColumnName4(), j); Put put = Put.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) - .textValue(COL_NAME2, Integer.toString(i + j)) - .intValue(COL_NAME3, i + j) - .booleanValue(COL_NAME5, j % 2 == 0) + .textValue(getColumnName2(), Integer.toString(i + j)) + .intValue(getColumnName3(), i + j) + .booleanValue(getColumnName5(), j % 2 == 0) .build(); puts.add(put); })); @@ -2290,11 +2398,11 @@ private List preparePuts() { } private Delete prepareDelete(int pKey, int cKey) { - Key partitionKey = Key.ofInt(COL_NAME1, pKey); - Key clusteringKey = Key.ofInt(COL_NAME4, cKey); + Key partitionKey = Key.ofInt(getColumnName1(), pKey); + Key clusteringKey = Key.ofInt(getColumnName4(), cKey); return Delete.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build(); @@ -2309,12 +2417,12 @@ private List prepareDeletes() { IntStream.range(0, 3) .forEach( j -> { - Key partitionKey = Key.ofInt(COL_NAME1, i); - Key clusteringKey = Key.ofInt(COL_NAME4, j); + Key partitionKey = Key.ofInt(getColumnName1(), i); + Key clusteringKey = Key.ofInt(getColumnName4(), j); Delete delete = Delete.newBuilder() .namespace(namespace) - .table(TABLE) + .table(getTableName()) .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build(); 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 7b5e8d9006..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,679 +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(); - } - - 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 = - Scan.newBuilder() - .namespace(namespace) - .table(tableName) - .partitionKey(Key.ofInt(columnName1, pKey)) - .projection(columnName1) - .projection(columnName2) - .projection(columnName3) - .build(); - 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 = - Scan.newBuilder() - .namespace(namespace) - .table(tableName) - .partitionKey(Key.ofInt(columnName1, pKey)) - .build(); - 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 = Key.ofInt(columnName1, pKey); - Key clusteringKey = Key.ofInt(columnName4, cKey); - Get get = - Get.newBuilder() - .namespace(namespace) - .table(tableName) - .partitionKey(partitionKey) - .clusteringKey(clusteringKey) - .build(); - - // 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 = - Scan.newBuilder() - .namespace(namespace) - .table(tableName) - .partitionKey(Key.ofInt(columnName1, pKey)) - .build(); - - // 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( - Scan.newBuilder() - .namespace(namespace) - .table(tableName) - .partitionKey(Key.ofInt(columnName1, 0)) - .build()); - 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; - - // Act - Delete delete = prepareDelete(pKey, cKey); - assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException(); - - // Assert - List results = - scanAll( - Scan.newBuilder() - .namespace(namespace) - .table(tableName) - .partitionKey(Key.ofInt(columnName1, pKey)) - .build()); - 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( - Scan.newBuilder() - .namespace(namespace) - .table(tableName) - .partitionKey(Key.ofInt(columnName1, 0)) - .build()); - assertThat(results.size()).isEqualTo(0); - } - - @Test - public void - delete_WithReservedKeywordAndDeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() - throws ExecutionException { - // Arrange - populateRecords(); - int pKey = 0; - int cKey = 0; - Key partitionKey = Key.ofInt(columnName1, pKey); - Key clusteringKey = Key.ofInt(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( - Get.newBuilder() - .namespace(namespace) - .table(tableName) - .partitionKey(partitionKey) - .clusteringKey(clusteringKey) - .build()); - 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 = - Get.newBuilder() - .namespace(namespace) - .table(tableName) - .indexKey(Key.ofInt(columnName3, c3)) - .build(); - - // 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 = - Scan.newBuilder() - .namespace(namespace) - .table(tableName) - .indexKey(Key.ofInt(columnName3, c3)) - .build(); - - // 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(Key.ofInt(columnName1, 1)) - .withStart(Key.ofInt(columnName4, 1), false) - .withEnd(Key.ofInt(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 = Key.ofInt(columnName1, pKey); - Key clusteringKey = Key.ofInt(columnName4, cKey); - return Get.newBuilder() - .namespace(namespace) - .table(tableName) - .partitionKey(partitionKey) - .clusteringKey(clusteringKey) - .build(); - } - - private List preparePuts() { - List puts = new ArrayList<>(); - - IntStream.range(0, 5) - .forEach( - i -> - IntStream.range(0, 3) - .forEach( - j -> { - Key partitionKey = Key.ofInt(columnName1, i); - Key clusteringKey = Key.ofInt(columnName4, j); - Put put = - Put.newBuilder() - .namespace(namespace) - .table(tableName) - .partitionKey(partitionKey) - .clusteringKey(clusteringKey) - .textValue(columnName2, Integer.toString(i + j)) - .intValue(columnName3, i + j) - .booleanValue(columnName5, j % 2 == 0) - .build(); - puts.add(put); - })); - - return puts; - } - - private Delete prepareDelete(int pKey, int cKey) { - Key partitionKey = Key.ofInt(columnName1, pKey); - Key clusteringKey = Key.ofInt(columnName4, cKey); - return Delete.newBuilder() - .namespace(namespace) - .table(tableName) - .partitionKey(partitionKey) - .clusteringKey(clusteringKey) - .build(); - } - - private List prepareDeletes() { - List deletes = new ArrayList<>(); - - IntStream.range(0, 5) - .forEach( - i -> - IntStream.range(0, 3) - .forEach( - j -> { - Key partitionKey = Key.ofInt(columnName1, i); - Key clusteringKey = Key.ofInt(columnName4, j); - Delete delete = - Delete.newBuilder() - .namespace(namespace) - .table(tableName) - .partitionKey(partitionKey) - .clusteringKey(clusteringKey) - .build(); - 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; } }