From 6071b6f5cbeeb80300ae33d472cfff5d962d61b7 Mon Sep 17 00:00:00 2001 From: brfrn169 Date: Wed, 13 Aug 2025 10:22:07 +0900 Subject: [PATCH 1/3] Remove deprecated operation constructors usages --- .../MultiStorageIntegrationTest.java | 524 +++++--- .../main/java/com/scalar/db/api/Mutation.java | 10 - .../db/common/AbstractDistributedStorage.java | 8 - .../db/storage/cassandra/Cassandra.java | 8 +- .../com/scalar/db/storage/cosmos/Cosmos.java | 8 +- .../com/scalar/db/storage/dynamo/Dynamo.java | 8 +- .../CommitMutationComposer.java | 15 +- .../consensuscommit/Coordinator.java | 31 +- .../consensuscommit/CrudHandler.java | 16 +- .../RollbackMutationComposer.java | 24 +- .../transaction/consensuscommit/Snapshot.java | 16 +- ...SingleCrudOperationTransactionManager.java | 8 +- .../com/scalar/db/util/ScalarDbUtils.java | 125 +- .../com/scalar/db/api/DeleteBuilderTest.java | 47 +- .../com/scalar/db/api/GetBuilderTest.java | 240 +++- .../com/scalar/db/api/PutBuilderTest.java | 133 +- .../com/scalar/db/api/ScanBuilderTest.java | 444 ++++++- .../common/checker/OperationCheckerTest.java | 1075 ++++++++++------- .../storage/cassandra/BatchHandlerTest.java | 45 +- .../cassandra/DeleteStatementHandlerTest.java | 98 +- .../cassandra/InsertStatementHandlerTest.java | 86 +- .../cassandra/SelectStatementHandlerTest.java | 116 +- .../cassandra/UpdateStatementHandlerTest.java | 108 +- .../db/storage/cosmos/BatchHandlerTest.java | 32 +- .../db/storage/cosmos/CosmosMutationTest.java | 41 +- .../storage/cosmos/CosmosOperationTest.java | 45 +- .../cosmos/DeleteStatementHandlerTest.java | 24 +- .../cosmos/PutStatementHandlerTest.java | 33 +- .../cosmos/SelectStatementHandlerTest.java | 175 +-- .../storage/dynamo/BatchHandlerTestBase.java | 32 +- .../DeleteStatementHandlerTestBase.java | 24 +- .../db/storage/dynamo/DynamoMutationTest.java | 25 +- .../dynamo/DynamoOperationCheckerTest.java | 23 +- .../storage/dynamo/DynamoOperationTest.java | 9 +- .../dynamo/PutStatementHandlerTestBase.java | 31 +- .../SelectStatementHandlerTestBase.java | 192 +-- .../db/storage/jdbc/JdbcDatabaseTest.java | 184 ++- .../db/storage/jdbc/JdbcServiceTest.java | 171 ++- .../multistorage/MultiStorageTest.java | 192 ++- .../consensuscommit/CommitHandlerTest.java | 33 +- .../CommitMutationComposerTest.java | 102 +- .../consensuscommit/ConsensusCommitTest.java | 35 +- .../consensuscommit/CrudHandlerTest.java | 72 +- .../consensuscommit/MergedResultTest.java | 116 +- .../PrepareMutationComposerTest.java | 126 +- .../RollbackMutationComposerTest.java | 42 +- .../consensuscommit/SnapshotKeyTest.java | 24 +- .../consensuscommit/SnapshotTest.java | 357 +++--- .../TransactionTableMetadataManagerTest.java | 12 +- .../TwoPhaseConsensusCommitTest.java | 35 +- .../jdbc/JdbcTransactionManagerTest.java | 191 ++- ...ibutedStorageAdminIntegrationTestBase.java | 30 +- ...onditionalMutationIntegrationTestBase.java | 173 ++- ...DistributedStorageIntegrationTestBase.java | 200 +-- ...edTransactionAdminIntegrationTestBase.java | 30 +- ...CrossPartitionScanIntegrationTestBase.java | 3 +- ...ributedTransactionIntegrationTestBase.java | 145 ++- ...eCommitTransactionIntegrationTestBase.java | 164 ++- ...CommitNullMetadataIntegrationTestBase.java | 2 +- ...nsusCommitSpecificIntegrationTestBase.java | 311 +++-- ...nsusCommitSpecificIntegrationTestBase.java | 326 +++-- 61 files changed, 4601 insertions(+), 2354 deletions(-) diff --git a/core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageIntegrationTest.java index 5359b1cbc2..35373f1ecf 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/multistorage/MultiStorageIntegrationTest.java @@ -186,18 +186,27 @@ public void whenPutDataIntoTable1_DataShouldBeWrittenIntoCassandra() throws Exec Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME4, 4); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL_NAME2, "val2") - .withValue(COL_NAME3, 3) - .withValue(COL_NAME5, true) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .textValue(COL_NAME2, "val2") + .intValue(COL_NAME3, 3) + .booleanValue(COL_NAME5, true) + .build(); // Act multiStorage.put(put); // Assert - Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); Optional result = multiStorage.get(get); assertThat(result.isPresent()).isTrue(); @@ -228,18 +237,27 @@ public void whenPutDataIntoTable2_DataShouldBeWrittenIntoJdbcDatabase() Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME4, 4); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL_NAME2, "val2") - .withValue(COL_NAME3, 3) - .withValue(COL_NAME5, true) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .textValue(COL_NAME2, "val2") + .intValue(COL_NAME3, 3) + .booleanValue(COL_NAME5, true) + .build(); // Act multiStorage.put(put); // Assert - Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); Optional result = multiStorage.get(get); assertThat(result.isPresent()).isTrue(); @@ -271,18 +289,27 @@ public void whenPutDataIntoTable3_DataShouldBeWrittenIntoDefaultStorage() Key clusteringKey = Key.ofInt(COL_NAME4, 4); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL_NAME2, "val2") - .withValue(COL_NAME3, 3) - .withValue(COL_NAME5, true) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .textValue(COL_NAME2, "val2") + .intValue(COL_NAME3, 3) + .booleanValue(COL_NAME5, true) + .build(); // Act multiStorage.put(put); // Assert - Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); Optional result = multiStorage.get(get); assertThat(result.isPresent()).isTrue(); @@ -317,21 +344,32 @@ public void whenScanDataFromTable1_DataShouldBeScannedFromCassandra() cassandra.mutate( Arrays.asList( - new Put(partitionKey, clusteringKey1) - .withValue(COL_NAME3, 2) - .forNamespace(namespace) - .forTable(table), - new Put(partitionKey, clusteringKey2) - .withValue(COL_NAME3, 1) - .forNamespace(namespace) - .forTable(table), - new Put(partitionKey, clusteringKey3) - .withValue(COL_NAME3, 0) - .forNamespace(namespace) - .forTable(table))); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .intValue(COL_NAME3, 2) + .build(), + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .intValue(COL_NAME3, 1) + .build(), + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey3) + .intValue(COL_NAME3, 0) + .build())); // Act - List results = scanAll(new Scan(partitionKey).forNamespace(namespace).forTable(table)); + List results = + scanAll( + Scan.newBuilder().namespace(namespace).table(table).partitionKey(partitionKey).build()); // Assert assertThat(results.size()).isEqualTo(3); @@ -359,21 +397,32 @@ public void whenScanDataFromTable2_DataShouldBeScannedFromJdbcDatabase() jdbcDatabase.mutate( Arrays.asList( - new Put(partitionKey, clusteringKey1) - .withValue(COL_NAME3, 2) - .forNamespace(namespace) - .forTable(table), - new Put(partitionKey, clusteringKey2) - .withValue(COL_NAME3, 1) - .forNamespace(namespace) - .forTable(table), - new Put(partitionKey, clusteringKey3) - .withValue(COL_NAME3, 0) - .forNamespace(namespace) - .forTable(table))); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .intValue(COL_NAME3, 2) + .build(), + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .intValue(COL_NAME3, 1) + .build(), + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey3) + .intValue(COL_NAME3, 0) + .build())); // Act - List results = scanAll(new Scan(partitionKey).forNamespace(namespace).forTable(table)); + List results = + scanAll( + Scan.newBuilder().namespace(namespace).table(table).partitionKey(partitionKey).build()); // Assert assertThat(results.size()).isEqualTo(3); @@ -401,21 +450,32 @@ public void whenScanDataFromTable3_DataShouldBeScannedFromDefaultStorage() cassandra.mutate( Arrays.asList( - new Put(partitionKey, clusteringKey1) - .withValue(COL_NAME3, 2) - .forNamespace(namespace) - .forTable(table), - new Put(partitionKey, clusteringKey2) - .withValue(COL_NAME3, 1) - .forNamespace(namespace) - .forTable(table), - new Put(partitionKey, clusteringKey3) - .withValue(COL_NAME3, 0) - .forNamespace(namespace) - .forTable(table))); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .intValue(COL_NAME3, 2) + .build(), + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .intValue(COL_NAME3, 1) + .build(), + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey3) + .intValue(COL_NAME3, 0) + .build())); // Act - List results = scanAll(new Scan(partitionKey).forNamespace(namespace).forTable(table)); + List results = + scanAll( + Scan.newBuilder().namespace(namespace).table(table).partitionKey(partitionKey).build()); // Assert assertThat(results.size()).isEqualTo(3); @@ -445,20 +505,34 @@ public void whenDeleteDataFromTable1_DataShouldBeDeletedFromCassandra() Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME4, 4); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL_NAME3, 3) + .build(); cassandra.put(put); jdbcDatabase.put(put); // Act multiStorage.delete( - new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table)); + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build()); // Assert - Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); Optional result = multiStorage.get(get); assertThat(result.isPresent()).isFalse(); @@ -482,20 +556,34 @@ public void whenDeleteDataFromTable2_DataShouldBeDeletedFromJdbcDatabase() Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME4, 4); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL_NAME3, 3) + .build(); cassandra.put(put); jdbcDatabase.put(put); // Act multiStorage.delete( - new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table)); + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build()); // Assert - Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); Optional result = multiStorage.get(get); assertThat(result.isPresent()).isFalse(); @@ -519,20 +607,34 @@ public void whenDeleteDataFromTable3_DataShouldBeDeletedFromDefaultStorage() Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME4, 4); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL_NAME3, 3) + .build(); cassandra.put(put); jdbcDatabase.put(put); // Act multiStorage.delete( - new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table)); + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build()); // Assert - Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); Optional result = multiStorage.get(get); assertThat(result.isPresent()).isFalse(); @@ -556,10 +658,13 @@ public void whenMutateDataToTable1_ShouldExecuteForCassandra() throws ExecutionE Key clusteringKey1 = Key.ofInt(COL_NAME4, 1); Key clusteringKey2 = Key.ofInt(COL_NAME4, 2); Put put = - new Put(partitionKey, clusteringKey1) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .intValue(COL_NAME3, 3) + .build(); cassandra.put(put); jdbcDatabase.put(put); @@ -567,15 +672,35 @@ public void whenMutateDataToTable1_ShouldExecuteForCassandra() throws ExecutionE // Act multiStorage.mutate( Arrays.asList( - new Put(partitionKey, clusteringKey2) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table), - new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .intValue(COL_NAME3, 3) + .build(), + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .build())); // Assert - Get get1 = new Get(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table); - Get get2 = new Get(partitionKey, clusteringKey2).forNamespace(namespace).forTable(table); + Get get1 = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .build(); + Get get2 = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .build(); Optional result = multiStorage.get(get1); assertThat(result.isPresent()).isFalse(); @@ -611,10 +736,13 @@ public void whenMutateDataToTable2_ShouldExecuteForJdbcDatabase() throws Executi Key clusteringKey1 = Key.ofInt(COL_NAME4, 1); Key clusteringKey2 = Key.ofInt(COL_NAME4, 2); Put put = - new Put(partitionKey, clusteringKey1) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .intValue(COL_NAME3, 3) + .build(); cassandra.put(put); jdbcDatabase.put(put); @@ -622,15 +750,35 @@ public void whenMutateDataToTable2_ShouldExecuteForJdbcDatabase() throws Executi // Act multiStorage.mutate( Arrays.asList( - new Put(partitionKey, clusteringKey2) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table), - new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .intValue(COL_NAME3, 3) + .build(), + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .build())); // Assert - Get get1 = new Get(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table); - Get get2 = new Get(partitionKey, clusteringKey2).forNamespace(namespace).forTable(table); + Get get1 = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .build(); + Get get2 = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .build(); Optional result = multiStorage.get(get1); assertThat(result.isPresent()).isFalse(); @@ -666,10 +814,13 @@ public void whenMutateDataToTable3_ShouldExecuteForDefaultStorage() throws Execu Key clusteringKey1 = Key.ofInt(COL_NAME4, 1); Key clusteringKey2 = Key.ofInt(COL_NAME4, 2); Put put = - new Put(partitionKey, clusteringKey1) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .intValue(COL_NAME3, 3) + .build(); cassandra.put(put); jdbcDatabase.put(put); @@ -677,15 +828,35 @@ public void whenMutateDataToTable3_ShouldExecuteForDefaultStorage() throws Execu // Act multiStorage.mutate( Arrays.asList( - new Put(partitionKey, clusteringKey2) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table), - new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .intValue(COL_NAME3, 3) + .build(), + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .build())); // Assert - Get get1 = new Get(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table); - Get get2 = new Get(partitionKey, clusteringKey2).forNamespace(namespace).forTable(table); + Get get1 = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .build(); + Get get2 = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .build(); Optional result = multiStorage.get(get1); assertThat(result.isPresent()).isFalse(); @@ -721,18 +892,27 @@ public void whenPutDataIntoTable1InNamespace2_DataShouldBeWrittenIntoJdbcDatabas Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME4, 4); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL_NAME2, "val2") - .withValue(COL_NAME3, 3) - .withValue(COL_NAME5, true) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .textValue(COL_NAME2, "val2") + .intValue(COL_NAME3, 3) + .booleanValue(COL_NAME5, true) + .build(); // Act multiStorage.put(put); // Assert - Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); Optional result = multiStorage.get(get); assertThat(result.isPresent()).isTrue(); @@ -767,21 +947,32 @@ public void whenScanDataFromTable1InNamespace2_DataShouldBeScannedFromJdbcDataba jdbcDatabase.mutate( Arrays.asList( - new Put(partitionKey, clusteringKey1) - .withValue(COL_NAME3, 2) - .forNamespace(namespace) - .forTable(table), - new Put(partitionKey, clusteringKey2) - .withValue(COL_NAME3, 1) - .forNamespace(namespace) - .forTable(table), - new Put(partitionKey, clusteringKey3) - .withValue(COL_NAME3, 0) - .forNamespace(namespace) - .forTable(table))); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .intValue(COL_NAME3, 2) + .build(), + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .intValue(COL_NAME3, 1) + .build(), + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey3) + .intValue(COL_NAME3, 0) + .build())); // Act - List results = scanAll(new Scan(partitionKey).forNamespace(namespace).forTable(table)); + List results = + scanAll( + Scan.newBuilder().namespace(namespace).table(table).partitionKey(partitionKey).build()); // Assert assertThat(results.size()).isEqualTo(3); @@ -805,20 +996,34 @@ public void whenDeleteDataFromTable1InNamespace2_DataShouldBeDeletedFromJdbcData Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME4, 4); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL_NAME3, 3) + .build(); cassandra.put(put); jdbcDatabase.put(put); // Act multiStorage.delete( - new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table)); + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build()); // Assert - Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); Optional result = multiStorage.get(get); assertThat(result.isPresent()).isFalse(); @@ -843,10 +1048,13 @@ public void whenMutateDataToTable1InNamespace2_ShouldExecuteForCassandra() Key clusteringKey1 = Key.ofInt(COL_NAME4, 1); Key clusteringKey2 = Key.ofInt(COL_NAME4, 2); Put put = - new Put(partitionKey, clusteringKey1) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .intValue(COL_NAME3, 3) + .build(); cassandra.put(put); jdbcDatabase.put(put); @@ -854,15 +1062,35 @@ public void whenMutateDataToTable1InNamespace2_ShouldExecuteForCassandra() // Act multiStorage.mutate( Arrays.asList( - new Put(partitionKey, clusteringKey2) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table), - new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .intValue(COL_NAME3, 3) + .build(), + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .build())); // Assert - Get get1 = new Get(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table); - Get get2 = new Get(partitionKey, clusteringKey2).forNamespace(namespace).forTable(table); + Get get1 = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .build(); + Get get2 = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .build(); Optional result = multiStorage.get(get1); assertThat(result.isPresent()).isFalse(); diff --git a/core/src/main/java/com/scalar/db/api/Mutation.java b/core/src/main/java/com/scalar/db/api/Mutation.java index 2626ad3651..e31eddf5e0 100644 --- a/core/src/main/java/com/scalar/db/api/Mutation.java +++ b/core/src/main/java/com/scalar/db/api/Mutation.java @@ -54,16 +54,6 @@ public Mutation(Mutation mutation) { condition = mutation.condition; } - Mutation( - @Nullable String namespace, - String tableName, - Key partitionKey, - @Nullable Key clusteringKey, - @Nullable MutationCondition condition) { - super(namespace, tableName, partitionKey, clusteringKey); - this.condition = condition; - } - /** * Returns the {@link MutationCondition} * diff --git a/core/src/main/java/com/scalar/db/common/AbstractDistributedStorage.java b/core/src/main/java/com/scalar/db/common/AbstractDistributedStorage.java index c7c87d2dfb..b5208268ae 100644 --- a/core/src/main/java/com/scalar/db/common/AbstractDistributedStorage.java +++ b/core/src/main/java/com/scalar/db/common/AbstractDistributedStorage.java @@ -76,12 +76,4 @@ protected Put copyAndSetTargetToIfNot(Put put) { protected Delete copyAndSetTargetToIfNot(Delete delete) { return ScalarDbUtils.copyAndSetTargetToIfNot(delete, namespace, tableName); } - - protected Get copyAndPrepareForDynamicFiltering(Get get) { - return ScalarDbUtils.copyAndPrepareForDynamicFiltering(get); - } - - protected Scan copyAndPrepareForDynamicFiltering(Scan scan) { - return ScalarDbUtils.copyAndPrepareForDynamicFiltering(scan); - } } diff --git a/core/src/main/java/com/scalar/db/storage/cassandra/Cassandra.java b/core/src/main/java/com/scalar/db/storage/cassandra/Cassandra.java index e8a0930ab1..d1b1dcda41 100644 --- a/core/src/main/java/com/scalar/db/storage/cassandra/Cassandra.java +++ b/core/src/main/java/com/scalar/db/storage/cassandra/Cassandra.java @@ -21,6 +21,7 @@ import com.scalar.db.common.checker.OperationChecker; import com.scalar.db.config.DatabaseConfig; import com.scalar.db.exception.storage.ExecutionException; +import com.scalar.db.util.ScalarDbUtils; import java.io.IOException; import java.util.List; import java.util.Optional; @@ -100,7 +101,9 @@ public Optional get(Get get) throws ExecutionException { if (get.getConjunctions().isEmpty()) { scanner = getInternal(get); } else { - scanner = new FilterableScanner(get, getInternal(copyAndPrepareForDynamicFiltering(get))); + scanner = + new FilterableScanner( + get, getInternal(ScalarDbUtils.copyAndPrepareForDynamicFiltering(get))); } Optional ret = scanner.one(); if (scanner.one().isPresent()) { @@ -134,7 +137,8 @@ public Scanner scan(Scan scan) throws ExecutionException { if (scan.getConjunctions().isEmpty()) { return scanInternal(scan); } else { - return new FilterableScanner(scan, scanInternal(copyAndPrepareForDynamicFiltering(scan))); + return new FilterableScanner( + scan, scanInternal(ScalarDbUtils.copyAndPrepareForDynamicFiltering(scan))); } } diff --git a/core/src/main/java/com/scalar/db/storage/cosmos/Cosmos.java b/core/src/main/java/com/scalar/db/storage/cosmos/Cosmos.java index 84ba08d5bd..f89b939725 100644 --- a/core/src/main/java/com/scalar/db/storage/cosmos/Cosmos.java +++ b/core/src/main/java/com/scalar/db/storage/cosmos/Cosmos.java @@ -21,6 +21,7 @@ import com.scalar.db.common.checker.OperationChecker; import com.scalar.db.config.DatabaseConfig; import com.scalar.db.exception.storage.ExecutionException; +import com.scalar.db.util.ScalarDbUtils; import java.io.IOException; import java.util.List; import java.util.Optional; @@ -105,7 +106,9 @@ public Optional get(Get get) throws ExecutionException { } else { scanner = new FilterableScanner( - get, selectStatementHandler.handle(copyAndPrepareForDynamicFiltering(get))); + get, + selectStatementHandler.handle( + ScalarDbUtils.copyAndPrepareForDynamicFiltering(get))); } Optional ret = scanner.one(); if (scanner.one().isPresent()) { @@ -133,7 +136,8 @@ public Scanner scan(Scan scan) throws ExecutionException { return selectStatementHandler.handle(scan); } else { return new FilterableScanner( - scan, selectStatementHandler.handle(copyAndPrepareForDynamicFiltering(scan))); + scan, + selectStatementHandler.handle(ScalarDbUtils.copyAndPrepareForDynamicFiltering(scan))); } } diff --git a/core/src/main/java/com/scalar/db/storage/dynamo/Dynamo.java b/core/src/main/java/com/scalar/db/storage/dynamo/Dynamo.java index 8789e2df44..d4d8dda0a4 100644 --- a/core/src/main/java/com/scalar/db/storage/dynamo/Dynamo.java +++ b/core/src/main/java/com/scalar/db/storage/dynamo/Dynamo.java @@ -20,6 +20,7 @@ import com.scalar.db.common.checker.OperationChecker; import com.scalar.db.config.DatabaseConfig; import com.scalar.db.exception.storage.ExecutionException; +import com.scalar.db.util.ScalarDbUtils; import java.io.IOException; import java.net.URI; import java.util.List; @@ -125,7 +126,9 @@ public Optional get(Get get) throws ExecutionException { } else { scanner = new FilterableScanner( - get, selectStatementHandler.handle(copyAndPrepareForDynamicFiltering(get))); + get, + selectStatementHandler.handle( + ScalarDbUtils.copyAndPrepareForDynamicFiltering(get))); } Optional ret = scanner.one(); if (scanner.one().isPresent()) { @@ -153,7 +156,8 @@ public Scanner scan(Scan scan) throws ExecutionException { return selectStatementHandler.handle(scan); } else { return new FilterableScanner( - scan, selectStatementHandler.handle(copyAndPrepareForDynamicFiltering(scan))); + scan, + selectStatementHandler.handle(ScalarDbUtils.copyAndPrepareForDynamicFiltering(scan))); } } diff --git a/core/src/main/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposer.java b/core/src/main/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposer.java index 2310c4e620..ae1da0e428 100644 --- a/core/src/main/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposer.java +++ b/core/src/main/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposer.java @@ -114,14 +114,17 @@ private Put composePut(Operation base, @Nullable TransactionResult result) private Delete composeDelete(Operation base, @Nullable TransactionResult result) throws ExecutionException { - return new Delete(getPartitionKey(base, result), getClusteringKey(base, result).orElse(null)) - .forNamespace(base.forNamespace().get()) - .forTable(base.forTable().get()) - .withConsistency(Consistency.LINEARIZABLE) - .withCondition( + return Delete.newBuilder() + .namespace(base.forNamespace().get()) + .table(base.forTable().get()) + .partitionKey(getPartitionKey(base, result)) + .clusteringKey(getClusteringKey(base, result).orElse(null)) + .consistency(Consistency.LINEARIZABLE) + .condition( ConditionBuilder.deleteIf(ConditionBuilder.column(ID).isEqualToText(id)) .and(ConditionBuilder.column(STATE).isEqualToInt(TransactionState.DELETED.get())) - .build()); + .build()) + .build(); } private Key getPartitionKey(Operation base, @Nullable TransactionResult result) diff --git a/core/src/main/java/com/scalar/db/transaction/consensuscommit/Coordinator.java b/core/src/main/java/com/scalar/db/transaction/consensuscommit/Coordinator.java index 773e280ff5..3c7867d1c8 100644 --- a/core/src/main/java/com/scalar/db/transaction/consensuscommit/Coordinator.java +++ b/core/src/main/java/com/scalar/db/transaction/consensuscommit/Coordinator.java @@ -11,6 +11,7 @@ import com.scalar.db.api.DistributedStorage; import com.scalar.db.api.Get; import com.scalar.db.api.Put; +import com.scalar.db.api.PutBuilder; import com.scalar.db.api.Result; import com.scalar.db.api.TableMetadata; import com.scalar.db.api.TransactionState; @@ -286,10 +287,12 @@ private void putStateForLazyRecoveryRollbackForGroupCommit(String id) @VisibleForTesting Get createGetWith(String id) { - return new Get(Key.ofText(Attribute.ID, id)) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(coordinatorNamespace) - .forTable(TABLE); + return Get.newBuilder() + .namespace(coordinatorNamespace) + .table(TABLE) + .partitionKey(Key.ofText(Attribute.ID, id)) + .consistency(Consistency.LINEARIZABLE) + .build(); } private Optional get(Get get, String id) throws CoordinatorException { @@ -327,17 +330,21 @@ private Optional get(Get get, String id) throws CoordinatorEx @VisibleForTesting Put createPutWith(Coordinator.State state) { - Put put = new Put(Key.ofText(Attribute.ID, state.getId())); String childIds = state.getChildIdsAsString(); + PutBuilder.Buildable builder = + Put.newBuilder() + .namespace(coordinatorNamespace) + .table(TABLE) + .partitionKey(Key.ofText(Attribute.ID, state.getId())) + .intValue(Attribute.STATE, state.getState().get()) + .bigIntValue(Attribute.CREATED_AT, state.getCreatedAt()) + .consistency(Consistency.LINEARIZABLE) + .condition(ConditionBuilder.putIfNotExists()); + if (!childIds.isEmpty()) { - put.withTextValue(Attribute.CHILD_IDS, childIds); + builder.textValue(Attribute.CHILD_IDS, childIds); } - return put.withIntValue(Attribute.STATE, state.getState().get()) - .withBigIntValue(Attribute.CREATED_AT, state.getCreatedAt()) - .withConsistency(Consistency.LINEARIZABLE) - .withCondition(ConditionBuilder.putIfNotExists()) - .forNamespace(coordinatorNamespace) - .forTable(TABLE); + return builder.build(); } private void put(Put put, String id) throws CoordinatorException { diff --git a/core/src/main/java/com/scalar/db/transaction/consensuscommit/CrudHandler.java b/core/src/main/java/com/scalar/db/transaction/consensuscommit/CrudHandler.java index 4a8fd44e75..84592ff046 100644 --- a/core/src/main/java/com/scalar/db/transaction/consensuscommit/CrudHandler.java +++ b/core/src/main/java/com/scalar/db/transaction/consensuscommit/CrudHandler.java @@ -713,9 +713,19 @@ private Set convertConjunctions( } private Selection prepareStorageSelection(Selection selection) { - selection.clearProjections(); - selection.withConsistency(Consistency.LINEARIZABLE); - return selection; + if (selection instanceof Get) { + return Get.newBuilder((Get) selection) + .clearProjections() + .consistency(Consistency.LINEARIZABLE) + .build(); + } else { + assert selection instanceof Scan; + + return Scan.newBuilder((Scan) selection) + .clearProjections() + .consistency(Consistency.LINEARIZABLE) + .build(); + } } private TransactionTableMetadata getTransactionTableMetadata(Operation operation) diff --git a/core/src/main/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposer.java b/core/src/main/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposer.java index 429240d5c2..bc70497476 100644 --- a/core/src/main/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposer.java +++ b/core/src/main/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposer.java @@ -121,14 +121,17 @@ private Delete composeDelete(Operation base, TransactionResult result) throws Ex Key partitionKey = ScalarDbUtils.getPartitionKey(result, tableMetadata); Optional clusteringKey = ScalarDbUtils.getClusteringKey(result, tableMetadata); - return new Delete(partitionKey, clusteringKey.orElse(null)) - .forNamespace(base.forNamespace().get()) - .forTable(base.forTable().get()) - .withCondition( + return Delete.newBuilder() + .namespace(base.forNamespace().get()) + .table(base.forTable().get()) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey.orElse(null)) + .condition( ConditionBuilder.deleteIf(ConditionBuilder.column(ID).isEqualToText(id)) .and(ConditionBuilder.column(STATE).isEqualToInt(result.getState().get())) .build()) - .withConsistency(Consistency.LINEARIZABLE); + .consistency(Consistency.LINEARIZABLE) + .build(); } private Optional getLatestResult( @@ -155,10 +158,13 @@ private Optional getLatestResult( } Get get = - new Get(partitionKey, clusteringKey) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(operation.forNamespace().get()) - .forTable(operation.forTable().get()); + Get.newBuilder() + .namespace(operation.forNamespace().get()) + .table(operation.forTable().get()) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); return storage.get(get).map(TransactionResult::new); } diff --git a/core/src/main/java/com/scalar/db/transaction/consensuscommit/Snapshot.java b/core/src/main/java/com/scalar/db/transaction/consensuscommit/Snapshot.java index e3cf2755f1..26429391bf 100644 --- a/core/src/main/java/com/scalar/db/transaction/consensuscommit/Snapshot.java +++ b/core/src/main/java/com/scalar/db/transaction/consensuscommit/Snapshot.java @@ -8,6 +8,7 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ComparisonChain; import com.google.common.collect.Iterators; +import com.google.common.collect.Streams; import com.scalar.db.api.ConditionSetBuilder; import com.scalar.db.api.Delete; import com.scalar.db.api.DistributedStorage; @@ -18,6 +19,7 @@ import com.scalar.db.api.Result; import com.scalar.db.api.Scan; import com.scalar.db.api.ScanAll; +import com.scalar.db.api.ScanBuilder; import com.scalar.db.api.ScanWithIndex; import com.scalar.db.api.Scanner; import com.scalar.db.api.Selection.Conjunction; @@ -593,9 +595,14 @@ private void validateScanResults( Scanner scanner = null; try { // Only get tx_id and primary key columns because we use only them to compare - scan.clearProjections(); - scan.withProjection(Attribute.ID); - ScalarDbUtils.addProjectionsForKeys(scan, getTableMetadata(scan)); + ScanBuilder.BuildableScanOrScanAllFromExisting builder = + Scan.newBuilder(scan).clearProjections().projection(Attribute.ID); + TableMetadata tableMetadata = getTableMetadata(scan); + Streams.concat( + tableMetadata.getPartitionKeyNames().stream(), + tableMetadata.getClusteringKeyNames().stream()) + .forEach(builder::projection); + scan = builder.build(); if (scan.getLimit() == 0) { scanner = storage.scan(scan); @@ -744,8 +751,7 @@ private void validateGetResult( DistributedStorage storage, Get get, Optional originalResult) throws ExecutionException, ValidationConflictException { // Only get the tx_id column because we use only them to compare - get.clearProjections(); - get.withProjection(Attribute.ID); + get = Get.newBuilder(get).clearProjections().projection(Attribute.ID).build(); // Check if a read record is not changed Optional latestResult = storage.get(get).map(TransactionResult::new); diff --git a/core/src/main/java/com/scalar/db/transaction/singlecrudoperation/SingleCrudOperationTransactionManager.java b/core/src/main/java/com/scalar/db/transaction/singlecrudoperation/SingleCrudOperationTransactionManager.java index 39cc6fdfdd..7d55093ab1 100644 --- a/core/src/main/java/com/scalar/db/transaction/singlecrudoperation/SingleCrudOperationTransactionManager.java +++ b/core/src/main/java/com/scalar/db/transaction/singlecrudoperation/SingleCrudOperationTransactionManager.java @@ -160,7 +160,7 @@ public Optional get(Get get) throws CrudException { get = copyAndSetTargetToIfNot(get); try { - return storage.get(get.withConsistency(Consistency.LINEARIZABLE)); + return storage.get(Get.newBuilder(get).consistency(Consistency.LINEARIZABLE).build()); } catch (ExecutionException e) { throw new CrudException(e.getMessage(), e, null); } @@ -171,7 +171,7 @@ public List scan(Scan scan) throws CrudException { scan = copyAndSetTargetToIfNot(scan); try (com.scalar.db.api.Scanner scanner = - storage.scan(scan.withConsistency(Consistency.LINEARIZABLE))) { + storage.scan(Scan.newBuilder(scan).consistency(Consistency.LINEARIZABLE).build())) { return scanner.all(); } catch (ExecutionException | IOException e) { throw new CrudException(e.getMessage(), e, null); @@ -226,7 +226,7 @@ public void put(Put put) throws CrudException { put = copyAndSetTargetToIfNot(put); try { - storage.put(put.withConsistency(Consistency.LINEARIZABLE)); + storage.put(Put.newBuilder(put).consistency(Consistency.LINEARIZABLE).build()); } catch (NoMutationException e) { throwUnsatisfiedConditionException(put); } catch (ExecutionException e) { @@ -331,7 +331,7 @@ public void delete(Delete delete) throws CrudException { delete = copyAndSetTargetToIfNot(delete); try { - storage.delete(delete.withConsistency(Consistency.LINEARIZABLE)); + storage.delete(Delete.newBuilder(delete).consistency(Consistency.LINEARIZABLE).build()); } catch (NoMutationException e) { throwUnsatisfiedConditionException(delete); } catch (ExecutionException e) { diff --git a/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java b/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java index 24eefd6fb9..542b227394 100644 --- a/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java +++ b/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java @@ -1,27 +1,33 @@ package com.scalar.db.util; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Streams; import com.scalar.db.api.ConditionalExpression; import com.scalar.db.api.ConditionalExpression.Operator; import com.scalar.db.api.Delete; +import com.scalar.db.api.DeleteBuilder; import com.scalar.db.api.Get; +import com.scalar.db.api.GetBuilder; import com.scalar.db.api.GetWithIndex; import com.scalar.db.api.Insert; +import com.scalar.db.api.InsertBuilder; import com.scalar.db.api.LikeExpression; import com.scalar.db.api.Mutation; import com.scalar.db.api.Operation; import com.scalar.db.api.Put; +import com.scalar.db.api.PutBuilder; import com.scalar.db.api.Result; import com.scalar.db.api.Scan; +import com.scalar.db.api.ScanBuilder; import com.scalar.db.api.ScanWithIndex; import com.scalar.db.api.Selection; import com.scalar.db.api.Selection.Conjunction; import com.scalar.db.api.TableMetadata; import com.scalar.db.api.Update; +import com.scalar.db.api.UpdateBuilder; import com.scalar.db.api.UpdateIf; import com.scalar.db.api.UpdateIfExists; import com.scalar.db.api.Upsert; +import com.scalar.db.api.UpsertBuilder; import com.scalar.db.common.CoreError; import com.scalar.db.io.BigIntColumn; import com.scalar.db.io.BigIntValue; @@ -66,15 +72,29 @@ public static List copyAndSetTargetToIfNot( public static Get copyAndSetTargetToIfNot( Get get, Optional namespace, Optional tableName) { - Get ret = Get.newBuilder(get).build(); // copy - setTargetToIfNot(ret, namespace, tableName); + GetBuilder.BuildableGetOrGetWithIndexFromExisting builder = Get.newBuilder(get); // copy + if (!get.forNamespace().isPresent() && namespace.isPresent()) { + builder.namespace(namespace.get()); + } + if (!get.forTable().isPresent() && tableName.isPresent()) { + builder.table(tableName.get()); + } + Get ret = builder.build(); + checkIfTargetIsSet(ret); return ret; } public static Scan copyAndSetTargetToIfNot( Scan scan, Optional namespace, Optional tableName) { - Scan ret = Scan.newBuilder(scan).build(); // copy - setTargetToIfNot(ret, namespace, tableName); + ScanBuilder.BuildableScanOrScanAllFromExisting builder = Scan.newBuilder(scan); // copy + if (!scan.forNamespace().isPresent() && namespace.isPresent()) { + builder.namespace(namespace.get()); + } + if (!scan.forTable().isPresent() && tableName.isPresent()) { + builder.table(tableName.get()); + } + Scan ret = builder.build(); + checkIfTargetIsSet(ret); return ret; } @@ -96,47 +116,75 @@ public static Mutation copyAndSetTargetToIfNot( public static Put copyAndSetTargetToIfNot( Put put, Optional namespace, Optional tableName) { - Put ret = Put.newBuilder(put).build(); // copy - setTargetToIfNot(ret, namespace, tableName); + PutBuilder.BuildableFromExisting builder = Put.newBuilder(put); // copy + if (!put.forNamespace().isPresent() && namespace.isPresent()) { + builder.namespace(namespace.get()); + } + if (!put.forTable().isPresent() && tableName.isPresent()) { + builder.table(tableName.get()); + } + Put ret = builder.build(); + checkIfTargetIsSet(ret); return ret; } public static Delete copyAndSetTargetToIfNot( Delete delete, Optional namespace, Optional tableName) { - Delete ret = Delete.newBuilder(delete).build(); // copy - setTargetToIfNot(ret, namespace, tableName); + DeleteBuilder.BuildableFromExisting builder = Delete.newBuilder(delete); // copy + if (!delete.forNamespace().isPresent() && namespace.isPresent()) { + builder.namespace(namespace.get()); + } + if (!delete.forTable().isPresent() && tableName.isPresent()) { + builder.table(tableName.get()); + } + Delete ret = builder.build(); + checkIfTargetIsSet(ret); return ret; } public static Insert copyAndSetTargetToIfNot( Insert insert, Optional namespace, Optional tableName) { - Insert ret = Insert.newBuilder(insert).build(); // copy - setTargetToIfNot(ret, namespace, tableName); + InsertBuilder.BuildableFromExisting builder = Insert.newBuilder(insert); // copy + if (!insert.forNamespace().isPresent() && namespace.isPresent()) { + builder.namespace(namespace.get()); + } + if (!insert.forTable().isPresent() && tableName.isPresent()) { + builder.table(tableName.get()); + } + Insert ret = builder.build(); + checkIfTargetIsSet(ret); return ret; } public static Upsert copyAndSetTargetToIfNot( Upsert upsert, Optional namespace, Optional tableName) { - Upsert ret = Upsert.newBuilder(upsert).build(); // copy - setTargetToIfNot(ret, namespace, tableName); + UpsertBuilder.BuildableFromExisting builder = Upsert.newBuilder(upsert); // copy + if (!upsert.forNamespace().isPresent() && namespace.isPresent()) { + builder.namespace(namespace.get()); + } + if (!upsert.forTable().isPresent() && tableName.isPresent()) { + builder.table(tableName.get()); + } + Upsert ret = builder.build(); + checkIfTargetIsSet(ret); return ret; } public static Update copyAndSetTargetToIfNot( Update update, Optional namespace, Optional tableName) { - Update ret = Update.newBuilder(update).build(); // copy - setTargetToIfNot(ret, namespace, tableName); + UpdateBuilder.BuildableFromExisting builder = Update.newBuilder(update); // copy + if (!update.forNamespace().isPresent() && namespace.isPresent()) { + builder.namespace(namespace.get()); + } + if (!update.forTable().isPresent() && tableName.isPresent()) { + builder.table(tableName.get()); + } + Update ret = builder.build(); + checkIfTargetIsSet(ret); return ret; } - private static void setTargetToIfNot( - Operation operation, Optional namespace, Optional tableName) { - if (!operation.forNamespace().isPresent()) { - operation.forNamespace(namespace.orElse(null)); - } - if (!operation.forTable().isPresent()) { - operation.forTable(tableName.orElse(null)); - } + private static void checkIfTargetIsSet(Operation operation) { if (!operation.forNamespace().isPresent() || !operation.forTable().isPresent()) { throw new IllegalArgumentException( CoreError.OPERATION_DOES_NOT_HAVE_TARGET_NAMESPACE_OR_TABLE_NAME.buildMessage(operation)); @@ -158,17 +206,6 @@ public static boolean isSecondaryIndexSpecified(Selection selection, TableMetada return false; } - public static void addProjectionsForKeys(Selection selection, TableMetadata metadata) { - List projections = selection.getProjections(); - if (projections.isEmpty()) { // meaning projecting all - return; - } - Streams.concat( - metadata.getPartitionKeyNames().stream(), metadata.getClusteringKeyNames().stream()) - .filter(n -> !projections.contains(n)) - .forEach(selection::withProjection); - } - public static Future takeUninterruptibly(CompletionService completionService) { boolean interrupted = false; try { @@ -275,28 +312,28 @@ public static void checkUpdate(Update update) { } public static Get copyAndPrepareForDynamicFiltering(Get get) { - Get ret = Get.newBuilder(get).build(); // copy - List projections = ret.getProjections(); + GetBuilder.BuildableGetOrGetWithIndexFromExisting builder = Get.newBuilder(get); // copy + List projections = get.getProjections(); if (!projections.isEmpty()) { // Add columns in conditions into projections to use them in dynamic filtering - ScalarDbUtils.getColumnNamesUsedIn(ret.getConjunctions()).stream() + ScalarDbUtils.getColumnNamesUsedIn(get.getConjunctions()).stream() .filter(columnName -> !projections.contains(columnName)) - .forEach(ret::withProjection); + .forEach(builder::projection); } - return ret; + return builder.build(); } public static Scan copyAndPrepareForDynamicFiltering(Scan scan) { // Ignore limit to control it during dynamic filtering - Scan ret = Scan.newBuilder(scan).limit(0).build(); // copy - List projections = ret.getProjections(); + ScanBuilder.BuildableScanOrScanAllFromExisting builder = Scan.newBuilder(scan).limit(0); // copy + List projections = scan.getProjections(); if (!projections.isEmpty()) { // Add columns in conditions into projections to use them in dynamic filtering - ScalarDbUtils.getColumnNamesUsedIn(ret.getConjunctions()).stream() + ScalarDbUtils.getColumnNamesUsedIn(scan.getConjunctions()).stream() .filter(columnName -> !projections.contains(columnName)) - .forEach(ret::withProjection); + .forEach(builder::projection); } - return ret; + return builder.build(); } public static Set getColumnNamesUsedIn(Set conjunctions) { diff --git a/core/src/test/java/com/scalar/db/api/DeleteBuilderTest.java b/core/src/test/java/com/scalar/db/api/DeleteBuilderTest.java index 853a87b356..5218ee0b27 100644 --- a/core/src/test/java/com/scalar/db/api/DeleteBuilderTest.java +++ b/core/src/test/java/com/scalar/db/api/DeleteBuilderTest.java @@ -33,7 +33,8 @@ public void build_WithMandatoryParameters_ShouldBuildDeleteWithMandatoryParamete Delete actual = Delete.newBuilder().table(TABLE_1).partitionKey(partitionKey1).build(); // Assert - assertThat(actual).isEqualTo(new Delete(partitionKey1).forTable(TABLE_1)); + assertThat(actual) + .isEqualTo(new Delete(null, TABLE_1, partitionKey1, null, null, ImmutableMap.of(), null)); } @Test @@ -50,7 +51,14 @@ public void build_WithClusteringKey_ShouldBuildDeleteWithClusteringKey() { // Assert assertThat(delete) .isEqualTo( - new Delete(partitionKey1, clusteringKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + new Delete( + NAMESPACE_1, + TABLE_1, + partitionKey1, + clusteringKey1, + null, + ImmutableMap.of(), + null)); } @Test @@ -97,11 +105,14 @@ public void build_WithAllParameters_ShouldBuildDeleteWithAllParameters() { public void build_FromExistingWithoutChange_ShouldCopy() { // Arrange Delete existingDelete = - new Delete(partitionKey1, clusteringKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withCondition(condition1) - .withConsistency(Consistency.LINEARIZABLE); + new Delete( + NAMESPACE_1, + TABLE_1, + partitionKey1, + clusteringKey1, + Consistency.LINEARIZABLE, + ImmutableMap.of(), + condition1); // Act Delete newDelete = Delete.newBuilder(existingDelete).build(); @@ -195,43 +206,47 @@ public void build_FromExistingAndUpdateAllParameters_ShouldBuildDeleteWithUpdate public void build_FromExistingAndClearCondition_ShouldBuildDeleteWithoutCondition() { // Arrange Delete existingDelete = - new Delete(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withCondition(condition1); + new Delete(NAMESPACE_1, TABLE_1, partitionKey1, null, null, ImmutableMap.of(), condition1); // Act Delete newDelete = Delete.newBuilder(existingDelete).clearCondition().build(); // Assert assertThat(newDelete) - .isEqualTo(new Delete(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new Delete(NAMESPACE_1, TABLE_1, partitionKey1, null, null, ImmutableMap.of(), null)); } @Test public void build_FromExistingAndClearClusteringKey_ShouldBuildDeleteWithoutClusteringKey() { // Arrange Delete existingDelete = - new Delete(partitionKey1, clusteringKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1); + new Delete( + NAMESPACE_1, TABLE_1, partitionKey1, clusteringKey1, null, ImmutableMap.of(), null); // Act Delete newDelete = Delete.newBuilder(existingDelete).clearClusteringKey().build(); // Assert assertThat(newDelete) - .isEqualTo(new Delete(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new Delete(NAMESPACE_1, TABLE_1, partitionKey1, null, null, ImmutableMap.of(), null)); } @Test public void build_FromExistingAndClearNamespace_ShouldBuildDeleteWithoutNamespace() { // Arrange Delete existingDelete = - new Delete(partitionKey1, clusteringKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1); + new Delete( + NAMESPACE_1, TABLE_1, partitionKey1, clusteringKey1, null, ImmutableMap.of(), null); // Act Delete newDelete = Delete.newBuilder(existingDelete).clearNamespace().build(); // Assert - assertThat(newDelete).isEqualTo(new Delete(partitionKey1, clusteringKey1).forTable(TABLE_1)); + assertThat(newDelete) + .isEqualTo( + new Delete( + null, TABLE_1, partitionKey1, clusteringKey1, null, ImmutableMap.of(), null)); } } diff --git a/core/src/test/java/com/scalar/db/api/GetBuilderTest.java b/core/src/test/java/com/scalar/db/api/GetBuilderTest.java index d99782ba33..ad5d3f3451 100644 --- a/core/src/test/java/com/scalar/db/api/GetBuilderTest.java +++ b/core/src/test/java/com/scalar/db/api/GetBuilderTest.java @@ -40,7 +40,17 @@ public void buildGet_WithMandatoryParameters_ShouldBuildGetWithMandatoryParamete Get actual = Get.newBuilder().table(TABLE_1).partitionKey(partitionKey1).build(); // Assert - assertThat(actual).isEqualTo(new Get(partitionKey1).forTable(TABLE_1)); + assertThat(actual) + .isEqualTo( + new Get( + null, + TABLE_1, + partitionKey1, + null, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of())); } @Test @@ -57,7 +67,15 @@ public void buildGet_WithClusteringKey_ShouldBuildGetWithClusteringKey() { // Assert assertThat(get) .isEqualTo( - new Get(partitionKey1, clusteringKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + clusteringKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of())); } @Test @@ -567,7 +585,17 @@ public void buildGet_WithEmptyOrConditionSet_ShouldBuildGetWithoutConjunctionCor .build(); // Assert - assertThat(get).isEqualTo(new Get(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + assertThat(get) + .isEqualTo( + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of())); } @Test @@ -583,7 +611,17 @@ public void buildGet_WithEmptyAndConditionSet_ShouldBuildGetWithoutConjunctionCo .build(); // Assert - assertThat(get).isEqualTo(new Get(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + assertThat(get) + .isEqualTo( + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of())); } @Test @@ -598,7 +636,17 @@ public void buildGet_WithEmptyOrConditionSets_ShouldBuildGetWithoutConjunctionCo .build(); // Assert - assertThat(get).isEqualTo(new Get(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + assertThat(get) + .isEqualTo( + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of())); } @Test @@ -613,18 +661,32 @@ public void buildGet_WithEmptyAndConditionSets_ShouldBuildGetWithoutConjunctionC .build(); // Assert - assertThat(get).isEqualTo(new Get(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + assertThat(get) + .isEqualTo( + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of())); } @Test public void buildGet_FromExistingWithoutChange_ShouldCopy() { // Arrange Get existingGet = - new Get(partitionKey1, clusteringKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withProjections(Arrays.asList("c1", "c2")) - .withConsistency(Consistency.LINEARIZABLE); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + clusteringKey1, + Consistency.LINEARIZABLE, + ImmutableMap.of(), + Arrays.asList("c1", "c2"), + ImmutableSet.of()); // Act Get newGet = Get.newBuilder(existingGet).build(); @@ -1207,14 +1269,31 @@ public void buildGet_FromExistingAndClearNamespaceAfterWhere_ShouldBuildGetWitho public void buildGet_FromExistingAndClearClusteringKey_ShouldBuildGetWithoutClusteringKey() { // Arrange Get existingGet = - new Get(partitionKey1, clusteringKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + clusteringKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of()); // Act Get newGet = Get.newBuilder(existingGet).clearClusteringKey().build(); // Assert assertThat(newGet) - .isEqualTo(new Get(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of())); } @Test @@ -1222,7 +1301,15 @@ public void buildGet_FromExistingAndClearClusteringKey_ShouldBuildGetWithoutClus buildGet_FromExistingWithUnsupportedOperation_ShouldThrowUnsupportedOperationException() { // Arrange Get existingGet = - new Get(partitionKey1, clusteringKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1); + new Get( + NAMESPACE_1, + TABLE_1, + partitionKey1, + clusteringKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of()); // Act Assert assertThatThrownBy(() -> Get.newBuilder(existingGet).indexKey(indexKey1)) @@ -1252,7 +1339,16 @@ public void buildGetWithIndex_WithMandatoryParameters_ShouldBuildGetWithMandator Get actual = Get.newBuilder().table(TABLE_1).indexKey(indexKey1).build(); // Assert - assertThat(actual).isEqualTo(new GetWithIndex(indexKey1).forTable(TABLE_1)); + assertThat(actual) + .isEqualTo( + new GetWithIndex( + null, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of())); } @Test @@ -1680,7 +1776,15 @@ public void buildGetWithIndex_WithAndConditionSets_ShouldBuildGetWithConditionsC // Assert assertThat(get) - .isEqualTo(new GetWithIndex(indexKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of())); } @Test @@ -1698,7 +1802,15 @@ public void buildGetWithIndex_WithAndConditionSets_ShouldBuildGetWithConditionsC // Assert assertThat(get) - .isEqualTo(new GetWithIndex(indexKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of())); } @Test @@ -1715,7 +1827,15 @@ public void buildGetWithIndex_WithAndConditionSets_ShouldBuildGetWithConditionsC // Assert assertThat(get) - .isEqualTo(new GetWithIndex(indexKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of())); } @Test @@ -1732,18 +1852,29 @@ public void buildGetWithIndex_WithAndConditionSets_ShouldBuildGetWithConditionsC // Assert assertThat(get) - .isEqualTo(new GetWithIndex(indexKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of())); } @Test public void buildGetWithIndex_FromExistingWithoutChange_ShouldCopy() { // Arrange GetWithIndex existingGet = - new GetWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withProjections(Arrays.asList("c1", "c2")) - .withConsistency(Consistency.LINEARIZABLE); + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.LINEARIZABLE, + ImmutableMap.of(), + Arrays.asList("c1", "c2"), + ImmutableSet.of()); // Act Get newGet = Get.newBuilder(existingGet).build(); @@ -1942,7 +2073,14 @@ public void buildGetWithIndex_FromExistingWithoutChange_ShouldCopy() { buildGetWithIndex_FromExistingWithUnsupportedOperation_ShouldThrowUnsupportedOperationException() { // Arrange GetWithIndex existingGet = - new GetWithIndex(indexKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1); + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of()); // Act Assert assertThatThrownBy(() -> Get.newBuilder(existingGet).partitionKey(partitionKey1)) @@ -1957,11 +2095,15 @@ public void buildGetWithIndex_FromExistingWithoutChange_ShouldCopy() { public void buildGet_FromExistingAndClearNamespace_ShouldBuildGetWithoutNamespace() { // Arrange Get existingGet = - new Get(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withProjections(Arrays.asList("c1", "c2")) - .withConsistency(Consistency.LINEARIZABLE); + new Get( + NAMESPACE_1, + TABLE_1, + indexKey1, + null, + Consistency.LINEARIZABLE, + ImmutableMap.of(), + Arrays.asList("c1", "c2"), + ImmutableSet.of()); // Act Get newGet = Get.newBuilder(existingGet).clearNamespace().build(); @@ -1969,21 +2111,29 @@ public void buildGet_FromExistingAndClearNamespace_ShouldBuildGetWithoutNamespac // Assert assertThat(newGet) .isEqualTo( - new Get(indexKey1) - .forTable(TABLE_1) - .withProjections(Arrays.asList("c1", "c2")) - .withConsistency(Consistency.LINEARIZABLE)); + new Get( + null, + TABLE_1, + indexKey1, + null, + Consistency.LINEARIZABLE, + ImmutableMap.of(), + Arrays.asList("c1", "c2"), + ImmutableSet.of())); } @Test public void buildGetWithIndex_FromExistingAndClearNamespace_ShouldBuildGetWithoutNamespace() { // Arrange GetWithIndex existingGet = - new GetWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withProjections(Arrays.asList("c1", "c2")) - .withConsistency(Consistency.LINEARIZABLE); + new GetWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.LINEARIZABLE, + ImmutableMap.of(), + Arrays.asList("c1", "c2"), + ImmutableSet.of()); // Act Get newGet = Get.newBuilder(existingGet).clearNamespace().build(); @@ -1991,9 +2141,13 @@ public void buildGetWithIndex_FromExistingAndClearNamespace_ShouldBuildGetWithou // Assert assertThat(newGet) .isEqualTo( - new GetWithIndex(indexKey1) - .forTable(TABLE_1) - .withProjections(Arrays.asList("c1", "c2")) - .withConsistency(Consistency.LINEARIZABLE)); + new GetWithIndex( + null, + TABLE_1, + indexKey1, + Consistency.LINEARIZABLE, + ImmutableMap.of(), + Arrays.asList("c1", "c2"), + ImmutableSet.of())); } } diff --git a/core/src/test/java/com/scalar/db/api/PutBuilderTest.java b/core/src/test/java/com/scalar/db/api/PutBuilderTest.java index 94c74cab62..788cca79b0 100644 --- a/core/src/test/java/com/scalar/db/api/PutBuilderTest.java +++ b/core/src/test/java/com/scalar/db/api/PutBuilderTest.java @@ -23,6 +23,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.LinkedHashMap; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -58,7 +59,17 @@ public void build_WithMandatoryParameters_ShouldBuildPutWithMandatoryParameters( Put actual = Put.newBuilder().table(TABLE_1).partitionKey(partitionKey1).build(); // Assert - assertThat(actual).isEqualTo(new Put(partitionKey1).forTable(TABLE_1)); + assertThat(actual) + .isEqualTo( + new Put( + null, + TABLE_1, + partitionKey1, + null, + null, + ImmutableMap.of(), + null, + new LinkedHashMap<>())); } @Test @@ -75,7 +86,15 @@ public void build_WithClusteringKey_ShouldBuildPutWithClusteringKey() { // Assert assertThat(put) .isEqualTo( - new Put(partitionKey1, clusteringKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + new Put( + NAMESPACE_1, + TABLE_1, + partitionKey1, + clusteringKey1, + null, + ImmutableMap.of(), + null, + new LinkedHashMap<>())); } @Test @@ -220,10 +239,15 @@ public void build_WithTwoValueUsingSameColumnName_ShouldBuildPutCorrectly() { // Assert assertThat(put) .isEqualTo( - new Put(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withTextValue("bigint", "a_value")); + new Put( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + null, + ImmutableMap.of(), + null, + ImmutableMap.of("bigint", TextColumn.of("bigint", "a_value")))); } @Test @@ -386,11 +410,18 @@ public void build_FromExistingAndUpdateAllParameters_ShouldBuildPutWithUpdatedPa public void build_FromExistingAndClearValue_ShouldBuildPutWithoutClearedValues() { // Arrange Put existingPut = - new Put(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withBooleanValue("bool", Boolean.TRUE) - .withDoubleValue("double", Double.MIN_VALUE); + new Put( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + null, + ImmutableMap.of(), + null, + ImmutableMap.>builder() + .put("bool", BooleanColumn.of("bool", true)) + .put("double", DoubleColumn.of("double", Double.MIN_VALUE)) + .build()); // Act Put newPut = @@ -399,53 +430,107 @@ public void build_FromExistingAndClearValue_ShouldBuildPutWithoutClearedValues() // Assert assertThat(newPut) .isEqualTo( - new Put(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withBooleanValue("bool", Boolean.TRUE)); + new Put( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + null, + ImmutableMap.of(), + null, + ImmutableMap.of("bool", BooleanColumn.of("bool", true)))); } @Test public void build_FromExistingAndClearCondition_ShouldBuildPutWithoutCondition() { // Arrange Put existingPut = - new Put(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withCondition(condition1); + new Put( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + null, + ImmutableMap.of(), + condition1, + new LinkedHashMap<>()); // Act Put newPut = Put.newBuilder(existingPut).clearCondition().build(); // Assert assertThat(newPut) - .isEqualTo(new Put(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new Put( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + null, + ImmutableMap.of(), + null, + new LinkedHashMap<>())); } @Test public void build_FromExistingAndClearClusteringKey_ShouldBuildPutWithoutClusteringKey() { // Arrange Put existingPut = - new Put(partitionKey1, clusteringKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1); + new Put( + NAMESPACE_1, + TABLE_1, + partitionKey1, + clusteringKey1, + null, + ImmutableMap.of(), + null, + new LinkedHashMap<>()); // Act Put newPut = Put.newBuilder(existingPut).clearClusteringKey().build(); // Assert assertThat(newPut) - .isEqualTo(new Put(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new Put( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + null, + ImmutableMap.of(), + null, + new LinkedHashMap<>())); } @Test public void build_FromExistingAndClearNamespace_ShouldBuildPutWithoutNamespace() { // Arrange Put existingPut = - new Put(partitionKey1, clusteringKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1); + new Put( + NAMESPACE_1, + TABLE_1, + partitionKey1, + clusteringKey1, + null, + ImmutableMap.of(), + null, + new LinkedHashMap<>()); // Act Put newPut = Put.newBuilder(existingPut).clearNamespace().build(); // Assert - assertThat(newPut).isEqualTo(new Put(partitionKey1, clusteringKey1).forTable(TABLE_1)); + assertThat(newPut) + .isEqualTo( + new Put( + null, + TABLE_1, + partitionKey1, + clusteringKey1, + null, + ImmutableMap.of(), + null, + new LinkedHashMap<>())); } } diff --git a/core/src/test/java/com/scalar/db/api/ScanBuilderTest.java b/core/src/test/java/com/scalar/db/api/ScanBuilderTest.java index db8d8fe2c6..124d1b9f0d 100644 --- a/core/src/test/java/com/scalar/db/api/ScanBuilderTest.java +++ b/core/src/test/java/com/scalar/db/api/ScanBuilderTest.java @@ -80,7 +80,22 @@ public void buildScan_WithMandatoryParameters_ShouldBuildScanWithMandatoryParame Scan actual = Scan.newBuilder().table(TABLE_1).partitionKey(partitionKey1).build(); // Assert - assertThat(actual).isEqualTo(new Scan(partitionKey1).forTable(TABLE_1)); + assertThat(actual) + .isEqualTo( + new Scan( + null, + TABLE_1, + partitionKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + null, + false, + null, + false, + Collections.emptyList(), + 0)); } @Test @@ -155,11 +170,20 @@ public void buildScan_ScanWithInclusiveStartAndEnd_ShouldBuildScanCorrectly() { // Assert Scan expectedScan = - new Scan(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withStart(startClusteringKey1, true) - .withEnd(endClusteringKey1, true); + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + startClusteringKey1, + true, + endClusteringKey1, + true, + Collections.emptyList(), + 0); assertThat(scan1).isEqualTo(expectedScan); assertThat(scan2).isEqualTo(expectedScan); } @@ -178,11 +202,20 @@ public void buildScan_ScanWithExclusiveStartAndEnd_ShouldBuildScanCorrectly() { // Assert Scan expectedScan = - new Scan(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withStart(startClusteringKey1, false) - .withEnd(endClusteringKey1, false); + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + startClusteringKey1, + false, + endClusteringKey1, + false, + Collections.emptyList(), + 0); assertThat(scan).isEqualTo(expectedScan); } @@ -190,16 +223,20 @@ public void buildScan_ScanWithExclusiveStartAndEnd_ShouldBuildScanCorrectly() { public void buildScan_FromExistingWithoutChange_ShouldCopy() { // Arrange Scan existingScan = - new Scan(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConsistency(Consistency.EVENTUAL) - .withStart(startClusteringKey1) - .withEnd(endClusteringKey1) - .withOrdering(ordering1) - .withOrdering(ordering2) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1")); + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + Consistency.EVENTUAL, + ImmutableMap.of(), + Arrays.asList("pk1", "ck1"), + ImmutableSet.of(), + startClusteringKey1, + true, + endClusteringKey1, + true, + Arrays.asList(ordering1, ordering2), + 10); // Act Scan newScan = Scan.newBuilder(existingScan).build(); @@ -315,37 +352,103 @@ public void buildScan_FromExistingAndUpdateAllParameters_ShouldBuildScanWithUpda public void buildScan_FromExistingAndClearBoundaries_ShouldBuildScanWithoutBoundaries() { // Arrange Scan existingScan = - new Scan(partitionKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withStart(startClusteringKey1) - .withEnd(endClusteringKey1); + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + startClusteringKey1, + true, + endClusteringKey1, + true, + Collections.emptyList(), + 0); // Act Scan newScan = Scan.newBuilder(existingScan).clearStart().clearEnd().build(); // Assert assertThat(newScan) - .isEqualTo(new Scan(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + null, + false, + null, + false, + Collections.emptyList(), + 0)); } @Test public void buildScan_FromExistingAndClearNamespace_ShouldBuildScanWithoutNamespace() { // Arrange - Scan existingScan = new Scan(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1); + Scan existingScan = + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + null, + false, + null, + false, + Collections.emptyList(), + 0); // Act Scan newScan = Scan.newBuilder(existingScan).clearNamespace().build(); // Assert - assertThat(newScan).isEqualTo(new Scan(partitionKey1).forTable(TABLE_1)); + assertThat(newScan) + .isEqualTo( + new Scan( + null, + TABLE_1, + partitionKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + null, + false, + null, + false, + Collections.emptyList(), + 0)); } @Test public void buildScan_FromExistingWithUnsupportedOperation_ShouldThrowUnsupportedOperationException() { // Arrange - Scan existingScan = new Scan(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1); + Scan existingScan = + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + null, + false, + null, + false, + Collections.emptyList(), + 0); // Act Assert assertThatThrownBy(() -> Scan.newBuilder(existingScan).indexKey(indexKey1)) @@ -358,7 +461,17 @@ public void buildScanAll_WithMandatoryParameters_ShouldBuildScanWithMandatoryPar Scan actual = Scan.newBuilder().table(TABLE_1).all().build(); // Assert - assertThat(actual).isEqualTo(new ScanAll().forTable(TABLE_1)); + assertThat(actual) + .isEqualTo( + new ScanAll( + null, + TABLE_1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + Collections.emptyList(), + 0)); } @Test @@ -410,12 +523,15 @@ public void buildScanAll_ScanWithAllParameters_ShouldBuildScanCorrectly() { public void buildScanAll_FromExistingWithoutChange_ShouldCopy() { // Arrange Scan existingScan = - new ScanAll() - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConsistency(Consistency.EVENTUAL) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1")); + new ScanAll( + NAMESPACE_1, + TABLE_1, + Consistency.EVENTUAL, + ImmutableMap.of(), + Arrays.asList("pk1", "ck1"), + ImmutableSet.of(), + Collections.emptyList(), + 10); // Act Scan newScan = Scan.newBuilder(existingScan).build(); @@ -509,7 +625,16 @@ public void buildScanAll_FromExistingWithoutChange_ShouldCopy() { public void buildScanAll_FromExistingWithUnsupportedOperation_ShouldThrowUnsupportedOperationException() { // Arrange - Scan existingScan = new ScanAll().forNamespace(NAMESPACE_1).forTable(TABLE_1); + Scan existingScan = + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + Collections.emptyList(), + 0); // Act Assert assertThatThrownBy(() -> Scan.newBuilder(existingScan).partitionKey(partitionKey1)) @@ -533,13 +658,32 @@ public void buildScanAll_FromExistingWithoutChange_ShouldCopy() { @Test public void buildScanAll_FromExistingAndClearNamespace_ShouldBuildScanWithoutNamespace() { // Arrange - ScanAll existingScan = new ScanAll().forNamespace(NAMESPACE_1).forTable(TABLE_1); + ScanAll existingScan = + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + Collections.emptyList(), + 0); // Act Scan newScan = Scan.newBuilder(existingScan).clearNamespace().build(); // Assert - assertThat(newScan).isEqualTo(new ScanAll().forTable(TABLE_1)); + assertThat(newScan) + .isEqualTo( + new ScanAll( + null, + TABLE_1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + Collections.emptyList(), + 0)); } @Test @@ -548,7 +692,17 @@ public void buildScanWithIndex_WithMandatoryParameters_ShouldBuildScanWithMandat Scan actual = Scan.newBuilder().table(TABLE_1).indexKey(indexKey1).build(); // Assert - assertThat(actual).isEqualTo(new ScanWithIndex(indexKey1).forTable(TABLE_1)); + assertThat(actual) + .isEqualTo( + new ScanWithIndex( + null, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + 0)); } @Test @@ -595,12 +749,15 @@ public void buildScanWithIndex_ScanWithAllParameters_ShouldBuildScanCorrectly() public void buildScanWithIndex_FromExistingWithoutChange_ShouldCopy() { // Arrange Scan existingScan = - new ScanWithIndex(indexKey1) - .forNamespace(NAMESPACE_1) - .forTable(TABLE_1) - .withConsistency(Consistency.EVENTUAL) - .withLimit(10) - .withProjections(Arrays.asList("pk1", "ck1")); + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + Consistency.EVENTUAL, + ImmutableMap.of(), + Arrays.asList("pk1", "ck1"), + ImmutableSet.of(), + 10); // Act Scan newScan = Scan.newBuilder(existingScan).build(); @@ -691,7 +848,16 @@ public void buildScanWithIndex_FromExistingWithoutChange_ShouldCopy() { public void buildScanWithIndex_FromExistingWithUnsupportedOperation_ShouldThrowUnsupportedOperationException() { // Arrange - Scan existingScan = new ScanWithIndex(indexKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1); + Scan existingScan = + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + 0); // Act Assert assertThatThrownBy(() -> Scan.newBuilder(existingScan).partitionKey(partitionKey1)) @@ -718,13 +884,31 @@ public void buildScanWithIndex_FromExistingWithoutChange_ShouldCopy() { public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWithoutNamespace() { // Arrange ScanWithIndex existingScan = - new ScanWithIndex(indexKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1); + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + 0); // Act Scan newScan = Scan.newBuilder(existingScan).clearNamespace().build(); // Assert - assertThat(newScan).isEqualTo(new ScanWithIndex(indexKey1).forTable(TABLE_1)); + assertThat(newScan) + .isEqualTo( + new ScanWithIndex( + null, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + 0)); } @Test @@ -1269,7 +1453,22 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith .build(); // Assert - assertThat(scan).isEqualTo(new Scan(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + assertThat(scan) + .isEqualTo( + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + null, + false, + null, + false, + Collections.emptyList(), + 0)); } @Test @@ -1286,7 +1485,22 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith .build(); // Assert - assertThat(scan).isEqualTo(new Scan(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + assertThat(scan) + .isEqualTo( + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + null, + false, + null, + false, + Collections.emptyList(), + 0)); } @Test @@ -1302,7 +1516,22 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith .build(); // Assert - assertThat(scan).isEqualTo(new Scan(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + assertThat(scan) + .isEqualTo( + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + null, + false, + null, + false, + Collections.emptyList(), + 0)); } @Test @@ -1318,7 +1547,22 @@ public void buildScanWithIndex_FromExistingAndClearNamespace_ShouldBuildScanWith .build(); // Assert - assertThat(scan).isEqualTo(new Scan(partitionKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + assertThat(scan) + .isEqualTo( + new Scan( + NAMESPACE_1, + TABLE_1, + partitionKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + null, + false, + null, + false, + Collections.emptyList(), + 0)); } @Test @@ -1758,7 +2002,16 @@ public void buildScanWithIndex_WithAndConditionSets_ShouldBuildScanWithCondition // Assert assertThat(scan) - .isEqualTo(new ScanWithIndex(indexKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + 0)); } @Test @@ -1776,7 +2029,16 @@ public void buildScanWithIndex_WithAndConditionSets_ShouldBuildScanWithCondition // Assert assertThat(scan) - .isEqualTo(new ScanWithIndex(indexKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + 0)); } @Test @@ -1793,7 +2055,16 @@ public void buildScanWithIndex_WithAndConditionSets_ShouldBuildScanWithCondition // Assert assertThat(scan) - .isEqualTo(new ScanWithIndex(indexKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + 0)); } @Test @@ -1810,7 +2081,16 @@ public void buildScanWithIndex_WithAndConditionSets_ShouldBuildScanWithCondition // Assert assertThat(scan) - .isEqualTo(new ScanWithIndex(indexKey1).forNamespace(NAMESPACE_1).forTable(TABLE_1)); + .isEqualTo( + new ScanWithIndex( + NAMESPACE_1, + TABLE_1, + indexKey1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + 0)); } @Test @@ -2871,7 +3151,17 @@ public void buildScanAll_ScanWithAndConditionSets_ShouldBuildScanWithConditionsC .build(); // Assert - assertThat(scan).isEqualTo(new ScanAll().forNamespace(NAMESPACE_1).forTable(TABLE_1)); + assertThat(scan) + .isEqualTo( + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + Collections.emptyList(), + 0)); } @Test @@ -2888,7 +3178,17 @@ public void buildScanAll_ScanWithAndConditionSets_ShouldBuildScanWithConditionsC .build(); // Assert - assertThat(scan).isEqualTo(new ScanAll().forNamespace(NAMESPACE_1).forTable(TABLE_1)); + assertThat(scan) + .isEqualTo( + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + Collections.emptyList(), + 0)); } @Test @@ -2904,7 +3204,17 @@ public void buildScanAll_ScanWithAndConditionSets_ShouldBuildScanWithConditionsC .build(); // Assert - assertThat(scan).isEqualTo(new ScanAll().forNamespace(NAMESPACE_1).forTable(TABLE_1)); + assertThat(scan) + .isEqualTo( + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + Collections.emptyList(), + 0)); } @Test @@ -2920,7 +3230,17 @@ public void buildScanAll_ScanWithAndConditionSets_ShouldBuildScanWithConditionsC .build(); // Assert - assertThat(scan).isEqualTo(new ScanAll().forNamespace(NAMESPACE_1).forTable(TABLE_1)); + assertThat(scan) + .isEqualTo( + new ScanAll( + NAMESPACE_1, + TABLE_1, + null, + ImmutableMap.of(), + Collections.emptyList(), + ImmutableSet.of(), + Collections.emptyList(), + 0)); } @Test diff --git a/core/src/test/java/com/scalar/db/common/checker/OperationCheckerTest.java b/core/src/test/java/com/scalar/db/common/checker/OperationCheckerTest.java index 41afffd154..e2a6e0febf 100644 --- a/core/src/test/java/com/scalar/db/common/checker/OperationCheckerTest.java +++ b/core/src/test/java/com/scalar/db/common/checker/OperationCheckerTest.java @@ -17,7 +17,6 @@ import com.scalar.db.api.Put; import com.scalar.db.api.Scan; import com.scalar.db.api.Scan.Ordering; -import com.scalar.db.api.ScanAll; import com.scalar.db.api.StorageInfo; import com.scalar.db.api.TableMetadata; import com.scalar.db.api.Update; @@ -27,14 +26,9 @@ import com.scalar.db.common.TableMetadataManager; import com.scalar.db.config.DatabaseConfig; import com.scalar.db.exception.storage.ExecutionException; -import com.scalar.db.io.BooleanValue; import com.scalar.db.io.DataType; -import com.scalar.db.io.DoubleValue; import com.scalar.db.io.IntColumn; -import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; -import com.scalar.db.io.Value; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -98,10 +92,13 @@ public void whenCheckingOperationWithWrongTable_shouldThrowIllegalArgumentExcept Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val2"); List projections = Arrays.asList(COL1, COL2, COL3); Get get = - new Get(partitionKey, clusteringKey) - .withProjections(projections) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .projections(projections) + .build(); // Returning null means table not found when(metadataManager.getTableMetadata(any())).thenReturn(null); @@ -118,10 +115,13 @@ public void whenCheckingGetOperationWithAllValidArguments_shouldNotThrowAnyExcep Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val2"); List projections = Arrays.asList(COL1, COL2, COL3); Get get = - new Get(partitionKey, clusteringKey) - .withProjections(projections) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .projections(projections) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(get)).doesNotThrowAnyException(); @@ -134,10 +134,13 @@ public void whenCheckingGetOperationWithInvalidProjections_shouldThrowIllegalArg Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val2"); List projections = Arrays.asList(COL1, COL2, "v4"); Get get = - new Get(partitionKey, clusteringKey) - .withProjections(projections) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .projections(projections) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(get)) @@ -152,10 +155,13 @@ public void whenCheckingGetOperationWithInvalidProjections_shouldThrowIllegalArg Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val2"); List projections = Arrays.asList(COL1, COL2, COL3); Get get = - new Get(partitionKey, clusteringKey) - .withProjections(projections) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .projections(projections) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(get)) @@ -170,10 +176,13 @@ public void whenCheckingGetOperationWithInvalidProjections_shouldThrowIllegalArg Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val2"); List projections = Arrays.asList(COL1, COL2, COL3); Get get = - new Get(partitionKey, clusteringKey) - .withProjections(projections) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .projections(projections) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(get)) @@ -188,10 +197,13 @@ public void whenCheckingGetOperationWithInvalidProjections_shouldThrowIllegalArg Key clusteringKey = Key.of(CKEY1, 2, "c3", "val2"); List projections = Arrays.asList(COL1, COL2, COL3); Get get = - new Get(partitionKey, clusteringKey) - .withProjections(projections) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .projections(projections) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(get)) @@ -206,10 +218,13 @@ public void whenCheckingGetOperationWithInvalidProjections_shouldThrowIllegalArg Key clusteringKey = Key.of(CKEY1, "2", CKEY2, "val2"); List projections = Arrays.asList(COL1, COL2, COL3); Get get = - new Get(partitionKey, clusteringKey) - .withProjections(projections) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .projections(projections) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(get)) @@ -221,13 +236,14 @@ public void whenCheckingGetOperationWithInvalidProjections_shouldThrowIllegalArg whenCheckingGetOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException() { // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); - Key clusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); Get get = - new Get(partitionKey, clusteringKey) - .withProjections(projections) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .projections(projections) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(get)) @@ -243,15 +259,17 @@ public void whenCheckingScanOperationWithAllValidArguments_shouldNotThrowAnyExce List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.asc(CKEY1)) - .withOrdering(Scan.Ordering.desc(CKEY2)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.asc(CKEY1)) + .ordering(Scan.Ordering.desc(CKEY2)) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(scan)).doesNotThrowAnyException(); @@ -261,20 +279,18 @@ public void whenCheckingScanOperationWithAllValidArguments_shouldNotThrowAnyExce public void whenCheckingScanOperationWithoutAnyClusteringKey_shouldNotThrowAnyException() { // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); - Key startClusteringKey = null; - Key endClusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.asc(CKEY1)) - .withOrdering(Scan.Ordering.desc(CKEY2)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.asc(CKEY1)) + .ordering(Scan.Ordering.desc(CKEY2)) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(scan)).doesNotThrowAnyException(); @@ -289,15 +305,17 @@ public void whenCheckingScanOperationWithPartialClusteringKey_shouldNotThrowAnyE List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.asc(CKEY1)) - .withOrdering(Scan.Ordering.desc(CKEY2)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.asc(CKEY1)) + .ordering(Scan.Ordering.desc(CKEY2)) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(scan)).doesNotThrowAnyException(); @@ -308,19 +326,19 @@ public void whenCheckingScanOperationWithoutAnyEndClusteringKey_shouldNotThrowAn // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key startClusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); - Key endClusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.asc(CKEY1)) - .withOrdering(Scan.Ordering.desc(CKEY2)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.asc(CKEY1)) + .ordering(Scan.Ordering.desc(CKEY2)) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(scan)).doesNotThrowAnyException(); @@ -335,15 +353,17 @@ public void whenCheckingScanOperationWithReverseOrderings_shouldNotThrowAnyExcep List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.desc(CKEY1)) - .withOrdering(Scan.Ordering.asc(CKEY2)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.desc(CKEY1)) + .ordering(Scan.Ordering.asc(CKEY2)) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(scan)).doesNotThrowAnyException(); @@ -358,14 +378,16 @@ public void whenCheckingScanOperationWithPartialOrdering_shouldNotThrowAnyExcept List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.asc(CKEY1)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.asc(CKEY1)) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(scan)).doesNotThrowAnyException(); @@ -380,13 +402,15 @@ public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyExceptio List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(scan)).doesNotThrowAnyException(); @@ -402,15 +426,17 @@ public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyExceptio List projections = Arrays.asList(COL1, COL2, "v4"); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.asc(CKEY1)) - .withOrdering(Scan.Ordering.desc(CKEY2)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.asc(CKEY1)) + .ordering(Scan.Ordering.desc(CKEY2)) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(scan)) @@ -427,15 +453,17 @@ public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyExceptio List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.asc(CKEY1)) - .withOrdering(Scan.Ordering.desc(CKEY2)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.asc(CKEY1)) + .ordering(Scan.Ordering.desc(CKEY2)) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(scan)) @@ -452,15 +480,17 @@ public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyExceptio List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.asc(CKEY1)) - .withOrdering(Scan.Ordering.desc(CKEY2)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.asc(CKEY1)) + .ordering(Scan.Ordering.desc(CKEY2)) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(scan)) @@ -477,15 +507,17 @@ public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyExceptio List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.asc(CKEY1)) - .withOrdering(Scan.Ordering.desc(CKEY2)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.asc(CKEY1)) + .ordering(Scan.Ordering.desc(CKEY2)) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(scan)) @@ -502,15 +534,17 @@ public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyExceptio List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.asc(CKEY1)) - .withOrdering(Scan.Ordering.desc(CKEY2)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.asc(CKEY1)) + .ordering(Scan.Ordering.desc(CKEY2)) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(scan)) @@ -527,15 +561,17 @@ public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyExceptio List projections = Arrays.asList(COL1, COL2, COL3); int limit = -10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.asc(CKEY1)) - .withOrdering(Scan.Ordering.desc(CKEY2)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.asc(CKEY1)) + .ordering(Scan.Ordering.desc(CKEY2)) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(scan)) @@ -551,15 +587,17 @@ public void whenCheckingScanOperationWithInvalidOrderings_shouldThrowIllegalArgu List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.desc(CKEY1)) - .withOrdering(Scan.Ordering.desc(CKEY2)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.desc(CKEY1)) + .ordering(Scan.Ordering.desc(CKEY2)) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(scan)) @@ -576,14 +614,16 @@ public void whenCheckingScanOperationWithInvalidOrderings_shouldThrowIllegalArgu List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withEnd(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.asc(CKEY2)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.asc(CKEY2)) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(scan)) @@ -595,16 +635,18 @@ public void whenCheckingPutOperationWithAllValidArguments_shouldNotThrowAnyExcep // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = ConditionBuilder.putIfNotExists(); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .condition(condition) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(put)).doesNotThrowAnyException(); @@ -617,13 +659,16 @@ public void whenCheckingPutOperationWithNullValue_shouldNotThrowAnyException() { Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); MutationCondition condition = ConditionBuilder.putIfNotExists(); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL1, 1) - .withValue(COL2, 0.1D) - .withBooleanValue(COL3, null) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1D) + .booleanValue(COL3, null) + .condition(condition) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(put)).doesNotThrowAnyException(); @@ -634,16 +679,16 @@ public void whenCheckingPutOperationWithoutAnyCondition_shouldNotThrowAnyExcepti // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); - MutationCondition condition = null; Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(put)).doesNotThrowAnyException(); @@ -655,16 +700,18 @@ public void whenCheckingPutOperationWithoutAnyCondition_shouldNotThrowAnyExcepti // Arrange Key partitionKey = Key.of(PKEY1, 1, "c3", "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = ConditionBuilder.putIfExists(); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -677,16 +724,18 @@ public void whenCheckingPutOperationWithoutAnyCondition_shouldNotThrowAnyExcepti // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, "c3", "val1"); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = ConditionBuilder.putIfExists(); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -698,17 +747,17 @@ public void whenCheckingPutOperationWithoutAnyCondition_shouldNotThrowAnyExcepti whenCheckingPutOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException() { // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); - Key clusteringKey = null; - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = ConditionBuilder.putIfNotExists(); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -720,16 +769,18 @@ public void whenCheckingPutOperationWithInvalidValues_shouldThrowIllegalArgument // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue("v4", true)); MutationCondition condition = ConditionBuilder.putIfExists(); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue("v4", true) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -741,16 +792,18 @@ public void whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgum // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); - List> values = - Arrays.asList( - new TextValue(COL1, "1"), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = ConditionBuilder.putIfNotExists(); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .textValue(COL1, "1") + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -763,17 +816,19 @@ public void whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgum // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = ConditionBuilder.putIf(ConditionBuilder.column(COL1).isEqualToText("1")).build(); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -786,20 +841,22 @@ public void whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgum // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = ConditionBuilder.putIf( ConditionBuilder.buildConditionalExpression( IntColumn.of(COL1, 1), Operator.IS_NULL)) .build(); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -812,20 +869,22 @@ public void whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgum // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = ConditionBuilder.putIf( ConditionBuilder.buildConditionalExpression( IntColumn.of(COL1, 1), Operator.IS_NOT_NULL)) .build(); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -838,16 +897,18 @@ public void whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgum // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = ConditionBuilder.deleteIfExists(); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -859,17 +920,19 @@ public void whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgu // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); MutationCondition condition = ConditionBuilder.deleteIf(ConditionBuilder.column("dummy").isEqualToText("dummy")).build(); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -882,14 +945,16 @@ public void whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgu // Arrange Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, null).build(); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val2"); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -902,14 +967,16 @@ public void whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgu // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, ""); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val2"); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -922,14 +989,16 @@ public void whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgu // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, null).build(); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -942,14 +1011,16 @@ public void whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgu // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, ""); - List> values = - Arrays.asList( - new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .doubleValue(COL2, 0.1) + .booleanValue(COL3, true) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -975,12 +1046,14 @@ public void whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgu Key partitionKey = Key.ofBlob(PKEY1, (byte[]) null); Key clusteringKey = Key.ofBlob(CKEY1, new byte[] {1, 1, 1}); - List> values = Collections.singletonList(new IntValue(COL1, 1)); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -1006,12 +1079,14 @@ public void whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgu Key partitionKey = Key.ofBlob(PKEY1, new byte[0]); Key clusteringKey = Key.ofBlob(CKEY1, new byte[] {1, 1, 1}); - List> values = Collections.singletonList(new IntValue(COL1, 1)); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -1037,12 +1112,14 @@ public void whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgu Key partitionKey = Key.ofBlob(PKEY1, new byte[] {1, 1, 1}); Key clusteringKey = Key.ofBlob(CKEY1, (byte[]) null); - List> values = Collections.singletonList(new IntValue(COL1, 1)); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -1068,12 +1145,14 @@ public void whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgu Key partitionKey = Key.ofBlob(PKEY1, new byte[] {1, 1, 1}); Key clusteringKey = Key.ofBlob(CKEY1, new byte[0]); - List> values = Collections.singletonList(new IntValue(COL1, 1)); Put put = - new Put(partitionKey, clusteringKey) - .withValues(values) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -1088,10 +1167,13 @@ public void whenCheckingDeleteOperationWithAllValidArguments_shouldNotThrowAnyEx MutationCondition condition = ConditionBuilder.deleteIf(ConditionBuilder.column(COL1).isEqualToInt(1)).build(); Delete delete = - new Delete(partitionKey, clusteringKey) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .condition(condition) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(delete)).doesNotThrowAnyException(); @@ -1102,12 +1184,13 @@ public void whenCheckingDeleteOperationWithoutAnyCondition_shouldNotThrowAnyExce // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); - MutationCondition condition = null; Delete delete = - new Delete(partitionKey, clusteringKey) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(delete)).doesNotThrowAnyException(); @@ -1121,10 +1204,13 @@ public void whenCheckingDeleteOperationWithoutAnyCondition_shouldNotThrowAnyExce Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); MutationCondition condition = ConditionBuilder.deleteIfExists(); Delete delete = - new Delete(partitionKey, clusteringKey) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(delete)) @@ -1139,10 +1225,13 @@ public void whenCheckingDeleteOperationWithoutAnyCondition_shouldNotThrowAnyExce Key clusteringKey = Key.of(CKEY1, 2, "c3", "val1"); MutationCondition condition = ConditionBuilder.deleteIfExists(); Delete delete = - new Delete(partitionKey, clusteringKey) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(delete)) @@ -1154,13 +1243,14 @@ public void whenCheckingDeleteOperationWithoutAnyCondition_shouldNotThrowAnyExce whenCheckingDeleteOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException() { // Arrange Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); - Key clusteringKey = null; MutationCondition condition = ConditionBuilder.deleteIfExists(); Delete delete = - new Delete(partitionKey, clusteringKey) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(delete)) @@ -1175,10 +1265,13 @@ public void whenCheckingDeleteOperationWithPutIfCondition_shouldThrowIllegalArgu MutationCondition condition = ConditionBuilder.putIf(ConditionBuilder.column("dummy").isEqualToText("dummy")).build(); Delete delete = - new Delete(partitionKey, clusteringKey) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(delete)) @@ -1193,10 +1286,13 @@ public void whenCheckingDeleteOperationWithPutIfCondition_shouldThrowIllegalArgu Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); MutationCondition condition = ConditionBuilder.putIfExists(); Delete delete = - new Delete(partitionKey, clusteringKey) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(delete)) @@ -1211,10 +1307,13 @@ public void whenCheckingDeleteOperationWithPutIfCondition_shouldThrowIllegalArgu Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); MutationCondition condition = ConditionBuilder.putIfNotExists(); Delete delete = - new Delete(partitionKey, clusteringKey) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(delete)) @@ -1230,10 +1329,13 @@ public void whenCheckingDeleteOperationWithPutIfCondition_shouldThrowIllegalArgu MutationCondition condition = ConditionBuilder.deleteIf(ConditionBuilder.column(COL1).isEqualToText("1")).build(); Delete delete = - new Delete(partitionKey, clusteringKey) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(delete)) @@ -1252,10 +1354,13 @@ public void whenCheckingDeleteOperationWithPutIfCondition_shouldThrowIllegalArgu IntColumn.of(COL1, 1), Operator.IS_NULL)) .build(); Delete delete = - new Delete(partitionKey, clusteringKey) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(delete)) @@ -1274,10 +1379,13 @@ public void whenCheckingDeleteOperationWithPutIfCondition_shouldThrowIllegalArgu IntColumn.of(COL1, 1), Operator.IS_NOT_NULL)) .build(); Delete delete = - new Delete(partitionKey, clusteringKey) - .withCondition(condition) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .condition(condition) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(delete)) @@ -1293,12 +1401,20 @@ public void whenCheckingMutateOperationWithAllValidArguments_shouldNotThrowAnyEx Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val1"); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL1, 1) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .build(); Delete delete = - new Delete(partitionKey, clusteringKey).forNamespace(NAMESPACE).forTable(TABLE_NAME); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(Arrays.asList(put, delete))) @@ -1325,12 +1441,20 @@ public void whenCheckingMutateOperationWithEmptyMutations_shouldThrowIllegalArgu Key partitionKey2 = Key.of(PKEY1, 2, PKEY2, "val2"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val3"); Put put = - new Put(partitionKey1, clusteringKey) - .withValue(COL1, 1) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey1) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .build(); Delete delete = - new Delete(partitionKey2, clusteringKey).forNamespace(NAMESPACE).forTable(TABLE_NAME); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey2) + .clusteringKey(clusteringKey) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(Arrays.asList(put, delete))) @@ -1347,11 +1471,20 @@ public void whenCheckingMutateOperationWithEmptyMutations_shouldThrowIllegalArgu Key partitionKey = Key.of(PKEY1, 1, PKEY2, "val1"); Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val3"); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL1, 1) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); - Delete delete = new Delete(partitionKey, clusteringKey).forNamespace("n2").forTable(TABLE_NAME); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL1, 1) + .build(); + Delete delete = + Delete.newBuilder() + .namespace("n2") + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(Arrays.asList(put, delete))) @@ -1433,13 +1566,14 @@ public void whenCheckingMutateOperationWithEmptyMutations_shouldThrowIllegalArgu public void whenCheckingGetOperationWithIndexedColumnAsPartitionKey_shouldNotThrowAnyException() { // Arrange Key partitionKey = Key.ofInt(COL1, 1); - Key clusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); Get get = - new Get(partitionKey, clusteringKey) - .withProjections(projections) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .projections(projections) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(get)).doesNotThrowAnyException(); @@ -1450,13 +1584,14 @@ public void whenCheckingGetOperationWithIndexedColumnAsPartitionKey_shouldNotThr whenCheckingGetOperationWithNonIndexedColumnAsPartitionKey_shouldThrowIllegalArgumentException() { // Arrange Key partitionKey = Key.ofDouble(COL2, 0.1d); - Key clusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); Get get = - new Get(partitionKey, clusteringKey) - .withProjections(projections) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .projections(projections) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(get)) @@ -1468,13 +1603,14 @@ public void whenCheckingGetOperationWithIndexedColumnAsPartitionKey_shouldNotThr whenCheckingGetOperationWithIndexedColumnAsPartitionKeyButWrongType_shouldThrowIllegalArgumentException() { // Arrange Key partitionKey = Key.ofText(COL1, "1"); - Key clusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); Get get = - new Get(partitionKey, clusteringKey) - .withProjections(projections) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .projections(projections) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(get)) @@ -1489,10 +1625,13 @@ public void whenCheckingGetOperationWithIndexedColumnAsPartitionKey_shouldNotThr Key clusteringKey = Key.of(CKEY1, 2, CKEY2, "val2"); List projections = Arrays.asList(COL1, COL2, COL3); Get get = - new Get(partitionKey, clusteringKey) - .withProjections(projections) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .projections(projections) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(get)) @@ -1570,18 +1709,16 @@ public void whenCheckingGetWithIndexOperationWithProperArguments_shouldNotThrowA whenCheckingScanOperationWithIndexedColumnAsPartitionKey_shouldNotThrowAnyException() { // Arrange Key partitionKey = Key.ofInt(COL1, 1); - Key startClusteringKey = null; - Key endClusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withStart(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .projections(projections) + .limit(limit) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(scan)).doesNotThrowAnyException(); @@ -1592,18 +1729,16 @@ public void whenCheckingGetWithIndexOperationWithProperArguments_shouldNotThrowA whenCheckingScanOperationWithNonIndexedColumnAsPartitionKey_shouldThrowIllegalArgumentException() { // Arrange Key partitionKey = Key.ofDouble(COL2, 0.1d); - Key startClusteringKey = null; - Key endClusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withStart(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .projections(projections) + .limit(limit) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(scan)) @@ -1615,18 +1750,16 @@ public void whenCheckingGetWithIndexOperationWithProperArguments_shouldNotThrowA whenCheckingScanOperationWithIndexedColumnAsPartitionKeyButWrongType_shouldThrowIllegalArgumentException() { // Arrange Key partitionKey = Key.ofText(COL1, "1"); - Key startClusteringKey = null; - Key endClusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withStart(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .projections(projections) + .limit(limit) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(scan)) @@ -1643,13 +1776,15 @@ public void whenCheckingGetWithIndexOperationWithProperArguments_shouldNotThrowA List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withStart(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .start(startClusteringKey) + .end(endClusteringKey) + .projections(projections) + .limit(limit) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(scan)) @@ -1661,19 +1796,17 @@ public void whenCheckingGetWithIndexOperationWithProperArguments_shouldNotThrowA whenCheckingScanOperationWithIndexedColumnAsPartitionKeyWithOrderings_shouldThrowIllegalArgumentException() { // Arrange Key partitionKey = Key.ofInt(COL1, 1); - Key startClusteringKey = null; - Key endClusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = - new Scan(partitionKey) - .withStart(startClusteringKey) - .withStart(endClusteringKey) - .withProjections(projections) - .withLimit(limit) - .withOrdering(Scan.Ordering.asc(CKEY1)) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .partitionKey(partitionKey) + .projections(projections) + .limit(limit) + .ordering(Scan.Ordering.asc(CKEY1)) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(scan)) @@ -1755,12 +1888,14 @@ public void whenCheckingScanAllOperationWithAllValidArguments_shouldNotThrowAnyE // Arrange List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; - ScanAll scanAll = - new ScanAll() - .withProjections(projections) - .withLimit(limit) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan scanAll = + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .all() + .projections(projections) + .limit(limit) + .build(); when(databaseConfig.isCrossPartitionScanEnabled()).thenReturn(true); operationChecker = new OperationChecker(databaseConfig, metadataManager, storageInfoProvider); @@ -1774,12 +1909,14 @@ public void whenCheckingScanAllOperationWithAllValidArguments_shouldNotThrowAnyE // Arrange List projections = Arrays.asList(COL1, COL2, COL3); int limit = -10; - ScanAll scanAll = - new ScanAll() - .withProjections(projections) - .withLimit(limit) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan scanAll = + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .all() + .projections(projections) + .limit(limit) + .build(); when(databaseConfig.isCrossPartitionScanEnabled()).thenReturn(true); operationChecker = new OperationChecker(databaseConfig, metadataManager, storageInfoProvider); @@ -1794,12 +1931,14 @@ public void whenCheckingScanAllOperationWithAllValidArguments_shouldNotThrowAnyE // Arrange List projections = Arrays.asList(COL1, COL2, "v4"); int limit = 10; - ScanAll scanAll = - new ScanAll() - .withProjections(projections) - .withLimit(limit) - .forNamespace(NAMESPACE) - .forTable(TABLE_NAME); + Scan scanAll = + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE_NAME) + .all() + .projections(projections) + .limit(limit) + .build(); when(databaseConfig.isCrossPartitionScanEnabled()).thenReturn(true); operationChecker = new OperationChecker(databaseConfig, metadataManager, storageInfoProvider); diff --git a/core/src/test/java/com/scalar/db/storage/cassandra/BatchHandlerTest.java b/core/src/test/java/com/scalar/db/storage/cassandra/BatchHandlerTest.java index c2d4c0da42..00485bad77 100644 --- a/core/src/test/java/com/scalar/db/storage/cassandra/BatchHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/cassandra/BatchHandlerTest.java @@ -22,6 +22,7 @@ import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.storage.NoMutationException; import com.scalar.db.io.Key; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.BeforeEach; @@ -81,23 +82,37 @@ private List prepareNonConditionalPuts() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey1 = Key.ofText(ANY_NAME_2, ANY_TEXT_2); Put put1 = - new Put(partitionKey, clusteringKey1) - .withValue(ANY_NAME_3, ANY_INT_1) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .intValue(ANY_NAME_3, ANY_INT_1) + .build(); Key clusteringKey2 = Key.ofText(ANY_NAME_2, ANY_TEXT_3); Put put2 = - new Put(partitionKey, clusteringKey2) - .withValue(ANY_NAME_3, ANY_INT_1) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .intValue(ANY_NAME_3, ANY_INT_1) + .build(); return Arrays.asList(put1, put2); } private List prepareConditionalPuts() { List mutations = prepareNonConditionalPuts(); - mutations.forEach(m -> m.withCondition(ConditionBuilder.putIfNotExists())); - return mutations; + List conditionalMutations = new ArrayList<>(); + for (Mutation m : mutations) { + if (m instanceof Put) { + conditionalMutations.add( + Put.newBuilder((Put) m).condition(ConditionBuilder.putIfNotExists()).build()); + } else { + conditionalMutations.add(m); + } + } + return conditionalMutations; } private BatchHandler prepareSpiedBatchHandler() { @@ -145,7 +160,9 @@ public void handle_CorrectHandlerAndConditionalPutAndUpdateGiven_ShouldExecutePr // Arrange configureBehavior(); mutations = prepareConditionalPuts(); - mutations.get(1).withCondition(ConditionBuilder.putIfExists()); + mutations.set( + 1, + Put.newBuilder((Put) mutations.get(1)).condition(ConditionBuilder.putIfExists()).build()); when(session.execute(any(Statement.class))).thenReturn(results); when(results.wasApplied()).thenReturn(true); @@ -164,7 +181,11 @@ public void handle_CorrectHandlerAndAtLeastOneConditionalPutGiven_ShouldSetConsi // Arrange configureBehavior(); mutations = prepareNonConditionalPuts(); - mutations.get(1).withCondition(ConditionBuilder.putIfNotExists()); + mutations.set( + 1, + Put.newBuilder((Put) mutations.get(1)) + .condition(ConditionBuilder.putIfNotExists()) + .build()); when(session.execute(any(Statement.class))).thenReturn(results); when(results.wasApplied()).thenReturn(true); spy = prepareSpiedBatchHandler(); diff --git a/core/src/test/java/com/scalar/db/storage/cassandra/DeleteStatementHandlerTest.java b/core/src/test/java/com/scalar/db/storage/cassandra/DeleteStatementHandlerTest.java index 9b24b758c7..1e2041ff2f 100644 --- a/core/src/test/java/com/scalar/db/storage/cassandra/DeleteStatementHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/cassandra/DeleteStatementHandlerTest.java @@ -54,21 +54,33 @@ public void setUp() throws Exception { private Delete prepareDelete() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); - return new Delete(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + return Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); } private Delete prepareDeleteWithClusteringKey() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Delete(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private Delete prepareDeleteWithReservedKeywords() { Key partitionKey = Key.ofText("from", ANY_TEXT_1); Key clusteringKey = Key.ofText("to", ANY_TEXT_2); - return new Delete(partitionKey, clusteringKey).forNamespace("keyspace").forTable("table"); + return Delete.newBuilder() + .namespace("keyspace") + .table("table") + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private void configureBehavior(String expected) { @@ -199,8 +211,10 @@ public void prepare_DeleteOperationWithIfExistsGiven_ShouldPrepareProperQuery() "IF EXISTS;" }); configureBehavior(expected); - del = prepareDeleteWithClusteringKey(); - del.withCondition(ConditionBuilder.deleteIfExists()); + del = + Delete.newBuilder(prepareDeleteWithClusteringKey()) + .condition(ConditionBuilder.deleteIfExists()) + .build(); // Act handler.prepare(del); @@ -230,11 +244,14 @@ public void prepare_DeleteOperationWithIfGiven_ShouldPrepareProperQuery() { ANY_NAME_4 + "=?;" }); configureBehavior(expected); - del = prepareDeleteWithClusteringKey(); - del.withCondition( - ConditionBuilder.deleteIf(ConditionBuilder.column(ANY_NAME_3).isEqualToInt(ANY_INT_1)) - .and(ConditionBuilder.column(ANY_NAME_4).isEqualToText(ANY_TEXT_3)) - .build()); + del = + Delete.newBuilder(prepareDeleteWithClusteringKey()) + .condition( + ConditionBuilder.deleteIf( + ConditionBuilder.column(ANY_NAME_3).isEqualToInt(ANY_INT_1)) + .and(ConditionBuilder.column(ANY_NAME_4).isEqualToText(ANY_TEXT_3)) + .build()) + .build(); // Act handler.prepare(del); @@ -249,7 +266,7 @@ public void prepare_DeleteOperationWithIfExistsGiven_ShouldCallAccept() { configureBehavior(null); del = prepareDeleteWithClusteringKey(); DeleteIfExists deleteIfExists = spy(ConditionBuilder.deleteIfExists()); - del.withCondition(deleteIfExists); + del = Delete.newBuilder(del).condition(deleteIfExists).build(); // Act handler.prepare(del); @@ -267,7 +284,7 @@ public void prepare_DeleteOperationWithIfGiven_ShouldCallAccept() { spy( ConditionBuilder.deleteIf(ConditionBuilder.column(ANY_NAME_4).isEqualToInt(ANY_INT_2)) .build()); - del.withCondition(deleteIf); + del = Delete.newBuilder(del).condition(deleteIf).build(); // Act handler.prepare(del); @@ -294,11 +311,14 @@ public void bind_DeleteOperationGiven_ShouldBindProperly() { public void bind_DeleteOperationWithIfGiven_ShouldBindProperly() { // Arrange configureBehavior(null); - del = prepareDeleteWithClusteringKey(); - del.withCondition( - ConditionBuilder.deleteIf(ConditionBuilder.column(ANY_NAME_3).isEqualToInt(ANY_INT_1)) - .and(ConditionBuilder.column(ANY_NAME_4).isEqualToText(ANY_TEXT_3)) - .build()); + del = + Delete.newBuilder(prepareDeleteWithClusteringKey()) + .condition( + ConditionBuilder.deleteIf( + ConditionBuilder.column(ANY_NAME_3).isEqualToInt(ANY_INT_1)) + .and(ConditionBuilder.column(ANY_NAME_4).isEqualToText(ANY_TEXT_3)) + .build()) + .build(); // Act handler.bind(prepared, del); @@ -314,8 +334,10 @@ public void bind_DeleteOperationWithIfGiven_ShouldBindProperly() { public void setConsistency_DeleteOperationWithStrongConsistencyGiven_ShouldBoundWithQuorum() { // Arrange configureBehavior(null); - del = prepareDeleteWithClusteringKey(); - del.withConsistency(Consistency.SEQUENTIAL); + del = + Delete.newBuilder(prepareDeleteWithClusteringKey()) + .consistency(Consistency.SEQUENTIAL) + .build(); // Act handler.setConsistency(bound, del); @@ -328,8 +350,10 @@ public void setConsistency_DeleteOperationWithStrongConsistencyGiven_ShouldBound public void setConsistency_DeleteOperationWithEventualConsistencyGiven_ShouldPrepareWithOne() { // Arrange configureBehavior(null); - del = prepareDeleteWithClusteringKey(); - del.withConsistency(Consistency.EVENTUAL); + del = + Delete.newBuilder(prepareDeleteWithClusteringKey()) + .consistency(Consistency.EVENTUAL) + .build(); // Act handler.setConsistency(bound, del); @@ -343,8 +367,10 @@ public void setConsistency_DeleteOperationWithEventualConsistencyGiven_ShouldPre setConsistency_DeleteOperationWithLinearizableConsistencyGiven_ShouldPrepareWithQuorum() { // Arrange configureBehavior(null); - del = prepareDeleteWithClusteringKey(); - del.withConsistency(Consistency.LINEARIZABLE); + del = + Delete.newBuilder(prepareDeleteWithClusteringKey()) + .consistency(Consistency.LINEARIZABLE) + .build(); // Act handler.setConsistency(bound, del); @@ -357,8 +383,11 @@ public void setConsistency_DeleteOperationWithEventualConsistencyGiven_ShouldPre public void setConsistency_DeleteOperationWithIfExistsGiven_ShouldPrepareWithQuorumAndSerial() { // Arrange configureBehavior(null); - del = prepareDeleteWithClusteringKey(); - del.withCondition(ConditionBuilder.deleteIfExists()).withConsistency(Consistency.EVENTUAL); + del = + Delete.newBuilder(prepareDeleteWithClusteringKey()) + .condition(ConditionBuilder.deleteIfExists()) + .consistency(Consistency.EVENTUAL) + .build(); // Act handler.setConsistency(bound, del); @@ -372,12 +401,15 @@ public void setConsistency_DeleteOperationWithIfExistsGiven_ShouldPrepareWithQuo public void setConsistency_DeleteOperationWithIfGiven_ShouldPrepareWithQuorumAndSerial() { // Arrange configureBehavior(null); - del = prepareDeleteWithClusteringKey(); - del.withCondition( - ConditionBuilder.deleteIf(ConditionBuilder.column(ANY_NAME_3).isEqualToInt(ANY_INT_1)) - .and(ConditionBuilder.column(ANY_NAME_4).isEqualToText(ANY_TEXT_3)) - .build()) - .withConsistency(Consistency.EVENTUAL); + del = + Delete.newBuilder(prepareDeleteWithClusteringKey()) + .condition( + ConditionBuilder.deleteIf( + ConditionBuilder.column(ANY_NAME_3).isEqualToInt(ANY_INT_1)) + .and(ConditionBuilder.column(ANY_NAME_4).isEqualToText(ANY_TEXT_3)) + .build()) + .consistency(Consistency.EVENTUAL) + .build(); // Act handler.setConsistency(bound, del); diff --git a/core/src/test/java/com/scalar/db/storage/cassandra/InsertStatementHandlerTest.java b/core/src/test/java/com/scalar/db/storage/cassandra/InsertStatementHandlerTest.java index 08973787e3..2fc05a7aff 100644 --- a/core/src/test/java/com/scalar/db/storage/cassandra/InsertStatementHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/cassandra/InsertStatementHandlerTest.java @@ -61,29 +61,37 @@ public void setUp() throws Exception { private Put preparePut() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); - return new Put(partitionKey) - .withValue(ANY_NAME_2, ANY_INT_1) - .withValue(ANY_NAME_3, ANY_INT_2) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .intValue(ANY_NAME_2, ANY_INT_1) + .intValue(ANY_NAME_3, ANY_INT_2) + .build(); } private Put preparePutWithClusteringKey() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Put(partitionKey, clusteringKey) - .withValue(ANY_NAME_3, ANY_INT_1) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(ANY_NAME_3, ANY_INT_1) + .build(); } private Put preparePutWithReservedKeywords() { Key partitionKey = Key.ofText("from", ANY_TEXT_1); Key clusteringKey = Key.ofText("to", ANY_TEXT_2); - return new Put(partitionKey, clusteringKey) - .withValue("one", ANY_INT_1) - .forNamespace("keyspace") - .forTable("table"); + return Put.newBuilder() + .namespace("keyspace") + .table("table") + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue("one", ANY_INT_1) + .build(); } private InsertStatementHandler prepareSpiedInsertStatementHandler() { @@ -215,8 +223,10 @@ public void prepare_PutOperationWithIfNotExistsGiven_ShouldPrepareProperQuery() "IF NOT EXISTS;" }); configureBehavior(expected); - put = preparePutWithClusteringKey(); - put.withCondition(ConditionBuilder.putIfNotExists()); + put = + Put.newBuilder(preparePutWithClusteringKey()) + .condition(ConditionBuilder.putIfNotExists()) + .build(); // Act handler.prepare(put); @@ -231,7 +241,7 @@ public void prepare_PutOperationWithIfNotExistsGiven_ShouldCallAccept() { configureBehavior(null); put = preparePutWithClusteringKey(); PutIfNotExists putIfNotExists = spy(ConditionBuilder.putIfNotExists()); - put.withCondition(putIfNotExists); + put = Put.newBuilder(put).condition(putIfNotExists).build(); // Act handler.prepare(put); @@ -259,8 +269,7 @@ public void bind_PutOperationGiven_ShouldBindProperly() { public void bind_PutOperationWithNullValueGiven_ShouldBindProperly() { // Arrange configureBehavior(null); - put = preparePutWithClusteringKey(); - put.withIntValue(ANY_NAME_3, null); + put = Put.newBuilder(preparePutWithClusteringKey()).intValue(ANY_NAME_3, null).build(); // Act handler.bind(prepared, put); @@ -275,8 +284,7 @@ public void bind_PutOperationWithNullValueGiven_ShouldBindProperly() { public void setConsistency_PutOperationWithStrongConsistencyGiven_ShouldPrepareWithQuorum() { // Arrange configureBehavior(null); - put = preparePutWithClusteringKey(); - put.withConsistency(Consistency.SEQUENTIAL); + put = Put.newBuilder(preparePutWithClusteringKey()).consistency(Consistency.SEQUENTIAL).build(); // Act handler.setConsistency(bound, put); @@ -289,8 +297,7 @@ public void setConsistency_PutOperationWithStrongConsistencyGiven_ShouldPrepareW public void setConsistency_PutOperationWithEventualConsistencyGiven_ShouldPrepareWithOne() { // Arrange configureBehavior(null); - put = preparePutWithClusteringKey(); - put.withConsistency(Consistency.EVENTUAL); + put = Put.newBuilder(preparePutWithClusteringKey()).consistency(Consistency.EVENTUAL).build(); // Act handler.setConsistency(bound, put); @@ -304,8 +311,8 @@ public void setConsistency_PutOperationWithEventualConsistencyGiven_ShouldPrepar setConsistency_PutOperationWithLinearizableConsistencyGiven_ShouldPrepareWithQuorum() { // Arrange configureBehavior(null); - put = preparePutWithClusteringKey(); - put.withConsistency(Consistency.LINEARIZABLE); + put = + Put.newBuilder(preparePutWithClusteringKey()).consistency(Consistency.LINEARIZABLE).build(); // Act handler.setConsistency(bound, put); @@ -318,8 +325,11 @@ public void setConsistency_PutOperationWithEventualConsistencyGiven_ShouldPrepar public void setConsistency_PutOperationWithIfNotExistsGiven_ShouldPrepareWithQuorumAndSerial() { // Arrange configureBehavior(null); - put = preparePutWithClusteringKey(); - put.withCondition(ConditionBuilder.putIfNotExists()).withConsistency(Consistency.EVENTUAL); + put = + Put.newBuilder(preparePutWithClusteringKey()) + .condition(ConditionBuilder.putIfNotExists()) + .consistency(Consistency.EVENTUAL) + .build(); // Act handler.setConsistency(bound, put); @@ -332,8 +342,10 @@ public void setConsistency_PutOperationWithIfNotExistsGiven_ShouldPrepareWithQuo @Test public void handle_WTEWithCasThrown_ShouldThrowExecutionException() { // Arrange - put = preparePutWithClusteringKey(); - put.withCondition(ConditionBuilder.putIfNotExists()); + put = + Put.newBuilder(preparePutWithClusteringKey()) + .condition(ConditionBuilder.putIfNotExists()) + .build(); spy = prepareSpiedInsertStatementHandler(); WriteTimeoutException toThrow = mock(WriteTimeoutException.class); @@ -349,8 +361,10 @@ public void handle_WTEWithCasThrown_ShouldThrowExecutionException() { @Test public void handle_PutWithConditionGivenAndWTEWithSimpleThrown_ShouldThrowExecutionException() { // Arrange - put = preparePutWithClusteringKey(); - put.withCondition(ConditionBuilder.putIfNotExists()); + put = + Put.newBuilder(preparePutWithClusteringKey()) + .condition(ConditionBuilder.putIfNotExists()) + .build(); spy = prepareSpiedInsertStatementHandler(); WriteTimeoutException toThrow = mock(WriteTimeoutException.class); @@ -398,8 +412,10 @@ public void handle_DriverExceptionThrown_ShouldThrowExecutionException() { @Test public void handle_PutWithConditionButNoMutationApplied_ShouldThrowProperExecutionException() { // Arrange - put = preparePutWithClusteringKey(); - put.withCondition(ConditionBuilder.putIfNotExists()); + put = + Put.newBuilder(preparePutWithClusteringKey()) + .condition(ConditionBuilder.putIfNotExists()) + .build(); spy = prepareSpiedInsertStatementHandler(); ResultSet results = mock(ResultSet.class); @@ -415,8 +431,10 @@ public void handle_PutWithConditionButNoMutationApplied_ShouldThrowProperExecuti @Test public void handle_PutWithoutConditionButNoMutationApplied_ShouldThrowProperExecutionException() { // Arrange - put = preparePutWithClusteringKey(); - put.withCondition(ConditionBuilder.putIfNotExists()); + put = + Put.newBuilder(preparePutWithClusteringKey()) + .condition(ConditionBuilder.putIfNotExists()) + .build(); spy = prepareSpiedInsertStatementHandler(); ResultSet results = mock(ResultSet.class); diff --git a/core/src/test/java/com/scalar/db/storage/cassandra/SelectStatementHandlerTest.java b/core/src/test/java/com/scalar/db/storage/cassandra/SelectStatementHandlerTest.java index c89e300300..33e8cf2a14 100644 --- a/core/src/test/java/com/scalar/db/storage/cassandra/SelectStatementHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/cassandra/SelectStatementHandlerTest.java @@ -21,10 +21,8 @@ import com.scalar.db.api.Operation; import com.scalar.db.api.Put; import com.scalar.db.api.Scan; -import com.scalar.db.api.ScanAll; import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.io.Key; -import java.util.Arrays; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -61,30 +59,46 @@ public void setUp() throws Exception { private Get prepareGet() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); - return new Get(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); } private Get prepareGetWithClusteringKey() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Get(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private Get prepareGetWithReservedKeywords() { Key partitionKey = Key.ofText("from", ANY_TEXT_1); Key clusteringKey = Key.ofText("to", ANY_TEXT_2); - return new Get(partitionKey, clusteringKey).forNamespace("keyspace").forTable("table"); + return Get.newBuilder() + .namespace("keyspace") + .table("table") + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private Scan prepareScan() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); - return new Scan(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + return Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); } - private ScanAll prepareScanAll() { - return new ScanAll().forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + private Scan prepareScanAll() { + return Scan.newBuilder().namespace(ANY_NAMESPACE_NAME).table(ANY_TABLE_NAME).all().build(); } private void configureBehavior(String expected) { @@ -210,8 +224,7 @@ public void prepare_GetOperationWithSomeProjectionGiven_ShouldPrepareProperQuery ANY_NAME_2 + "=?;", }); configureBehavior(expected); - get = prepareGetWithClusteringKey(); - get.withProjection(ANY_NAME_1); + get = Get.newBuilder(prepareGetWithClusteringKey()).projection(ANY_NAME_1).build(); // Act handler.prepare(get); @@ -238,8 +251,11 @@ public void prepare_ScanOperationWithSingleClusteringKey_ShouldPrepareProperQuer ANY_NAME_2 + "<=?;", }); configureBehavior(expected); - scan = prepareScan(); - scan.withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2)).withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_3)); + scan = + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_3)) + .build(); // Act handler.prepare(scan); @@ -268,9 +284,11 @@ public void prepare_ScanOperationWithMultipleClusteringKeys_ShouldPrepareProperQ ANY_NAME_3 + "<=?;", }); configureBehavior(expected); - scan = prepareScan(); - scan.withStart(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3)) - .withEnd(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4)); + scan = + Scan.newBuilder(prepareScan()) + .start(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3)) + .end(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4)) + .build(); // Act handler.prepare(scan); @@ -297,9 +315,11 @@ public void prepare_ScanOperationWithNeitherInclusive_ShouldPrepareProperQuery() ANY_NAME_2 + " handler.handle(Arrays.asList(put, delete))) diff --git a/core/src/test/java/com/scalar/db/storage/cosmos/CosmosMutationTest.java b/core/src/test/java/com/scalar/db/storage/cosmos/CosmosMutationTest.java index 34adc2ea41..e30b3f70ce 100644 --- a/core/src/test/java/com/scalar/db/storage/cosmos/CosmosMutationTest.java +++ b/core/src/test/java/com/scalar/db/storage/cosmos/CosmosMutationTest.java @@ -45,19 +45,25 @@ public void setUp() throws Exception { private Put preparePut() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Put(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_INT_1) - .withValue(ANY_NAME_4, ANY_INT_2); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(ANY_NAME_3, ANY_INT_1) + .intValue(ANY_NAME_4, ANY_INT_2) + .build(); } private Delete prepareDelete() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Delete(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } @Test @@ -84,7 +90,7 @@ public void makeRecord_PutGiven_ShouldReturnWithValues() { public void makeRecord_PutWithNullValueGiven_ShouldReturnWithValues() { // Arrange Put put = preparePut(); - put.withIntValue(ANY_NAME_3, null); + put = Put.newBuilder(put).intValue(ANY_NAME_3, null).build(); CosmosMutation cosmosMutation = new CosmosMutation(put, metadata); String id = cosmosMutation.getId(); String concatenatedPartitionKey = cosmosMutation.getConcatenatedPartitionKey(); @@ -138,7 +144,11 @@ public void makeConditionalQuery_MutationWithoutClusteringKeyGiven_ShouldReturnQ Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Delete delete = - new Delete(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); CosmosMutation cosmosMutation = new CosmosMutation(delete, metadata); String concatenatedPartitionKey = cosmosMutation.getConcatenatedPartitionKey(); @@ -163,9 +173,12 @@ public void makeConditionalQuery_MutationWithoutAllClusteringKeyGiven_ShouldRetu Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); Delete delete = - new Delete(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); CosmosMutation cosmosMutation = new CosmosMutation(delete, metadata); String concatenatedPartitionKey = cosmosMutation.getConcatenatedPartitionKey(); @@ -194,7 +207,7 @@ public void makeConditionalQuery_MutationWithConditionsGiven_ShouldReturnQuery() ConditionBuilder.column(ANY_NAME_3).isEqualToInt(ANY_INT_VALUE.get())) .and(ConditionBuilder.column(ANY_NAME_4).isGreaterThanInt(ANY_INT_VALUE.get())) .build(); - Put put = preparePut().withCondition(conditions); + Put put = Put.newBuilder(preparePut()).condition(conditions).build(); CosmosMutation cosmosMutation = new CosmosMutation(put, metadata); String id = cosmosMutation.getId(); diff --git a/core/src/test/java/com/scalar/db/storage/cosmos/CosmosOperationTest.java b/core/src/test/java/com/scalar/db/storage/cosmos/CosmosOperationTest.java index 8e6a3918a4..4e8c1ebe03 100644 --- a/core/src/test/java/com/scalar/db/storage/cosmos/CosmosOperationTest.java +++ b/core/src/test/java/com/scalar/db/storage/cosmos/CosmosOperationTest.java @@ -54,7 +54,12 @@ public void isPrimaryKeySpecified_PrimaryKeyWithoutClusteringKeyGiven_ShouldRetu when(metadata.getClusteringKeyNames()).thenReturn(new LinkedHashSet<>()); Key partitionKey = Key.of(ANY_NAME_1, ANY_TEXT_1, ANY_NAME_3, ANY_INT_1); - Get get = new Get(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + Get get = + Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); CosmosOperation cosmosOperation = new CosmosOperation(get, metadata); // Act @@ -73,9 +78,12 @@ public void isPrimaryKeySpecified_PrimaryKeyWithClusteringKeyGiven_ShouldReturnT Key partitionKey = Key.of(ANY_NAME_1, ANY_TEXT_1, ANY_NAME_3, ANY_INT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); Get get = - new Get(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); CosmosOperation cosmosOperation = new CosmosOperation(get, metadata); // Act @@ -93,7 +101,11 @@ public void isPrimaryKeySpecified_NoClusteringKeyGiven_ShouldReturnTrue() { Key partitionKey = Key.of(ANY_NAME_1, ANY_TEXT_1, ANY_NAME_3, ANY_INT_1); Delete delete = - new Delete(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); CosmosOperation cosmosOperation = new CosmosOperation(delete, metadata); // Act @@ -111,7 +123,12 @@ public void getConcatenatedPartitionKey_MultipleKeysGiven_ShouldReturnConcatenat Key partitionKey = Key.of(ANY_NAME_1, ANY_TEXT_1, ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_INT_1); - Get get = new Get(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + Get get = + Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); CosmosOperation cosmosOperation = new CosmosOperation(get, metadata); // Act @@ -129,7 +146,12 @@ public void getCosmosPartitionKey_MultipleKeysGiven_ShouldReturnPartitionKey() { Key partitionKey = Key.of(ANY_NAME_1, ANY_TEXT_1, ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_INT_1); - Get get = new Get(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + Get get = + Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); CosmosOperation cosmosOperation = new CosmosOperation(get, metadata); // Act @@ -150,9 +172,12 @@ public void getId_MultipleKeysGiven_ShouldReturnConcatenatedPartitionKey() { Key partitionKey = Key.of(ANY_NAME_1, ANY_TEXT_1, ANY_NAME_3, ANY_INT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); Get get = - new Get(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); CosmosOperation cosmosOperation = new CosmosOperation(get, metadata); // Act diff --git a/core/src/test/java/com/scalar/db/storage/cosmos/DeleteStatementHandlerTest.java b/core/src/test/java/com/scalar/db/storage/cosmos/DeleteStatementHandlerTest.java index e574de8c82..14050a3e32 100644 --- a/core/src/test/java/com/scalar/db/storage/cosmos/DeleteStatementHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/cosmos/DeleteStatementHandlerTest.java @@ -85,9 +85,12 @@ private Delete prepareDelete() { Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); id = ANY_TEXT_1 + ":" + ANY_TEXT_2; cosmosPartitionKey = new PartitionKey(ANY_TEXT_1); - return new Delete(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } @Test @@ -148,7 +151,11 @@ public void handle_DeleteWithoutClusteringKeyGiven_ShouldCallStoredProcedure() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); cosmosPartitionKey = new PartitionKey(ANY_TEXT_1); Delete delete = - new Delete(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); CosmosMutation cosmosMutation = new CosmosMutation(delete, metadata); String query = cosmosMutation.makeConditionalQuery(); @@ -174,7 +181,8 @@ public void handle_DeleteWithConditionsGiven_ShouldCallStoredProcedure() { when(storedProcedure.execute(anyList(), any(CosmosStoredProcedureRequestOptions.class))) .thenReturn(spResponse); - Delete delete = prepareDelete().withCondition(ConditionBuilder.deleteIfExists()); + Delete delete = + Delete.newBuilder(prepareDelete()).condition(ConditionBuilder.deleteIfExists()).build(); CosmosMutation cosmosMutation = new CosmosMutation(delete, metadata); String query = cosmosMutation.makeConditionalQuery(); @@ -202,7 +210,8 @@ public void handle_CosmosExceptionWithPreconditionFailed_ShouldThrowNoMutationEx .execute(anyList(), any(CosmosStoredProcedureRequestOptions.class)); when(toThrow.getSubStatusCode()).thenReturn(CosmosErrorCode.PRECONDITION_FAILED.get()); - Delete delete = prepareDelete().withCondition(ConditionBuilder.deleteIfExists()); + Delete delete = + Delete.newBuilder(prepareDelete()).condition(ConditionBuilder.deleteIfExists()).build(); // Act Assert assertThatThrownBy(() -> handler.handle(delete)).isInstanceOf(NoMutationException.class); @@ -218,7 +227,8 @@ public void handle_DeleteWithConditionCosmosExceptionThrown_ShouldThrowExecution .when(storedProcedure) .execute(anyList(), any(CosmosStoredProcedureRequestOptions.class)); - Delete delete = prepareDelete().withCondition(ConditionBuilder.deleteIfExists()); + Delete delete = + Delete.newBuilder(prepareDelete()).condition(ConditionBuilder.deleteIfExists()).build(); // Act Assert assertThatThrownBy(() -> handler.handle(delete)) diff --git a/core/src/test/java/com/scalar/db/storage/cosmos/PutStatementHandlerTest.java b/core/src/test/java/com/scalar/db/storage/cosmos/PutStatementHandlerTest.java index 1cbc475c20..0c37ad19d9 100644 --- a/core/src/test/java/com/scalar/db/storage/cosmos/PutStatementHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/cosmos/PutStatementHandlerTest.java @@ -77,11 +77,14 @@ public void setUp() throws Exception { private Put preparePut() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Put(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_INT_1) - .withValue(ANY_NAME_4, ANY_INT_2); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(ANY_NAME_3, ANY_INT_1) + .intValue(ANY_NAME_4, ANY_INT_2) + .build(); } @Test @@ -122,11 +125,13 @@ public void handle_PutWithoutClusteringKeyGiven_ShouldCallStoredProcedure() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Put put = - new Put(partitionKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_INT_1) - .withValue(ANY_NAME_4, ANY_INT_2); + Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .intValue(ANY_NAME_3, ANY_INT_1) + .intValue(ANY_NAME_4, ANY_INT_2) + .build(); CosmosMutation cosmosMutation = new CosmosMutation(put, metadata); Record record = cosmosMutation.makeRecord(); String query = cosmosMutation.makeConditionalQuery(); @@ -170,7 +175,7 @@ public void handle_PutIfNotExistsGiven_ShouldCallStoredProcedure() { .thenReturn(spResponse); when(spResponse.getResponseAsString()).thenReturn("true"); - Put put = preparePut().withCondition(ConditionBuilder.putIfNotExists()); + Put put = Put.newBuilder(preparePut()).condition(ConditionBuilder.putIfNotExists()).build(); CosmosMutation cosmosMutation = new CosmosMutation(put, metadata); Record record = cosmosMutation.makeRecord(); String query = cosmosMutation.makeConditionalQuery(); @@ -197,7 +202,7 @@ public void handle_PutIfExistsGiven_ShouldCallStoredProcedure() { when(storedProcedure.execute(anyList(), any(CosmosStoredProcedureRequestOptions.class))) .thenReturn(spResponse); - Put put = preparePut().withCondition(ConditionBuilder.putIfExists()); + Put put = Put.newBuilder(preparePut()).condition(ConditionBuilder.putIfExists()).build(); CosmosMutation cosmosMutation = new CosmosMutation(put, metadata); Record record = cosmosMutation.makeRecord(); String query = cosmosMutation.makeConditionalQuery(); @@ -226,7 +231,7 @@ public void handle_CosmosExceptionWithPreconditionFailed_ShouldThrowNoMutationEx .execute(anyList(), any(CosmosStoredProcedureRequestOptions.class)); when(toThrow.getSubStatusCode()).thenReturn(CosmosErrorCode.PRECONDITION_FAILED.get()); - Put put = preparePut().withCondition(ConditionBuilder.putIfExists()); + Put put = Put.newBuilder(preparePut()).condition(ConditionBuilder.putIfExists()).build(); // Act Assert assertThatThrownBy(() -> handler.handle(put)).isInstanceOf(NoMutationException.class); @@ -243,7 +248,7 @@ public void handle_PutWithConditionCosmosExceptionThrown_ShouldThrowExecutionExc .execute(anyList(), any(CosmosStoredProcedureRequestOptions.class)); when(toThrow.getSubStatusCode()).thenReturn(CosmosErrorCode.RETRY_WITH.get()); - Put put = preparePut().withCondition(ConditionBuilder.putIfExists()); + Put put = Put.newBuilder(preparePut()).condition(ConditionBuilder.putIfExists()).build(); // Act Assert assertThatThrownBy(() -> handler.handle(put)) diff --git a/core/src/test/java/com/scalar/db/storage/cosmos/SelectStatementHandlerTest.java b/core/src/test/java/com/scalar/db/storage/cosmos/SelectStatementHandlerTest.java index 6e36ad5b0f..d318b56472 100644 --- a/core/src/test/java/com/scalar/db/storage/cosmos/SelectStatementHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/cosmos/SelectStatementHandlerTest.java @@ -25,7 +25,6 @@ import com.scalar.db.api.Operation; import com.scalar.db.api.Scan; import com.scalar.db.api.Scan.Ordering.Order; -import com.scalar.db.api.ScanAll; import com.scalar.db.api.Scanner; import com.scalar.db.api.TableMetadata; import com.scalar.db.common.TableMetadataManager; @@ -94,19 +93,26 @@ private Get prepareGet() { Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); id = ANY_TEXT_1 + ":" + ANY_TEXT_2; cosmosPartitionKey = new PartitionKey(ANY_TEXT_1); - return new Get(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private Scan prepareScan() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); cosmosPartitionKey = new PartitionKey(ANY_TEXT_1); - return new Scan(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + return Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); } - private ScanAll prepareScanAll() { - return new ScanAll().forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + private Scan prepareScanAll() { + return Scan.newBuilder().namespace(ANY_NAMESPACE_NAME).table(ANY_TABLE_NAME).all().build(); } @Test @@ -133,7 +139,12 @@ public void handle_GetOperationWithIndexGiven_ShouldCallQueryItems() { when(responseIterable.iterableByPage(anyInt())).thenReturn(pagesIterable); when(pagesIterable.iterator()).thenReturn(pagesIterator); Key indexKey = Key.ofText(ANY_NAME_3, ANY_TEXT_3); - Get get = new Get(indexKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + Get get = + Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(indexKey) + .build(); String query = "select * from Record r where r.values[\"" + ANY_NAME_3 + "\"]" + " = '" + ANY_TEXT_3 + "'"; @@ -222,7 +233,12 @@ public void handle_ScanOperationWithIndexGiven_ShouldCallQueryItems() { when(pagesIterable.iterator()).thenReturn(pagesIterator); Key indexKey = Key.ofText(ANY_NAME_3, ANY_TEXT_3); - Scan scan = new Scan(indexKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + Scan scan = + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(indexKey) + .build(); String query = "select * from Record r where r.values[\"" + ANY_NAME_3 + "\"]" + " = '" + ANY_TEXT_3 + "'"; @@ -263,9 +279,10 @@ public void handle_ScanOperationWithSingleClusteringKey_ShouldCallQueryItemsWith when(pagesIterable.iterator()).thenReturn(pagesIterator); Scan scan = - prepareScan() - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_3)); + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_3)) + .build(); String query = "select * from Record r where (r.concatenatedPartitionKey = '" @@ -309,9 +326,10 @@ public void handle_ScanOperationWithMultipleClusteringKeys_ShouldCallQueryItemsW when(pagesIterable.iterator()).thenReturn(pagesIterator); Scan scan = - prepareScan() - .withStart(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3)) - .withEnd(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4)); + Scan.newBuilder(prepareScan()) + .start(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3)) + .end(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4)) + .build(); String query = "select * from Record r where (r.concatenatedPartitionKey = '" @@ -361,9 +379,10 @@ public void handle_ScanOperationWithNeitherInclusive_ShouldCallQueryItemsWithPro when(pagesIterable.iterator()).thenReturn(pagesIterator); Scan scan = - prepareScan() - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false) - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_3), false); + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false) + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_3), false) + .build(); String query = "select * from Record r where (r.concatenatedPartitionKey = '" @@ -403,10 +422,11 @@ public void handle_ScanOperationWithOrderingAndLimit_ShouldCallQueryItemsWithPro when(pagesIterable.iterator()).thenReturn(pagesIterator); Scan scan = - prepareScan() - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withOrdering(Scan.Ordering.asc(ANY_NAME_2)) - .withLimit(ANY_LIMIT); + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .ordering(Scan.Ordering.asc(ANY_NAME_2)) + .limit(ANY_LIMIT) + .build(); String query = "select * from Record r where (r.concatenatedPartitionKey = '" @@ -444,10 +464,11 @@ public void handle_ScanOperationWithOrderingAndLimit_ShouldCallQueryItemsWithPro when(pagesIterable.iterator()).thenReturn(pagesIterator); Scan scan = - prepareScan() - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withOrdering(Scan.Ordering.desc(ANY_NAME_2)) - .withLimit(ANY_LIMIT); + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .ordering(Scan.Ordering.desc(ANY_NAME_2)) + .limit(ANY_LIMIT) + .build(); String query = "select * from Record r where (r.concatenatedPartitionKey = '" @@ -489,11 +510,12 @@ public void handle_ScanOperationWithOrderingAndLimit_ShouldCallQueryItemsWithPro when(pagesIterable.iterator()).thenReturn(pagesIterator); Scan scan = - prepareScan() - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withOrdering(Scan.Ordering.asc(ANY_NAME_2)) - .withOrdering(Scan.Ordering.desc(ANY_NAME_3)) - .withLimit(ANY_LIMIT); + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .ordering(Scan.Ordering.asc(ANY_NAME_2)) + .ordering(Scan.Ordering.desc(ANY_NAME_3)) + .limit(ANY_LIMIT) + .build(); String query = "select * from Record r where (r.concatenatedPartitionKey = '" @@ -537,11 +559,12 @@ public void handle_ScanOperationWithOrderingAndLimit_ShouldCallQueryItemsWithPro when(pagesIterable.iterator()).thenReturn(pagesIterator); Scan scan = - prepareScan() - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withOrdering(Scan.Ordering.desc(ANY_NAME_2)) - .withOrdering(Scan.Ordering.asc(ANY_NAME_3)) - .withLimit(ANY_LIMIT); + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .ordering(Scan.Ordering.desc(ANY_NAME_2)) + .ordering(Scan.Ordering.asc(ANY_NAME_3)) + .limit(ANY_LIMIT) + .build(); String query = "select * from Record r where (r.concatenatedPartitionKey = '" @@ -578,7 +601,7 @@ public void handle_ScanAllOperationWithLimit_ShouldCallQueryItemsWithProperQuery .thenReturn(responseIterable); when(responseIterable.iterableByPage(anyInt())).thenReturn(pagesIterable); when(pagesIterable.iterator()).thenReturn(pagesIterator); - ScanAll scanAll = prepareScanAll().withLimit(ANY_LIMIT); + Scan scanAll = Scan.newBuilder(prepareScanAll()).limit(ANY_LIMIT).build(); // Act Assert assertThatCode(() -> handler.handle(scanAll)).doesNotThrowAnyException(); @@ -600,7 +623,7 @@ public void handle_ScanAllOperationWithoutLimit_ShouldCallQueryItemsWithProperQu .thenReturn(responseIterable); when(responseIterable.iterableByPage(anyInt())).thenReturn(pagesIterable); when(pagesIterable.iterator()).thenReturn(pagesIterator); - ScanAll scanAll = prepareScanAll(); + Scan scanAll = prepareScanAll(); // Act Assert assertThatCode(() -> handler.handle(scanAll)).doesNotThrowAnyException(); @@ -622,7 +645,7 @@ public void handle_GetOperationWithProjectedColumns_ShouldCallQueryItemsWithProj .thenReturn(responseIterable); when(responseIterable.iterableByPage(anyInt())).thenReturn(pagesIterable); when(pagesIterable.iterator()).thenReturn(pagesIterator); - Get get = prepareGet().withProjections(Arrays.asList(ANY_NAME_3, ANY_NAME_4)); + Get get = Get.newBuilder(prepareGet()).projections(ANY_NAME_3, ANY_NAME_4).build(); // Act Assert assertThatCode(() -> handler.handle(get)).doesNotThrowAnyException(); @@ -658,7 +681,7 @@ public void handle_GetOperationWithProjectedColumns_ShouldCallQueryItemsWithProj .thenReturn(responseIterable); when(responseIterable.iterableByPage(anyInt())).thenReturn(pagesIterable); when(pagesIterable.iterator()).thenReturn(pagesIterator); - Get get = prepareGet().withProjections(Arrays.asList(ANY_NAME_1, ANY_NAME_2)); + Get get = Get.newBuilder(prepareGet()).projections(ANY_NAME_1, ANY_NAME_2).build(); // Act Assert assertThatCode(() -> handler.handle(get)).doesNotThrowAnyException(); @@ -696,10 +719,12 @@ public void handle_GetOperationWithIndexGivenAndProjections_ShouldCallQueryItems when(pagesIterable.iterator()).thenReturn(pagesIterator); Key indexKey = Key.ofText(ANY_NAME_3, ANY_TEXT_3); Get get = - new Get(indexKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withProjections(Arrays.asList(ANY_NAME_3, ANY_NAME_4)); + Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(indexKey) + .projections(ANY_NAME_3, ANY_NAME_4) + .build(); String query = "select r.id, " + "r.concatenatedPartitionKey, " @@ -731,7 +756,7 @@ public void handle_GetOperationWithIndexGivenAndProjections_ShouldCallQueryItems .thenReturn(responseIterable); when(responseIterable.iterableByPage(anyInt())).thenReturn(pagesIterable); when(pagesIterable.iterator()).thenReturn(pagesIterator); - ScanAll scanAll = prepareScanAll().withProjections(Arrays.asList(ANY_NAME_3, ANY_NAME_4)); + Scan scanAll = Scan.newBuilder(prepareScanAll()).projections(ANY_NAME_3, ANY_NAME_4).build(); // Act Assert assertThatCode(() -> handler.handle(scanAll)).doesNotThrowAnyException(); @@ -758,7 +783,7 @@ public void handle_GetOperationWithIndexGivenAndProjections_ShouldCallQueryItems .thenReturn(responseIterable); when(responseIterable.iterableByPage(anyInt())).thenReturn(pagesIterable); when(pagesIterable.iterator()).thenReturn(pagesIterator); - ScanAll scanAll = prepareScanAll().withProjections(Arrays.asList(ANY_NAME_1, ANY_NAME_2)); + Scan scanAll = Scan.newBuilder(prepareScanAll()).projections(ANY_NAME_1, ANY_NAME_2).build(); // Act Assert assertThatCode(() -> handler.handle(scanAll)).doesNotThrowAnyException(); @@ -786,7 +811,7 @@ public void handle_GetOperationWithIndexGivenAndProjections_ShouldCallQueryItems .thenReturn(responseIterable); when(responseIterable.iterableByPage(anyInt())).thenReturn(pagesIterable); when(pagesIterable.iterator()).thenReturn(pagesIterator); - ScanAll scanAll = prepareScanAll().withProjections(Arrays.asList(ANY_NAME_1, ANY_NAME_4)); + Scan scanAll = Scan.newBuilder(prepareScanAll()).projections(ANY_NAME_1, ANY_NAME_4).build(); // Act Assert assertThatCode(() -> handler.handle(scanAll)).doesNotThrowAnyException(); @@ -814,7 +839,7 @@ public void handle_GetOperationWithIndexGivenAndProjections_ShouldCallQueryItems .thenReturn(responseIterable); when(responseIterable.iterableByPage(anyInt())).thenReturn(pagesIterable); when(pagesIterable.iterator()).thenReturn(pagesIterator); - ScanAll scanAll = prepareScanAll().withProjections(Arrays.asList(ANY_NAME_2, ANY_NAME_4)); + Scan scanAll = Scan.newBuilder(prepareScanAll()).projections(ANY_NAME_2, ANY_NAME_4).build(); // Act Assert assertThatCode(() -> handler.handle(scanAll)).doesNotThrowAnyException(); @@ -844,10 +869,12 @@ public void handle_ScanOperationWithIndexAndProjected_ShouldCallQueryItems() { Key indexKey = Key.ofText(ANY_NAME_3, ANY_TEXT_3); Scan scan = - new Scan(indexKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withProjections(Arrays.asList(ANY_NAME_3, ANY_NAME_4)); + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(indexKey) + .projections(ANY_NAME_3, ANY_NAME_4) + .build(); String query = "select r.id, " + "r.concatenatedPartitionKey, " @@ -881,11 +908,12 @@ public void handle_ScanOperationWithIndexAndProjected_ShouldCallQueryItems() { when(pagesIterable.iterator()).thenReturn(pagesIterator); Scan scan = - prepareScan() - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withOrdering(Scan.Ordering.asc(ANY_NAME_2)) - .withLimit(ANY_LIMIT) - .withProjections(Arrays.asList(ANY_NAME_3, ANY_NAME_4)); + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .ordering(Scan.Ordering.asc(ANY_NAME_2)) + .limit(ANY_LIMIT) + .projections(ANY_NAME_3, ANY_NAME_4) + .build(); String query = "select r.id, " @@ -933,10 +961,12 @@ public void handle_ScanOperationWithIndexAndProjected_ShouldCallQueryItems() { when(pagesIterable.iterator()).thenReturn(pagesIterator); Key partitionKey = Key.of(ANY_NAME_1, ANY_TEXT_1, ANY_NAME_2, ANY_TEXT_2); Scan scan = - new Scan(partitionKey) - .withProjections(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_NAME_3, ANY_NAME_4)) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .projections(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_NAME_3, ANY_NAME_4)) + .build(); cosmosPartitionKey = new PartitionKey(ANY_TEXT_1 + ":" + ANY_TEXT_2); String query = @@ -977,11 +1007,13 @@ public void handle_ScanOperationWithIndexAndProjected_ShouldCallQueryItems() { .thenReturn(responseIterable); when(responseIterable.iterableByPage(anyInt())).thenReturn(pagesIterable); when(pagesIterable.iterator()).thenReturn(pagesIterator); - ScanAll scanAll = - new ScanAll() - .withProjections(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_NAME_3, ANY_NAME_4)) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Scan scanAll = + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .all() + .projections(ANY_NAME_1, ANY_NAME_2, ANY_NAME_3, ANY_NAME_4) + .build(); String query = "select r.id, " @@ -1020,10 +1052,13 @@ public void handle_ScanOperationWithIndexAndProjected_ShouldCallQueryItems() { Key partitionKey = Key.of(ANY_NAME_1, ANY_TEXT_1, ANY_NAME_2, ANY_TEXT_2); Key clusteringKey = Key.of(ANY_NAME_3, ANY_TEXT_3, ANY_NAME_4, ANY_TEXT_4); Get get = - new Get(partitionKey, clusteringKey) - .withProjections(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_NAME_3, ANY_NAME_4)) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .projections(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_NAME_3, ANY_NAME_4)) + .build(); cosmosPartitionKey = new PartitionKey(ANY_TEXT_1 + ":" + ANY_TEXT_2); String query = diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/BatchHandlerTestBase.java b/core/src/test/java/com/scalar/db/storage/dynamo/BatchHandlerTestBase.java index 0f5ff07149..aba31b1ae7 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/BatchHandlerTestBase.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/BatchHandlerTestBase.java @@ -73,19 +73,25 @@ private String getFullTableName() { private Put preparePut() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Put(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_INT_1) - .withValue(ANY_NAME_4, ANY_INT_2); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(ANY_NAME_3, ANY_INT_1) + .intValue(ANY_NAME_4, ANY_INT_2) + .build(); } private Delete prepareDelete() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Delete(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } @Test @@ -109,8 +115,9 @@ public void handle_TooManyOperationsGiven_ShouldThrowIllegalArgumentException() .build(); doThrow(toThrow).when(client).transactWriteItems(any(TransactWriteItemsRequest.class)); - Put put = preparePut().withCondition(ConditionBuilder.putIfNotExists()); - Delete delete = prepareDelete().withCondition(ConditionBuilder.deleteIfExists()); + Put put = Put.newBuilder(preparePut()).condition(ConditionBuilder.putIfNotExists()).build(); + Delete delete = + Delete.newBuilder(prepareDelete()).condition(ConditionBuilder.deleteIfExists()).build(); // Act Assert assertThatThrownBy(() -> handler.handle(Arrays.asList(put, delete))) @@ -128,8 +135,9 @@ public void handle_TooManyOperationsGiven_ShouldThrowIllegalArgumentException() .build(); doThrow(toThrow).when(client).transactWriteItems(any(TransactWriteItemsRequest.class)); - Put put = preparePut().withCondition(ConditionBuilder.putIfNotExists()); - Delete delete = prepareDelete().withCondition(ConditionBuilder.deleteIfExists()); + Put put = Put.newBuilder(preparePut()).condition(ConditionBuilder.putIfNotExists()).build(); + Delete delete = + Delete.newBuilder(prepareDelete()).condition(ConditionBuilder.deleteIfExists()).build(); // Act Assert assertThatThrownBy(() -> handler.handle(Arrays.asList(put, delete))) diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/DeleteStatementHandlerTestBase.java b/core/src/test/java/com/scalar/db/storage/dynamo/DeleteStatementHandlerTestBase.java index 9e6589e48d..bd59ef5fc2 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/DeleteStatementHandlerTestBase.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/DeleteStatementHandlerTestBase.java @@ -65,9 +65,12 @@ private String getFullTableName() { private Delete prepareDelete() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Delete(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } @Test @@ -113,7 +116,11 @@ public void handle_DeleteWithoutClusteringKeyGiven_ShouldCallDeleteItem() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Delete delete = - new Delete(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); DynamoMutation dynamoMutation = new DynamoMutation(delete, metadata); @@ -136,7 +143,8 @@ public void handle_DeleteWithConditionsGiven_ShouldCallDeleteItem() { .thenReturn(new LinkedHashSet<>(Collections.singletonList(ANY_NAME_2))); when(client.deleteItem(any(DeleteItemRequest.class))).thenReturn(response); - Delete delete = prepareDelete().withCondition(ConditionBuilder.deleteIfExists()); + Delete delete = + Delete.newBuilder(prepareDelete()).condition(ConditionBuilder.deleteIfExists()).build(); DynamoMutation dynamoMutation = new DynamoMutation(delete, metadata); @@ -162,7 +170,8 @@ public void handle_DynamoDbExceptionWithConditionalCheckFailed_ShouldThrowNoMuta ConditionalCheckFailedException toThrow = mock(ConditionalCheckFailedException.class); doThrow(toThrow).when(client).deleteItem(any(DeleteItemRequest.class)); - Delete delete = prepareDelete().withCondition(ConditionBuilder.deleteIfExists()); + Delete delete = + Delete.newBuilder(prepareDelete()).condition(ConditionBuilder.deleteIfExists()).build(); // Act Assert assertThatThrownBy(() -> handler.handle(delete)).isInstanceOf(NoMutationException.class); @@ -177,7 +186,8 @@ public void handle_DeleteWithConditionDynamoDbExceptionThrown_ShouldThrowExecuti DynamoDbException toThrow = mock(DynamoDbException.class); doThrow(toThrow).when(client).deleteItem(any(DeleteItemRequest.class)); - Delete delete = prepareDelete().withCondition(ConditionBuilder.deleteIfExists()); + Delete delete = + Delete.newBuilder(prepareDelete()).condition(ConditionBuilder.deleteIfExists()).build(); // Act Assert assertThatThrownBy(() -> handler.handle(delete)) diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoMutationTest.java b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoMutationTest.java index d88825ff79..066147d067 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoMutationTest.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoMutationTest.java @@ -46,11 +46,14 @@ public void setUp() throws Exception { private Put preparePut() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Put(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_INT_1) - .withValue(ANY_NAME_4, ANY_INT_2); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(ANY_NAME_3, ANY_INT_1) + .intValue(ANY_NAME_4, ANY_INT_2) + .build(); } @Test @@ -99,7 +102,7 @@ public void getCondition_PutGiven_ShouldReturnCondition() { ConditionBuilder.column(ANY_NAME_3).isEqualToInt(ANY_INT_VALUE.get())) .and(ConditionBuilder.column(ANY_NAME_4).isGreaterThanInt(ANY_INT_VALUE.get())) .build(); - Put put = preparePut().withCondition(conditions); + Put put = Put.newBuilder(preparePut()).condition(conditions).build(); DynamoMutation dynamoMutation = new DynamoMutation(put, metadata); @@ -127,7 +130,7 @@ public void getConditionColumnMap_PutGiven_ShouldReturnCondition() { ConditionBuilder.column(ANY_NAME_3).isEqualToInt(ANY_INT_VALUE.get())) .and(ConditionBuilder.column(ANY_NAME_4).isGreaterThanInt(ANY_INT_VALUE.get())) .build(); - Put put = preparePut().withCondition(conditions); + Put put = Put.newBuilder(preparePut()).condition(conditions).build(); Map expected = new HashMap<>(); expected.put(DynamoOperation.CONDITION_COLUMN_NAME_ALIAS + "0", ANY_NAME_3); @@ -145,7 +148,7 @@ public void getConditionColumnMap_PutGiven_ShouldReturnCondition() { @Test public void getUpdateExpression_PutWithIfExistsGiven_ShouldReturnExpression() { // Arrange - Put put = preparePut().withCondition(ConditionBuilder.putIfExists()); + Put put = Put.newBuilder(preparePut()).condition(ConditionBuilder.putIfExists()).build(); DynamoMutation dynamoMutation = new DynamoMutation(put, metadata); // Act @@ -173,7 +176,7 @@ public void getConditionBindMap_PutWithPutIfGiven_ShouldReturnBindMap() { ConditionBuilder.column(ANY_NAME_3).isEqualToInt(ANY_INT_VALUE.get())) .and(ConditionBuilder.column(ANY_NAME_4).isGreaterThanInt(ANY_INT_VALUE.get())) .build(); - Put put = preparePut().withCondition(conditions); + Put put = Put.newBuilder(preparePut()).condition(conditions).build(); Map expected = new HashMap<>(); expected.put( DynamoOperation.CONDITION_VALUE_ALIAS + "0", @@ -194,7 +197,7 @@ public void getConditionBindMap_PutWithPutIfGiven_ShouldReturnBindMap() { @Test public void getValueBindMap_PutWithPutIfExistsGiven_ShouldReturnBindMap() { // Arrange - Put put = preparePut().withCondition(ConditionBuilder.putIfExists()); + Put put = Put.newBuilder(preparePut()).condition(ConditionBuilder.putIfExists()).build(); Map expected = new HashMap<>(); expected.put( DynamoOperation.VALUE_ALIAS + "0", @@ -215,7 +218,7 @@ public void getValueBindMap_PutWithPutIfExistsGiven_ShouldReturnBindMap() { @Test public void getValueBindMap_PutWithNullValueGiven_ShouldReturnBindMap() { // Arrange - Put put = preparePut().withIntValue(ANY_NAME_3, null); + Put put = Put.newBuilder(preparePut()).intValue(ANY_NAME_3, null).build(); Map expected = new HashMap<>(); expected.put(DynamoOperation.VALUE_ALIAS + "0", AttributeValue.builder().nul(true).build()); expected.put( diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoOperationCheckerTest.java b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoOperationCheckerTest.java index 941f22bf7c..59e2fbad47 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoOperationCheckerTest.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoOperationCheckerTest.java @@ -72,7 +72,13 @@ public void setUp() throws Exception { @Test public void check_ForPutWithNullIndex_ShouldThrowIllegalArgumentException() { // Arrange - Put put = new Put(Key.ofInt(PKEY1, 0), Key.ofInt(CKEY1, 0)).withIntValue(COL1, null); + Put put = + Put.newBuilder() + .table(TABLE_NAME) + .partitionKey(Key.ofInt(PKEY1, 0)) + .clusteringKey(Key.ofInt(CKEY1, 0)) + .intValue(COL1, null) + .build(); // Act Assert assertThatThrownBy(() -> operationChecker.check(put)) @@ -82,7 +88,13 @@ public void check_ForPutWithNullIndex_ShouldThrowIllegalArgumentException() { @Test public void check_ForPutWithNonNullIndex_ShouldDoNothing() { // Arrange - Put put = new Put(Key.ofInt(PKEY1, 0), Key.ofInt(CKEY1, 0)).withIntValue(COL1, 1); + Put put = + Put.newBuilder() + .table(TABLE_NAME) + .partitionKey(Key.ofInt(PKEY1, 0)) + .clusteringKey(Key.ofInt(CKEY1, 0)) + .intValue(COL1, 1) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(put)).doesNotThrowAnyException(); @@ -91,7 +103,12 @@ public void check_ForPutWithNonNullIndex_ShouldDoNothing() { @Test public void check_ForPutWithoutSettingIndex_ShouldDoNothing() { // Arrange - Put put = new Put(Key.ofInt(PKEY1, 0), Key.ofInt(CKEY1, 0)); + Put put = + Put.newBuilder() + .table(TABLE_NAME) + .partitionKey(Key.ofInt(PKEY1, 0)) + .clusteringKey(Key.ofInt(CKEY1, 0)) + .build(); // Act Assert assertThatCode(() -> operationChecker.check(put)).doesNotThrowAnyException(); diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoOperationTest.java b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoOperationTest.java index f2c7c6baf0..fbac970495 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoOperationTest.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoOperationTest.java @@ -41,9 +41,12 @@ public void setUp() throws Exception { private Get prepareGet() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Get(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } @Test diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/PutStatementHandlerTestBase.java b/core/src/test/java/com/scalar/db/storage/dynamo/PutStatementHandlerTestBase.java index 2371e36e49..978a098b13 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/PutStatementHandlerTestBase.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/PutStatementHandlerTestBase.java @@ -71,11 +71,14 @@ private String getFullTableName() { private Put preparePut() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Put(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_INT_1) - .withValue(ANY_NAME_4, ANY_INT_2); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(ANY_NAME_3, ANY_INT_1) + .intValue(ANY_NAME_4, ANY_INT_2) + .build(); } @Test @@ -108,11 +111,13 @@ public void handle_PutWithoutClusteringKeyGiven_ShouldCallUpdateItem() { when(client.updateItem(any(UpdateItemRequest.class))).thenReturn(updateResponse); Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Put put = - new Put(partitionKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_INT_1) - .withValue(ANY_NAME_4, ANY_INT_2); + Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .intValue(ANY_NAME_3, ANY_INT_1) + .intValue(ANY_NAME_4, ANY_INT_2) + .build(); DynamoMutation dynamoMutation = new DynamoMutation(put, metadata); Map expectedKeys = dynamoMutation.getKeyMap(); String updateExpression = dynamoMutation.getUpdateExpressionWithKey(); @@ -150,7 +155,7 @@ public void handle_PutWithoutConditionsDynamoDbExceptionThrown_ShouldThrowExecut public void handle_PutIfNotExistsGiven_ShouldCallUpdateItemWithCondition() { // Arrange when(client.updateItem(any(UpdateItemRequest.class))).thenReturn(updateResponse); - Put put = preparePut().withCondition(ConditionBuilder.putIfNotExists()); + Put put = Put.newBuilder(preparePut()).condition(ConditionBuilder.putIfNotExists()).build(); DynamoMutation dynamoMutation = new DynamoMutation(put, metadata); Map expectedKeys = dynamoMutation.getKeyMap(); @@ -176,7 +181,7 @@ public void handle_PutIfNotExistsGiven_ShouldCallUpdateItemWithCondition() { public void handle_PutIfExistsGiven_ShouldCallUpdateItemWithCondition() { // Arrange when(client.updateItem(any(UpdateItemRequest.class))).thenReturn(updateResponse); - Put put = preparePut().withCondition(ConditionBuilder.putIfExists()); + Put put = Put.newBuilder(preparePut()).condition(ConditionBuilder.putIfExists()).build(); DynamoMutation dynamoMutation = new DynamoMutation(put, metadata); Map expectedKeys = dynamoMutation.getKeyMap(); String updateExpression = dynamoMutation.getUpdateExpression(); @@ -203,7 +208,7 @@ public void handle_DynamoDbExceptionWithConditionalCheckFailed_ShouldThrowNoMuta ConditionalCheckFailedException toThrow = mock(ConditionalCheckFailedException.class); doThrow(toThrow).when(client).updateItem(any(UpdateItemRequest.class)); - Put put = preparePut().withCondition(ConditionBuilder.putIfExists()); + Put put = Put.newBuilder(preparePut()).condition(ConditionBuilder.putIfExists()).build(); // Act Assert assertThatThrownBy(() -> handler.handle(put)).isInstanceOf(NoMutationException.class); diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/SelectStatementHandlerTestBase.java b/core/src/test/java/com/scalar/db/storage/dynamo/SelectStatementHandlerTestBase.java index 3a7a2fe5fd..04a5155326 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/SelectStatementHandlerTestBase.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/SelectStatementHandlerTestBase.java @@ -15,7 +15,6 @@ import com.scalar.db.api.Result; import com.scalar.db.api.Scan; import com.scalar.db.api.Scan.Ordering.Order; -import com.scalar.db.api.ScanAll; import com.scalar.db.api.Scanner; import com.scalar.db.api.TableMetadata; import com.scalar.db.common.TableMetadataManager; @@ -95,18 +94,25 @@ private String getFullTableName() { private Get prepareGet() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Get(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private Scan prepareScan() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); - return new Scan(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + return Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); } - private ScanAll prepareScanAll() { - return new ScanAll().forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + private Scan prepareScanAll() { + return Scan.newBuilder().namespace(ANY_NAMESPACE_NAME).table(ANY_TABLE_NAME).all().build(); } @Test @@ -157,7 +163,12 @@ public void handle_GetOperationWithIndexGiven_ShouldCallQuery() { when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Key indexKey = Key.ofText(ANY_NAME_3, ANY_TEXT_3); - Get get = new Get(indexKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + Get get = + Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .indexKey(indexKey) + .build(); String expectedKeyCondition = DynamoOperation.COLUMN_NAME_ALIAS + "0 = " + DynamoOperation.VALUE_ALIAS + "0"; Map expectedBindMap = new HashMap<>(); @@ -224,7 +235,12 @@ public void handle_ScanOperationWithIndexGiven_ShouldCallQuery() { when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Key indexKey = Key.ofText(ANY_NAME_3, ANY_TEXT_3); - Scan scan = new Scan(indexKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + Scan scan = + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .indexKey(indexKey) + .build(); String expectedKeyCondition = DynamoOperation.COLUMN_NAME_ALIAS + "0 = " + DynamoOperation.VALUE_ALIAS + "0"; Map expectedBindMap = new HashMap<>(); @@ -251,11 +267,13 @@ public void handle_ScanOperationWithIndexGiven_WithProjections_ShouldCallQuery() Key indexKey = Key.ofText(ANY_NAME_3, ANY_TEXT_3); Scan scan = - new Scan(indexKey) - .withProjection(ANY_NAME_1) - .withProjection(ANY_NAME_2) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .indexKey(indexKey) + .projection(ANY_NAME_1) + .projection(ANY_NAME_2) + .build(); String expectedKeyCondition = DynamoOperation.COLUMN_NAME_ALIAS + "0 = " + DynamoOperation.VALUE_ALIAS + "0"; Map expectedBindMap = new HashMap<>(); @@ -305,9 +323,10 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan() - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true) - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_3), true); + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true) + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_3), true) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -366,9 +385,10 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan() - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false) - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_3), false); + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false) + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_3), false) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -432,7 +452,8 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(client.query(any(QueryRequest.class))).thenReturn(queryResponse); when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); - Scan scan = prepareScan().withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true); + Scan scan = + Scan.newBuilder(prepareScan()).start(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true).build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -479,7 +500,8 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(client.query(any(QueryRequest.class))).thenReturn(queryResponse); when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); - Scan scan = prepareScan().withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false); + Scan scan = + Scan.newBuilder(prepareScan()).start(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false).build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -526,7 +548,8 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(client.query(any(QueryRequest.class))).thenReturn(queryResponse); when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); - Scan scan = prepareScan().withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true); + Scan scan = + Scan.newBuilder(prepareScan()).end(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true).build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -573,7 +596,8 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(client.query(any(QueryRequest.class))).thenReturn(queryResponse); when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); - Scan scan = prepareScan().withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false); + Scan scan = + Scan.newBuilder(prepareScan()).end(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false).build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -629,9 +653,10 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan() - .withStart(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), true) - .withEnd(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4), true); + Scan.newBuilder(prepareScan()) + .start(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), true) + .end(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4), true) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -701,9 +726,10 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan() - .withStart(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), true) - .withEnd(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4), true); + Scan.newBuilder(prepareScan()) + .start(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), true) + .end(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4), true) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -772,9 +798,10 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan() - .withStart(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), false) - .withEnd(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4), false); + Scan.newBuilder(prepareScan()) + .start(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), false) + .end(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4), false) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -848,9 +875,10 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan() - .withStart(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), false) - .withEnd(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4), false); + Scan.newBuilder(prepareScan()) + .start(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), false) + .end(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_4), false) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -923,9 +951,10 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan() - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true) - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_3), true); + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true) + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_3), true) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -995,9 +1024,10 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan() - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false) - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_3), false); + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false) + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_3), false) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1067,7 +1097,9 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan().withStart(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), true); + Scan.newBuilder(prepareScan()) + .start(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), true) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1139,7 +1171,9 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan().withStart(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), true); + Scan.newBuilder(prepareScan()) + .start(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), true) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1207,7 +1241,9 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan().withStart(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), false); + Scan.newBuilder(prepareScan()) + .start(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), false) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1281,7 +1317,9 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan().withStart(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), false); + Scan.newBuilder(prepareScan()) + .start(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), false) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1350,7 +1388,8 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(client.query(any(QueryRequest.class))).thenReturn(queryResponse); when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); - Scan scan = prepareScan().withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true); + Scan scan = + Scan.newBuilder(prepareScan()).start(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true).build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1405,7 +1444,8 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(client.query(any(QueryRequest.class))).thenReturn(queryResponse); when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); - Scan scan = prepareScan().withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false); + Scan scan = + Scan.newBuilder(prepareScan()).start(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false).build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1463,7 +1503,10 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(client.query(any(QueryRequest.class))).thenReturn(queryResponse); when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); - Scan scan = prepareScan().withEnd(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), true); + Scan scan = + Scan.newBuilder(prepareScan()) + .end(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), true) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1531,7 +1574,10 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(client.query(any(QueryRequest.class))).thenReturn(queryResponse); when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); - Scan scan = prepareScan().withEnd(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), true); + Scan scan = + Scan.newBuilder(prepareScan()) + .end(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), true) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1602,7 +1648,9 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan().withEnd(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), false); + Scan.newBuilder(prepareScan()) + .end(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), false) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1673,7 +1721,9 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan().withEnd(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), false); + Scan.newBuilder(prepareScan()) + .end(Key.of(ANY_NAME_2, ANY_TEXT_2, ANY_NAME_3, ANY_TEXT_3), false) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1745,7 +1795,8 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(client.query(any(QueryRequest.class))).thenReturn(queryResponse); when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); - Scan scan = prepareScan().withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true); + Scan scan = + Scan.newBuilder(prepareScan()).end(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true).build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1803,7 +1854,8 @@ public void handle_ScanOperationCosmosExceptionThrown_ShouldThrowExecutionExcept when(client.query(any(QueryRequest.class))).thenReturn(queryResponse); when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); - Scan scan = prepareScan().withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false); + Scan scan = + Scan.newBuilder(prepareScan()).end(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false).build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1850,10 +1902,11 @@ public void handle_ScanOperationWithOrderingAndLimit_ShouldCallQueryWithProperRe when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan() - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withOrdering(Scan.Ordering.asc(ANY_NAME_2)) - .withLimit(ANY_LIMIT); + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .ordering(Scan.Ordering.asc(ANY_NAME_2)) + .limit(ANY_LIMIT) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1900,11 +1953,12 @@ public void handle_ScanOperationWithMultipleOrderings_ShouldCallQueryWithProperR when(queryResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); Scan scan = - prepareScan() - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withOrdering(Scan.Ordering.asc(ANY_NAME_2)) - .withOrdering(Scan.Ordering.desc(ANY_NAME_3)) - .withLimit(ANY_LIMIT); + Scan.newBuilder(prepareScan()) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .ordering(Scan.Ordering.asc(ANY_NAME_2)) + .ordering(Scan.Ordering.desc(ANY_NAME_3)) + .limit(ANY_LIMIT) + .build(); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -1950,7 +2004,7 @@ public void prepare_ScanAllOperationWithLimit_ShouldPrepareProperQuery() { when(client.scan(any(ScanRequest.class))).thenReturn(scanResponse); when(scanResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); - ScanAll scanAll = prepareScanAll().withLimit(ANY_LIMIT); + Scan scanAll = Scan.newBuilder(prepareScanAll()).limit(ANY_LIMIT).build(); // Act Assert assertThatCode(() -> handler.handle(scanAll)).doesNotThrowAnyException(); @@ -1969,7 +2023,7 @@ public void prepare_ScanAllOperationWithoutLimit_ShouldPrepareProperQuery() { when(client.scan(any(ScanRequest.class))).thenReturn(scanResponse); when(scanResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); - ScanAll scanAll = prepareScanAll(); + Scan scanAll = prepareScanAll(); // Act Assert assertThatCode(() -> handler.handle(scanAll)).doesNotThrowAnyException(); @@ -1988,12 +2042,8 @@ public void prepare_ScanAllOperationWithProjectedColumns_ShouldPrepareProperQuer when(client.scan(any(ScanRequest.class))).thenReturn(scanResponse); when(scanResponse.items()).thenReturn(Collections.singletonList(new HashMap<>())); - ScanAll scanAll = - prepareScanAll() - .withProjection(ANY_NAME_1) - .withProjection(ANY_NAME_2) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Scan scanAll = + Scan.newBuilder(prepareScanAll()).projection(ANY_NAME_1).projection(ANY_NAME_2).build(); Map expectedExpressionAttributeNames = new HashMap<>(); expectedExpressionAttributeNames.put(DynamoOperation.COLUMN_NAME_ALIAS + "0", ANY_NAME_1); diff --git a/core/src/test/java/com/scalar/db/storage/jdbc/JdbcDatabaseTest.java b/core/src/test/java/com/scalar/db/storage/jdbc/JdbcDatabaseTest.java index 1b185427a0..7c32566f79 100644 --- a/core/src/test/java/com/scalar/db/storage/jdbc/JdbcDatabaseTest.java +++ b/core/src/test/java/com/scalar/db/storage/jdbc/JdbcDatabaseTest.java @@ -70,7 +70,12 @@ public void whenGetOperationExecuted_shouldCallJdbcService() throws Exception { // Arrange // Act - Get get = new Get(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Get get = + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); jdbcDatabase.get(get); // Assert @@ -89,7 +94,12 @@ public void whenGetOperationExecuted_shouldCallJdbcService() throws Exception { // Act Assert assertThatThrownBy( () -> { - Get get = new Get(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Get get = + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); jdbcDatabase.get(get); }) .isInstanceOf(ExecutionException.class) @@ -106,7 +116,12 @@ public void whenScanOperationExecutedAndScannerClosed_shouldCallJdbcService() th new ScannerImpl(resultInterpreter, connection, preparedStatement, resultSet, true)); // Act - Scan scan = new Scan(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Scan scan = + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); Scanner scanner = jdbcDatabase.scan(scan); scanner.close(); @@ -128,7 +143,12 @@ public void whenScanOperationExecutedAndScannerClosed_shouldCallJdbcService() th // Act Assert assertThatThrownBy( () -> { - Scan scan = new Scan(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Scan scan = + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); jdbcDatabase.scan(scan); }) .isInstanceOf(ExecutionException.class) @@ -151,7 +171,12 @@ public void whenScanOperationExecutedAndScannerClosed_shouldCallJdbcService() th // Act Assert assertThatThrownBy( () -> { - Scan scan = new Scan(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Scan scan = + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); jdbcDatabase.scan(scan); }) .isInstanceOf(IllegalArgumentException.class); @@ -169,7 +194,12 @@ public void whenScanOperationExecutedAndScannerClosed_shouldCallJdbcService() th doThrow(sqlException).when(connection).commit(); // Act - Scan scan = new Scan(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Scan scan = + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); Scanner scanner = jdbcDatabase.scan(scan); assertThatThrownBy(scanner::close).isInstanceOf(IOException.class).hasCause(sqlException); @@ -189,10 +219,12 @@ public void whenPutOperationExecuted_shouldCallJdbcService() throws Exception { // Act Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); jdbcDatabase.put(put); // Assert @@ -211,11 +243,13 @@ public void whenPutOperationExecuted_shouldCallJdbcService() throws Exception { assertThatThrownBy( () -> { Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .withCondition(ConditionBuilder.putIfNotExists()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .condition(ConditionBuilder.putIfNotExists()) + .build(); jdbcDatabase.put(put); }) .isInstanceOf(NoMutationException.class); @@ -233,10 +267,12 @@ public void whenPutOperationExecuted_shouldCallJdbcService() throws Exception { assertThatThrownBy( () -> { Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); jdbcDatabase.put(put); }) .isInstanceOf(ExecutionException.class) @@ -250,7 +286,12 @@ public void whenDeleteOperationExecuted_shouldCallJdbcService() throws Exception when(jdbcService.delete(any(), any())).thenReturn(true); // Act - Delete delete = new Delete(Key.ofText("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE); + Delete delete = + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .build(); jdbcDatabase.delete(delete); // Assert @@ -269,10 +310,12 @@ public void whenDeleteOperationExecuted_shouldCallJdbcService() throws Exception assertThatThrownBy( () -> { Delete delete = - new Delete(Key.ofText("p1", "val1")) - .withCondition(ConditionBuilder.deleteIfExists()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .condition(ConditionBuilder.deleteIfExists()) + .build(); jdbcDatabase.delete(delete); }) .isInstanceOf(NoMutationException.class); @@ -290,7 +333,11 @@ public void whenDeleteOperationExecuted_shouldCallJdbcService() throws Exception assertThatThrownBy( () -> { Delete delete = - new Delete(Key.ofText("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .build(); jdbcDatabase.delete(delete); }) .isInstanceOf(ExecutionException.class) @@ -305,11 +352,18 @@ public void whenMutateOperationExecuted_shouldCallJdbcService() throws Exception // Act Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); - Delete delete = new Delete(Key.ofText("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); + Delete delete = + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .build(); jdbcDatabase.mutate(Arrays.asList(put, delete)); // Assert @@ -330,16 +384,20 @@ public void whenMutateOperationExecuted_shouldCallJdbcService() throws Exception assertThatThrownBy( () -> { Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .withCondition(ConditionBuilder.putIfNotExists()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .condition(ConditionBuilder.putIfNotExists()) + .build(); Delete delete = - new Delete(Key.ofText("p1", "val1")) - .withCondition(ConditionBuilder.deleteIfExists()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .condition(ConditionBuilder.deleteIfExists()) + .build(); jdbcDatabase.mutate(Arrays.asList(put, delete)); }) .isInstanceOf(NoMutationException.class); @@ -360,12 +418,18 @@ public void whenMutateOperationExecuted_shouldCallJdbcService() throws Exception assertThatThrownBy( () -> { Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); Delete delete = - new Delete(Key.ofText("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .build(); jdbcDatabase.mutate(Arrays.asList(put, delete)); }) .isInstanceOf(ExecutionException.class) @@ -387,12 +451,18 @@ public void mutate_withConflictError_shouldThrowRetriableExecutionException() assertThatThrownBy( () -> { Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); Delete delete = - new Delete(Key.ofText("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .build(); jdbcDatabase.mutate(Arrays.asList(put, delete)); }) .isInstanceOf(RetriableExecutionException.class) @@ -414,12 +484,18 @@ public void mutate_WhenSettingAutoCommitFails_ShouldThrowExceptionAndCloseConnec assertThatThrownBy( () -> { Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); Delete delete = - new Delete(Key.ofText("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .build(); jdbcDatabase.mutate(Arrays.asList(put, delete)); }) .isEqualTo(exception); diff --git a/core/src/test/java/com/scalar/db/storage/jdbc/JdbcServiceTest.java b/core/src/test/java/com/scalar/db/storage/jdbc/JdbcServiceTest.java index cf2a0975a0..c696c357f6 100644 --- a/core/src/test/java/com/scalar/db/storage/jdbc/JdbcServiceTest.java +++ b/core/src/test/java/com/scalar/db/storage/jdbc/JdbcServiceTest.java @@ -100,7 +100,12 @@ public void whenGetOperationExecuted_shouldCallQueryBuilder() throws Exception { when(resultSet.next()).thenReturn(false); // Act - Get get = new Get(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Get get = + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); jdbcService.get(get, connection); // Assert @@ -125,7 +130,12 @@ public void whenGetScannerExecuted_withScan_shouldCallQueryBuilder() throws Exce when(resultSet.next()).thenReturn(false); // Act - Scan scan = new Scan(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Scan scan = + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); Scanner scanner = jdbcService.getScanner(scan, connection); // Assert @@ -153,7 +163,7 @@ public void whenGetScannerExecuted_withScanAll_shouldCallQueryBuilder() throws E when(resultSet.next()).thenReturn(false); // Act - Scan scan = new ScanAll().forNamespace(NAMESPACE).forTable(TABLE); + Scan scan = Scan.newBuilder().namespace(NAMESPACE).table(TABLE).all().build(); Scanner scanner = jdbcService.getScanner(scan, connection); // Assert @@ -221,7 +231,12 @@ public void whenScanExecuted_withScan_shouldCallQueryBuilder() throws Exception when(resultSet.next()).thenReturn(false); // Act - Scan scan = new Scan(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Scan scan = + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); jdbcService.scan(scan, connection); // Assert @@ -245,7 +260,7 @@ public void whenScanExecuted_withScanAll_shouldCallQueryBuilder() throws Excepti when(resultSet.next()).thenReturn(false); // Act - ScanAll scanAll = new ScanAll().forNamespace(NAMESPACE).forTable(TABLE); + Scan scanAll = Scan.newBuilder().namespace(NAMESPACE).table(TABLE).all().build(); jdbcService.scan(scanAll, connection); // Assert @@ -296,10 +311,12 @@ public void whenPutOperationExecuted_shouldReturnTrueAndCallQueryBuilder() throw // Act Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); boolean ret = jdbcService.put(put, connection); // Assert @@ -321,12 +338,14 @@ public void whenPutOperationWithPutIfConditionExecuted_shouldReturnTrueAndCallQu // Act Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .withCondition( + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .condition( ConditionBuilder.putIf(ConditionBuilder.column("v1").isEqualToText("val2")).build()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + .build(); boolean ret = jdbcService.put(put, connection); // Assert @@ -348,12 +367,14 @@ public void whenPutOperationWithPutIfConditionFails_shouldReturnFalseAndCallQuer // Act Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .withCondition( + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .condition( ConditionBuilder.putIf(ConditionBuilder.column("v1").isEqualToText("val2")).build()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + .build(); boolean ret = jdbcService.put(put, connection); // Assert @@ -375,11 +396,13 @@ public void whenPutOperationWithPutIfExistsConditionExecuted_shouldReturnTrueAnd // Act Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .withCondition(ConditionBuilder.putIfExists()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .condition(ConditionBuilder.putIfExists()) + .build(); boolean ret = jdbcService.put(put, connection); // Assert @@ -401,11 +424,13 @@ public void whenPutOperationWithPutIfExistsConditionFails_shouldReturnFalseAndCa // Act Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .withCondition(ConditionBuilder.putIfExists()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .condition(ConditionBuilder.putIfExists()) + .build(); boolean ret = jdbcService.put(put, connection); // Assert @@ -426,11 +451,13 @@ public void whenPutOperationWithPutIfExistsConditionFails_shouldReturnFalseAndCa // Act Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .withCondition(ConditionBuilder.putIfNotExists()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .condition(ConditionBuilder.putIfNotExists()) + .build(); boolean ret = jdbcService.put(put, connection); // Assert @@ -453,11 +480,13 @@ public void whenPutOperationWithPutIfExistsConditionFails_shouldReturnFalseAndCa // Act Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .withCondition(ConditionBuilder.putIfNotExists()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .condition(ConditionBuilder.putIfNotExists()) + .build(); boolean ret = jdbcService.put(put, connection); // Assert @@ -475,7 +504,12 @@ public void whenDeleteOperationExecuted_shouldReturnTrueAndCallQueryBuilder() th when(connection.prepareStatement(any())).thenReturn(preparedStatement); // Act - Delete delete = new Delete(Key.ofText("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE); + Delete delete = + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .build(); boolean ret = jdbcService.delete(delete, connection); // Assert @@ -496,12 +530,14 @@ public void whenDeleteOperationWithDeleteIfConditionExecuted_shouldReturnTrueAnd // Act Delete delete = - new Delete(Key.ofText("p1", "val1")) - .withCondition( + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .condition( ConditionBuilder.deleteIf(ConditionBuilder.column("v1").isEqualToText("val2")) .build()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + .build(); boolean ret = jdbcService.delete(delete, connection); // Assert @@ -522,12 +558,14 @@ public void whenDeleteOperationWithDeleteIfConditionFails_shouldReturnFalseAndCa // Act Delete delete = - new Delete(Key.ofText("p1", "val1")) - .withCondition( + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .condition( ConditionBuilder.deleteIf(ConditionBuilder.column("v1").isEqualToText("val2")) .build()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + .build(); boolean ret = jdbcService.delete(delete, connection); // Assert @@ -549,10 +587,12 @@ public void whenDeleteOperationWithDeleteIfConditionFails_shouldReturnFalseAndCa // Act Delete delete = - new Delete(Key.ofText("p1", "val1")) - .withCondition(ConditionBuilder.deleteIfExists()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .condition(ConditionBuilder.deleteIfExists()) + .build(); boolean ret = jdbcService.delete(delete, connection); // Assert @@ -574,10 +614,12 @@ public void whenDeleteOperationWithDeleteIfConditionFails_shouldReturnFalseAndCa // Act Delete delete = - new Delete(Key.ofText("p1", "val1")) - .withCondition(ConditionBuilder.deleteIfExists()) - .forNamespace(NAMESPACE) - .forTable(TABLE); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .condition(ConditionBuilder.deleteIfExists()) + .build(); boolean ret = jdbcService.delete(delete, connection); // Assert @@ -601,11 +643,18 @@ public void whenMutateOperationExecuted_shouldReturnTrueAndCallQueryBuilder() th // Act Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); - Delete delete = new Delete(Key.ofText("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); + Delete delete = + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .build(); boolean ret = jdbcService.mutate(Arrays.asList(put, delete), connection); // Assert diff --git a/core/src/test/java/com/scalar/db/storage/multistorage/MultiStorageTest.java b/core/src/test/java/com/scalar/db/storage/multistorage/MultiStorageTest.java index 2bc4cfdde5..f1952e0786 100644 --- a/core/src/test/java/com/scalar/db/storage/multistorage/MultiStorageTest.java +++ b/core/src/test/java/com/scalar/db/storage/multistorage/MultiStorageTest.java @@ -61,7 +61,13 @@ public void whenGetDataFromTable1_DataShouldBeGottenFromStorage1() throws Execut String table = TABLE1; Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME2, 2); - Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act multiStorage.get(get); @@ -77,7 +83,13 @@ public void whenGetDataFromTable2_DataShouldBeGottenFromStorage2() throws Execut String table = TABLE2; Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME2, 2); - Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act multiStorage.get(get); @@ -94,7 +106,13 @@ public void whenGetDataFromTable3_DataShouldBeGottenFromDefaultStorage() String table = TABLE3; Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME2, 2); - Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act multiStorage.get(get); @@ -109,7 +127,8 @@ public void whenScanDataFromTable1_DataShouldBeScannedFromStorage1() throws Exec String namespace = NAMESPACE1; String table = TABLE1; Key partitionKey = Key.ofInt(COL_NAME1, 1); - Scan scan = new Scan(partitionKey).forNamespace(namespace).forTable(table); + Scan scan = + Scan.newBuilder().namespace(namespace).table(table).partitionKey(partitionKey).build(); // Act multiStorage.scan(scan); @@ -123,7 +142,8 @@ public void whenScanDataFromTable2_DataShouldBeScannedFromStorage2() throws Exec String namespace = NAMESPACE1; String table = TABLE2; Key partitionKey = Key.ofInt(COL_NAME1, 1); - Scan scan = new Scan(partitionKey).forNamespace(namespace).forTable(table); + Scan scan = + Scan.newBuilder().namespace(namespace).table(table).partitionKey(partitionKey).build(); // Act multiStorage.scan(scan); @@ -139,7 +159,8 @@ public void whenScanDataFromTable3_DataShouldBeScannedFromDefaultStorage() String namespace = NAMESPACE1; String table = TABLE3; Key partitionKey = Key.ofInt(COL_NAME1, 1); - Scan scan = new Scan(partitionKey).forNamespace(namespace).forTable(table); + Scan scan = + Scan.newBuilder().namespace(namespace).table(table).partitionKey(partitionKey).build(); // Act multiStorage.scan(scan); @@ -156,10 +177,13 @@ public void whenPutDataIntoTable1_DataShouldBeWrittenIntoStorage1() throws Execu Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME2, 2); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL_NAME3, 3) + .build(); // Act multiStorage.put(put); @@ -176,10 +200,13 @@ public void whenPutDataIntoTable2_DataShouldBeWrittenIntoStorage2() throws Execu Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME2, 2); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL_NAME3, 3) + .build(); // Act multiStorage.put(put); @@ -197,10 +224,13 @@ public void whenPutDataIntoTable3_DataShouldBeWrittenIntoDefaultStorage() Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME2, 2); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL_NAME3, 3) + .build(); // Act multiStorage.put(put); @@ -216,7 +246,13 @@ public void whenDeleteDataFromTable1_DataShouldBeDeletedFromStorage1() throws Ex String table = TABLE1; Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME2, 2); - Delete delete = new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Delete delete = + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act multiStorage.delete(delete); @@ -232,7 +268,13 @@ public void whenDeleteDataFromTable2_DataShouldBeDeletedFromStorage2() throws Ex String table = TABLE2; Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME2, 2); - Delete delete = new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Delete delete = + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act multiStorage.delete(delete); @@ -249,7 +291,13 @@ public void whenDeleteDataFromTable3_DataShouldBeDeletedFromDefaultStorage() String table = TABLE3; Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME2, 2); - Delete delete = new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Delete delete = + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act multiStorage.delete(delete); @@ -270,11 +318,19 @@ public void whenMutateDataToTable1_ShouldExecuteForStorage1() throws ExecutionEx // Act multiStorage.mutate( Arrays.asList( - new Put(partitionKey, clusteringKey2) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table), - new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .intValue(COL_NAME3, 3) + .build(), + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .build())); // Assert verify(storage1).mutate(anyList()); @@ -292,11 +348,19 @@ public void whenMutateDataToTable2_ShouldExecuteForStorage2() throws ExecutionEx // Act multiStorage.mutate( Arrays.asList( - new Put(partitionKey, clusteringKey2) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table), - new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .intValue(COL_NAME3, 3) + .build(), + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .build())); // Assert verify(storage2).mutate(anyList()); @@ -314,11 +378,19 @@ public void whenMutateDataToTable3_ShouldExecuteForDefaultStorage() throws Execu // Act multiStorage.mutate( Arrays.asList( - new Put(partitionKey, clusteringKey2) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table), - new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .intValue(COL_NAME3, 3) + .build(), + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .build())); // Assert verify(storage3).mutate(anyList()); @@ -339,7 +411,13 @@ public void whenGetDataFromTable1InNamespace2_DataShouldBeGottenFromStorage2() String table = TABLE1; Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME2, 2); - Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Get get = + Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act multiStorage.get(get); @@ -355,7 +433,8 @@ public void whenScanDataFromTable1InNamespace2_DataShouldBeScannedFromStorage2() String namespace = NAMESPACE2; String table = TABLE1; Key partitionKey = Key.ofInt(COL_NAME1, 1); - Scan scan = new Scan(partitionKey).forNamespace(namespace).forTable(table); + Scan scan = + Scan.newBuilder().namespace(namespace).table(table).partitionKey(partitionKey).build(); // Act multiStorage.scan(scan); @@ -373,10 +452,13 @@ public void whenPutDataIntoTable1InNamespace2_DataShouldBeWrittenIntoStorage2() Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME2, 2); Put put = - new Put(partitionKey, clusteringKey) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL_NAME3, 3) + .build(); // Act multiStorage.put(put); @@ -393,7 +475,13 @@ public void whenDeleteDataFromTable1InNamespace2_DataShouldBeDeletedFromStorage1 String table = TABLE1; Key partitionKey = Key.ofInt(COL_NAME1, 1); Key clusteringKey = Key.ofInt(COL_NAME2, 2); - Delete delete = new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); + Delete delete = + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); // Act multiStorage.delete(delete); @@ -415,11 +503,19 @@ public void whenMutateDataToTable1InNamespace2_ShouldExecuteForStorage2() // Act multiStorage.mutate( Arrays.asList( - new Put(partitionKey, clusteringKey2) - .withValue(COL_NAME3, 3) - .forNamespace(namespace) - .forTable(table), - new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey2) + .intValue(COL_NAME3, 3) + .build(), + Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey1) + .build())); // Assert verify(storage2).mutate(anyList()); diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitHandlerTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitHandlerTest.java index 314fb399a9..e303490c1e 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitHandlerTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitHandlerTest.java @@ -122,28 +122,37 @@ void tearDown() { private Put preparePut1() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Put(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_INT_1); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(ANY_NAME_3, ANY_INT_1) + .build(); } private Put preparePut2() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_3); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_4); - return new Put(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_INT_2); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(ANY_NAME_3, ANY_INT_2) + .build(); } private Put preparePut3() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_3); - return new Put(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_INT_2); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(ANY_NAME_3, ANY_INT_2) + .build(); } private Get prepareGet() { diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposerTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposerTest.java index 2325809bf2..c6fe6dbc83 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposerTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposerTest.java @@ -98,26 +98,35 @@ public void setUp() throws Exception { private Put preparePut() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Put(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_INT_1); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(ANY_NAME_3, ANY_INT_1) + .build(); } private Delete prepareDelete() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Delete(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private Get prepareGet() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Get(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private TransactionResult prepareResult(TransactionState state) { @@ -193,16 +202,21 @@ public void add_PutAndNullResultGiven_ShouldComposePutWithPutIfCondition() // Assert Put actual = (Put) composer.get().get(0); Put expected = - new Put(put.getPartitionKey(), put.getClusteringKey().orElse(null)) - .forNamespace(put.forNamespace().get()) - .forTable(put.forTable().get()); - expected.withConsistency(Consistency.LINEARIZABLE); - expected.withCondition( - ConditionBuilder.putIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID)) - .and(ConditionBuilder.column(STATE).isEqualToInt(TransactionState.PREPARED.get())) - .build()); - expected.withBigIntValue(Attribute.COMMITTED_AT, ANY_TIME_2); - expected.withIntValue(Attribute.STATE, TransactionState.COMMITTED.get()); + Put.newBuilder() + .namespace(put.forNamespace().get()) + .table(put.forTable().get()) + .partitionKey(put.getPartitionKey()) + .clusteringKey(put.getClusteringKey().orElse(null)) + .consistency(Consistency.LINEARIZABLE) + .condition( + ConditionBuilder.putIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID)) + .and( + ConditionBuilder.column(STATE) + .isEqualToInt(TransactionState.PREPARED.get())) + .build()) + .bigIntValue(Attribute.COMMITTED_AT, ANY_TIME_2) + .intValue(Attribute.STATE, TransactionState.COMMITTED.get()) + .build(); assertThat(actual).isEqualTo(expected); } @@ -218,11 +232,15 @@ public void add_DeleteAndDeletedResultGiven_ShouldComposeDeleteWithDeleteIfCondi // Assert Delete actual = (Delete) composer.get().get(0); - delete.withConsistency(Consistency.LINEARIZABLE); - delete.withCondition( - ConditionBuilder.deleteIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID)) - .and(ConditionBuilder.column(STATE).isEqualToInt(TransactionState.DELETED.get())) - .build()); + delete = + Delete.newBuilder(delete) + .consistency(Consistency.LINEARIZABLE) + .condition( + ConditionBuilder.deleteIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID)) + .and( + ConditionBuilder.column(STATE).isEqualToInt(TransactionState.DELETED.get())) + .build()) + .build(); assertThat(actual).isEqualTo(delete); } @@ -237,11 +255,15 @@ public void add_DeleteAndNullResultGiven_ShouldComposeDeleteWithDeleteIfConditio // Assert Delete actual = (Delete) composer.get().get(0); - delete.withConsistency(Consistency.LINEARIZABLE); - delete.withCondition( - ConditionBuilder.deleteIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID)) - .and(ConditionBuilder.column(STATE).isEqualToInt(TransactionState.DELETED.get())) - .build()); + delete = + Delete.newBuilder(delete) + .consistency(Consistency.LINEARIZABLE) + .condition( + ConditionBuilder.deleteIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID)) + .and( + ConditionBuilder.column(STATE).isEqualToInt(TransactionState.DELETED.get())) + .build()) + .build(); assertThat(actual).isEqualTo(delete); } @@ -305,14 +327,18 @@ public void add_SelectionAndDeletedResultGiven_ShouldComposeDeleteForRollforward // Assert Delete actual = (Delete) composer.get().get(0); Delete expected = - new Delete(get.getPartitionKey(), get.getClusteringKey().orElse(null)) - .forNamespace(get.forNamespace().get()) - .forTable(get.forTable().get()); - expected.withConsistency(Consistency.LINEARIZABLE); - expected.withCondition( - ConditionBuilder.deleteIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID)) - .and(ConditionBuilder.column(STATE).isEqualToInt(TransactionState.DELETED.get())) - .build()); + Delete.newBuilder() + .namespace(get.forNamespace().get()) + .table(get.forTable().get()) + .partitionKey(get.getPartitionKey()) + .clusteringKey(get.getClusteringKey().orElse(null)) + .consistency(Consistency.LINEARIZABLE) + .condition( + ConditionBuilder.deleteIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID)) + .and( + ConditionBuilder.column(STATE).isEqualToInt(TransactionState.DELETED.get())) + .build()) + .build(); assertThat(actual).isEqualTo(expected); } } diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitTest.java index 152ff2a030..0a0fb5ca94 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitTest.java @@ -77,31 +77,44 @@ public void setUp() throws Exception { private Get prepareGet() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Get(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE) - .forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private Scan prepareScan() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); - return new Scan(partitionKey).forNamespace(ANY_NAMESPACE).forTable(ANY_TABLE_NAME); + return Scan.newBuilder() + .namespace(ANY_NAMESPACE) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); } private Put preparePut() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Put(partitionKey, clusteringKey) - .withValue(ANY_NAME_3, ANY_TEXT_3) - .forNamespace(ANY_NAMESPACE) - .forTable(ANY_TABLE_NAME); + return Put.newBuilder() + .namespace(ANY_NAMESPACE) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .textValue(ANY_NAME_3, ANY_TEXT_3) + .build(); } private Delete prepareDelete() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Delete(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE) - .forTable(ANY_TABLE_NAME); + return Delete.newBuilder() + .namespace(ANY_NAMESPACE) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } @Test diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/CrudHandlerTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/CrudHandlerTest.java index fba9f50547..ade215db15 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/CrudHandlerTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/CrudHandlerTest.java @@ -130,9 +130,12 @@ public void setUp() throws Exception { private Get prepareGet() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Get(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private Get toGetForStorageFrom(Get get) { @@ -141,7 +144,11 @@ private Get toGetForStorageFrom(Get get) { private Scan prepareScan() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); - return new Scan(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + return Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); } private Scan prepareCrossPartitionScan() { @@ -226,7 +233,7 @@ public void get_GetExistsInSnapshot_ShouldReturnFromSnapshot() throws CrudExcept expected.get(), Collections.emptyList(), TABLE_METADATA, false))); verify(storage).get(getForStorage); verify(snapshot).putIntoReadSet(key, Optional.of((TransactionResult) expected.get())); - verify(snapshot).putIntoGetSet(get, Optional.of((TransactionResult) expected.get())); + verify(snapshot).putIntoGetSet(getForStorage, Optional.of((TransactionResult) expected.get())); } @Test @@ -266,7 +273,7 @@ public void get_GetExistsInSnapshot_ShouldReturnFromSnapshot() throws CrudExcept expected.get(), Collections.emptyList(), TABLE_METADATA, false))); verify(storage).get(getForStorage); verify(snapshot, never()).putIntoReadSet(any(), any()); - verify(snapshot).putIntoGetSet(get, Optional.of((TransactionResult) expected.get())); + verify(snapshot).putIntoGetSet(getForStorage, Optional.of((TransactionResult) expected.get())); } @Test @@ -350,7 +357,7 @@ public void get_GetExistsInSnapshot_ShouldReturnFromSnapshot() throws CrudExcept expected.get(), Collections.emptyList(), TABLE_METADATA, false))); verify(storage).get(getForStorage); verify(snapshot, never()).putIntoReadSet(any(), any()); - verify(snapshot).putIntoGetSet(get, Optional.of((TransactionResult) expected.get())); + verify(snapshot).putIntoGetSet(getForStorage, Optional.of((TransactionResult) expected.get())); } @Test @@ -401,7 +408,7 @@ public void get_GetExistsInSnapshot_ShouldReturnFromSnapshot() throws CrudExcept .or(column(Attribute.BEFORE_PREFIX + ANY_NAME_3).isEqualToText(ANY_TEXT_3)) .build()); verify(snapshot, never()).putIntoReadSet(any(), any()); - verify(snapshot).putIntoGetSet(get, Optional.of((TransactionResult) expected.get())); + verify(snapshot).putIntoGetSet(getForStorage, Optional.of((TransactionResult) expected.get())); } @Test @@ -855,8 +862,9 @@ public void get_ForNonExistingTable_ShouldThrowIllegalArgumentException() .partitionKey(partitionKey) .clusteringKey(clusteringKey) .build(); + Get getForStorage = toGetForStorageFrom(get); - when(tableMetadataManager.getTransactionTableMetadata(get)).thenReturn(null); + when(tableMetadataManager.getTransactionTableMetadata(getForStorage)).thenReturn(null); // Act Assert assertThatThrownBy(() -> handler.get(get)).isInstanceOf(IllegalArgumentException.class); @@ -923,8 +931,9 @@ void scanOrGetScanner_ResultGivenFromStorage_ShouldUpdateSnapshotAndReturn(ScanT // Assert verify(scanner).close(); verify(snapshot).putIntoReadSet(key, Optional.of(expected)); - verify(snapshot).putIntoScanSet(scan, Maps.newLinkedHashMap(ImmutableMap.of(key, expected))); - verify(snapshot).verifyNoOverlap(scan, ImmutableMap.of(key, expected)); + verify(snapshot) + .putIntoScanSet(scanForStorage, Maps.newLinkedHashMap(ImmutableMap.of(key, expected))); + verify(snapshot).verifyNoOverlap(scanForStorage, ImmutableMap.of(key, expected)); assertThat(results.size()).isEqualTo(1); assertThat(results.get(0)) .isEqualTo(new FilteredResult(expected, Collections.emptyList(), TABLE_METADATA, false)); @@ -964,7 +973,8 @@ void scanOrGetScanner_ResultGivenFromStorage_InReadOnlyMode_ShouldUpdateSnapshot // Assert verify(snapshot, never()).putIntoReadSet(any(), any()); - verify(snapshot).putIntoScanSet(scan, Maps.newLinkedHashMap(ImmutableMap.of(key, expected))); + verify(snapshot) + .putIntoScanSet(scanForStorage, Maps.newLinkedHashMap(ImmutableMap.of(key, expected))); verify(snapshot, never()).verifyNoOverlap(any(), any()); assertThat(results.size()).isEqualTo(1); assertThat(results.get(0)) @@ -1049,7 +1059,8 @@ void scanOrGetScanner_ResultGivenFromStorage_InReadOnlyMode_ShouldUpdateSnapshot // Assert verify(snapshot, never()).putIntoReadSet(any(), any()); - verify(snapshot).putIntoScanSet(scan, Maps.newLinkedHashMap(ImmutableMap.of(key, expected))); + verify(snapshot) + .putIntoScanSet(scanForStorage, Maps.newLinkedHashMap(ImmutableMap.of(key, expected))); verify(snapshot, never()).verifyNoOverlap(any(), any()); assertThat(results.size()).isEqualTo(1); assertThat(results.get(0)) @@ -1331,7 +1342,7 @@ void scanOrGetScanner_GetCalledAfterScan_ShouldReturnFromStorage(ScanType scanTy Get getForStorage = toGetForStorageFrom(get); Optional transactionResult = Optional.of(new TransactionResult(result)); when(storage.get(getForStorage)).thenReturn(Optional.of(result)); - when(snapshot.getResult(key, get)).thenReturn(transactionResult); + when(snapshot.getResult(key, getForStorage)).thenReturn(transactionResult); when(snapshot.getResult(key)).thenReturn(transactionResult); // Act @@ -1373,7 +1384,8 @@ void scanOrGetScanner_GetCalledAfterScanUnderRealSnapshot_ShouldReturnFromStorag } when(storage.scan(scan)).thenReturn(scanner); Get get = prepareGet(); - when(storage.get(get)).thenReturn(Optional.of(result)); + Get getForStorage = toGetForStorageFrom(get); + when(storage.get(getForStorage)).thenReturn(Optional.of(result)); // Act List results = scanOrGetScanner(scan, scanType); @@ -1381,7 +1393,7 @@ void scanOrGetScanner_GetCalledAfterScanUnderRealSnapshot_ShouldReturnFromStorag // Assert verify(storage).scan(scan); - verify(storage).get(get); + verify(storage).get(getForStorage); verify(scanner).close(); assertThat(results.size()).isEqualTo(1); @@ -1448,9 +1460,12 @@ void scanOrGetScanner_CalledAfterDeleteUnderRealSnapshot_ShouldThrowIllegalArgum when(storage.scan(scanForStorage)).thenReturn(scanner); Delete delete = - new Delete(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_3)) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_3)) + .build(); // Act Assert handler.delete(delete); @@ -1472,6 +1487,7 @@ void scanOrGetScanner_CalledAfterDeleteUnderRealSnapshot_ShouldThrowIllegalArgum ScanType scanType) throws ExecutionException, CrudException, IOException { // Arrange Scan scan = prepareCrossPartitionScan(); + Scan scanForStorage = toScanForStorageFrom(scan); result = prepareResult(TransactionState.COMMITTED); Snapshot.Key key = new Snapshot.Key(scan, result); if (scanType == ScanType.SCAN) { @@ -1489,8 +1505,9 @@ void scanOrGetScanner_CalledAfterDeleteUnderRealSnapshot_ShouldThrowIllegalArgum verify(scanner).close(); verify(snapshot).putIntoReadSet(key, Optional.of(transactionResult)); verify(snapshot) - .putIntoScanSet(scan, Maps.newLinkedHashMap(ImmutableMap.of(key, transactionResult))); - verify(snapshot).verifyNoOverlap(scan, ImmutableMap.of(key, transactionResult)); + .putIntoScanSet( + scanForStorage, Maps.newLinkedHashMap(ImmutableMap.of(key, transactionResult))); + verify(snapshot).verifyNoOverlap(scanForStorage, ImmutableMap.of(key, transactionResult)); assertThat(results.size()).isEqualTo(1); assertThat(results.get(0)) .isEqualTo( @@ -1621,8 +1638,9 @@ void scanOrGetScanner_WithLimit_ShouldReturnLimitedResults(ScanType scanType) throws CrudException, ExecutionException, IOException { // Arrange Scan scanWithoutLimit = prepareScan(); + Scan scanWithoutLimitForStorage = toScanForStorageFrom(scanWithoutLimit); Scan scanWithLimit = Scan.newBuilder(scanWithoutLimit).limit(2).build(); - Scan scanForStorage = toScanForStorageFrom(scanWithoutLimit); + Scan scanWithLimitForStorage = toScanForStorageFrom(scanWithLimit); Result result1 = prepareResult(ANY_TEXT_1, ANY_TEXT_2, TransactionState.COMMITTED); Result result2 = prepareResult(ANY_TEXT_1, ANY_TEXT_3, TransactionState.COMMITTED); @@ -1642,7 +1660,7 @@ void scanOrGetScanner_WithLimit_ShouldReturnLimitedResults(ScanType scanType) .thenReturn(Optional.of(result2)) .thenReturn(Optional.empty()); } - when(storage.scan(scanForStorage)).thenReturn(scanner); + when(storage.scan(scanWithoutLimitForStorage)).thenReturn(scanner); // Act List results = scanOrGetScanner(scanWithLimit, scanType); @@ -1663,7 +1681,7 @@ void scanOrGetScanner_WithLimit_ShouldReturnLimitedResults(ScanType scanType) @SuppressWarnings("unchecked") ArgumentCaptor> resultsCaptor = ArgumentCaptor.forClass(LinkedHashMap.class); - verify(snapshot).putIntoScanSet(eq(scanWithLimit), resultsCaptor.capture()); + verify(snapshot).putIntoScanSet(eq(scanWithLimitForStorage), resultsCaptor.capture()); LinkedHashMap capturedResults = resultsCaptor.getValue(); assertThat(capturedResults).hasSize(2); @@ -1890,8 +1908,8 @@ public void getScanner_ExecutionExceptionThrownByScannerOne_ShouldThrowCrudExcep verify(scanner).close(); verify(snapshot).putIntoReadSet(key1, Optional.of(txResult1)); verify(snapshot) - .putIntoScannerSet(scan, Maps.newLinkedHashMap(ImmutableMap.of(key1, txResult1))); - verify(snapshot).verifyNoOverlap(scan, ImmutableMap.of(key1, txResult1)); + .putIntoScannerSet(scanForStorage, Maps.newLinkedHashMap(ImmutableMap.of(key1, txResult1))); + verify(snapshot).verifyNoOverlap(scanForStorage, ImmutableMap.of(key1, txResult1)); assertThat(actualResult) .hasValue(new FilteredResult(txResult1, Collections.emptyList(), TABLE_METADATA, false)); @@ -1978,7 +1996,7 @@ public void getScanner_ExecutionExceptionThrownByScannerOne_ShouldThrowCrudExcep // Assert verify(snapshot, never()).putIntoReadSet(any(), any()); verify(snapshot) - .putIntoScannerSet(scan, Maps.newLinkedHashMap(ImmutableMap.of(key1, txResult1))); + .putIntoScannerSet(scanForStorage, Maps.newLinkedHashMap(ImmutableMap.of(key1, txResult1))); verify(snapshot, never()).verifyNoOverlap(any(), any()); assertThat(actualResult) diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/MergedResultTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/MergedResultTest.java index be71d3dd11..8c1a1ae197 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/MergedResultTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/MergedResultTest.java @@ -107,8 +107,12 @@ public void setUp() { public void getPartitionKey_ResultAndPutGiven_ShouldReturnCorrectKey() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .build(); MergedResult mergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA); @@ -123,8 +127,12 @@ public void getPartitionKey_ResultAndPutGiven_ShouldReturnCorrectKey() { public void getPartitionKey_OnlyPutGiven_ShouldReturnCorrectKey() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .build(); MergedResult mergedResult = new MergedResult(Optional.empty(), put, TABLE_METADATA); @@ -139,8 +147,12 @@ public void getPartitionKey_OnlyPutGiven_ShouldReturnCorrectKey() { public void getClusteringKey_ResultAndPutGiven_ShouldReturnCorrectKey() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .build(); MergedResult mergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA); @@ -155,8 +167,12 @@ public void getClusteringKey_ResultAndPutGiven_ShouldReturnCorrectKey() { public void getClusteringKey_OnlyPutGiven_ShouldReturnCorrectKey() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .build(); MergedResult mergedResult = new MergedResult(Optional.empty(), put, TABLE_METADATA); @@ -171,8 +187,12 @@ public void getClusteringKey_OnlyPutGiven_ShouldReturnCorrectKey() { public void getValue_ResultAndPutGiven_ShouldReturnMergedValue() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .build(); MergedResult mergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA); @@ -319,8 +339,12 @@ public void getValue_ResultAndPutGiven_ShouldReturnMergedValue() { public void getValue_OnlyPutGiven_ShouldReturnMergedValue() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .build(); MergedResult mergedResult = new MergedResult(Optional.empty(), put, TABLE_METADATA); @@ -462,9 +486,13 @@ public void getValue_OnlyPutGiven_ShouldReturnMergedValue() { public void getValue_ResultAndPutWithNullValueGiven_ShouldReturnMergedValue() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3) - .withTextValue(ANY_NAME_4, null); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .textValue(ANY_NAME_4, null) + .build(); MergedResult mergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA); @@ -611,8 +639,12 @@ public void getValue_ResultAndPutWithNullValueGiven_ShouldReturnMergedValue() { public void getValues_ResultAndPutGiven_ShouldReturnMergedValues() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .build(); MergedResult mergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA); @@ -651,8 +683,12 @@ public void getValues_ResultAndPutGiven_ShouldReturnMergedValues() { public void getValues_OnlyPutGiven_ShouldReturnMergedValues() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .build(); MergedResult mergedResult = new MergedResult(Optional.empty(), put, TABLE_METADATA); @@ -689,9 +725,13 @@ public void getValues_OnlyPutGiven_ShouldReturnMergedValues() { public void getValues_ResultAndPutWithNullValueGiven_ShouldReturnMergedValues() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3) - .withTextValue(ANY_NAME_4, null); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .textValue(ANY_NAME_4, null) + .build(); MergedResult mergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA); @@ -730,8 +770,12 @@ public void getValues_ResultAndPutWithNullValueGiven_ShouldReturnMergedValues() public void equals_SamePutAndResultGiven_ShouldReturnTrue() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .build(); MergedResult mergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA); MergedResult anotherMergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA); @@ -747,8 +791,12 @@ public void equals_SamePutAndResultGiven_ShouldReturnTrue() { public void equals_DifferentPutAndResultGiven_ShouldReturnFalse() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .build(); MergedResult mergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA); MergedResult anotherMergedResult = new MergedResult(Optional.empty(), put, TABLE_METADATA); @@ -764,8 +812,12 @@ public void equals_DifferentPutAndResultGiven_ShouldReturnFalse() { public void equals_ResultImplWithSamePutAndResultGiven_ShouldReturnTrue() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .build(); MergedResult mergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA); Result another = @@ -811,8 +863,12 @@ public void equals_ResultImplWithSamePutAndResultGiven_ShouldReturnTrue() { public void equals_ResultImplWithDifferentPutAndResultGiven_ShouldReturnFalse() { // Arrange Put put = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withValue(ANY_NAME_3, ANY_INT_3); + Put.newBuilder() + .table("test") + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .intValue(ANY_NAME_3, ANY_INT_3) + .build(); MergedResult mergedResult = new MergedResult(Optional.of(result), put, TABLE_METADATA); Result another = new ResultImpl(Collections.emptyMap(), TABLE_METADATA); diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/PrepareMutationComposerTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/PrepareMutationComposerTest.java index 5f800fa2c9..e118bce6fa 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/PrepareMutationComposerTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/PrepareMutationComposerTest.java @@ -78,19 +78,25 @@ public void setUp() throws Exception { private Put preparePut() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Put(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_INT_3) - .withValue(ANY_NAME_WITH_BEFORE_PREFIX, ANY_INT_3); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(ANY_NAME_3, ANY_INT_3) + .intValue(ANY_NAME_WITH_BEFORE_PREFIX, ANY_INT_3) + .build(); } private Delete prepareDelete() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Delete(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private Scan prepareScan() { @@ -166,20 +172,23 @@ public void add_PutAndResultGiven_ShouldComposePutWithPutIfCondition() throws Ex // Assert Put actual = (Put) composer.get().get(0); - put.withConsistency(Consistency.LINEARIZABLE); - put.withCondition( - ConditionBuilder.putIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID_2)).build()); - put.withValue(Attribute.PREPARED_AT, ANY_TIME_5); - put.withValue(Attribute.ID, ANY_ID_3); - put.withValue(Attribute.STATE, TransactionState.PREPARED.get()); - put.withValue(Attribute.VERSION, 3); - put.withValue(Attribute.BEFORE_PREPARED_AT, ANY_TIME_3); - put.withValue(Attribute.BEFORE_COMMITTED_AT, ANY_TIME_4); - put.withValue(Attribute.BEFORE_ID, ANY_ID_2); - put.withValue(Attribute.BEFORE_STATE, TransactionState.COMMITTED.get()); - put.withValue(Attribute.BEFORE_VERSION, 2); - put.withValue(Attribute.BEFORE_PREFIX + ANY_NAME_3, ANY_INT_2); - put.withValue(Attribute.BEFORE_PREFIX + ANY_NAME_WITH_BEFORE_PREFIX, ANY_INT_2); + put = + Put.newBuilder(put) + .consistency(Consistency.LINEARIZABLE) + .condition( + ConditionBuilder.putIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID_2)).build()) + .bigIntValue(Attribute.PREPARED_AT, ANY_TIME_5) + .textValue(Attribute.ID, ANY_ID_3) + .intValue(Attribute.STATE, TransactionState.PREPARED.get()) + .intValue(Attribute.VERSION, 3) + .bigIntValue(Attribute.BEFORE_PREPARED_AT, ANY_TIME_3) + .bigIntValue(Attribute.BEFORE_COMMITTED_AT, ANY_TIME_4) + .textValue(Attribute.BEFORE_ID, ANY_ID_2) + .intValue(Attribute.BEFORE_STATE, TransactionState.COMMITTED.get()) + .intValue(Attribute.BEFORE_VERSION, 2) + .intValue(Attribute.BEFORE_PREFIX + ANY_NAME_3, ANY_INT_2) + .intValue(Attribute.BEFORE_PREFIX + ANY_NAME_WITH_BEFORE_PREFIX, ANY_INT_2) + .build(); assertThat(actual).isEqualTo(put); } @@ -225,12 +234,15 @@ public void add_PutAndNullResultGiven_ShouldComposePutWithPutIfNotExistsConditio // Assert Put actual = (Put) composer.get().get(0); - put.withConsistency(Consistency.LINEARIZABLE); - put.withCondition(ConditionBuilder.putIfNotExists()); - put.withValue(Attribute.PREPARED_AT, ANY_TIME_5); - put.withValue(Attribute.ID, ANY_ID_3); - put.withValue(Attribute.STATE, TransactionState.PREPARED.get()); - put.withValue(Attribute.VERSION, 1); + put = + Put.newBuilder(put) + .consistency(Consistency.LINEARIZABLE) + .condition(ConditionBuilder.putIfNotExists()) + .bigIntValue(Attribute.PREPARED_AT, ANY_TIME_5) + .textValue(Attribute.ID, ANY_ID_3) + .intValue(Attribute.STATE, TransactionState.PREPARED.get()) + .intValue(Attribute.VERSION, 1) + .build(); assertThat(actual).isEqualTo(put); } @@ -296,23 +308,26 @@ public void add_DeleteAndResultGiven_ShouldComposePutWithPutIfCondition() // Assert Put actual = (Put) composer.get().get(0); Put expected = - new Put(delete.getPartitionKey(), delete.getClusteringKey().orElse(null)) - .forNamespace(delete.forNamespace().get()) - .forTable(delete.forTable().get()); - expected.withConsistency(Consistency.LINEARIZABLE); - expected.withCondition( - ConditionBuilder.putIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID_2)).build()); - expected.withValue(Attribute.PREPARED_AT, ANY_TIME_5); - expected.withValue(Attribute.ID, ANY_ID_3); - expected.withValue(Attribute.STATE, TransactionState.DELETED.get()); - expected.withValue(Attribute.VERSION, 3); - expected.withValue(Attribute.BEFORE_PREPARED_AT, ANY_TIME_3); - expected.withValue(Attribute.BEFORE_COMMITTED_AT, ANY_TIME_4); - expected.withValue(Attribute.BEFORE_ID, ANY_ID_2); - expected.withValue(Attribute.BEFORE_STATE, TransactionState.COMMITTED.get()); - expected.withValue(Attribute.BEFORE_VERSION, 2); - expected.withValue(Attribute.BEFORE_PREFIX + ANY_NAME_3, ANY_INT_2); - expected.withValue(Attribute.BEFORE_PREFIX + ANY_NAME_WITH_BEFORE_PREFIX, ANY_INT_2); + Put.newBuilder() + .namespace(delete.forNamespace().get()) + .table(delete.forTable().get()) + .partitionKey(delete.getPartitionKey()) + .clusteringKey(delete.getClusteringKey().orElse(null)) + .consistency(Consistency.LINEARIZABLE) + .condition( + ConditionBuilder.putIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID_2)).build()) + .bigIntValue(Attribute.PREPARED_AT, ANY_TIME_5) + .textValue(Attribute.ID, ANY_ID_3) + .intValue(Attribute.STATE, TransactionState.DELETED.get()) + .intValue(Attribute.VERSION, 3) + .bigIntValue(Attribute.BEFORE_PREPARED_AT, ANY_TIME_3) + .bigIntValue(Attribute.BEFORE_COMMITTED_AT, ANY_TIME_4) + .textValue(Attribute.BEFORE_ID, ANY_ID_2) + .intValue(Attribute.BEFORE_STATE, TransactionState.COMMITTED.get()) + .intValue(Attribute.BEFORE_VERSION, 2) + .intValue(Attribute.BEFORE_PREFIX + ANY_NAME_3, ANY_INT_2) + .intValue(Attribute.BEFORE_PREFIX + ANY_NAME_WITH_BEFORE_PREFIX, ANY_INT_2) + .build(); assertThat(actual).isEqualTo(expected); } @@ -363,15 +378,18 @@ public void add_DeleteAndNullResultGiven_ShouldComposePutWithPutIfNotExistsCondi // Assert Put actual = (Put) composer.get().get(0); Put expected = - new Put(delete.getPartitionKey(), delete.getClusteringKey().orElse(null)) - .forNamespace(delete.forNamespace().get()) - .forTable(delete.forTable().get()); - expected.withConsistency(Consistency.LINEARIZABLE); - expected.withCondition(ConditionBuilder.putIfNotExists()); - expected.withValue(Attribute.PREPARED_AT, ANY_TIME_5); - expected.withValue(Attribute.ID, ANY_ID_3); - expected.withValue(Attribute.STATE, TransactionState.DELETED.get()); - expected.withValue(Attribute.VERSION, 1); + Put.newBuilder() + .namespace(delete.forNamespace().get()) + .table(delete.forTable().get()) + .partitionKey(delete.getPartitionKey()) + .clusteringKey(delete.getClusteringKey().orElse(null)) + .consistency(Consistency.LINEARIZABLE) + .condition(ConditionBuilder.putIfNotExists()) + .bigIntValue(Attribute.PREPARED_AT, ANY_TIME_5) + .textValue(Attribute.ID, ANY_ID_3) + .intValue(Attribute.STATE, TransactionState.DELETED.get()) + .intValue(Attribute.VERSION, 1) + .build(); assertThat(actual).isEqualTo(expected); } diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposerTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposerTest.java index 9ab76db1b7..6c554e57d1 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposerTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposerTest.java @@ -149,18 +149,23 @@ public void setUp() throws Exception { private Get prepareGet() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Get(partitionKey, clusteringKey) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private Scan prepareScan() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); - return new Scan(partitionKey) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private Put preparePut() { @@ -801,14 +806,19 @@ public void add_ScanAndPreparedResultByThisGivenAndBeforeResultNotGiven_ShouldCo // Assert Delete actual = (Delete) composer.get().get(0); Delete expected = - new Delete(scan.getPartitionKey(), result.getClusteringKey().orElse(null)) - .forNamespace(scan.forNamespace().get()) - .forTable(scan.forTable().get()); - expected.withConsistency(Consistency.LINEARIZABLE); - expected.withCondition( - ConditionBuilder.deleteIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID_2)) - .and(ConditionBuilder.column(STATE).isEqualToInt(TransactionState.PREPARED.get())) - .build()); + Delete.newBuilder() + .namespace(scan.forNamespace().get()) + .table(scan.forTable().get()) + .partitionKey(scan.getPartitionKey()) + .clusteringKey(result.getClusteringKey().orElse(null)) + .consistency(Consistency.LINEARIZABLE) + .condition( + ConditionBuilder.deleteIf(ConditionBuilder.column(ID).isEqualToText(ANY_ID_2)) + .and( + ConditionBuilder.column(STATE) + .isEqualToInt(TransactionState.PREPARED.get())) + .build()) + .build(); assertThat(actual).isEqualTo(expected); } } diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/SnapshotKeyTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/SnapshotKeyTest.java index 72326f5b8f..fd504bb82b 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/SnapshotKeyTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/SnapshotKeyTest.java @@ -19,22 +19,32 @@ public class SnapshotKeyTest { private Get prepareGet() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Get(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private Get prepareGetWithoutClusteringKey() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); - return new Get(partitionKey).forNamespace(ANY_NAMESPACE_NAME).forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); } private Get prepareAnotherGet() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_3); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_4); - return new Get(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } @Test diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/SnapshotTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/SnapshotTest.java index 710a51ee73..864ca98031 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/SnapshotTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/SnapshotTest.java @@ -30,7 +30,6 @@ import com.scalar.db.common.ResultImpl; import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.transaction.CrudException; -import com.scalar.db.exception.transaction.PreparationConflictException; import com.scalar.db.exception.transaction.ValidationConflictException; import com.scalar.db.io.Column; import com.scalar.db.io.DataType; @@ -177,19 +176,25 @@ private TransactionResult prepareResultWithNullMetadata() { private Get prepareGet() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Get(partitionKey, clusteringKey) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private Get prepareAnotherGet() { Key partitionKey = Key.ofText(ANY_NAME_5, ANY_TEXT_5); Key clusteringKey = Key.ofText(ANY_NAME_6, ANY_TEXT_6); - return new Get(partitionKey, clusteringKey) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private Get prepareGetWithIndex() { @@ -204,11 +209,13 @@ private Get prepareGetWithIndex() { private Scan prepareScan() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Scan(partitionKey) - .withStart(clusteringKey) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .start(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private Scan prepareScanWithLimit(int limit) { @@ -262,20 +269,25 @@ private Put preparePut(String partitionKeyColumnValue, String clusteringKeyColum private Put prepareAnotherPut() { Key partitionKey = Key.ofText(ANY_NAME_5, ANY_TEXT_5); Key clusteringKey = Key.ofText(ANY_NAME_6, ANY_TEXT_6); - return new Put(partitionKey, clusteringKey) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private Put preparePutWithPartitionKeyOnly() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); - return new Put(partitionKey) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_TEXT_3) - .withValue(ANY_NAME_4, ANY_TEXT_4); + return Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .textValue(ANY_NAME_3, ANY_TEXT_3) + .textValue(ANY_NAME_4, ANY_TEXT_4) + .consistency(Consistency.LINEARIZABLE) + .build(); } private Put preparePutWithIntColumns() { @@ -322,10 +334,13 @@ private Delete prepareDelete(String partitionKeyColumnValue, String clusteringKe private Delete prepareAnotherDelete() { Key partitionKey = Key.ofText(ANY_NAME_5, ANY_TEXT_5); Key clusteringKey = Key.ofText(ANY_NAME_6, ANY_TEXT_6); - return new Delete(partitionKey, clusteringKey) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + return Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private void configureBehavior() throws ExecutionException { @@ -807,7 +822,7 @@ public void getResult_KeyContainedInDeleteSetAndGetContainedInGetSetGiven_Should } @Test - public void getResults_ScanNotContainedInScanSetGiven_ShouldReturnEmpty() throws CrudException { + public void getResults_ScanNotContainedInScanSetGiven_ShouldReturnEmpty() { // Arrange snapshot = prepareSnapshot(Isolation.SNAPSHOT); Scan scan = prepareScan(); @@ -820,8 +835,7 @@ public void getResults_ScanNotContainedInScanSetGiven_ShouldReturnEmpty() throws } @Test - public void getResults_ScanContainedInScanSetGiven_ShouldReturnProperResults() - throws CrudException { + public void getResults_ScanContainedInScanSetGiven_ShouldReturnProperResults() { // Arrange snapshot = prepareSnapshot(Isolation.SNAPSHOT); Scan scan = prepareScan(); @@ -914,7 +928,7 @@ private void assertMergedResultIsEqualTo(TransactionResult result) { @Test public void to_PrepareMutationComposerGivenAndSnapshotIsolationSet_ShouldCallComposerProperly() - throws PreparationConflictException, ExecutionException { + throws ExecutionException { // Arrange snapshot = prepareSnapshot(Isolation.SNAPSHOT); Put put = preparePut(); @@ -936,7 +950,7 @@ public void to_PrepareMutationComposerGivenAndSnapshotIsolationSet_ShouldCallCom @Test public void to_CommitMutationComposerGiven_ShouldCallComposerProperly() - throws PreparationConflictException, ExecutionException { + throws ExecutionException { // Arrange snapshot = prepareSnapshot(Isolation.SNAPSHOT); Put put = preparePut(); @@ -957,7 +971,7 @@ public void to_CommitMutationComposerGiven_ShouldCallComposerProperly() @Test public void to_RollbackMutationComposerGiven_ShouldCallComposerProperly() - throws PreparationConflictException, ExecutionException { + throws ExecutionException { // Arrange snapshot = prepareSnapshot(Isolation.SNAPSHOT); Put put = preparePut(); @@ -989,7 +1003,7 @@ public void toSerializable_ReadSetNotChanged_ShouldProcessWithoutExceptions() snapshot.putIntoGetSet(get, Optional.of(txResult)); snapshot.putIntoWriteSet(new Snapshot.Key(put), put); DistributedStorage storage = mock(DistributedStorage.class); - Get getWithProjections = prepareAnotherGet().withProjection(Attribute.ID); + Get getWithProjections = Get.newBuilder(prepareAnotherGet()).projection(Attribute.ID).build(); when(storage.get(getWithProjections)).thenReturn(Optional.of(txResult)); // Act Assert @@ -1011,7 +1025,7 @@ public void toSerializable_ReadSetUpdated_ShouldThrowValidationConflictException snapshot.putIntoWriteSet(new Snapshot.Key(put), put); DistributedStorage storage = mock(DistributedStorage.class); TransactionResult changedTxResult = prepareResult(ANY_ID + "x"); - Get getWithProjections = prepareAnotherGet().withProjection(Attribute.ID); + Get getWithProjections = Get.newBuilder(prepareAnotherGet()).projection(Attribute.ID).build(); when(storage.get(getWithProjections)).thenReturn(Optional.of(changedTxResult)); // Act Assert @@ -1033,7 +1047,7 @@ public void toSerializable_ReadSetExtended_ShouldThrowValidationConflictExceptio snapshot.putIntoWriteSet(new Snapshot.Key(put), put); DistributedStorage storage = mock(DistributedStorage.class); TransactionResult txResult = prepareResult(ANY_ID); - Get getWithProjections = prepareAnotherGet().withProjection(Attribute.ID); + Get getWithProjections = Get.newBuilder(prepareAnotherGet()).projection(Attribute.ID).build(); when(storage.get(getWithProjections)).thenReturn(Optional.of(txResult)); // Act Assert @@ -1054,7 +1068,9 @@ public void toSerializable_GetSetWithGetWithIndex_ShouldProcessWithoutExceptions snapshot.putIntoGetSet(getWithIndex, Optional.of(txResult)); DistributedStorage storage = mock(DistributedStorage.class); Scan scanWithIndex = - prepareScanWithIndex().withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder(prepareScanWithIndex()) + .projections(Attribute.ID, ANY_NAME_1, ANY_NAME_2) + .build(); Scanner scanner = mock(Scanner.class); when(scanner.one()).thenReturn(Optional.of(txResult)).thenReturn(Optional.empty()); when(storage.scan(scanWithIndex)).thenReturn(scanner); @@ -1078,7 +1094,9 @@ public void toSerializable_GetSetWithGetWithIndex_ShouldProcessWithoutExceptions snapshot.putIntoGetSet(getWithIndex, Optional.of(result1)); DistributedStorage storage = mock(DistributedStorage.class); Scan scanWithIndex = - prepareScanWithIndex().withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder(prepareScanWithIndex()) + .projections(Attribute.ID, ANY_NAME_1, ANY_NAME_2) + .build(); Scanner scanner = mock(Scanner.class); when(scanner.one()) .thenReturn(Optional.of(result1)) @@ -1106,7 +1124,9 @@ public void toSerializable_GetSetWithGetWithIndex_ShouldProcessWithoutExceptions snapshot.putIntoGetSet(getWithIndex, Optional.of(result1)); DistributedStorage storage = mock(DistributedStorage.class); Scan scanWithIndex = - prepareScanWithIndex().withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder(prepareScanWithIndex()) + .projections(Attribute.ID, ANY_NAME_1, ANY_NAME_2) + .build(); Scanner scanner = mock(Scanner.class); when(scanner.one()) .thenReturn(Optional.of(result1)) @@ -1134,7 +1154,7 @@ public void toSerializable_ScanSetNotChanged_ShouldProcessWithoutExceptions() Scanner scanner = mock(Scanner.class); when(scanner.one()).thenReturn(Optional.of(txResult)).thenReturn(Optional.empty()); Scan scanWithProjections = - prepareScan().withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder(prepareScan()).projections(Attribute.ID, ANY_NAME_1, ANY_NAME_2).build(); when(storage.scan(scanWithProjections)).thenReturn(scanner); // Act Assert @@ -1158,7 +1178,7 @@ public void toSerializable_ScanSetUpdated_ShouldThrowValidationConflictException Scanner scanner = mock(Scanner.class); when(scanner.one()).thenReturn(Optional.of(changedTxResult)).thenReturn(Optional.empty()); Scan scanWithProjections = - prepareScan().withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder(prepareScan()).projections(Attribute.ID, ANY_NAME_1, ANY_NAME_2).build(); when(storage.scan(scanWithProjections)).thenReturn(scanner); // Act Assert @@ -1183,7 +1203,7 @@ public void toSerializable_ScanSetUpdatedByMyself_ShouldProcessWithoutExceptions Scanner scanner = mock(Scanner.class); when(scanner.one()).thenReturn(Optional.of(changedTxResult)).thenReturn(Optional.empty()); Scan scanWithProjections = - prepareScan().withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder(prepareScan()).projections(Attribute.ID, ANY_NAME_1, ANY_NAME_2).build(); when(storage.scan(scanWithProjections)).thenReturn(scanner); // Act Assert @@ -1206,7 +1226,7 @@ public void toSerializable_ScanSetExtended_ShouldThrowValidationConflictExceptio Scanner scanner = mock(Scanner.class); when(scanner.one()).thenReturn(Optional.of(txResult)).thenReturn(Optional.empty()); Scan scanWithProjections = - prepareScan().withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder(prepareScan()).projections(Attribute.ID, ANY_NAME_1, ANY_NAME_2).build(); when(storage.scan(scanWithProjections)).thenReturn(scanner); // Act Assert @@ -1235,7 +1255,7 @@ public void toSerializable_ScanSetExtended_ShouldThrowValidationConflictExceptio .thenReturn(Optional.of(result2)) .thenReturn(Optional.empty()); Scan scanWithProjections = - prepareScan().withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder(prepareScan()).projections(Attribute.ID, ANY_NAME_1, ANY_NAME_2).build(); when(storage.scan(scanWithProjections)).thenReturn(scanner); // Act Assert @@ -1259,7 +1279,7 @@ public void toSerializable_ScanSetExtendedByMyself_ShouldProcessWithoutException Scanner scanner = mock(Scanner.class); when(scanner.one()).thenReturn(Optional.of(txResult)).thenReturn(Optional.empty()); Scan scanWithProjections = - prepareScan().withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder(prepareScan()).projections(Attribute.ID, ANY_NAME_1, ANY_NAME_2).build(); when(storage.scan(scanWithProjections)).thenReturn(scanner); // Act Assert @@ -1287,7 +1307,7 @@ public void toSerializable_ScanSetExtendedByMyself_ShouldProcessWithoutException .thenReturn(Optional.of(result2)) .thenReturn(Optional.empty()); Scan scanWithProjections = - prepareScan().withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder(prepareScan()).projections(Attribute.ID, ANY_NAME_1, ANY_NAME_2).build(); when(storage.scan(scanWithProjections)).thenReturn(scanner); // Act Assert @@ -1310,7 +1330,7 @@ public void toSerializable_ScanSetDeleted_ShouldThrowValidationConflictException Scanner scanner = mock(Scanner.class); when(scanner.one()).thenReturn(Optional.empty()); Scan scanWithProjections = - prepareScan().withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder(prepareScan()).projections(Attribute.ID, ANY_NAME_1, ANY_NAME_2).build(); when(storage.scan(scanWithProjections)).thenReturn(scanner); // Act Assert @@ -1339,7 +1359,7 @@ public void toSerializable_ScanSetDeleted_ShouldThrowValidationConflictException Scanner scanner = mock(Scanner.class); when(scanner.one()).thenReturn(Optional.of(result2)).thenReturn(Optional.empty()); Scan scanWithProjections = - prepareScan().withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder(prepareScan()).projections(Attribute.ID, ANY_NAME_1, ANY_NAME_2).build(); when(storage.scan(scanWithProjections)).thenReturn(scanner); // Act Assert @@ -1357,17 +1377,21 @@ public void toSerializable_MultipleScansInScanSetExist_ShouldProcessWithoutExcep snapshot = prepareSnapshot(Isolation.SERIALIZABLE); Scan scan1 = - new Scan(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .consistency(Consistency.LINEARIZABLE) + .build(); Scan scan2 = - new Scan(Key.ofText(ANY_NAME_1, ANY_TEXT_2)) - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_1)) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_2)) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_1)) + .consistency(Consistency.LINEARIZABLE) + .build(); Result result1 = new TransactionResult( @@ -1408,23 +1432,27 @@ public void toSerializable_MultipleScansInScanSetExist_ShouldProcessWithoutExcep Scanner scanner1 = mock(Scanner.class); when(scanner1.one()).thenReturn(Optional.of(result1)).thenReturn(Optional.empty()); Scan scan1WithProjections = - new Scan(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .consistency(Consistency.LINEARIZABLE) + .projections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)) + .build(); when(storage.scan(scan1WithProjections)).thenReturn(scanner1); Scanner scanner2 = mock(Scanner.class); when(scanner2.one()).thenReturn(Optional.of(result2)).thenReturn(Optional.empty()); Scan scan2WithProjections = - new Scan(Key.ofText(ANY_NAME_1, ANY_TEXT_2)) - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_1)) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withProjections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)); + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_2)) + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_1)) + .consistency(Consistency.LINEARIZABLE) + .projections(Arrays.asList(Attribute.ID, ANY_NAME_1, ANY_NAME_2)) + .build(); when(storage.scan(scan2WithProjections)).thenReturn(scanner2); // Act Assert @@ -1824,11 +1852,13 @@ public void toSerializable_ScannerSetNotChanged_ShouldProcessWithoutExceptions() Snapshot.Key putKey = new Snapshot.Key(put); snapshot.putIntoWriteSet(putKey, put); Scan scan = - new Scan(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) // (-infinite, infinite) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + .consistency(Consistency.LINEARIZABLE) + .build(); // Act Assert Throwable thrown = catchThrowable(() -> snapshot.verifyNoOverlap(scan, Collections.emptyMap())); @@ -1871,30 +1901,35 @@ public void toSerializable_ScannerSetNotChanged_ShouldProcessWithoutExceptions() Snapshot.Key putKey = new Snapshot.Key(put); snapshot.putIntoWriteSet(putKey, put); Scan scan1 = - prepareScan() + Scan.newBuilder(prepareScan()) // ["text1", "text3"] - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_1), true) - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_3), true); + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_1), true) + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_3), true) + .build(); Scan scan2 = - prepareScan() + Scan.newBuilder(prepareScan()) // ["text2", "text3"] - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true) - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_3), true); + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true) + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_3), true) + .build(); Scan scan3 = - prepareScan() + Scan.newBuilder(prepareScan()) // ["text1", "text2"] - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_1), true) - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true); + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_1), true) + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true) + .build(); Scan scan4 = - prepareScan() + Scan.newBuilder(prepareScan()) // ("text2", "text3"] - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false) - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_3), true); + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false) + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_3), true) + .build(); Scan scan5 = - prepareScan() + Scan.newBuilder(prepareScan()) // ["text1", "text2") - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_1), true) - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false); + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_1), true) + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false) + .build(); // Act Assert Throwable thrown1 = @@ -1926,26 +1961,32 @@ public void toSerializable_ScannerSetNotChanged_ShouldProcessWithoutExceptions() Snapshot.Key putKey = new Snapshot.Key(put); snapshot.putIntoWriteSet(putKey, put); Scan scan1 = - new Scan(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) // (-infinite, "text3"] - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_3), true) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_3), true) + .consistency(Consistency.LINEARIZABLE) + .build(); Scan scan2 = - new Scan(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) // (-infinite, "text2"] - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true) + .consistency(Consistency.LINEARIZABLE) + .build(); Scan scan3 = - new Scan(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) // (-infinite, "text2") - .withEnd(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + .end(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false) + .consistency(Consistency.LINEARIZABLE) + .build(); // Act Assert Throwable thrown1 = @@ -1971,26 +2012,32 @@ public void toSerializable_ScannerSetNotChanged_ShouldProcessWithoutExceptions() Snapshot.Key putKey = new Snapshot.Key(put); snapshot.putIntoWriteSet(putKey, put); Scan scan1 = - new Scan(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) // ["text1", infinite) - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_1), true) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_1), true) + .consistency(Consistency.LINEARIZABLE) + .build(); Scan scan2 = - new Scan(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) // ["text2", infinite) - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2), true) + .consistency(Consistency.LINEARIZABLE) + .build(); Scan scan3 = - new Scan(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + Scan.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) // ("text2", infinite) - .withStart(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + .start(Key.ofText(ANY_NAME_2, ANY_TEXT_2), false) + .consistency(Consistency.LINEARIZABLE) + .build(); // Act Assert Throwable thrown1 = @@ -2154,11 +2201,13 @@ public void verifyNoOverlap_ScanAllGivenAndPutInWriteSetInSameTable_ShouldThrowE Put put = preparePut(); Snapshot.Key putKey = new Snapshot.Key(put); snapshot.putIntoWriteSet(putKey, put); - ScanAll scanAll = - new ScanAll() - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Scan scanAll = + ScanAll.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .all() + .consistency(Consistency.LINEARIZABLE) + .build(); TransactionResult result = prepareResult(ANY_ID); Snapshot.Key key = new Snapshot.Key(scanAll, result); @@ -2180,11 +2229,13 @@ public void verifyNoOverlap_ScanAllGivenAndPutInWriteSetInSameTable_ShouldThrowE Put put = preparePut(); Snapshot.Key putKey = new Snapshot.Key(put); snapshot.putIntoWriteSet(putKey, put); - ScanAll scanAll = - new ScanAll() - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME_2) - .forTable(ANY_TABLE_NAME_2); + Scan scanAll = + ScanAll.newBuilder() + .namespace(ANY_NAMESPACE_NAME_2) + .table(ANY_TABLE_NAME_2) + .all() + .consistency(Consistency.LINEARIZABLE) + .build(); TransactionResult result = prepareResult(ANY_ID); Snapshot.Key key = new Snapshot.Key(scanAll, result); @@ -2398,19 +2449,25 @@ void getReadWriteSet_ReadSetAndWriteSetGiven_ShouldReturnProperValue() { { // The method returns an immutable value, so the following update shouldn't be included. Get delayedGet = - new Get(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_1)) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_1)) + .consistency(Consistency.LINEARIZABLE) + .build(); TransactionResult delayedResult = prepareResult("t3"); snapshot.putIntoReadSet(new Snapshot.Key(delayedGet), Optional.of(delayedResult)); Put delayedPut = - new Put(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_2)) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME) - .withValue(ANY_NAME_3, ANY_TEXT_3); + Put.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_2)) + .textValue(ANY_NAME_3, ANY_TEXT_3) + .consistency(Consistency.LINEARIZABLE) + .build(); snapshot.putIntoWriteSet(new Snapshot.Key(delayedPut), delayedPut); } @@ -2465,18 +2522,24 @@ void getReadWriteSet_ReadSetAndDeleteSetGiven_ShouldReturnProperValue() { { // The method returns an immutable value, so the following update shouldn't be included. Get delayedGet = - new Get(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_1)) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Get.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_1)) + .consistency(Consistency.LINEARIZABLE) + .build(); TransactionResult delayedResult = prepareResult("t3"); snapshot.putIntoReadSet(new Snapshot.Key(delayedGet), Optional.of(delayedResult)); Delete delayedDelete = - new Delete(Key.ofText(ANY_NAME_1, ANY_TEXT_1), Key.ofText(ANY_NAME_2, ANY_TEXT_1)) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(ANY_NAMESPACE_NAME) - .forTable(ANY_TABLE_NAME); + Delete.newBuilder() + .namespace(ANY_NAMESPACE_NAME) + .table(ANY_TABLE_NAME) + .partitionKey(Key.ofText(ANY_NAME_1, ANY_TEXT_1)) + .clusteringKey(Key.ofText(ANY_NAME_2, ANY_TEXT_1)) + .consistency(Consistency.LINEARIZABLE) + .build(); snapshot.putIntoDeleteSet(new Snapshot.Key(delayedDelete), delayedDelete); } diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/TransactionTableMetadataManagerTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/TransactionTableMetadataManagerTest.java index e99dc7af09..1df39fc38b 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/TransactionTableMetadataManagerTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/TransactionTableMetadataManagerTest.java @@ -74,7 +74,11 @@ public void getTransactionTableMetadata_CalledOnce_ShouldCallDistributedStorageA // Act TransactionTableMetadata actual = tableMetadataManager.getTransactionTableMetadata( - new Get(Key.ofText("c1", "aaa")).forNamespace("ns").forTable("tbl")); + Get.newBuilder() + .namespace("ns") + .table("tbl") + .partitionKey(Key.ofText("c1", "aaa")) + .build()); // Assert verify(admin).getTableMetadata(anyString(), anyString()); @@ -88,7 +92,8 @@ public void getTransactionTableMetadata_CalledTwice_ShouldCallDistributedStorage TransactionTableMetadataManager tableMetadataManager = new TransactionTableMetadataManager(admin, -1); - Get get = new Get(Key.ofText("c1", "aaa")).forNamespace("ns").forTable("tbl"); + Get get = + Get.newBuilder().namespace("ns").table("tbl").partitionKey(Key.ofText("c1", "aaa")).build(); // Act tableMetadataManager.getTransactionTableMetadata(get); @@ -107,7 +112,8 @@ public void getTransactionTableMetadata_CalledTwice_ShouldCallDistributedStorage TransactionTableMetadataManager tableMetadataManager = new TransactionTableMetadataManager(admin, 1); // one second - Get get = new Get(Key.ofText("c1", "aaa")).forNamespace("ns").forTable("tbl"); + Get get = + Get.newBuilder().namespace("ns").table("tbl").partitionKey(Key.ofText("c1", "aaa")).build(); // Act tableMetadataManager.getTransactionTableMetadata(get); diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitTest.java index bad178d08c..ccd26b85f8 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitTest.java @@ -75,31 +75,44 @@ public void setUp() throws Exception { private Get prepareGet() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Get(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE) - .forTable(ANY_TABLE_NAME); + return Get.newBuilder() + .namespace(ANY_NAMESPACE) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } private Scan prepareScan() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); - return new Scan(partitionKey).forNamespace(ANY_NAMESPACE).forTable(ANY_TABLE_NAME); + return Scan.newBuilder() + .namespace(ANY_NAMESPACE) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .build(); } private Put preparePut() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Put(partitionKey, clusteringKey) - .withValue(ANY_NAME_3, ANY_TEXT_3) - .forNamespace(ANY_NAMESPACE) - .forTable(ANY_TABLE_NAME); + return Put.newBuilder() + .namespace(ANY_NAMESPACE) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .textValue(ANY_NAME_3, ANY_TEXT_3) + .build(); } private Delete prepareDelete() { Key partitionKey = Key.ofText(ANY_NAME_1, ANY_TEXT_1); Key clusteringKey = Key.ofText(ANY_NAME_2, ANY_TEXT_2); - return new Delete(partitionKey, clusteringKey) - .forNamespace(ANY_NAMESPACE) - .forTable(ANY_TABLE_NAME); + return Delete.newBuilder() + .namespace(ANY_NAMESPACE) + .table(ANY_TABLE_NAME) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .build(); } @Test diff --git a/core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionManagerTest.java b/core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionManagerTest.java index 4f483a6c2c..a4d13422df 100644 --- a/core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionManagerTest.java +++ b/core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionManagerTest.java @@ -92,17 +92,34 @@ public void whenSomeOperationsExecutedAndCommit_shouldCallJdbcService() throws E // Act DistributedTransaction transaction = manager.begin(); - Get get = new Get(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Get get = + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); transaction.get(get); - Scan scan = new Scan(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Scan scan = + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); transaction.scan(scan); Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); transaction.put(put); - Delete delete = new Delete(Key.ofText("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE); + Delete delete = + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .build(); transaction.delete(delete); transaction.mutate(Arrays.asList(put, delete)); transaction.commit(); @@ -126,7 +143,12 @@ public void whenGetOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThro assertThatThrownBy( () -> { DistributedTransaction transaction = manager.start(); - Get get = new Get(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Get get = + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); transaction.get(get); }) .isInstanceOf(CrudException.class); @@ -214,7 +236,12 @@ public void get_withConflictError_shouldThrowCrudConflictException() assertThatThrownBy( () -> { DistributedTransaction transaction = manager.begin(); - Get get = new Get(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Get get = + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); transaction.get(get); }) .isInstanceOf(CrudConflictException.class); @@ -230,7 +257,12 @@ public void whenScanOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThr assertThatThrownBy( () -> { DistributedTransaction transaction = manager.start(); - Scan scan = new Scan(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Scan scan = + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); transaction.scan(scan); }) .isInstanceOf(CrudException.class); @@ -247,7 +279,12 @@ public void scan_withConflictError_shouldThrowCrudConflictException() assertThatThrownBy( () -> { DistributedTransaction transaction = manager.begin(); - Scan scan = new Scan(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Scan scan = + Scan.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); transaction.scan(scan); }) .isInstanceOf(CrudConflictException.class); @@ -627,10 +664,12 @@ public void whenPutOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThro () -> { DistributedTransaction transaction = manager.start(); Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); transaction.put(put); }) .isInstanceOf(CrudException.class); @@ -648,10 +687,12 @@ public void put_withConflictError_shouldThrowCrudConflictException() () -> { DistributedTransaction transaction = manager.begin(); Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); transaction.put(put); }) .isInstanceOf(CrudConflictException.class); @@ -669,7 +710,11 @@ public void put_withConflictError_shouldThrowCrudConflictException() () -> { DistributedTransaction transaction = manager.start(); Delete delete = - new Delete(Key.ofText("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .build(); transaction.delete(delete); }) .isInstanceOf(CrudException.class); @@ -687,7 +732,11 @@ public void delete_withConflictError_shouldThrowCrudConflictException() () -> { DistributedTransaction transaction = manager.begin(); Delete delete = - new Delete(Key.ofText("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .build(); transaction.delete(delete); }) .isInstanceOf(CrudConflictException.class); @@ -705,12 +754,18 @@ public void delete_withConflictError_shouldThrowCrudConflictException() () -> { DistributedTransaction transaction = manager.start(); Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); Delete delete = - new Delete(Key.ofText("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .build(); transaction.mutate(Arrays.asList(put, delete)); }) .isInstanceOf(CrudException.class); @@ -728,12 +783,18 @@ public void mutate_withConflictError_shouldThrowCrudConflictException() () -> { DistributedTransaction transaction = manager.begin(); Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); Delete delete = - new Delete(Key.ofText("p1", "val1")).forNamespace(NAMESPACE).forTable(TABLE); + Delete.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .build(); transaction.mutate(Arrays.asList(put, delete)); }) .isInstanceOf(CrudConflictException.class); @@ -749,13 +810,20 @@ public void whenCommitFails_shouldThrowCommitExceptionAndRollback() throws Excep assertThatThrownBy( () -> { DistributedTransaction transaction = manager.start(); - Get get = new Get(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Get get = + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); transaction.get(get); Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); transaction.put(put); transaction.commit(); }) @@ -774,13 +842,20 @@ public void whenRollbackFails_shouldThrowAbortException() throws Exception { assertThatThrownBy( () -> { DistributedTransaction transaction = manager.begin(); - Get get = new Get(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Get get = + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); transaction.get(get); Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); transaction.put(put); transaction.abort(); }) @@ -798,13 +873,20 @@ public void whenRollbackFails_shouldThrowRollbackException() throws Exception { assertThatThrownBy( () -> { DistributedTransaction transaction = manager.begin(); - Get get = new Get(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Get get = + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); transaction.get(get); Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); transaction.put(put); transaction.rollback(); }) @@ -824,13 +906,20 @@ public void whenCommitAndRollbackFails_shouldThrowUnknownTransactionStatusExcept assertThatThrownBy( () -> { DistributedTransaction transaction = manager.start(); - Get get = new Get(Key.ofText("p1", "val")).forNamespace(NAMESPACE).forTable(TABLE); + Get get = + Get.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val")) + .build(); transaction.get(get); Put put = - new Put(Key.ofText("p1", "val1")) - .withValue("v1", "val2") - .forNamespace(NAMESPACE) - .forTable(TABLE); + Put.newBuilder() + .namespace(NAMESPACE) + .table(TABLE) + .partitionKey(Key.ofText("p1", "val1")) + .textValue("v1", "val2") + .build(); transaction.put(put); transaction.commit(); }) 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 81b2a1a8d5..0798c86ffa 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 @@ -522,23 +522,31 @@ public void truncateTable_ShouldTruncateProperly() throws ExecutionException, IO Key clusteringKey = Key.of(getColumnName4(), 2, getColumnName3(), "bbb"); storage = storageFactory.getStorage(); storage.put( - new Put(partitionKey, clusteringKey) - .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(getTable1())); + Put.newBuilder() + .namespace(namespace1) + .table(getTable1()) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(getColumnName5(), 3) + .textValue(getColumnName6(), "ccc") + .bigIntValue(getColumnName7(), 4L) + .floatValue(getColumnName8(), 1.0f) + .doubleValue(getColumnName9(), 1.0d) + .booleanValue(getColumnName10(), true) + .blobValue(getColumnName11(), "ddd".getBytes(StandardCharsets.UTF_8)) + .build()); // Act admin.truncateTable(namespace1, getTable1()); // Assert Scanner scanner = - storage.scan(new Scan(partitionKey).forNamespace(namespace1).forTable(getTable1())); + storage.scan( + Scan.newBuilder() + .namespace(namespace1) + .table(getTable1()) + .partitionKey(partitionKey) + .build()); assertThat(scanner.all()).isEmpty(); scanner.close(); } finally { diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java index c486c9172e..1974c9f675 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageConditionalMutationIntegrationTestBase.java @@ -215,7 +215,8 @@ private void put_withPutIfWithSingleConditionWithSameValue_shouldPutProperly( MutationCondition condition = ConditionBuilder.putIf(buildConditionalExpression(columnToCompare, operator)).build(); - Put put = preparePutWithRandomValues(operator, dataType).withCondition(condition); + Put put = + Put.newBuilder(preparePutWithRandomValues(operator, dataType)).condition(condition).build(); boolean shouldMutate = shouldMutate(initialData.get(columnName), columnToCompare, operator); @@ -239,7 +240,10 @@ private void put_withPutIfWithSingleConditionWithRandomValue_shouldPutProperly( MutationCondition condition = ConditionBuilder.putIf(buildConditionalExpression(columnToCompare, operator)).build(); - Put put = preparePutWithRandomValues(operator, dataType).withCondition(condition); + Put put = + Put.newBuilder(preparePutWithRandomValues(operator, dataType)) + .condition(condition) + .build(); boolean shouldMutate = shouldMutate(initialData.get(columnName), columnToCompare, operator); @@ -263,7 +267,8 @@ private void put_withPutIfWithInitialDataWithNullValuesWithSingleCondition_shoul MutationCondition condition = ConditionBuilder.putIf(buildConditionalExpression(columnToCompare, operator)).build(); - Put put = preparePutWithRandomValues(operator, dataType).withCondition(condition); + Put put = + Put.newBuilder(preparePutWithRandomValues(operator, dataType)).condition(condition).build(); boolean shouldMutate = shouldMutate(initialData.get(columnName), columnToCompare, operator); @@ -286,7 +291,8 @@ private void put_withPutIfWithInitialDataWithoutValuesWithSingleCondition_should MutationCondition condition = ConditionBuilder.putIf(buildConditionalExpression(columnToCompare, operator)).build(); - Put put = preparePutWithRandomValues(operator, dataType).withCondition(condition); + Put put = + Put.newBuilder(preparePutWithRandomValues(operator, dataType)).condition(condition).build(); boolean shouldMutate = shouldMutate(initialData.get(columnName), columnToCompare, operator); @@ -337,8 +343,11 @@ private void put_withPutIfWithMultipleConditionsWithSameValue_shouldPutProperly( .and(buildConditionalExpression(secondColumnToCompare, secondOperator)) .build(); Put put = - preparePutWithRandomValues(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(condition); + Put.newBuilder( + preparePutWithRandomValues( + firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(condition) + .build(); boolean shouldMutate = shouldMutate(initialData.get(firstColumnName), firstColumnToCompare, firstOperator) @@ -385,8 +394,11 @@ private void put_withPutIfWithMultipleConditionsWithRandomValue_shouldPutProperl .and(buildConditionalExpression(secondColumnToCompare, secondOperator)) .build(); Put put = - preparePutWithRandomValues(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(condition); + Put.newBuilder( + preparePutWithRandomValues( + firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(condition) + .build(); boolean shouldMutate = shouldMutate(initialData.get(firstColumnName), firstColumnToCompare, firstOperator) @@ -432,8 +444,11 @@ private void put_withPutIfWithInitialDataWithNullValuesWithMultipleConditions_sh .and(buildConditionalExpression(secondColumnToCompare, secondOperator)) .build(); Put put = - preparePutWithRandomValues(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(condition); + Put.newBuilder( + preparePutWithRandomValues( + firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(condition) + .build(); boolean shouldMutate = shouldMutate(initialData.get(firstColumnName), firstColumnToCompare, firstOperator) @@ -478,8 +493,11 @@ private void put_withPutIfWithInitialDataWithoutValuesWithMultipleConditions_sho .and(buildConditionalExpression(secondColumnToCompare, secondOperator)) .build(); Put put = - preparePutWithRandomValues(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(condition); + Put.newBuilder( + preparePutWithRandomValues( + firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(condition) + .build(); boolean shouldMutate = shouldMutate(initialData.get(firstColumnName), firstColumnToCompare, firstOperator) @@ -597,7 +615,10 @@ public void put_withPutIfExistsWhenRecordExists_shouldPutProperly() throws Execu // Arrange putInitialDataWithRandomValues(); - Put put = preparePutWithRandomValues().withCondition(ConditionBuilder.putIfExists()); + Put put = + Put.newBuilder(preparePutWithRandomValues()) + .condition(ConditionBuilder.putIfExists()) + .build(); // Act storage.put(put); @@ -645,7 +666,10 @@ public void put_withPutIfExistsWhenRecordDoesNotExist_shouldThrowNoMutationExcep random.get().setSeed(seed); // Arrange - Put put = preparePutWithRandomValues().withCondition(ConditionBuilder.putIfExists()); + Put put = + Put.newBuilder(preparePutWithRandomValues()) + .condition(ConditionBuilder.putIfExists()) + .build(); // Act Assert assertThatThrownBy(() -> storage.put(put)).isInstanceOf(NoMutationException.class); @@ -660,7 +684,10 @@ public void put_withPutIfNotExistsWhenRecordDoesNotExist_shouldPutProperly() random.get().setSeed(seed); // Arrange - Put put = preparePutWithRandomValues().withCondition(ConditionBuilder.putIfNotExists()); + Put put = + Put.newBuilder(preparePutWithRandomValues()) + .condition(ConditionBuilder.putIfNotExists()) + .build(); // Act storage.put(put); @@ -710,7 +737,10 @@ public void put_withPutIfNotExistsWhenRecordExists_shouldThrowNoMutationExceptio // Arrange Map> initialData = putInitialDataWithRandomValues(); - Put put = preparePutWithRandomValues().withCondition(ConditionBuilder.putIfNotExists()); + Put put = + Put.newBuilder(preparePutWithRandomValues()) + .condition(ConditionBuilder.putIfNotExists()) + .build(); // Act Assert assertThatThrownBy(() -> storage.put(put)).isInstanceOf(NoMutationException.class); @@ -783,7 +813,8 @@ private void delete_withDeleteIfWithSingleConditionWithSameValue_shouldPutProper MutationCondition condition = ConditionBuilder.deleteIf(buildConditionalExpression(columnToCompare, operator)).build(); - Delete delete = prepareDelete(operator, dataType).withCondition(condition); + Delete delete = + Delete.newBuilder(prepareDelete(operator, dataType)).condition(condition).build(); boolean shouldMutate = shouldMutate(initialData.get(columnName), columnToCompare, operator); @@ -807,7 +838,8 @@ private void delete_withDeleteWithSingleConditionWithRandomValue_shouldPutProper MutationCondition condition = ConditionBuilder.deleteIf(buildConditionalExpression(columnToCompare, operator)).build(); - Delete delete = prepareDelete(operator, dataType).withCondition(condition); + Delete delete = + Delete.newBuilder(prepareDelete(operator, dataType)).condition(condition).build(); boolean shouldMutate = shouldMutate(initialData.get(columnName), columnToCompare, operator); @@ -832,7 +864,8 @@ private void delete_withDeleteWithSingleConditionWithRandomValue_shouldPutProper MutationCondition condition = ConditionBuilder.deleteIf(buildConditionalExpression(columnToCompare, operator)).build(); - Delete delete = prepareDelete(operator, dataType).withCondition(condition); + Delete delete = + Delete.newBuilder(prepareDelete(operator, dataType)).condition(condition).build(); boolean shouldMutate = shouldMutate(initialData.get(columnName), columnToCompare, operator); @@ -855,7 +888,8 @@ private void delete_withDeleteIfWithInitialDataWithoutValuesWithSingleCondition_ MutationCondition condition = ConditionBuilder.deleteIf(buildConditionalExpression(columnToCompare, operator)).build(); - Delete delete = prepareDelete(operator, dataType).withCondition(condition); + Delete delete = + Delete.newBuilder(prepareDelete(operator, dataType)).condition(condition).build(); boolean shouldMutate = shouldMutate(initialData.get(columnName), columnToCompare, operator); @@ -912,8 +946,10 @@ && shouldMutate( initialData.get(secondColumnName), secondColumnToCompare, secondOperator); Delete delete = - prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(condition); + Delete.newBuilder( + prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(condition) + .build(); // Act Assert delete_withDeleteIf_shouldPutProperly( @@ -961,8 +997,10 @@ && shouldMutate( initialData.get(secondColumnName), secondColumnToCompare, secondOperator); Delete delete = - prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(condition); + Delete.newBuilder( + prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(condition) + .build(); // Act Assert delete_withDeleteIf_shouldPutProperly( @@ -1010,8 +1048,10 @@ && shouldMutate( initialData.get(secondColumnName), secondColumnToCompare, secondOperator); Delete delete = - prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(condition); + Delete.newBuilder( + prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(condition) + .build(); // Act Assert delete_withDeleteIf_shouldPutProperly( @@ -1058,8 +1098,10 @@ && shouldMutate( initialData.get(secondColumnName), secondColumnToCompare, secondOperator); Delete delete = - prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(condition); + Delete.newBuilder( + prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(condition) + .build(); // Act Assert delete_withDeleteIf_shouldPutProperly( @@ -1175,7 +1217,8 @@ public void delete_withDeleteIfExistsWhenRecordExists_shouldPutProperly() // Arrange putInitialDataWithRandomValues(); - Delete delete = prepareDelete().withCondition(ConditionBuilder.deleteIfExists()); + Delete delete = + Delete.newBuilder(prepareDelete()).condition(ConditionBuilder.deleteIfExists()).build(); // Act storage.delete(delete); @@ -1191,7 +1234,8 @@ public void delete_withDeleteIfExistsWhenRecordDoesNotExist_shouldThrowNoMutatio random.get().setSeed(seed); // Arrange - Delete delete = prepareDelete().withCondition(ConditionBuilder.deleteIfExists()); + Delete delete = + Delete.newBuilder(prepareDelete()).condition(ConditionBuilder.deleteIfExists()).build(); // Act Assert assertThatThrownBy(() -> storage.delete(delete)).isInstanceOf(NoMutationException.class); @@ -1213,13 +1257,15 @@ private Get prepareGet( DataType firstDataType, @Nullable Operator secondOperator, @Nullable DataType secondDataType) { - return new Get( + return Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey( Key.ofText( PARTITION_KEY, getPartitionKeyValue(firstOperator, firstDataType, secondOperator, secondDataType))) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(namespace) - .forTable(TABLE); + .consistency(Consistency.LINEARIZABLE) + .build(); } private Put preparePutWithRandomValues() { @@ -1275,13 +1321,15 @@ private Delete prepareDelete( DataType firstDataType, @Nullable Operator secondOperator, @Nullable DataType secondDataType) { - return new Delete( + return Delete.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey( Key.ofText( PARTITION_KEY, getPartitionKeyValue(firstOperator, firstDataType, secondOperator, secondDataType))) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(namespace) - .forTable(TABLE); + .consistency(Consistency.LINEARIZABLE) + .build(); } private Map> putInitialDataWithRandomValues() throws ExecutionException { @@ -1301,15 +1349,20 @@ private Map> putInitialDataWithRandomValues( throws ExecutionException { try { storage.delete( - prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(ConditionBuilder.deleteIfExists())); + Delete.newBuilder( + prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(ConditionBuilder.deleteIfExists()) + .build()); } catch (NoMutationException ignored) { // ignored } Put initialPut = - preparePutWithRandomValues(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(ConditionBuilder.putIfNotExists()); + Put.newBuilder( + preparePutWithRandomValues( + firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(ConditionBuilder.putIfNotExists()) + .build(); storage.put(initialPut); return initialPut.getColumns(); } @@ -1327,15 +1380,20 @@ private Map> putInitialDataWithNullValues( throws ExecutionException { try { storage.delete( - prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(ConditionBuilder.deleteIfExists())); + Delete.newBuilder( + prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(ConditionBuilder.deleteIfExists()) + .build()); } catch (NoMutationException ignored) { // ignored } Put initialPut = - preparePutWithNullValues(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(ConditionBuilder.putIfNotExists()); + Put.newBuilder( + preparePutWithNullValues( + firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(ConditionBuilder.putIfNotExists()) + .build(); storage.put(initialPut); return initialPut.getColumns(); } @@ -1386,15 +1444,20 @@ private Map> putInitialDataWithoutValues( throws ExecutionException { try { storage.delete( - prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(ConditionBuilder.deleteIfExists())); + Delete.newBuilder( + prepareDelete(firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(ConditionBuilder.deleteIfExists()) + .build()); } catch (NoMutationException ignored) { // ignored } Put initialPut = - preparePutWithoutValues(firstOperator, firstDataType, secondOperator, secondDataType) - .withCondition(ConditionBuilder.putIfNotExists()); + Put.newBuilder( + preparePutWithoutValues( + firstOperator, firstDataType, secondOperator, secondDataType)) + .condition(ConditionBuilder.putIfNotExists()) + .build(); storage.put(initialPut); ImmutableMap.Builder> columns = ImmutableMap.>builder() @@ -1426,13 +1489,15 @@ private Put preparePutWithoutValues( DataType firstDataType, @Nullable Operator secondOperator, @Nullable DataType secondDataType) { - return new Put( + return Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey( Key.ofText( PARTITION_KEY, getPartitionKeyValue(firstOperator, firstDataType, secondOperator, secondDataType))) - .withConsistency(Consistency.LINEARIZABLE) - .forNamespace(namespace) - .forTable(TABLE); + .consistency(Consistency.LINEARIZABLE) + .build(); } private String getPartitionKeyValue( 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 3f24b03a05..605ab5b08c 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 @@ -346,9 +346,10 @@ public void get_GetWithProjectionsGiven_ShouldRetrieveSpecifiedValues() int cKey = 0; // Act - Get get = prepareGet(pKey, cKey); - get.withProjections( - Arrays.asList(getColumnName1(), getColumnName2(), getColumnName3(), getColumnName6())); + Get get = + Get.newBuilder(prepareGet(pKey, cKey)) + .projections(getColumnName1(), getColumnName2(), getColumnName3(), getColumnName6()) + .build(); Optional actual = storage.get(get); // Assert @@ -888,7 +889,7 @@ public void put_SinglePutWithIfNotExistsGiven_ShouldStoreProperly() throws Execu int pKey = 0; int cKey = 0; List puts = preparePuts(); - puts.get(0).withCondition(ConditionBuilder.putIfNotExists()); + puts.set(0, Put.newBuilder(puts.get(0)).condition(ConditionBuilder.putIfNotExists()).build()); Key partitionKey = Key.ofInt(getColumnName1(), pKey); Key clusteringKey = Key.ofInt(getColumnName4(), cKey); Get get = @@ -901,8 +902,13 @@ public void put_SinglePutWithIfNotExistsGiven_ShouldStoreProperly() throws Execu // Act storage.put(puts.get(0)); - puts.get(0).withValue(getColumnName3(), Integer.MAX_VALUE); - assertThatThrownBy(() -> storage.put(puts.get(0))).isInstanceOf(NoMutationException.class); + assertThatThrownBy( + () -> + storage.put( + Put.newBuilder(puts.get(0)) + .intValue(getColumnName3(), Integer.MAX_VALUE) + .build())) + .isInstanceOf(NoMutationException.class); // Assert Optional actual = storage.get(get); @@ -962,9 +968,9 @@ public void put_MultiplePutWithIfNotExistsGiven_ShouldStoreProperly() int pKey = 0; int cKey = 0; List puts = preparePuts(); - puts.get(0).withCondition(ConditionBuilder.putIfNotExists()); - puts.get(1).withCondition(ConditionBuilder.putIfNotExists()); - puts.get(2).withCondition(ConditionBuilder.putIfNotExists()); + puts.set(0, Put.newBuilder(puts.get(0)).condition(ConditionBuilder.putIfNotExists()).build()); + puts.set(1, Put.newBuilder(puts.get(1)).condition(ConditionBuilder.putIfNotExists()).build()); + puts.set(2, Put.newBuilder(puts.get(2)).condition(ConditionBuilder.putIfNotExists()).build()); Scan scan = Scan.newBuilder() .namespace(namespace) @@ -1073,9 +1079,9 @@ public void put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutati int cKey = 0; List puts = preparePuts(); assertThatCode(() -> storage.put(puts.get(0))).doesNotThrowAnyException(); - puts.get(0).withCondition(ConditionBuilder.putIfNotExists()); - puts.get(1).withCondition(ConditionBuilder.putIfNotExists()); - puts.get(2).withCondition(ConditionBuilder.putIfNotExists()); + puts.set(0, Put.newBuilder(puts.get(0)).condition(ConditionBuilder.putIfNotExists()).build()); + puts.set(1, Put.newBuilder(puts.get(1)).condition(ConditionBuilder.putIfNotExists()).build()); + puts.set(2, Put.newBuilder(puts.get(2)).condition(ConditionBuilder.putIfNotExists()).build()); Scan scan = Scan.newBuilder() .namespace(namespace) @@ -1100,11 +1106,14 @@ public void put_MultiplePutWithDifferentConditionsGiven_ShouldStoreProperly() // Arrange List puts = preparePuts(); storage.put(puts.get(1)); - puts.get(0).withCondition(ConditionBuilder.putIfNotExists()); - puts.get(1) - .withCondition( - ConditionBuilder.putIf(ConditionBuilder.column(getColumnName2()).isEqualToText("1")) - .build()); + puts.set(0, Put.newBuilder(puts.get(0)).condition(ConditionBuilder.putIfNotExists()).build()); + puts.set( + 1, + Put.newBuilder(puts.get(1)) + .condition( + ConditionBuilder.putIf(ConditionBuilder.column(getColumnName2()).isEqualToText("1")) + .build()) + .build()); // Act assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1)))) @@ -1136,7 +1145,7 @@ public void put_PutWithIfExistsGivenWhenNoSuchRecord_ShouldThrowNoMutationExcept int pKey = 0; int cKey = 0; List puts = preparePuts(); - puts.get(0).withCondition(ConditionBuilder.putIfExists()); + puts.set(0, Put.newBuilder(puts.get(0)).condition(ConditionBuilder.putIfExists()).build()); Get get = prepareGet(pKey, cKey); // Act Assert @@ -1158,9 +1167,14 @@ public void put_PutWithIfExistsGivenWhenSuchRecordExists_ShouldUpdateRecord() // Act Assert storage.put(puts.get(0)); - puts.get(0).withCondition(ConditionBuilder.putIfExists()); - puts.get(0).withValue(getColumnName3(), Integer.MAX_VALUE); - assertThatCode(() -> storage.put(puts.get(0))).doesNotThrowAnyException(); + assertThatCode( + () -> + storage.put( + Put.newBuilder(puts.get(0)) + .intValue(getColumnName3(), Integer.MAX_VALUE) + .condition(ConditionBuilder.putIfExists()) + .build())) + .doesNotThrowAnyException(); // Assert Optional actual = storage.get(get); @@ -1185,13 +1199,18 @@ public void put_PutWithIfGivenWhenSuchRecordExists_ShouldUpdateRecord() // Act Assert storage.put(puts.get(0)); - puts.get(0) - .withCondition( - ConditionBuilder.putIf( - ConditionBuilder.column(getColumnName3()).isEqualToInt(pKey + cKey)) - .build()); - puts.get(0).withValue(getColumnName3(), Integer.MAX_VALUE); - assertThatCode(() -> storage.put(puts.get(0))).doesNotThrowAnyException(); + assertThatCode( + () -> + storage.put( + Put.newBuilder(puts.get(0)) + .intValue(getColumnName3(), Integer.MAX_VALUE) + .condition( + ConditionBuilder.putIf( + ConditionBuilder.column(getColumnName3()) + .isEqualToInt(pKey + cKey)) + .build()) + .build())) + .doesNotThrowAnyException(); // Assert Optional actual = storage.get(get); @@ -1216,13 +1235,18 @@ public void put_PutWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationException() // Act Assert storage.put(puts.get(0)); - puts.get(0) - .withCondition( - ConditionBuilder.putIf( - ConditionBuilder.column(getColumnName3()).isEqualToInt(pKey + cKey + 1)) - .build()); - puts.get(0).withValue(getColumnName3(), Integer.MAX_VALUE); - assertThatThrownBy(() -> storage.put(puts.get(0))).isInstanceOf(NoMutationException.class); + assertThatThrownBy( + () -> + storage.put( + Put.newBuilder(puts.get(0)) + .intValue(getColumnName3(), Integer.MAX_VALUE) + .condition( + ConditionBuilder.putIf( + ConditionBuilder.column(getColumnName3()) + .isEqualToInt(pKey + cKey + 1)) + .build()) + .build())) + .isInstanceOf(NoMutationException.class); // Assert Optional actual = storage.get(get); @@ -1242,8 +1266,11 @@ public void put_PutWithNullValue_ShouldPutProperly() throws ExecutionException { Put put = preparePuts().get(0); storage.put(put); - put.withTextValue(getColumnName2(), null); - put.withBooleanValue(getColumnName5(), null); + put = + Put.newBuilder(put) + .textValue(getColumnName2(), null) + .booleanValue(getColumnName5(), null) + .build(); // Act storage.put(put); @@ -1365,8 +1392,10 @@ public void delete_DeleteWithIfExistsGivenWhenNoSuchRecord_ShouldThrowNoMutation // Act Assert Delete delete = prepareDelete(pKey, Integer.MAX_VALUE); - delete.withCondition(ConditionBuilder.deleteIfExists()); - assertThatThrownBy(() -> storage.delete(delete)).isInstanceOf(NoMutationException.class); + Delete deleteWithCondition = + Delete.newBuilder(delete).condition(ConditionBuilder.deleteIfExists()).build(); + assertThatThrownBy(() -> storage.delete(deleteWithCondition)) + .isInstanceOf(NoMutationException.class); } @Test @@ -1381,8 +1410,9 @@ public void delete_DeleteWithIfExistsGivenWhenSuchRecordExists_ShouldDeletePrope // Act Delete delete = prepareDelete(pKey, cKey); - delete.withCondition(ConditionBuilder.deleteIfExists()); - assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException(); + Delete deleteWithCondition = + Delete.newBuilder(delete).condition(ConditionBuilder.deleteIfExists()).build(); + assertThatCode(() -> storage.delete(deleteWithCondition)).doesNotThrowAnyException(); // Assert Optional actual = @@ -1408,12 +1438,16 @@ public void delete_DeleteWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationExcept // Act Delete delete = prepareDelete(pKey, cKey); - delete.withCondition( - ConditionBuilder.deleteIf( - ConditionBuilder.column(getColumnName2()) - .isEqualToText(Integer.toString(Integer.MAX_VALUE))) - .build()); - assertThatThrownBy(() -> storage.delete(delete)).isInstanceOf(NoMutationException.class); + Delete deleteWithCondition = + Delete.newBuilder(delete) + .condition( + ConditionBuilder.deleteIf( + ConditionBuilder.column(getColumnName2()) + .isEqualToText(Integer.toString(Integer.MAX_VALUE))) + .build()) + .build(); + assertThatThrownBy(() -> storage.delete(deleteWithCondition)) + .isInstanceOf(NoMutationException.class); // Assert Optional actual = @@ -1439,11 +1473,15 @@ public void delete_DeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() // Act Delete delete = prepareDelete(pKey, cKey); - delete.withCondition( - ConditionBuilder.deleteIf( - ConditionBuilder.column(getColumnName2()).isEqualToText(Integer.toString(pKey))) - .build()); - assertThatCode(() -> storage.delete(delete)).doesNotThrowAnyException(); + Delete deleteWithCondition = + Delete.newBuilder(delete) + .condition( + ConditionBuilder.deleteIf( + ConditionBuilder.column(getColumnName2()) + .isEqualToText(Integer.toString(pKey))) + .build()) + .build(); + assertThatCode(() -> storage.delete(deleteWithCondition)).doesNotThrowAnyException(); // Assert Optional actual = @@ -1464,12 +1502,16 @@ public void delete_MultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProper List puts = preparePuts(); List deletes = prepareDeletes(); storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2))); - deletes.get(0).withCondition(ConditionBuilder.deleteIfExists()); - deletes - .get(1) - .withCondition( - ConditionBuilder.deleteIf(ConditionBuilder.column(getColumnName2()).isEqualToText("1")) - .build()); + deletes.set( + 0, Delete.newBuilder(deletes.get(0)).condition(ConditionBuilder.deleteIfExists()).build()); + deletes.set( + 1, + Delete.newBuilder(deletes.get(1)) + .condition( + ConditionBuilder.deleteIf( + ConditionBuilder.column(getColumnName2()).isEqualToText("1")) + .build()) + .build()); // Act assertThatCode( @@ -1540,8 +1582,6 @@ public void mutate_PutAndDeleteGiven_ShouldUpdateAndDeleteRecordsProperly() // Arrange populateRecords(); List puts = preparePuts(); - puts.get(1).withValue(getColumnName3(), Integer.MAX_VALUE); - puts.get(2).withValue(getColumnName3(), Integer.MIN_VALUE); int pKey = 0; int cKey = 0; @@ -1555,7 +1595,17 @@ public void mutate_PutAndDeleteGiven_ShouldUpdateAndDeleteRecordsProperly() .build(); // Act - assertThatCode(() -> storage.mutate(Arrays.asList(delete, puts.get(1), puts.get(2)))) + assertThatCode( + () -> + storage.mutate( + Arrays.asList( + delete, + Put.newBuilder(puts.get(1)) + .intValue(getColumnName3(), Integer.MAX_VALUE) + .build(), + Put.newBuilder(puts.get(2)) + .intValue(getColumnName3(), Integer.MIN_VALUE) + .build()))) .doesNotThrowAnyException(); // Assert @@ -1692,8 +1742,11 @@ public void put_IncorrectPutGiven_ShouldThrowIllegalArgumentException() { @Test public void put_PutGivenForIndexedColumnWithNullValue_ShouldPut() throws ExecutionException { // Arrange - storage.put(preparePuts().get(0).withValue(IntColumn.ofNull(getColumnName3()))); // (0,0) - Get get = new Get(prepareGet(0, 0)); + storage.put( + Put.newBuilder(preparePuts().get(0)) + .value(IntColumn.ofNull(getColumnName3())) + .build()); // (0,0) + Get get = prepareGet(0, 0); // Act Optional actual = storage.get(get); @@ -2179,16 +2232,23 @@ public void get_GetWithProjectionsGivenOnNonPrimaryKey_ShouldRetrieveOnlyProject throws ExecutionException { // Arrange Put put = - new Put(Key.ofInt(getColumnName1(), 0), Key.ofInt(getColumnName4(), 0)) - .withTextValue(getColumnName2(), "foo") - .withIntValue(getColumnName3(), 0) - .withBooleanValue(getColumnName5(), true) - .forNamespace(namespace) - .forTable(getTableName()); + Put.newBuilder() + .namespace(namespace) + .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); // Act - Get get = prepareGet(0, 0).withProjection(getColumnName3()).withProjection(getColumnName5()); + Get get = + Get.newBuilder(prepareGet(0, 0)) + .projection(getColumnName3()) + .projection(getColumnName5()) + .build(); Optional actual = storage.get(get); // Assert diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java index f2922111ae..bc040e9f0a 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminIntegrationTestBase.java @@ -428,23 +428,31 @@ public void truncateTable_ShouldTruncateProperly() Key clusteringKey = Key.of(COL_NAME4, 2, COL_NAME3, "bbb"); manager = transactionFactory.getTransactionManager(); manager.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)) - .forNamespace(namespace1) - .forTable(TABLE1)); + Put.newBuilder() + .namespace(namespace1) + .table(TABLE1) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(COL_NAME5, 3) + .textValue(COL_NAME6, "ccc") + .bigIntValue(COL_NAME7, 4L) + .floatValue(COL_NAME8, 1.0f) + .doubleValue(COL_NAME9, 1.0d) + .booleanValue(COL_NAME10, true) + .blobValue(COL_NAME11, "ddd".getBytes(StandardCharsets.UTF_8)) + .build()); // Act admin.truncateTable(namespace1, TABLE1); // Assert List results = - manager.scan(new Scan(partitionKey).forNamespace(namespace1).forTable(TABLE1)); + manager.scan( + Scan.newBuilder() + .namespace(namespace1) + .table(TABLE1) + .partitionKey(partitionKey) + .build()); assertThat(results).isEmpty(); } finally { if (manager != null) { diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionCrossPartitionScanIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionCrossPartitionScanIntegrationTestBase.java index 0785417605..5b3674cdb4 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionCrossPartitionScanIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionCrossPartitionScanIntegrationTestBase.java @@ -18,7 +18,6 @@ import com.scalar.db.util.TestUtils.ExpectedResult; import com.scalar.db.util.TestUtils.ExpectedResult.ExpectedResultBuilder; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -262,7 +261,7 @@ public void scan_CrossPartitionScanGivenForNonExisting_ShouldReturnEmpty() populateSingleRecord(); Scan scan = Scan.newBuilder(prepareCrossPartitionScan(0, 0, 0)) - .projections(Arrays.asList(BALANCE, SOME_COLUMN)) + .projections(BALANCE, SOME_COLUMN) .build(); // Act diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionIntegrationTestBase.java index 97436f4651..01b6d5feff 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionIntegrationTestBase.java @@ -220,10 +220,11 @@ public void get_GetWithProjectionGivenForCommittedRecord_ShouldReturnRecord() populateRecords(); DistributedTransaction transaction = manager.start(); Get get = - prepareGet(0, 0) - .withProjection(ACCOUNT_ID) - .withProjection(ACCOUNT_TYPE) - .withProjection(BALANCE); + Get.newBuilder(prepareGet(0, 0)) + .projection(ACCOUNT_ID) + .projection(ACCOUNT_TYPE) + .projection(BALANCE) + .build(); // Act Optional result = transaction.get(get); @@ -369,10 +370,11 @@ public void scanOrGetScanner_ScanWithProjectionsGivenForCommittedRecord_ShouldRe populateRecords(); DistributedTransaction transaction = manager.start(); Scan scan = - prepareScan(1, 0, 2) - .withProjection(ACCOUNT_ID) - .withProjection(ACCOUNT_TYPE) - .withProjection(BALANCE); + Scan.newBuilder(prepareScan(1, 0, 2)) + .projection(ACCOUNT_ID) + .projection(ACCOUNT_TYPE) + .projection(BALANCE) + .build(); // Act List results = scanOrGetScanner(transaction, scan, scanType); @@ -403,7 +405,7 @@ public void scanOrGetScanner_ScanWithOrderingGivenForCommittedRecord_ShouldRetur // Arrange populateRecords(); DistributedTransaction transaction = manager.start(); - Scan scan = prepareScan(1, 0, 2).withOrdering(Ordering.desc(ACCOUNT_TYPE)); + Scan scan = Scan.newBuilder(prepareScan(1, 0, 2)).ordering(Ordering.desc(ACCOUNT_TYPE)).build(); // Act List results = scanOrGetScanner(transaction, scan, scanType); @@ -434,7 +436,7 @@ public void scanOrGetScanner_ScanWithLimitGivenForCommittedRecord_ShouldReturnRe // Arrange populateRecords(); DistributedTransaction transaction = manager.start(); - Scan scan = prepareScan(1, 0, 2).withLimit(2); + Scan scan = Scan.newBuilder(prepareScan(1, 0, 2)).limit(2).build(); // Act List results = scanOrGetScanner(transaction, scan, scanType); @@ -502,10 +504,12 @@ public void get_GetGivenForIndexColumn_ShouldReturnRecords() throws TransactionE transaction = manager.start(); Get getBuiltByConstructor = - new Get(Key.ofInt(SOME_COLUMN, 2)) - .forNamespace(namespace) - .forTable(TABLE) - .withConsistency(Consistency.LINEARIZABLE); + Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .indexKey(Key.ofInt(SOME_COLUMN, 2)) + .consistency(Consistency.LINEARIZABLE) + .build(); Get getBuiltByBuilder = Get.newBuilder() @@ -538,10 +542,12 @@ public void scanOrGetScanner_ScanGivenForIndexColumn_ShouldReturnRecords(ScanTyp populateRecords(); DistributedTransaction transaction = manager.start(); Scan scanBuiltByConstructor = - new Scan(Key.ofInt(SOME_COLUMN, 2)) - .forNamespace(namespace) - .forTable(TABLE) - .withConsistency(Consistency.LINEARIZABLE); + Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .indexKey(Key.ofInt(SOME_COLUMN, 2)) + .consistency(Consistency.LINEARIZABLE) + .build(); Scan scanBuiltByBuilder = Scan.newBuilder() @@ -610,7 +616,7 @@ public void scanOrGetScanner_ScanAllGivenForCommittedRecord_ShouldReturnRecords( // Arrange populateRecords(); DistributedTransaction transaction = manager.start(); - ScanAll scanAll = prepareScanAll(); + Scan scanAll = prepareScanAll(); // Act List results = scanOrGetScanner(transaction, scanAll, scanType); @@ -641,7 +647,7 @@ public void scanOrGetScanner_ScanAllGivenWithLimit_ShouldReturnLimitedAmountOfRe insert(prepareInsert(1, 1), prepareInsert(1, 2), prepareInsert(2, 1), prepareInsert(3, 0)); DistributedTransaction scanAllTransaction = manager.start(); - ScanAll scanAll = prepareScanAll().withLimit(2); + Scan scanAll = Scan.newBuilder(prepareScanAll()).limit(2).build(); // Act List results = scanOrGetScanner(scanAllTransaction, scanAll, scanType); @@ -681,7 +687,8 @@ public void scanOrGetScanner_ScanAllWithProjectionsGiven_ShouldRetrieveSpecified // Arrange populateRecords(); DistributedTransaction transaction = manager.start(); - ScanAll scanAll = prepareScanAll().withProjection(ACCOUNT_TYPE).withProjection(BALANCE); + Scan scanAll = + Scan.newBuilder(prepareScanAll()).projection(ACCOUNT_TYPE).projection(BALANCE).build(); // Act List results = scanOrGetScanner(transaction, scanAll, scanType); @@ -709,7 +716,7 @@ public void scanOrGetScanner_ScanAllGivenForNonExisting_ShouldReturnEmpty(ScanTy throws TransactionException { // Arrange DistributedTransaction transaction = manager.start(); - ScanAll scanAll = prepareScanAll(); + Scan scanAll = prepareScanAll(); // Act List results = scanOrGetScanner(transaction, scanAll, scanType); @@ -780,7 +787,7 @@ public void putAndCommit_PutGivenForExisting_ShouldUpdateRecord() throws Transac @Test public void putWithNullValueAndCommit_ShouldCreateRecordProperly() throws TransactionException { // Arrange - Put put = preparePut(0, 0).withIntValue(BALANCE, null); + Put put = Put.newBuilder(preparePut(0, 0)).intValue(BALANCE, null).build(); DistributedTransaction transaction = manager.begin(); // Act @@ -839,7 +846,7 @@ public void putAndCommit_GetsAndPutsGiven_ShouldCommitProperly() throws Transact @Test public void putAndAbort_ShouldNotCreateRecord() throws TransactionException { // Arrange - Put put = preparePut(0, 0).withValue(BALANCE, INITIAL_BALANCE); + Put put = Put.newBuilder(preparePut(0, 0)).intValue(BALANCE, INITIAL_BALANCE).build(); DistributedTransaction transaction = manager.begin(); // Act @@ -857,7 +864,7 @@ public void putAndAbort_ShouldNotCreateRecord() throws TransactionException { @Test public void putAndRollback_ShouldNotCreateRecord() throws TransactionException { // Arrange - Put put = preparePut(0, 0).withValue(BALANCE, INITIAL_BALANCE); + Put put = Put.newBuilder(preparePut(0, 0)).intValue(BALANCE, INITIAL_BALANCE).build(); DistributedTransaction transaction = manager.begin(); // Act @@ -955,7 +962,7 @@ public void mutateAndCommit_AfterRead_ShouldMutateRecordsProperly() throws Trans populateRecords(); Get get1 = prepareGet(0, 0); Get get2 = prepareGet(1, 0); - Put put = preparePut(0, 0).withIntValue(BALANCE, INITIAL_BALANCE - 100); + Put put = Put.newBuilder(preparePut(0, 0)).intValue(BALANCE, INITIAL_BALANCE - 100).build(); Delete delete = prepareDelete(1, 0); DistributedTransaction transaction = manager.begin(); @@ -1017,7 +1024,7 @@ public void getState_forSuccessfulTransaction_ShouldReturnCommittedState() // Arrange DistributedTransaction transaction = manager.begin(); transaction.get(prepareGet(0, 0)); - transaction.put(preparePut(0, 0).withValue(BALANCE, 1)); + transaction.put(Put.newBuilder(preparePut(0, 0)).intValue(BALANCE, 1).build()); transaction.commit(); // Act @@ -1032,11 +1039,11 @@ public void getState_forFailedTransaction_ShouldReturnAbortedState() throws Tran // Arrange DistributedTransaction transaction1 = manager.begin(); transaction1.get(prepareGet(0, 0)); - transaction1.put(preparePut(0, 0).withValue(BALANCE, 1)); + transaction1.put(Put.newBuilder(preparePut(0, 0)).intValue(BALANCE, 1).build()); DistributedTransaction transaction2 = manager.begin(); transaction2.get(prepareGet(0, 0)); - transaction2.put(preparePut(0, 0).withValue(BALANCE, 1)); + transaction2.put(Put.newBuilder(preparePut(0, 0)).intValue(BALANCE, 1).build()); transaction2.commit(); assertThatCode(transaction1::commit).isInstanceOf(CommitConflictException.class); @@ -1053,7 +1060,7 @@ public void abort_forOngoingTransaction_ShouldAbortCorrectly() throws Transactio // Arrange DistributedTransaction transaction = manager.begin(); transaction.get(prepareGet(0, 0)); - transaction.put(preparePut(0, 0).withValue(BALANCE, 1)); + transaction.put(Put.newBuilder(preparePut(0, 0)).intValue(BALANCE, 1).build()); // Act manager.abort(transaction.getId()); @@ -1070,7 +1077,7 @@ public void rollback_forOngoingTransaction_ShouldRollbackCorrectly() throws Tran // Arrange DistributedTransaction transaction = manager.begin(); transaction.get(prepareGet(0, 0)); - transaction.put(preparePut(0, 0).withValue(BALANCE, 1)); + transaction.put(Put.newBuilder(preparePut(0, 0)).intValue(BALANCE, 1).build()); // Act manager.rollback(transaction.getId()); @@ -1089,7 +1096,7 @@ public void rollback_forOngoingTransaction_ShouldRollbackCorrectly() throws Tran // Arrange populateSingleRecord(); DistributedTransaction transaction = manager.begin(); - Get get = prepareGet(0, 0).withProjections(Arrays.asList(BALANCE, SOME_COLUMN)); + Get get = Get.newBuilder(prepareGet(0, 0)).projections(BALANCE, SOME_COLUMN).build(); // Act Optional result = transaction.get(get); @@ -1110,7 +1117,7 @@ public void rollback_forOngoingTransaction_ShouldRollbackCorrectly() throws Tran // Arrange populateSingleRecord(); DistributedTransaction transaction = manager.begin(); - Scan scan = prepareScan(0, 0, 0).withProjections(Arrays.asList(BALANCE, SOME_COLUMN)); + Scan scan = Scan.newBuilder(prepareScan(0, 0, 0)).projections(BALANCE, SOME_COLUMN).build(); // Act List results = scanOrGetScanner(transaction, scan, scanType); @@ -1133,7 +1140,7 @@ public void rollback_forOngoingTransaction_ShouldRollbackCorrectly() throws Tran // Arrange populateSingleRecord(); DistributedTransaction transaction = manager.begin(); - ScanAll scanAll = prepareScanAll().withProjections(Arrays.asList(BALANCE, SOME_COLUMN)); + Scan scanAll = Scan.newBuilder(prepareScanAll()).projections(BALANCE, SOME_COLUMN).build(); // Act List results = scanOrGetScanner(transaction, scanAll, scanType); @@ -2675,10 +2682,13 @@ protected void populateRecords() throws TransactionException { protected void populateSingleRecord() throws TransactionException { Put put = - new Put(Key.ofInt(ACCOUNT_ID, 0), Key.ofInt(ACCOUNT_TYPE, 0)) - .forNamespace(namespace) - .forTable(TABLE) - .withIntValue(BALANCE, INITIAL_BALANCE); + Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(Key.ofInt(ACCOUNT_ID, 0)) + .clusteringKey(Key.ofInt(ACCOUNT_TYPE, 0)) + .intValue(BALANCE, INITIAL_BALANCE) + .build(); DistributedTransaction transaction = manager.start(); transaction.put(put); transaction.commit(); @@ -2687,10 +2697,13 @@ protected void populateSingleRecord() throws TransactionException { protected Get prepareGet(int id, int type) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); - return new Get(partitionKey, clusteringKey) - .forNamespace(namespace) - .forTable(TABLE) - .withConsistency(Consistency.LINEARIZABLE); + return Get.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } protected List prepareGets() { @@ -2702,28 +2715,35 @@ protected List prepareGets() { protected Scan prepareScan(int id, int fromType, int toType) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); - return new Scan(partitionKey) - .forNamespace(namespace) - .forTable(TABLE) - .withConsistency(Consistency.LINEARIZABLE) - .withStart(Key.ofInt(ACCOUNT_TYPE, fromType)) - .withEnd(Key.ofInt(ACCOUNT_TYPE, toType)); + return Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .consistency(Consistency.LINEARIZABLE) + .start(Key.ofInt(ACCOUNT_TYPE, fromType)) + .end(Key.ofInt(ACCOUNT_TYPE, toType)) + .build(); } - protected ScanAll prepareScanAll() { - return new ScanAll() - .forNamespace(namespace) - .forTable(TABLE) - .withConsistency(Consistency.LINEARIZABLE); + protected Scan prepareScanAll() { + return Scan.newBuilder() + .namespace(namespace) + .table(TABLE) + .all() + .consistency(Consistency.LINEARIZABLE) + .build(); } protected Put preparePut(int id, int type) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); - return new Put(partitionKey, clusteringKey) - .forNamespace(namespace) - .forTable(TABLE) - .withConsistency(Consistency.LINEARIZABLE); + return Put.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } protected Insert prepareInsert(int id, int type) { @@ -2751,10 +2771,13 @@ protected List preparePuts() { protected Delete prepareDelete(int id, int type) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); - return new Delete(partitionKey, clusteringKey) - .forNamespace(namespace) - .forTable(TABLE) - .withConsistency(Consistency.LINEARIZABLE); + return Delete.newBuilder() + .namespace(namespace) + .table(TABLE) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } protected int getBalance(Result result) { diff --git a/integration-test/src/main/java/com/scalar/db/api/TwoPhaseCommitTransactionIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/TwoPhaseCommitTransactionIntegrationTestBase.java index 6830d7de00..90e2758a40 100644 --- a/integration-test/src/main/java/com/scalar/db/api/TwoPhaseCommitTransactionIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/TwoPhaseCommitTransactionIntegrationTestBase.java @@ -239,10 +239,11 @@ public void get_GetWithProjectionGivenForCommittedRecord_ShouldReturnRecord() populateRecords(manager1, namespace1, TABLE_1); TwoPhaseCommitTransaction transaction = manager1.start(); Get get = - prepareGet(0, 0, namespace1, TABLE_1) - .withProjection(ACCOUNT_ID) - .withProjection(ACCOUNT_TYPE) - .withProjection(BALANCE); + Get.newBuilder(prepareGet(0, 0, namespace1, TABLE_1)) + .projection(ACCOUNT_ID) + .projection(ACCOUNT_TYPE) + .projection(BALANCE) + .build(); // Act Optional result = transaction.get(get); @@ -376,10 +377,11 @@ public void scanOrGetScanner_ScanWithProjectionsGivenForCommittedRecord_ShouldRe populateRecords(manager1, namespace1, TABLE_1); TwoPhaseCommitTransaction transaction = manager1.start(); Scan scan = - prepareScan(1, 0, 2, namespace1, TABLE_1) - .withProjection(ACCOUNT_ID) - .withProjection(ACCOUNT_TYPE) - .withProjection(BALANCE); + Scan.newBuilder(prepareScan(1, 0, 2, namespace1, TABLE_1)) + .projection(ACCOUNT_ID) + .projection(ACCOUNT_TYPE) + .projection(BALANCE) + .build(); // Act List results = scanOrGetScanner(transaction, scan, scanType); @@ -412,7 +414,10 @@ public void scanOrGetScanner_ScanWithOrderingGivenForCommittedRecord_ShouldRetur // Arrange populateRecords(manager1, namespace1, TABLE_1); TwoPhaseCommitTransaction transaction = manager1.start(); - Scan scan = prepareScan(1, 0, 2, namespace1, TABLE_1).withOrdering(Ordering.desc(ACCOUNT_TYPE)); + Scan scan = + Scan.newBuilder(prepareScan(1, 0, 2, namespace1, TABLE_1)) + .ordering(Ordering.desc(ACCOUNT_TYPE)) + .build(); // Act List results = scanOrGetScanner(transaction, scan, scanType); @@ -445,7 +450,7 @@ public void scanOrGetScanner_ScanWithLimitGivenForCommittedRecord_ShouldReturnRe // Arrange populateRecords(manager1, namespace1, TABLE_1); TwoPhaseCommitTransaction transaction = manager1.start(); - Scan scan = prepareScan(1, 0, 2, namespace1, TABLE_1).withLimit(2); + Scan scan = Scan.newBuilder(prepareScan(1, 0, 2, namespace1, TABLE_1)).limit(2).build(); // Act List results = scanOrGetScanner(transaction, scan, scanType); @@ -521,10 +526,12 @@ public void get_GetGivenForIndexColumn_ShouldReturnRecords() throws TransactionE transaction = manager1.start(); Get getBuiltByConstructor = - new Get(Key.ofInt(SOME_COLUMN, 2)) - .forNamespace(namespace1) - .forTable(TABLE_1) - .withConsistency(Consistency.LINEARIZABLE); + Get.newBuilder() + .namespace(namespace1) + .table(TABLE_1) + .indexKey(Key.ofInt(SOME_COLUMN, 2)) + .consistency(Consistency.LINEARIZABLE) + .build(); Get getBuiltByBuilder = Get.newBuilder() @@ -559,10 +566,12 @@ public void scanOrGetScanner_ScanGivenForIndexColumn_ShouldReturnRecords(ScanTyp populateRecords(manager1, namespace1, TABLE_1); TwoPhaseCommitTransaction transaction = manager1.start(); Scan scanBuiltByConstructor = - new Scan(Key.ofInt(SOME_COLUMN, 2)) - .forNamespace(namespace1) - .forTable(TABLE_1) - .withConsistency(Consistency.LINEARIZABLE); + Scan.newBuilder() + .namespace(namespace1) + .table(TABLE_1) + .indexKey(Key.ofInt(SOME_COLUMN, 2)) + .consistency(Consistency.LINEARIZABLE) + .build(); Scan scanBuiltByBuilder = Scan.newBuilder() @@ -666,7 +675,7 @@ public void putAndCommit_PutGivenForExisting_ShouldUpdateRecord() throws Transac @Test public void putWithNullValueAndCommit_ShouldCreateRecordProperly() throws TransactionException { // Arrange - Put put = preparePut(0, 0, namespace1, TABLE_1).withIntValue(BALANCE, null); + Put put = Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, null).build(); TwoPhaseCommitTransaction transaction = manager1.begin(); // Act @@ -733,7 +742,10 @@ public void putAndCommit_GetsAndPutsGiven_ShouldCommitProperly() throws Transact @Test public void putAndRollback_ShouldNotCreateRecord() throws TransactionException { // Arrange - Put put = preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, INITIAL_BALANCE); + Put put = + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, INITIAL_BALANCE) + .build(); TwoPhaseCommitTransaction transaction = manager1.begin(); // Act @@ -753,7 +765,10 @@ public void putAndRollback_ShouldNotCreateRecord() throws TransactionException { @Test public void putAndAbort_ShouldNotCreateRecord() throws TransactionException { // Arrange - Put put = preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, INITIAL_BALANCE); + Put put = + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, INITIAL_BALANCE) + .build(); TwoPhaseCommitTransaction transaction = manager1.begin(); // Act @@ -865,7 +880,10 @@ public void mutateAndCommit_AfterRead_ShouldMutateRecordsProperly() throws Trans populateRecords(manager1, namespace1, TABLE_1); Get get1 = prepareGet(0, 0, namespace1, TABLE_1); Get get2 = prepareGet(1, 0, namespace1, TABLE_1); - Put put = preparePut(0, 0, namespace1, TABLE_1).withIntValue(BALANCE, INITIAL_BALANCE - 100); + Put put = + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, INITIAL_BALANCE - 100) + .build(); Delete delete = prepareDelete(1, 0, namespace1, TABLE_1); TwoPhaseCommitTransaction transaction = manager1.begin(); @@ -1054,7 +1072,8 @@ public void getState_forSuccessfulTransaction_ShouldReturnCommittedState() // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); transaction.get(prepareGet(0, 0, namespace1, TABLE_1)); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.prepare(); transaction.validate(); transaction.commit(); @@ -1071,11 +1090,13 @@ public void getState_forFailedTransaction_ShouldReturnAbortedState() throws Tran // Arrange TwoPhaseCommitTransaction transaction1 = manager1.begin(); transaction1.get(prepareGet(0, 0, namespace1, TABLE_1)); - transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); TwoPhaseCommitTransaction transaction2 = manager1.begin(); transaction2.get(prepareGet(0, 0, namespace1, TABLE_1)); - transaction2.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction2.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction2.prepare(); transaction2.validate(); transaction2.commit(); @@ -1095,7 +1116,8 @@ public void rollback_forOngoingTransaction_ShouldRollbackCorrectly() throws Tran // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); transaction.get(prepareGet(0, 0, namespace1, TABLE_1)); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); // Act manager1.rollback(transaction.getId()); @@ -1115,7 +1137,8 @@ public void abort_forOngoingTransaction_ShouldAbortCorrectly() throws Transactio // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); transaction.get(prepareGet(0, 0, namespace1, TABLE_1)); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); // Act manager1.abort(transaction.getId()); @@ -1137,7 +1160,7 @@ public void scanOrGetScanner_ScanAllGivenForCommittedRecord_ShouldReturnRecords( // Arrange populateRecords(manager1, namespace1, TABLE_1); TwoPhaseCommitTransaction transaction = manager1.begin(); - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); // Act List results = scanOrGetScanner(transaction, scanAll, scanType); @@ -1178,7 +1201,7 @@ public void scanOrGetScanner_ScanAllGivenWithLimit_ShouldReturnLimitedAmountOfRe putTransaction.commit(); TwoPhaseCommitTransaction scanAllTransaction = manager1.begin(); - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1).withLimit(2); + Scan scanAll = Scan.newBuilder(prepareScanAll(namespace1, TABLE_1)).limit(2).build(); // Act List results = scanOrGetScanner(scanAllTransaction, scanAll, scanType); @@ -1220,8 +1243,11 @@ public void scanOrGetScanner_ScanAllWithProjectionsGiven_ShouldRetrieveSpecified // Arrange populateRecords(manager1, namespace1, TABLE_1); TwoPhaseCommitTransaction transaction = manager1.begin(); - ScanAll scanAll = - prepareScanAll(namespace1, TABLE_1).withProjection(ACCOUNT_TYPE).withProjection(BALANCE); + Scan scanAll = + Scan.newBuilder(prepareScanAll(namespace1, TABLE_1)) + .projection(ACCOUNT_TYPE) + .projection(BALANCE) + .build(); // Act List results = scanOrGetScanner(transaction, scanAll, scanType); @@ -1256,7 +1282,7 @@ public void scanOrGetScanner_ScanAllGivenForNonExisting_ShouldReturnEmpty(ScanTy throws TransactionException { // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); // Act List results = scanOrGetScanner(transaction, scanAll, scanType); @@ -1276,7 +1302,9 @@ public void scanOrGetScanner_ScanAllGivenForNonExisting_ShouldReturnEmpty(ScanTy populateSingleRecord(namespace1, TABLE_1); TwoPhaseCommitTransaction transaction = manager1.begin(); Get get = - prepareGet(0, 0, namespace1, TABLE_1).withProjections(Arrays.asList(BALANCE, SOME_COLUMN)); + Get.newBuilder(prepareGet(0, 0, namespace1, TABLE_1)) + .projections(BALANCE, SOME_COLUMN) + .build(); // Act Optional result = transaction.get(get); @@ -1300,8 +1328,9 @@ public void scanOrGetScanner_ScanAllGivenForNonExisting_ShouldReturnEmpty(ScanTy TwoPhaseCommitTransaction transaction = manager1.begin(); populateSingleRecord(namespace1, TABLE_1); Scan scan = - prepareScan(0, 0, 0, namespace1, TABLE_1) - .withProjections(Arrays.asList(BALANCE, SOME_COLUMN)); + Scan.newBuilder(prepareScan(0, 0, 0, namespace1, TABLE_1)) + .projections(BALANCE, SOME_COLUMN) + .build(); // Act List results = scanOrGetScanner(transaction, scan, scanType); @@ -1326,8 +1355,10 @@ public void scanOrGetScanner_ScanAllGivenForNonExisting_ShouldReturnEmpty(ScanTy // Arrange populateSingleRecord(namespace1, TABLE_1); TwoPhaseCommitTransaction transaction = manager1.begin(); - ScanAll scanAll = - prepareScanAll(namespace1, TABLE_1).withProjections(Arrays.asList(BALANCE, SOME_COLUMN)); + Scan scanAll = + Scan.newBuilder(prepareScanAll(namespace1, TABLE_1)) + .projections(BALANCE, SOME_COLUMN) + .build(); // Act List results = scanOrGetScanner(transaction, scanAll, scanType); @@ -2964,10 +2995,13 @@ protected void populateSingleRecord(String namespaceName, String tableName) protected Get prepareGet(int id, int type, String namespaceName, String tableName) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); - return new Get(partitionKey, clusteringKey) - .forNamespace(namespaceName) - .forTable(tableName) - .withConsistency(Consistency.LINEARIZABLE); + return Get.newBuilder() + .namespace(namespaceName) + .table(tableName) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } protected List prepareGets(String namespaceName, String tableName) { @@ -2983,28 +3017,35 @@ protected List prepareGets(String namespaceName, String tableName) { protected Scan prepareScan( int id, int fromType, int toType, String namespaceName, String tableName) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); - return new Scan(partitionKey) - .forNamespace(namespaceName) - .forTable(tableName) - .withConsistency(Consistency.LINEARIZABLE) - .withStart(Key.ofInt(ACCOUNT_TYPE, fromType)) - .withEnd(Key.ofInt(ACCOUNT_TYPE, toType)); + return Scan.newBuilder() + .namespace(namespaceName) + .table(tableName) + .partitionKey(partitionKey) + .consistency(Consistency.LINEARIZABLE) + .start(Key.ofInt(ACCOUNT_TYPE, fromType)) + .end(Key.ofInt(ACCOUNT_TYPE, toType)) + .build(); } - protected ScanAll prepareScanAll(String namespaceName, String tableName) { - return new ScanAll() - .forNamespace(namespaceName) - .forTable(tableName) - .withConsistency(Consistency.LINEARIZABLE); + protected Scan prepareScanAll(String namespaceName, String tableName) { + return Scan.newBuilder() + .namespace(namespaceName) + .table(tableName) + .all() + .consistency(Consistency.LINEARIZABLE) + .build(); } protected Put preparePut(int id, int type, String namespaceName, String tableName) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); - return new Put(partitionKey, clusteringKey) - .forNamespace(namespaceName) - .forTable(tableName) - .withConsistency(Consistency.LINEARIZABLE); + return Put.newBuilder() + .namespace(namespaceName) + .table(tableName) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } protected Insert prepareInsert(int id, int type, String namespaceName, String tableName) { @@ -3035,10 +3076,13 @@ protected List preparePuts(String namespaceName, String tableName) { protected Delete prepareDelete(int id, int type, String namespaceName, String tableName) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); - return new Delete(partitionKey, clusteringKey) - .forNamespace(namespaceName) - .forTable(tableName) - .withConsistency(Consistency.LINEARIZABLE); + return Delete.newBuilder() + .namespace(namespaceName) + .table(tableName) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } protected int getBalance(Result result) { diff --git a/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitNullMetadataIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitNullMetadataIntegrationTestBase.java index ba2f8b5638..c77c5414f5 100644 --- a/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitNullMetadataIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitNullMetadataIntegrationTestBase.java @@ -1101,7 +1101,7 @@ public void scanAll_ScanAllGivenForCommittedRecord_ShouldReturnRecord() // Arrange populateRecordsWithNullMetadata(namespace1, TABLE_1); DistributedTransaction transaction = manager.begin(); - Scan scanAll = prepareScanAll(namespace1, TABLE_1).withLimit(1); + Scan scanAll = Scan.newBuilder(prepareScanAll(namespace1, TABLE_1)).limit(1).build(); // Act List results = transaction.scan(scanAll); diff --git a/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitSpecificIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitSpecificIntegrationTestBase.java index 8b42f9e1ba..c07ae3660e 100644 --- a/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitSpecificIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitSpecificIntegrationTestBase.java @@ -30,7 +30,6 @@ import com.scalar.db.api.Put; import com.scalar.db.api.Result; import com.scalar.db.api.Scan; -import com.scalar.db.api.ScanAll; import com.scalar.db.api.Selection; import com.scalar.db.api.StorageInfo; import com.scalar.db.api.TableMetadata; @@ -1338,7 +1337,7 @@ void getScanner_ScanGivenForPreparedWhenCoordinatorStateCommitted_ShouldBehaveCo void scanAll_ScanAllGivenForPreparedWhenCoordinatorStateCommitted_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForPreparedWhenCoordinatorStateCommitted_ShouldBehaveCorrectly( scanAll, false, isolation, readOnly, commitType); } @@ -1348,7 +1347,7 @@ void scanAll_ScanAllGivenForPreparedWhenCoordinatorStateCommitted_ShouldBehaveCo void getScanner_ScanAllGivenForPreparedWhenCoordinatorStateCommitted_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForPreparedWhenCoordinatorStateCommitted_ShouldBehaveCorrectly( scanAll, true, isolation, readOnly, commitType); } @@ -1446,7 +1445,7 @@ void getScanner_ScanGivenForPreparedWhenCoordinatorStateAborted_ShouldBehaveCorr void scanAll_ScanAllGivenForPreparedWhenCoordinatorStateAborted_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws TransactionException, ExecutionException, CoordinatorException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForPreparedWhenCoordinatorStateAborted_ShouldBehaveCorrectly( scanAll, false, isolation, readOnly, commitType); } @@ -1456,7 +1455,7 @@ void scanAll_ScanAllGivenForPreparedWhenCoordinatorStateAborted_ShouldBehaveCorr void getScanner_ScanAllGivenForPreparedWhenCoordinatorStateAborted_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws TransactionException, ExecutionException, CoordinatorException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForPreparedWhenCoordinatorStateAborted_ShouldBehaveCorrectly( scanAll, true, isolation, readOnly, commitType); } @@ -1579,7 +1578,7 @@ void scan_ScanGivenForPreparedWhenCoordinatorStateNotExistAndNotExpired_ShouldBe scanAll_ScanAllGivenForPreparedWhenCoordinatorStateNotExistAndNotExpired_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForPreparedWhenCoordinatorStateNotExistAndNotExpired_ShouldBehaveCorrectly( scanAll, false, isolation, readOnly, commitType); } @@ -1590,7 +1589,7 @@ void scan_ScanGivenForPreparedWhenCoordinatorStateNotExistAndNotExpired_ShouldBe getScanner_ScanAllGivenForPreparedWhenCoordinatorStateNotExistAndNotExpired_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForPreparedWhenCoordinatorStateNotExistAndNotExpired_ShouldBehaveCorrectly( scanAll, true, isolation, readOnly, commitType); } @@ -1692,7 +1691,7 @@ void getScanner_ScanGivenForPreparedWhenCoordinatorStateNotExistAndExpired_Shoul getScanner_ScanAllGivenForPreparedWhenCoordinatorStateNotExistAndExpired_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForPreparedWhenCoordinatorStateNotExistAndExpired_ShouldBehaveCorrectly( scanAll, true, isolation, readOnly, commitType); } @@ -1702,7 +1701,7 @@ void getScanner_ScanGivenForPreparedWhenCoordinatorStateNotExistAndExpired_Shoul void scanAll_ScanAllGivenForPreparedWhenCoordinatorStateNotExistAndExpired_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForPreparedWhenCoordinatorStateNotExistAndExpired_ShouldBehaveCorrectly( scanAll, false, isolation, readOnly, commitType); } @@ -1826,7 +1825,7 @@ void getScanner_ScanGivenForDeletedWhenCoordinatorStateCommitted_ShouldBehaveCor void scanAll_ScanAllGivenForDeletedWhenCoordinatorStateCommitted_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForDeletedWhenCoordinatorStateCommitted_ShouldBehaveCorrectly( scanAll, false, isolation, readOnly, commitType); } @@ -1836,7 +1835,7 @@ void scanAll_ScanAllGivenForDeletedWhenCoordinatorStateCommitted_ShouldBehaveCor void getScanner_ScanAllGivenForDeletedWhenCoordinatorStateCommitted_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForDeletedWhenCoordinatorStateCommitted_ShouldBehaveCorrectly( scanAll, true, isolation, readOnly, commitType); } @@ -1934,7 +1933,7 @@ void getScanner_ScanGivenForDeletedWhenCoordinatorStateAborted_ShouldBehaveCorre void scanAll_ScanAllGivenForDeletedWhenCoordinatorStateAborted_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForDeletedWhenCoordinatorStateAborted_ShouldBehaveCorrectly( scanAll, false, isolation, readOnly, commitType); } @@ -1944,7 +1943,7 @@ void scanAll_ScanAllGivenForDeletedWhenCoordinatorStateAborted_ShouldBehaveCorre void getScanner_ScanAllGivenForDeletedWhenCoordinatorStateAborted_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForDeletedWhenCoordinatorStateAborted_ShouldBehaveCorrectly( scanAll, true, isolation, readOnly, commitType); } @@ -2067,7 +2066,7 @@ void scan_ScanGivenForDeletedWhenCoordinatorStateNotExistAndNotExpired_ShouldBeh scanAll_ScanAllGivenForDeletedWhenCoordinatorStateNotExistAndNotExpired_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForDeletedWhenCoordinatorStateNotExistAndNotExpired_ShouldBehaveCorrectly( scanAll, false, isolation, readOnly, commitType); } @@ -2078,7 +2077,7 @@ void scan_ScanGivenForDeletedWhenCoordinatorStateNotExistAndNotExpired_ShouldBeh getScanner_ScanAllGivenForDeletedWhenCoordinatorStateNotExistAndNotExpired_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForDeletedWhenCoordinatorStateNotExistAndNotExpired_ShouldBehaveCorrectly( scanAll, true, isolation, readOnly, commitType); } @@ -2178,7 +2177,7 @@ void getScanner_ScanGivenForDeletedWhenCoordinatorStateNotExistAndExpired_Should void scanAll_ScanAllGivenForDeletedWhenCoordinatorStateNotExistAndExpired_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForDeletedWhenCoordinatorStateNotExistAndExpired_ShouldBehaveCorrectly( scanAll, false, isolation, readOnly, commitType); } @@ -2189,7 +2188,7 @@ void scanAll_ScanAllGivenForDeletedWhenCoordinatorStateNotExistAndExpired_Should getScanner_ScanAllGivenForDeletedWhenCoordinatorStateNotExistAndExpired_ShouldBehaveCorrectly( Isolation isolation, boolean readOnly, CommitType commitType) throws ExecutionException, CoordinatorException, TransactionException { - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); selection_SelectionGivenForDeletedWhenCoordinatorStateNotExistAndExpired_ShouldBehaveCorrectly( scanAll, true, isolation, readOnly, commitType); } @@ -2655,7 +2654,8 @@ void getThenScanAndGet_CommitHappenedInBetween_BehaveCorrectly( // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.commit(); DistributedTransaction transaction1 = begin(manager, readOnly); @@ -2663,7 +2663,8 @@ void getThenScanAndGet_CommitHappenedInBetween_BehaveCorrectly( DistributedTransaction transaction2 = manager.begin(); transaction2.get(prepareGet(0, 0, namespace1, TABLE_1)); - transaction2.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 2)); + transaction2.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 2).build()); transaction2.commit(); // Act Assert @@ -2711,7 +2712,8 @@ void putAndCommit_PutGivenForNonExisting_ShouldCreateRecord(Isolation isolation) // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); int expected = INITIAL_BALANCE; - Put put = preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, expected); + Put put = + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, expected).build(); DistributedTransaction transaction = manager.begin(); // Act @@ -2776,7 +2778,8 @@ void putAndCommit_PutGivenForExistingAfterRead_ShouldUpdateRecord(Isolation isol Optional result = transaction.get(get); assertThat(result).isPresent(); int expected = getBalance(result.get()) + 100; - Put put = preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, expected); + Put put = + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, expected).build(); transaction.put(put); transaction.commit(); @@ -3008,8 +3011,8 @@ private void commit_ConflictingPutsGivenForNonExisting_ShouldCommitOneAndAbortTh int to = NUM_TYPES; int anotherFrom = to; int anotherTo = NUM_TYPES * 2; - puts1.get(from).withValue(BALANCE, expected); - puts2.get(to).withValue(BALANCE, expected); + puts1.set(from, Put.newBuilder(puts1.get(from)).intValue(BALANCE, expected).build()); + puts2.set(to, Put.newBuilder(puts2.get(to)).intValue(BALANCE, expected).build()); DistributedTransaction transaction1 = manager.begin(); transaction1.get(gets1.get(from)); @@ -3018,7 +3021,7 @@ private void commit_ConflictingPutsGivenForNonExisting_ShouldCommitOneAndAbortTh transaction1.put(puts2.get(to)); DistributedTransaction transaction2 = manager.begin(); - puts1.get(anotherTo).withValue(BALANCE, expected); + puts1.set(anotherTo, Put.newBuilder(puts1.get(anotherTo)).intValue(BALANCE, expected).build()); // Act Assert assertThatCode( @@ -3300,16 +3303,16 @@ void putAndCommit_GetsAndPutsForSameKeyButDifferentTablesGiven_ShouldCommitBoth( int to = NUM_TYPES; int anotherFrom = from; int anotherTo = to; - puts1.get(from).withValue(BALANCE, expected); - puts1.get(to).withValue(BALANCE, expected); + puts1.set(from, Put.newBuilder(puts1.get(from)).intValue(BALANCE, expected).build()); + puts1.set(to, Put.newBuilder(puts1.get(to)).intValue(BALANCE, expected).build()); DistributedTransaction transaction1 = manager.begin(); transaction1.put(puts1.get(from)); transaction1.put(puts1.get(to)); DistributedTransaction transaction2 = manager.begin(); - puts2.get(from).withValue(BALANCE, expected); - puts2.get(to).withValue(BALANCE, expected); + puts2.set(from, Put.newBuilder(puts2.get(from)).intValue(BALANCE, expected).build()); + puts2.set(to, Put.newBuilder(puts2.get(to)).intValue(BALANCE, expected).build()); // Act Assert assertThatCode( @@ -3462,8 +3465,8 @@ private void commit_WriteSkewOnExistingRecords_ShouldBehaveCorrectly( ConsensusCommitManager manager = createConsensusCommitManager(isolation); List puts = Arrays.asList( - preparePut(0, 0, namespace1, table1).withValue(BALANCE, 1), - preparePut(0, 1, namespace2, table2).withValue(BALANCE, 1)); + Put.newBuilder(preparePut(0, 0, namespace1, table1)).intValue(BALANCE, 1).build(), + Put.newBuilder(preparePut(0, 1, namespace2, table2)).intValue(BALANCE, 1).build()); DistributedTransaction transaction = manager.begin(); transaction.put(puts); transaction.commit(); @@ -3484,9 +3487,15 @@ private void commit_WriteSkewOnExistingRecords_ShouldBehaveCorrectly( int current2 = getBalance(result2.get()); Get get2_2 = prepareGet(0, 1, namespace2, table2); transaction2.get(get2_2); - Put put1 = preparePut(0, 0, namespace1, table1).withValue(BALANCE, current1 + 1); + Put put1 = + Put.newBuilder(preparePut(0, 0, namespace1, table1)) + .intValue(BALANCE, current1 + 1) + .build(); transaction1.put(put1); - Put put2 = preparePut(0, 1, namespace2, table2).withValue(BALANCE, current2 + 1); + Put put2 = + Put.newBuilder(preparePut(0, 1, namespace2, table2)) + .intValue(BALANCE, current2 + 1) + .build(); transaction2.put(put2); transaction1.commit(); @@ -3561,9 +3570,15 @@ private void commit_WriteSkewOnNonExistingRecords_ShouldBehaveCorrectly( Get get2_2 = prepareGet(0, 1, namespace2, table2); transaction2.get(get2_2); int current2 = 0; - Put put1 = preparePut(0, 0, namespace1, table1).withValue(BALANCE, current1 + 1); + Put put1 = + Put.newBuilder(preparePut(0, 0, namespace1, table1)) + .intValue(BALANCE, current1 + 1) + .build(); transaction1.put(put1); - Put put2 = preparePut(0, 1, namespace2, table2).withValue(BALANCE, current2 + 1); + Put put2 = + Put.newBuilder(preparePut(0, 1, namespace2, table2)) + .intValue(BALANCE, current2 + 1) + .build(); transaction2.put(put2); Throwable thrown1 = catchThrowable(transaction1::commit); Throwable thrown2 = catchThrowable(transaction2::commit); @@ -3630,8 +3645,8 @@ void commit_WriteSkewWithScanOnExistingRecords_ShouldBehaveCorrectly(Isolation i ConsensusCommitManager manager = createConsensusCommitManager(isolation); List puts = Arrays.asList( - preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1), - preparePut(0, 1, namespace1, TABLE_1).withValue(BALANCE, 1)); + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build(), + Put.newBuilder(preparePut(0, 1, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); DistributedTransaction transaction = manager.begin(); transaction.put(puts); transaction.commit(); @@ -3643,9 +3658,11 @@ void commit_WriteSkewWithScanOnExistingRecords_ShouldBehaveCorrectly(Isolation i int count1 = results1.size(); List results2 = transaction2.scan(prepareScan(0, 0, 1, namespace1, TABLE_1)); int count2 = results2.size(); - Put put1 = preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, count1 + 1); + Put put1 = + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, count1 + 1).build(); transaction1.put(put1); - Put put2 = preparePut(0, 1, namespace1, TABLE_1).withValue(BALANCE, count2 + 1); + Put put2 = + Put.newBuilder(preparePut(0, 1, namespace1, TABLE_1)).intValue(BALANCE, count2 + 1).build(); transaction2.put(put2); Throwable thrown1 = catchThrowable(transaction1::commit); Throwable thrown2 = catchThrowable(transaction2::commit); @@ -3702,9 +3719,11 @@ void commit_WriteSkewWithScanOnNonExistingRecords_ShouldBehaveCorrectly(Isolatio int count1 = results1.size(); List results2 = transaction2.scan(prepareScan(0, 0, 1, namespace1, TABLE_1)); int count2 = results2.size(); - Put put1 = preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, count1 + 1); + Put put1 = + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, count1 + 1).build(); transaction1.put(put1); - Put put2 = preparePut(0, 1, namespace1, TABLE_1).withValue(BALANCE, count2 + 1); + Put put2 = + Put.newBuilder(preparePut(0, 1, namespace1, TABLE_1)).intValue(BALANCE, count2 + 1).build(); transaction2.put(put2); Throwable thrown1 = catchThrowable(transaction1::commit); Throwable thrown2 = catchThrowable(transaction2::commit); @@ -3807,7 +3826,8 @@ void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializableResu // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 2)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 2).build()); transaction.commit(); // Act @@ -3817,7 +3837,10 @@ void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializableResu if (result1.isPresent()) { balance1 = getBalance(result1.get()); } - transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, balance1 + 1)); + transaction1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, balance1 + 1) + .build()); DistributedTransaction transaction2 = manager.begin(); transaction2.get(prepareGet(0, 0, namespace1, TABLE_1)); @@ -3831,7 +3854,10 @@ void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializableResu if (result3.isPresent()) { balance3 = getBalance(result3.get()); } - transaction3.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, balance3 + 1)); + transaction3.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, balance3 + 1) + .build()); transaction3.commit(); Throwable thrown = catchThrowable(transaction1::commit); @@ -3852,7 +3878,8 @@ void deleteAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializableR // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 2)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 2).build()); transaction.commit(); // Act @@ -3872,7 +3899,10 @@ void deleteAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializableR if (result3.isPresent()) { balance3 = getBalance(result3.get()); } - transaction3.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, balance3 + 1)); + transaction3.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, balance3 + 1) + .build()); transaction3.commit(); Throwable thrown = catchThrowable(transaction1::commit); @@ -3895,7 +3925,8 @@ void get_PutThenGetWithoutConjunctionReturnEmptyFromStorage_ShouldReturnResult( DistributedTransaction transaction = manager.begin(); // Act - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); Get get = prepareGet(0, 0, namespace1, TABLE_1); Optional result = transaction.get(get); assertThatCode(transaction::commit).doesNotThrowAnyException(); @@ -3914,7 +3945,8 @@ void get_PutThenGetWithConjunctionReturnEmptyFromStorageAndMatchedWithPut_Should DistributedTransaction transaction = manager.begin(); // Act - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); Get get = Get.newBuilder(prepareGet(0, 0, namespace1, TABLE_1)) .where(column(BALANCE).isEqualToInt(1)) @@ -3936,7 +3968,8 @@ void get_PutThenGetWithConjunctionReturnEmptyFromStorageAndUnmatchedWithPut_Shou DistributedTransaction transaction = manager.begin(); // Act - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); Get get = Get.newBuilder(prepareGet(0, 0, namespace1, TABLE_1)) .where(column(BALANCE).isEqualToInt(0)) @@ -3956,7 +3989,7 @@ void get_PutThenGetWithConjunctionReturnResultFromStorageAndMatchedWithPut_Shoul ConsensusCommitManager manager = createConsensusCommitManager(isolation); populateRecord(manager, namespace1, TABLE_1); DistributedTransaction transaction = manager.begin(); - Put put = preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1); + Put put = Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build(); Get get = Get.newBuilder(prepareGet(0, 0, namespace1, TABLE_1)) .where(column(BALANCE).isLessThanOrEqualToInt(INITIAL_BALANCE)) @@ -3980,7 +4013,7 @@ void get_PutThenGetWithConjunctionReturnResultFromStorageButUnmatchedWithPut_Sho ConsensusCommitManager manager = createConsensusCommitManager(isolation); populateRecord(manager, namespace1, TABLE_1); DistributedTransaction transaction = manager.begin(); - Put put = preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1); + Put put = Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build(); Get get = Get.newBuilder(prepareGet(0, 0, namespace1, TABLE_1)) .where(column(BALANCE).isEqualToInt(0)) @@ -4002,7 +4035,8 @@ void get_DeleteCalledBefore_ShouldReturnEmpty(Isolation isolation) throws Transa // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.commit(); // Act @@ -4024,14 +4058,16 @@ void delete_PutCalledBefore_ShouldDelete(Isolation isolation) throws Transaction // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.commit(); // Act DistributedTransaction transaction1 = manager.begin(); Get get = prepareGet(0, 0, namespace1, TABLE_1); Optional resultBefore = transaction1.get(get); - transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 2)); + transaction1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 2).build()); transaction1.delete(prepareDelete(0, 0, namespace1, TABLE_1)); assertThatCode(transaction1::commit).doesNotThrowAnyException(); @@ -4050,7 +4086,8 @@ void put_DeleteCalledBefore_ShouldThrowIllegalArgumentException(Isolation isolat // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.commit(); // Act @@ -4060,7 +4097,11 @@ void put_DeleteCalledBefore_ShouldThrowIllegalArgumentException(Isolation isolat transaction1.delete(prepareDelete(0, 0, namespace1, TABLE_1)); Throwable thrown = catchThrowable( - () -> transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 2))); + () -> + transaction1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, 2) + .build())); transaction1.rollback(); // Assert @@ -4074,7 +4115,8 @@ void scan_OverlappingPutGivenBefore_ShouldThrowIllegalArgumentException(Isolatio // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); // Act Scan scan = prepareScan(0, 0, 0, namespace1, TABLE_1); @@ -4092,7 +4134,8 @@ void scan_NonOverlappingPutGivenBefore_ShouldScan(Isolation isolation) // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); // Act Scan scan = prepareScan(0, 1, 1, namespace1, TABLE_1); @@ -4110,7 +4153,8 @@ void scan_PutWithOverlappedClusteringKeyAndNonOverlappedConjunctionsGivenBefore_ // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 1, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 1, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); Scan scan = Scan.newBuilder() .namespace(namespace1) @@ -4136,7 +4180,8 @@ void scan_NonOverlappingPutGivenButOverlappingPutExists_ShouldThrowIllegalArgume ConsensusCommitManager manager = createConsensusCommitManager(isolation); populateRecords(manager, namespace1, TABLE_1); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 1, namespace1, TABLE_1).withValue(BALANCE, 9999)); + transaction.put( + Put.newBuilder(preparePut(0, 1, namespace1, TABLE_1)).intValue(BALANCE, 9999).build()); Scan scan = Scan.newBuilder(prepareScan(0, 1, 1, namespace1, TABLE_1)) .where(column(BALANCE).isLessThanOrEqualToInt(INITIAL_BALANCE)) @@ -4158,9 +4203,10 @@ void scan_OverlappingPutWithConjunctionsGivenBefore_ShouldThrowIllegalArgumentEx ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); transaction.put( - preparePut(0, 0, namespace1, TABLE_1) - .withValue(BALANCE, 999) - .withValue(SOME_COLUMN, "aaa")); + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, 999) + .textValue(SOME_COLUMN, "aaa") + .build()); Scan scan = Scan.newBuilder(prepareScan(0, namespace1, TABLE_1)) .where(column(BALANCE).isLessThanInt(1000)) @@ -4273,9 +4319,10 @@ void scanWithIndex_OverlappingPutWithIndexedColumnGivenBefore_ShouldThrowIllegal ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); transaction.put( - preparePut(0, 0, namespace1, TABLE_1) - .withValue(BALANCE, 999) - .withValue(SOME_COLUMN, "aaa")); + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, 999) + .textValue(SOME_COLUMN, "aaa") + .build()); Scan scan = Scan.newBuilder(prepareScanWithIndex(namespace1, TABLE_1, 999)) .where(column(BALANCE).isLessThanInt(1000)) @@ -4297,8 +4344,10 @@ void scan_DeleteGivenBefore_ShouldThrowIllegalArgumentException(Isolation isolat // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); - transaction.put(preparePut(0, 1, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); + transaction.put( + Put.newBuilder(preparePut(0, 1, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.commit(); // Act Assert @@ -4316,14 +4365,16 @@ void scanAll_DeleteGivenBefore_ShouldThrowIllegalArgumentException(Isolation iso // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withIntValue(BALANCE, 1)); - transaction.put(preparePut(0, 1, namespace1, TABLE_1).withIntValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); + transaction.put( + Put.newBuilder(preparePut(0, 1, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.commit(); // Act Assert DistributedTransaction transaction1 = manager.begin(); transaction1.delete(prepareDelete(0, 0, namespace1, TABLE_1)); - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); assertThatThrownBy(() -> transaction1.scan(scanAll)) .isInstanceOf(IllegalArgumentException.class); transaction1.rollback(); @@ -4336,10 +4387,11 @@ void scanAll_NonOverlappingPutGivenBefore_ShouldScanAll(Isolation isolation) // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withIntValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); // Act - ScanAll scanAll = prepareScanAll(namespace2, TABLE_2); + Scan scanAll = prepareScanAll(namespace2, TABLE_2); Throwable thrown = catchThrowable(() -> transaction.scan(scanAll)); transaction.commit(); @@ -4354,10 +4406,11 @@ void scanAll_OverlappingPutGivenBefore_ShouldThrowIllegalArgumentException(Isola // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withIntValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); // Act - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); Throwable thrown = catchThrowable(() -> transaction.scan(scanAll)); transaction.rollback(); @@ -4373,7 +4426,7 @@ void scanAll_ScanAllGivenForCommittedRecord_ShouldReturnRecord( ConsensusCommitManager manager = createConsensusCommitManager(isolation); populateRecords(manager, namespace1, TABLE_1); DistributedTransaction transaction = begin(manager, readOnly); - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1).withLimit(1); + Scan scanAll = Scan.newBuilder(prepareScanAll(namespace1, TABLE_1)).limit(1).build(); // Act List results = transaction.scan(scanAll); @@ -4397,7 +4450,7 @@ void scanAll_ScanAllGivenForNonExisting_ShouldReturnEmpty(Isolation isolation, b putTransaction.commit(); DistributedTransaction transaction = begin(manager, readOnly); - ScanAll scanAll = prepareScanAll(namespace2, TABLE_2); + Scan scanAll = prepareScanAll(namespace2, TABLE_2); // Act List results = transaction.scan(scanAll); @@ -4462,7 +4515,8 @@ void scan_CalledTwiceWithSameConditionsAndUpdateForHappenedInBetween_ShouldBehav // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.commit(); // Act Assert @@ -4524,7 +4578,8 @@ void scan_CalledTwiceWithDifferentConditionsAndUpdateHappenedInBetween_ShouldBeh // Arrange ConsensusCommitManager manager = createConsensusCommitManager(isolation); DistributedTransaction transaction = manager.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.commit(); DistributedTransaction transaction1 = begin(manager, readOnly); @@ -8254,20 +8309,23 @@ private String populatePreparedRecordAndCoordinatorStateRecord( } Put put = - new Put(partitionKey, clusteringKey) - .forNamespace(namespace) - .forTable(table) - .withValue(BALANCE, NEW_BALANCE) - .withTextValue(Attribute.ID, ongoingTxId) - .withIntValue(Attribute.STATE, recordState.get()) - .withIntValue(Attribute.VERSION, 2) - .withBigIntValue(Attribute.PREPARED_AT, preparedAt) - .withValue(Attribute.BEFORE_PREFIX + BALANCE, INITIAL_BALANCE) - .withTextValue(Attribute.BEFORE_ID, ANY_ID_1) - .withIntValue(Attribute.BEFORE_STATE, TransactionState.COMMITTED.get()) - .withIntValue(Attribute.BEFORE_VERSION, 1) - .withBigIntValue(Attribute.BEFORE_PREPARED_AT, 1) - .withBigIntValue(Attribute.BEFORE_COMMITTED_AT, 1); + Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(BALANCE, NEW_BALANCE) + .textValue(Attribute.ID, ongoingTxId) + .intValue(Attribute.STATE, recordState.get()) + .intValue(Attribute.VERSION, 2) + .bigIntValue(Attribute.PREPARED_AT, preparedAt) + .intValue(Attribute.BEFORE_PREFIX + BALANCE, INITIAL_BALANCE) + .textValue(Attribute.BEFORE_ID, ANY_ID_1) + .intValue(Attribute.BEFORE_STATE, TransactionState.COMMITTED.get()) + .intValue(Attribute.BEFORE_VERSION, 1) + .bigIntValue(Attribute.BEFORE_PREPARED_AT, 1) + .bigIntValue(Attribute.BEFORE_COMMITTED_AT, 1) + .build(); storage.put(put); if (coordinatorState == null) { @@ -8298,10 +8356,13 @@ private String populatePreparedRecordAndCoordinatorStateRecord( private Get prepareGet(int id, int type, String namespace, String table) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); - return new Get(partitionKey, clusteringKey) - .forNamespace(namespace) - .forTable(table) - .withConsistency(Consistency.LINEARIZABLE); + return Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private List prepareGets(String namespace, String table) { @@ -8316,20 +8377,24 @@ private List prepareGets(String namespace, String table) { private Scan prepareScan(int id, int fromType, int toType, String namespace, String table) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); - return new Scan(partitionKey) - .forNamespace(namespace) - .forTable(table) - .withConsistency(Consistency.LINEARIZABLE) - .withStart(Key.ofInt(ACCOUNT_TYPE, fromType)) - .withEnd(Key.ofInt(ACCOUNT_TYPE, toType)); + return Scan.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .consistency(Consistency.LINEARIZABLE) + .start(Key.ofInt(ACCOUNT_TYPE, fromType)) + .end(Key.ofInt(ACCOUNT_TYPE, toType)) + .build(); } private Scan prepareScan(int id, String namespace, String table) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); - return new Scan(partitionKey) - .forNamespace(namespace) - .forTable(table) - .withConsistency(Consistency.LINEARIZABLE); + return Scan.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private Scan prepareScanWithIndex(String namespace, String table, int balance) { @@ -8342,20 +8407,25 @@ private Scan prepareScanWithIndex(String namespace, String table, int balance) { .build(); } - private ScanAll prepareScanAll(String namespace, String table) { - return new ScanAll() - .forNamespace(namespace) - .forTable(table) - .withConsistency(Consistency.LINEARIZABLE); + private Scan prepareScanAll(String namespace, String table) { + return Scan.newBuilder() + .namespace(namespace) + .table(table) + .all() + .consistency(Consistency.LINEARIZABLE) + .build(); } private Put preparePut(int id, int type, String namespace, String table) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); - return new Put(partitionKey, clusteringKey) - .forNamespace(namespace) - .forTable(table) - .withConsistency(Consistency.LINEARIZABLE); + return Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private List preparePuts(String namespace, String table) { @@ -8371,10 +8441,13 @@ private List preparePuts(String namespace, String table) { private Delete prepareDelete(int id, int type, String namespace, String table) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); - return new Delete(partitionKey, clusteringKey) - .forNamespace(namespace) - .forTable(table) - .withConsistency(Consistency.LINEARIZABLE); + return Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private List prepareDeletes(String namespace, String table) { diff --git a/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitSpecificIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitSpecificIntegrationTestBase.java index 3208379155..9e4fe3fc7f 100644 --- a/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitSpecificIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitSpecificIntegrationTestBase.java @@ -13,7 +13,6 @@ import com.scalar.db.api.Put; import com.scalar.db.api.Result; import com.scalar.db.api.Scan; -import com.scalar.db.api.ScanAll; import com.scalar.db.api.TableMetadata; import com.scalar.db.api.TransactionState; import com.scalar.db.api.TwoPhaseCommitTransaction; @@ -25,7 +24,6 @@ import com.scalar.db.exception.transaction.TransactionException; import com.scalar.db.exception.transaction.ValidationException; import com.scalar.db.io.DataType; -import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; import com.scalar.db.io.Value; import com.scalar.db.service.StorageFactory; @@ -640,7 +638,8 @@ public void getThenScanAndGet_CommitHappenedInBetween_OnlyGetShouldReadRepeatabl throws TransactionException { // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.prepare(); transaction.commit(); @@ -649,7 +648,8 @@ public void getThenScanAndGet_CommitHappenedInBetween_OnlyGetShouldReadRepeatabl TwoPhaseCommitTransaction transaction2 = manager1.begin(); transaction2.get(prepareGet(0, 0, namespace1, TABLE_1)); - transaction2.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 2)); + transaction2.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 2).build()); transaction2.prepare(); transaction2.commit(); @@ -673,7 +673,8 @@ public void putAndCommit_PutGivenForNonExisting_ShouldCreateRecord() throws Tran TwoPhaseCommitTransaction transaction = manager1.begin(); // Act - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, expected)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, expected).build()); transaction.prepare(); transaction.commit(); @@ -733,7 +734,10 @@ public void putAndCommit_PutGivenForExistingAfterRead_ShouldUpdateRecord() assertThat(result.isPresent()).isTrue(); int afterBalance = getBalance(result.get()) + 100; - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, afterBalance)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, afterBalance) + .build()); transaction.prepare(); transaction.commit(); @@ -963,8 +967,14 @@ public void commit_ConflictingPutsGivenForNonExisting_ShouldCommitOneAndAbortThe TwoPhaseCommitTransaction toTx = manager2.join(fromTx.getId()); fromTx.get(prepareGet(fromId, fromType, namespace1, TABLE_1)); toTx.get(prepareGet(toId, toType, namespace2, TABLE_2)); - fromTx.put(preparePut(fromId, fromType, namespace1, TABLE_1).withValue(BALANCE, expected)); - toTx.put(preparePut(toId, toType, namespace2, TABLE_2).withValue(BALANCE, expected)); + fromTx.put( + Put.newBuilder(preparePut(fromId, fromType, namespace1, TABLE_1)) + .intValue(BALANCE, expected) + .build()); + toTx.put( + Put.newBuilder(preparePut(toId, toType, namespace2, TABLE_2)) + .intValue(BALANCE, expected) + .build()); // Act Assert assertThatCode( @@ -972,11 +982,13 @@ public void commit_ConflictingPutsGivenForNonExisting_ShouldCommitOneAndAbortThe TwoPhaseCommitTransaction anotherFromTx = manager2.begin(); TwoPhaseCommitTransaction anotherToTx = manager1.join(anotherFromTx.getId()); anotherFromTx.put( - preparePut(anotherFromId, anotherFromType, namespace2, TABLE_2) - .withValue(BALANCE, expected)); + Put.newBuilder(preparePut(anotherFromId, anotherFromType, namespace2, TABLE_2)) + .intValue(BALANCE, expected) + .build()); anotherToTx.put( - preparePut(anotherToId, anotherToType, namespace1, TABLE_1) - .withValue(BALANCE, expected)); + Put.newBuilder(preparePut(anotherToId, anotherToType, namespace1, TABLE_1)) + .intValue(BALANCE, expected) + .build()); anotherFromTx.prepare(); anotherToTx.prepare(); anotherFromTx.commit(); @@ -1292,8 +1304,14 @@ public void putAndCommit_GetsAndPutsForSameKeyButDifferentTablesGiven_ShouldComm TwoPhaseCommitTransaction fromTx = manager1.begin(); TwoPhaseCommitTransaction toTx = manager2.join(fromTx.getId()); - fromTx.put(preparePut(fromId, fromType, namespace1, TABLE_1).withValue(BALANCE, expected)); - toTx.put(preparePut(toId, toType, namespace2, TABLE_2).withValue(BALANCE, expected)); + fromTx.put( + Put.newBuilder(preparePut(fromId, fromType, namespace1, TABLE_1)) + .intValue(BALANCE, expected) + .build()); + toTx.put( + Put.newBuilder(preparePut(toId, toType, namespace2, TABLE_2)) + .intValue(BALANCE, expected) + .build()); // Act Assert assertThatCode( @@ -1301,11 +1319,13 @@ public void putAndCommit_GetsAndPutsForSameKeyButDifferentTablesGiven_ShouldComm TwoPhaseCommitTransaction anotherFromTx = manager2.begin(); TwoPhaseCommitTransaction anotherToTx = manager1.join(anotherFromTx.getId()); anotherFromTx.put( - preparePut(anotherFromId, anotherFromType, namespace2, TABLE_2) - .withValue(BALANCE, expected)); + Put.newBuilder(preparePut(anotherFromId, anotherFromType, namespace2, TABLE_2)) + .intValue(BALANCE, expected) + .build()); anotherToTx.put( - preparePut(anotherToId, anotherToType, namespace1, TABLE_1) - .withValue(BALANCE, expected)); + Put.newBuilder(preparePut(anotherToId, anotherToType, namespace1, TABLE_1)) + .intValue(BALANCE, expected) + .build()); anotherFromTx.prepare(); anotherToTx.prepare(); @@ -1579,8 +1599,10 @@ public void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSerial // Arrange TwoPhaseCommitTransaction transaction1 = manager1.begin(); TwoPhaseCommitTransaction transaction2 = manager2.join(transaction1.getId()); - transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); - transaction2.put(preparePut(1, 0, namespace2, TABLE_2).withValue(BALANCE, 1)); + transaction1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); + transaction2.put( + Put.newBuilder(preparePut(1, 0, namespace2, TABLE_2)).intValue(BALANCE, 1).build()); transaction1.prepare(); transaction2.prepare(); transaction1.commit(); @@ -1593,7 +1615,10 @@ public void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSerial assertThat(result).isPresent(); int current1 = getBalance(result.get()); tx1Sub1.get(prepareGet(0, 0, namespace1, TABLE_1)); - tx1Sub1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, current1 + 1)); + tx1Sub1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, current1 + 1) + .build()); TwoPhaseCommitTransaction tx2Sub1 = manager1.begin(); TwoPhaseCommitTransaction tx2Sub2 = manager2.join(tx2Sub1.getId()); @@ -1601,7 +1626,10 @@ public void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSerial assertThat(result).isPresent(); int current2 = getBalance(result.get()); tx2Sub2.get(prepareGet(1, 0, namespace2, TABLE_2)); - tx2Sub2.put(preparePut(1, 0, namespace2, TABLE_2).withValue(BALANCE, current2 + 1)); + tx2Sub2.put( + Put.newBuilder(preparePut(1, 0, namespace2, TABLE_2)) + .intValue(BALANCE, current2 + 1) + .build()); tx1Sub1.prepare(); tx1Sub2.prepare(); @@ -1638,8 +1666,10 @@ public void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSerial // Arrange TwoPhaseCommitTransaction transaction1 = manager1.begin(); TwoPhaseCommitTransaction transaction2 = manager2.join(transaction1.getId()); - transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); - transaction2.put(preparePut(1, 0, namespace2, TABLE_2).withValue(BALANCE, 1)); + transaction1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); + transaction2.put( + Put.newBuilder(preparePut(1, 0, namespace2, TABLE_2)).intValue(BALANCE, 1).build()); transaction1.prepare(); transaction2.prepare(); transaction1.commit(); @@ -1652,7 +1682,10 @@ public void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSerial assertThat(result).isPresent(); int current1 = getBalance(result.get()); tx1Sub1.get(prepareGet(0, 0, namespace1, TABLE_1)); - tx1Sub1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, current1 + 1)); + tx1Sub1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, current1 + 1) + .build()); TwoPhaseCommitTransaction tx2Sub1 = manager1.begin(Isolation.SERIALIZABLE); TwoPhaseCommitTransaction tx2Sub2 = manager2.join(tx2Sub1.getId(), Isolation.SERIALIZABLE); @@ -1660,7 +1693,10 @@ public void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSerial assertThat(result).isPresent(); int current2 = getBalance(result.get()); tx2Sub2.get(prepareGet(1, 0, namespace2, TABLE_2)); - tx2Sub2.put(preparePut(1, 0, namespace2, TABLE_2).withValue(BALANCE, current2 + 1)); + tx2Sub2.put( + Put.newBuilder(preparePut(1, 0, namespace2, TABLE_2)) + .intValue(BALANCE, current2 + 1) + .build()); tx1Sub1.prepare(); tx1Sub2.prepare(); @@ -1710,7 +1746,10 @@ public void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSerial assertThat(result).isNotPresent(); int current1 = 0; tx1Sub1.get(prepareGet(0, 0, namespace1, TABLE_1)); - tx1Sub1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, current1 + 1)); + tx1Sub1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, current1 + 1) + .build()); TwoPhaseCommitTransaction tx2Sub1 = manager1.begin(Isolation.SERIALIZABLE); TwoPhaseCommitTransaction tx2Sub2 = manager2.join(tx2Sub1.getId(), Isolation.SERIALIZABLE); @@ -1718,7 +1757,10 @@ public void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSerial assertThat(result).isNotPresent(); int current2 = 0; tx2Sub2.get(prepareGet(1, 0, namespace2, TABLE_2)); - tx2Sub2.put(preparePut(1, 0, namespace2, TABLE_2).withValue(BALANCE, current2 + 1)); + tx2Sub2.put( + Put.newBuilder(preparePut(1, 0, namespace2, TABLE_2)) + .intValue(BALANCE, current2 + 1) + .build()); tx1Sub1.prepare(); tx1Sub2.prepare(); @@ -1765,13 +1807,19 @@ public void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSerial List results = transaction1.scan(prepareScan(0, 0, 1, namespace1, TABLE_1)); assertThat(results).isEmpty(); int count1 = 0; - transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, count1 + 1)); + transaction1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, count1 + 1) + .build()); TwoPhaseCommitTransaction transaction2 = manager1.begin(Isolation.SERIALIZABLE); results = transaction2.scan(prepareScan(0, 0, 1, namespace1, TABLE_1)); assertThat(results).isEmpty(); int count2 = 0; - transaction2.put(preparePut(0, 1, namespace1, TABLE_1).withValue(BALANCE, count2 + 1)); + transaction2.put( + Put.newBuilder(preparePut(0, 1, namespace1, TABLE_1)) + .intValue(BALANCE, count2 + 1) + .build()); assertThatCode( () -> { @@ -1803,8 +1851,10 @@ public void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSerial throws TransactionException { // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); - transaction.put(preparePut(0, 1, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); + transaction.put( + Put.newBuilder(preparePut(0, 1, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.prepare(); transaction.commit(); @@ -1813,13 +1863,19 @@ public void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSerial List results = transaction1.scan(prepareScan(0, 0, 1, namespace1, TABLE_1)); assertThat(results.size()).isEqualTo(2); int count1 = results.size(); - transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, count1 + 1)); + transaction1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, count1 + 1) + .build()); TwoPhaseCommitTransaction transaction2 = manager1.begin(Isolation.SERIALIZABLE); results = transaction2.scan(prepareScan(0, 0, 1, namespace1, TABLE_1)); assertThat(results.size()).isEqualTo(2); int count2 = results.size(); - transaction2.put(preparePut(0, 1, namespace1, TABLE_1).withValue(BALANCE, count2 + 1)); + transaction2.put( + Put.newBuilder(preparePut(0, 1, namespace1, TABLE_1)) + .intValue(BALANCE, count2 + 1) + .build()); assertThatCode( () -> { @@ -1870,7 +1926,8 @@ public void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializa throws TransactionException { // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 2)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 2).build()); transaction.prepare(); transaction.commit(); @@ -1879,7 +1936,10 @@ public void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializa Optional result = transaction1.get(prepareGet(0, 0, namespace1, TABLE_1)); assertThat(result).isPresent(); int balance1 = getBalance(result.get()); - transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, balance1 + 1)); + transaction1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, balance1 + 1) + .build()); TwoPhaseCommitTransaction transaction2 = manager1.begin(); transaction2.get(prepareGet(0, 0, namespace1, TABLE_1)); @@ -1892,7 +1952,10 @@ public void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializa result = transaction3.get(prepareGet(0, 0, namespace1, TABLE_1)); assertThat(result).isNotPresent(); int balance3 = 0; - transaction3.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, balance3 + 1)); + transaction3.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, balance3 + 1) + .build()); transaction3.prepare(); transaction3.commit(); @@ -1914,7 +1977,8 @@ public void deleteAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerial throws TransactionException { // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 2)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 2).build()); transaction.prepare(); transaction.commit(); @@ -1933,7 +1997,10 @@ public void deleteAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerial Optional result = transaction3.get(prepareGet(0, 0, namespace1, TABLE_1)); assertThat(result).isNotPresent(); int balance3 = 0; - transaction3.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, balance3 + 1)); + transaction3.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, balance3 + 1) + .build()); transaction3.prepare(); transaction3.commit(); @@ -1956,7 +2023,8 @@ public void get_PutCalledBefore_ShouldGet() throws TransactionException { TwoPhaseCommitTransaction transaction = manager1.begin(); // Act - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); Get get = prepareGet(0, 0, namespace1, TABLE_1); Optional result = transaction.get(get); assertThatCode( @@ -1975,7 +2043,8 @@ public void get_PutCalledBefore_ShouldGet() throws TransactionException { public void get_DeleteCalledBefore_ShouldReturnEmpty() throws TransactionException { // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.prepare(); transaction.commit(); @@ -2001,14 +2070,16 @@ public void get_DeleteCalledBefore_ShouldReturnEmpty() throws TransactionExcepti public void delete_PutCalledBefore_ShouldDelete() throws TransactionException { // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.prepare(); transaction.commit(); // Act Assert TwoPhaseCommitTransaction transaction1 = manager1.begin(); Optional resultBefore = transaction1.get(prepareGet(0, 0, namespace1, TABLE_1)); - transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 2)); + transaction1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 2).build()); transaction1.delete(prepareDelete(0, 0, namespace1, TABLE_1)); assertThatCode( @@ -2034,7 +2105,8 @@ public void put_DeleteCalledBefore_ShouldThrowIllegalArgumentException() throws TransactionException { // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.prepare(); transaction.commit(); @@ -2045,7 +2117,11 @@ public void put_DeleteCalledBefore_ShouldThrowIllegalArgumentException() transaction1.delete(prepareDelete(0, 0, namespace1, TABLE_1)); Throwable thrown = catchThrowable( - () -> transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 2))); + () -> + transaction1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)) + .intValue(BALANCE, 2) + .build())); transaction1.rollback(); // Assert @@ -2057,7 +2133,8 @@ public void scan_OverlappingPutGivenBefore_ShouldIllegalArgumentException() throws TransactionException { // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); // Act Assert assertThatThrownBy(() -> transaction.scan(prepareScan(0, 0, 0, namespace1, TABLE_1))) @@ -2070,7 +2147,8 @@ public void scan_OverlappingPutGivenBefore_ShouldIllegalArgumentException() public void scan_NonOverlappingPutGivenBefore_ShouldScan() throws TransactionException { // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); // Act Assert assertThatCode(() -> transaction.scan(prepareScan(0, 1, 1, namespace1, TABLE_1))) @@ -2085,8 +2163,10 @@ public void scan_DeleteGivenBefore_ShouldThrowIllegalArgumentException() throws TransactionException { // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); - transaction.put(preparePut(0, 1, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); + transaction.put( + Put.newBuilder(preparePut(0, 1, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.prepare(); transaction.commit(); @@ -2129,7 +2209,8 @@ public void getState_forSuccessfulTransaction_ShouldReturnCommittedState() // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); transaction.get(prepareGet(0, 0, namespace1, TABLE_1)); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.prepare(); transaction.commit(); @@ -2145,11 +2226,13 @@ public void getState_forFailedTransaction_ShouldReturnAbortedState() throws Tran // Arrange TwoPhaseCommitTransaction transaction1 = manager1.begin(); transaction1.get(prepareGet(0, 0, namespace1, TABLE_1)); - transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); TwoPhaseCommitTransaction transaction2 = manager1.begin(); transaction2.get(prepareGet(0, 0, namespace1, TABLE_1)); - transaction2.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction2.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction2.prepare(); transaction2.commit(); @@ -2168,7 +2251,8 @@ public void abort_forOngoingTransaction_ShouldAbortCorrectly() throws Transactio // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); transaction.get(prepareGet(0, 0, namespace1, TABLE_1)); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); // Act manager1.abort(transaction.getId()); @@ -2187,15 +2271,17 @@ public void scanAll_DeleteGivenBefore_ShouldThrowIllegalArgumentException() throws TransactionException { // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withIntValue(BALANCE, 1)); - transaction.put(preparePut(0, 1, namespace1, TABLE_1).withIntValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); + transaction.put( + Put.newBuilder(preparePut(0, 1, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); transaction.prepare(); transaction.commit(); // Act Assert TwoPhaseCommitTransaction transaction1 = manager1.begin(); transaction1.delete(prepareDelete(0, 0, namespace1, TABLE_1)); - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1); + Scan scanAll = prepareScanAll(namespace1, TABLE_1); assertThatThrownBy(() -> transaction1.scan(scanAll)) .isInstanceOf(IllegalArgumentException.class); transaction1.rollback(); @@ -2207,7 +2293,8 @@ public void scanAll_NonOverlappingPutGivenBefore_ShouldScanAll() throws Transact TwoPhaseCommitTransaction transaction1 = manager1.begin(); TwoPhaseCommitTransaction transaction2 = manager2.join(transaction1.getId()); - transaction1.put(preparePut(0, 0, namespace1, TABLE_1).withIntValue(BALANCE, 1)); + transaction1.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); // Act assertThatCode(() -> transaction2.scan(prepareScanAll(namespace2, TABLE_2))) @@ -2222,7 +2309,8 @@ public void scanAll_OverlappingPutGivenBefore_ShouldThrowIllegalArgumentExceptio throws TransactionException { // Arrange TwoPhaseCommitTransaction transaction = manager1.begin(); - transaction.put(preparePut(0, 0, namespace1, TABLE_1).withIntValue(BALANCE, 1)); + transaction.put( + Put.newBuilder(preparePut(0, 0, namespace1, TABLE_1)).intValue(BALANCE, 1).build()); // Act assertThatThrownBy(() -> transaction.scan(prepareScanAll(namespace1, TABLE_1))) @@ -2237,7 +2325,7 @@ public void scanAll_ScanAllGivenForCommittedRecord_ShouldReturnRecord() // Arrange populate(manager1, namespace1, TABLE_1); TwoPhaseCommitTransaction transaction = manager1.begin(); - ScanAll scanAll = prepareScanAll(namespace1, TABLE_1).withLimit(1); + Scan scanAll = Scan.newBuilder(prepareScanAll(namespace1, TABLE_1)).limit(1).build(); // Act List results = transaction.scan(scanAll); @@ -2290,11 +2378,13 @@ public void scanAll_ScanAllGivenForNonExisting_ShouldReturnEmpty() throws Transa putTransaction.commit(); TwoPhaseCommitTransaction transaction = manager2.begin(); - ScanAll scanAll = - new ScanAll() - .forNamespace(namespace2) - .forTable(TABLE_2) - .withConsistency(Consistency.LINEARIZABLE); + Scan scanAll = + Scan.newBuilder() + .namespace(namespace2) + .table(TABLE_2) + .all() + .consistency(Consistency.LINEARIZABLE) + .build(); // Act List results = transaction.scan(scanAll); @@ -2356,11 +2446,13 @@ private void populate(TwoPhaseConsensusCommitManager manager, String namespace, transaction.commit(); } - private ScanAll prepareScanAll(String namespace, String table) { - return new ScanAll() - .forNamespace(namespace) - .forTable(table) - .withConsistency(Consistency.LINEARIZABLE); + private Scan prepareScanAll(String namespace, String table) { + return Scan.newBuilder() + .namespace(namespace) + .table(table) + .all() + .consistency(Consistency.LINEARIZABLE) + .build(); } private void populatePreparedRecordAndCoordinatorStateRecordForStorage1( @@ -2369,19 +2461,22 @@ private void populatePreparedRecordAndCoordinatorStateRecordForStorage1( Key partitionKey = Key.ofInt(ACCOUNT_ID, 0); Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, 0); Put put = - new Put(partitionKey, clusteringKey) - .forNamespace(namespace1) - .forTable(TABLE_1) - .withValue(new IntValue(BALANCE, INITIAL_BALANCE)) - .withTextValue(Attribute.ID, ANY_ID_2) - .withIntValue(Attribute.STATE, recordState.get()) - .withIntValue(Attribute.VERSION, 2) - .withBigIntValue(Attribute.PREPARED_AT, preparedAt) - .withTextValue(Attribute.BEFORE_ID, ANY_ID_1) - .withIntValue(Attribute.BEFORE_STATE, TransactionState.COMMITTED.get()) - .withIntValue(Attribute.BEFORE_VERSION, 1) - .withBigIntValue(Attribute.BEFORE_PREPARED_AT, 1) - .withBigIntValue(Attribute.BEFORE_COMMITTED_AT, 1); + Put.newBuilder() + .namespace(namespace1) + .table(TABLE_1) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .intValue(BALANCE, INITIAL_BALANCE) + .textValue(Attribute.ID, ANY_ID_2) + .intValue(Attribute.STATE, recordState.get()) + .intValue(Attribute.VERSION, 2) + .bigIntValue(Attribute.PREPARED_AT, preparedAt) + .textValue(Attribute.BEFORE_ID, ANY_ID_1) + .intValue(Attribute.BEFORE_STATE, TransactionState.COMMITTED.get()) + .intValue(Attribute.BEFORE_VERSION, 1) + .bigIntValue(Attribute.BEFORE_PREPARED_AT, 1) + .bigIntValue(Attribute.BEFORE_COMMITTED_AT, 1) + .build(); storage1.put(put); if (coordinatorState == null) { @@ -2418,9 +2513,13 @@ private void transfer( .get() .getAsInt(); fromTx.put( - preparePut(fromId, fromType, fromNamespace, fromTable) - .withValue(BALANCE, fromBalance - amount)); - toTx.put(preparePut(toId, toType, toNamespace, toTable).withValue(BALANCE, toBalance + amount)); + Put.newBuilder(preparePut(fromId, fromType, fromNamespace, fromTable)) + .intValue(BALANCE, fromBalance - amount) + .build()); + toTx.put( + Put.newBuilder(preparePut(toId, toType, toNamespace, toTable)) + .intValue(BALANCE, toBalance + amount) + .build()); } private void deletes( @@ -2444,46 +2543,59 @@ private void deletes( private Get prepareGet(int id, int type, String namespace, String table) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); - return new Get(partitionKey, clusteringKey) - .forNamespace(namespace) - .forTable(table) - .withConsistency(Consistency.LINEARIZABLE); + return Get.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private Scan prepareScan(int id, int fromType, int toType, String namespace, String table) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); - return new Scan(partitionKey) - .forNamespace(namespace) - .forTable(table) - .withConsistency(Consistency.LINEARIZABLE) - .withStart(Key.ofInt(ACCOUNT_TYPE, fromType)) - .withEnd(Key.ofInt(ACCOUNT_TYPE, toType)); + return Scan.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .consistency(Consistency.LINEARIZABLE) + .start(Key.ofInt(ACCOUNT_TYPE, fromType)) + .end(Key.ofInt(ACCOUNT_TYPE, toType)) + .build(); } private Scan prepareScan(int id, String namespace, String table) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); - return new Scan(partitionKey) - .forNamespace(namespace) - .forTable(table) - .withConsistency(Consistency.LINEARIZABLE); + return Scan.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private Put preparePut(int id, int type, String namespace, String table) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); - return new Put(partitionKey, clusteringKey) - .forNamespace(namespace) - .forTable(table) - .withConsistency(Consistency.LINEARIZABLE); + return Put.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private Delete prepareDelete(int id, int type, String namespace, String table) { Key partitionKey = Key.ofInt(ACCOUNT_ID, id); Key clusteringKey = Key.ofInt(ACCOUNT_TYPE, type); - return new Delete(partitionKey, clusteringKey) - .forNamespace(namespace) - .forTable(table) - .withConsistency(Consistency.LINEARIZABLE); + return Delete.newBuilder() + .namespace(namespace) + .table(table) + .partitionKey(partitionKey) + .clusteringKey(clusteringKey) + .consistency(Consistency.LINEARIZABLE) + .build(); } private int getAccountId(Result result) { From 3b31262ab5b28aa8567cb3124e85fcd6535e2dbf Mon Sep 17 00:00:00 2001 From: brfrn169 Date: Tue, 19 Aug 2025 22:52:53 +0900 Subject: [PATCH 2/3] Fix based on feedback --- .../storage/cassandra/BatchHandlerTest.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/core/src/test/java/com/scalar/db/storage/cassandra/BatchHandlerTest.java b/core/src/test/java/com/scalar/db/storage/cassandra/BatchHandlerTest.java index 00485bad77..80ec483ecc 100644 --- a/core/src/test/java/com/scalar/db/storage/cassandra/BatchHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/cassandra/BatchHandlerTest.java @@ -22,9 +22,9 @@ import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.storage.NoMutationException; import com.scalar.db.io.Key; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -102,17 +102,15 @@ private List prepareNonConditionalPuts() { } private List prepareConditionalPuts() { - List mutations = prepareNonConditionalPuts(); - List conditionalMutations = new ArrayList<>(); - for (Mutation m : mutations) { - if (m instanceof Put) { - conditionalMutations.add( - Put.newBuilder((Put) m).condition(ConditionBuilder.putIfNotExists()).build()); - } else { - conditionalMutations.add(m); - } - } - return conditionalMutations; + return prepareNonConditionalPuts().stream() + .map( + m -> { + if (m instanceof Put) { + return Put.newBuilder((Put) m).condition(ConditionBuilder.putIfNotExists()).build(); + } + return m; + }) + .collect(Collectors.toList()); } private BatchHandler prepareSpiedBatchHandler() { From 017eb791b77e1fef1da12511ca103c69fed6197f Mon Sep 17 00:00:00 2001 From: brfrn169 Date: Wed, 20 Aug 2025 14:10:46 +0900 Subject: [PATCH 3/3] Fix --- .../consensuscommit/Coordinator.java | 2 +- .../transaction/consensuscommit/Snapshot.java | 17 ++++--- .../com/scalar/db/util/ScalarDbUtils.java | 46 ++++++++++--------- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/com/scalar/db/transaction/consensuscommit/Coordinator.java b/core/src/main/java/com/scalar/db/transaction/consensuscommit/Coordinator.java index 3c7867d1c8..718e5ff360 100644 --- a/core/src/main/java/com/scalar/db/transaction/consensuscommit/Coordinator.java +++ b/core/src/main/java/com/scalar/db/transaction/consensuscommit/Coordinator.java @@ -342,7 +342,7 @@ Put createPutWith(Coordinator.State state) { .condition(ConditionBuilder.putIfNotExists()); if (!childIds.isEmpty()) { - builder.textValue(Attribute.CHILD_IDS, childIds); + builder = builder.textValue(Attribute.CHILD_IDS, childIds); } return builder.build(); } diff --git a/core/src/main/java/com/scalar/db/transaction/consensuscommit/Snapshot.java b/core/src/main/java/com/scalar/db/transaction/consensuscommit/Snapshot.java index 26429391bf..7b2658c891 100644 --- a/core/src/main/java/com/scalar/db/transaction/consensuscommit/Snapshot.java +++ b/core/src/main/java/com/scalar/db/transaction/consensuscommit/Snapshot.java @@ -8,7 +8,6 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ComparisonChain; import com.google.common.collect.Iterators; -import com.google.common.collect.Streams; import com.scalar.db.api.ConditionSetBuilder; import com.scalar.db.api.Delete; import com.scalar.db.api.DistributedStorage; @@ -165,14 +164,16 @@ public void putIntoWriteSet(Key key, Put put) { // merge the previous put in the write set and the new put Put originalPut = writeSet.get(key); PutBuilder.BuildableFromExisting putBuilder = Put.newBuilder(originalPut); - put.getColumns().values().forEach(putBuilder::value); + for (Column value : put.getColumns().values()) { + putBuilder = putBuilder.value(value); + } // If the implicit pre-read is enabled for the new put, it should also be enabled for the // merged put. However, if the previous put is in insert mode, this doesn’t apply. This is // because, in insert mode, the read set is not used during the preparation phase. Therefore, // we only need to enable the implicit pre-read if the previous put is not in insert mode if (isImplicitPreReadEnabled(put) && !isInsertModeEnabled(originalPut)) { - putBuilder.enableImplicitPreRead(); + putBuilder = putBuilder.enableImplicitPreRead(); } writeSet.put(key, putBuilder.build()); @@ -598,10 +599,12 @@ private void validateScanResults( ScanBuilder.BuildableScanOrScanAllFromExisting builder = Scan.newBuilder(scan).clearProjections().projection(Attribute.ID); TableMetadata tableMetadata = getTableMetadata(scan); - Streams.concat( - tableMetadata.getPartitionKeyNames().stream(), - tableMetadata.getClusteringKeyNames().stream()) - .forEach(builder::projection); + for (String partitionKeyName : tableMetadata.getPartitionKeyNames()) { + builder = builder.projection(partitionKeyName); + } + for (String clusteringKeyName : tableMetadata.getClusteringKeyNames()) { + builder = builder.projection(clusteringKeyName); + } scan = builder.build(); if (scan.getLimit() == 0) { diff --git a/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java b/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java index 542b227394..70d5aa1303 100644 --- a/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java +++ b/core/src/main/java/com/scalar/db/util/ScalarDbUtils.java @@ -74,10 +74,10 @@ public static Get copyAndSetTargetToIfNot( Get get, Optional namespace, Optional tableName) { GetBuilder.BuildableGetOrGetWithIndexFromExisting builder = Get.newBuilder(get); // copy if (!get.forNamespace().isPresent() && namespace.isPresent()) { - builder.namespace(namespace.get()); + builder = builder.namespace(namespace.get()); } if (!get.forTable().isPresent() && tableName.isPresent()) { - builder.table(tableName.get()); + builder = builder.table(tableName.get()); } Get ret = builder.build(); checkIfTargetIsSet(ret); @@ -88,10 +88,10 @@ public static Scan copyAndSetTargetToIfNot( Scan scan, Optional namespace, Optional tableName) { ScanBuilder.BuildableScanOrScanAllFromExisting builder = Scan.newBuilder(scan); // copy if (!scan.forNamespace().isPresent() && namespace.isPresent()) { - builder.namespace(namespace.get()); + builder = builder.namespace(namespace.get()); } if (!scan.forTable().isPresent() && tableName.isPresent()) { - builder.table(tableName.get()); + builder = builder.table(tableName.get()); } Scan ret = builder.build(); checkIfTargetIsSet(ret); @@ -118,10 +118,10 @@ public static Put copyAndSetTargetToIfNot( Put put, Optional namespace, Optional tableName) { PutBuilder.BuildableFromExisting builder = Put.newBuilder(put); // copy if (!put.forNamespace().isPresent() && namespace.isPresent()) { - builder.namespace(namespace.get()); + builder = builder.namespace(namespace.get()); } if (!put.forTable().isPresent() && tableName.isPresent()) { - builder.table(tableName.get()); + builder = builder.table(tableName.get()); } Put ret = builder.build(); checkIfTargetIsSet(ret); @@ -132,10 +132,10 @@ public static Delete copyAndSetTargetToIfNot( Delete delete, Optional namespace, Optional tableName) { DeleteBuilder.BuildableFromExisting builder = Delete.newBuilder(delete); // copy if (!delete.forNamespace().isPresent() && namespace.isPresent()) { - builder.namespace(namespace.get()); + builder = builder.namespace(namespace.get()); } if (!delete.forTable().isPresent() && tableName.isPresent()) { - builder.table(tableName.get()); + builder = builder.table(tableName.get()); } Delete ret = builder.build(); checkIfTargetIsSet(ret); @@ -146,10 +146,10 @@ public static Insert copyAndSetTargetToIfNot( Insert insert, Optional namespace, Optional tableName) { InsertBuilder.BuildableFromExisting builder = Insert.newBuilder(insert); // copy if (!insert.forNamespace().isPresent() && namespace.isPresent()) { - builder.namespace(namespace.get()); + builder = builder.namespace(namespace.get()); } if (!insert.forTable().isPresent() && tableName.isPresent()) { - builder.table(tableName.get()); + builder = builder.table(tableName.get()); } Insert ret = builder.build(); checkIfTargetIsSet(ret); @@ -160,10 +160,10 @@ public static Upsert copyAndSetTargetToIfNot( Upsert upsert, Optional namespace, Optional tableName) { UpsertBuilder.BuildableFromExisting builder = Upsert.newBuilder(upsert); // copy if (!upsert.forNamespace().isPresent() && namespace.isPresent()) { - builder.namespace(namespace.get()); + builder = builder.namespace(namespace.get()); } if (!upsert.forTable().isPresent() && tableName.isPresent()) { - builder.table(tableName.get()); + builder = builder.table(tableName.get()); } Upsert ret = builder.build(); checkIfTargetIsSet(ret); @@ -174,10 +174,10 @@ public static Update copyAndSetTargetToIfNot( Update update, Optional namespace, Optional tableName) { UpdateBuilder.BuildableFromExisting builder = Update.newBuilder(update); // copy if (!update.forNamespace().isPresent() && namespace.isPresent()) { - builder.namespace(namespace.get()); + builder = builder.namespace(namespace.get()); } if (!update.forTable().isPresent() && tableName.isPresent()) { - builder.table(tableName.get()); + builder = builder.table(tableName.get()); } Update ret = builder.build(); checkIfTargetIsSet(ret); @@ -316,9 +316,11 @@ public static Get copyAndPrepareForDynamicFiltering(Get get) { List projections = get.getProjections(); if (!projections.isEmpty()) { // Add columns in conditions into projections to use them in dynamic filtering - ScalarDbUtils.getColumnNamesUsedIn(get.getConjunctions()).stream() - .filter(columnName -> !projections.contains(columnName)) - .forEach(builder::projection); + for (String columnName : getColumnNamesUsedIn(get.getConjunctions())) { + if (!projections.contains(columnName)) { + builder = builder.projection(columnName); + } + } } return builder.build(); } @@ -329,14 +331,16 @@ public static Scan copyAndPrepareForDynamicFiltering(Scan scan) { List projections = scan.getProjections(); if (!projections.isEmpty()) { // Add columns in conditions into projections to use them in dynamic filtering - ScalarDbUtils.getColumnNamesUsedIn(scan.getConjunctions()).stream() - .filter(columnName -> !projections.contains(columnName)) - .forEach(builder::projection); + for (String columnName : getColumnNamesUsedIn(scan.getConjunctions())) { + if (!projections.contains(columnName)) { + builder = builder.projection(columnName); + } + } } return builder.build(); } - public static Set getColumnNamesUsedIn(Set conjunctions) { + private static Set getColumnNamesUsedIn(Set conjunctions) { Set columns = new HashSet<>(); conjunctions.forEach( conjunction ->