diff --git a/core/src/integration-test/java/com/scalar/db/storage/IntegrationTestBase.java b/core/src/integration-test/java/com/scalar/db/storage/IntegrationTestBase.java index 116ed7f157..0c3c36d16c 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/IntegrationTestBase.java +++ b/core/src/integration-test/java/com/scalar/db/storage/IntegrationTestBase.java @@ -56,8 +56,8 @@ protected void setUp(DistributedStorage storage) { public void operation_NoTargetGiven_ShouldThrowIllegalArgumentException() { // Arrange storage.with(null, TABLE); - Key partitionKey = new Key(new IntValue(COL_NAME1, 0)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, 0)); + Key partitionKey = new Key(COL_NAME1, 0); + Key clusteringKey = new Key(COL_NAME4, 0); Get get = new Get(partitionKey, clusteringKey); // Act Assert @@ -68,8 +68,8 @@ public void operation_NoTargetGiven_ShouldThrowIllegalArgumentException() { public void operation_WrongNamespaceGiven_ShouldThrowIllegalArgumentException() { // Arrange storage.with("wrong_" + NAMESPACE, TABLE); // a wrong namespace - Key partitionKey = new Key(new IntValue(COL_NAME1, 0)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, 0)); + Key partitionKey = new Key(COL_NAME1, 0); + Key clusteringKey = new Key(COL_NAME4, 0); Get get = new Get(partitionKey, clusteringKey); // Act Assert @@ -80,8 +80,8 @@ public void operation_WrongNamespaceGiven_ShouldThrowIllegalArgumentException() public void operation_WrongTableGiven_ShouldThrowIllegalArgumentException() { // Arrange storage.with(NAMESPACE, "wrong_" + TABLE); // a wrong table - Key partitionKey = new Key(new IntValue(COL_NAME1, 0)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, 0)); + Key partitionKey = new Key(COL_NAME1, 0); + Key clusteringKey = new Key(COL_NAME4, 0); Get get = new Get(partitionKey, clusteringKey); // Act Assert @@ -113,7 +113,7 @@ public void get_GetWithoutPartitionKeyGiven_ShouldThrowInvalidUsageException() { int pKey = 0; // Act Assert - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); + Key partitionKey = new Key(COL_NAME1, pKey); Get get = new Get(partitionKey); assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class); } @@ -151,7 +151,7 @@ public void scan_ScanWithProjectionsGiven_ShouldRetrieveSpecifiedValues() throws // Act Scan scan = - new Scan(new Key(new IntValue(COL_NAME1, pKey))) + new Scan(new Key(COL_NAME1, pKey)) .withProjection(COL_NAME1) .withProjection(COL_NAME2) .withProjection(COL_NAME3); @@ -177,7 +177,7 @@ public void scan_ScanWithPartitionKeyGivenAndResultsIteratedWithOne_ShouldReturn int pKey = 0; // Act - Scan scan = new Scan(new Key(new IntValue(COL_NAME1, pKey))); + Scan scan = new Scan(new Key(COL_NAME1, pKey)); Scanner scanner = storage.scan(scan); // Assert @@ -211,7 +211,7 @@ public void scan_ScanWithPartitionGivenThreeTimes_ShouldRetrieveResultsProperlyE int pKey = 0; // Act - Scan scan = new Scan(new Key(new IntValue(COL_NAME1, pKey))); + Scan scan = new Scan(new Key(COL_NAME1, pKey)); double t1 = System.currentTimeMillis(); List actual = scanAll(scan); double t2 = System.currentTimeMillis(); @@ -241,9 +241,9 @@ public void scan_ScanWithStartInclusiveRangeGiven_ShouldRetrieveResultsOfGivenRa // Act Scan scan = - new Scan(new Key(new IntValue(COL_NAME1, pKey))) - .withStart(new Key(new IntValue(COL_NAME4, 0)), true) - .withEnd(new Key(new IntValue(COL_NAME4, 2)), false); + new Scan(new Key(COL_NAME1, pKey)) + .withStart(new Key(COL_NAME4, 0), true) + .withEnd(new Key(COL_NAME4, 2), false); List actual = scanAll(scan); // verify @@ -259,9 +259,9 @@ public void scan_ScanWithEndInclusiveRangeGiven_ShouldRetrieveResultsOfGivenRang // Act Scan scan = - new Scan(new Key(new IntValue(COL_NAME1, pKey))) - .withStart(new Key(new IntValue(COL_NAME4, 0)), false) - .withEnd(new Key(new IntValue(COL_NAME4, 2)), true); + new Scan(new Key(COL_NAME1, pKey)) + .withStart(new Key(COL_NAME4, 0), false) + .withEnd(new Key(COL_NAME4, 2), true); List actual = scanAll(scan); // verify @@ -274,7 +274,7 @@ public void scan_ScanWithOrderAscGiven_ShouldReturnAscendingOrderedResults() thr puts = preparePuts(); storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2))); Scan scan = - new Scan(new Key(new IntValue(COL_NAME1, 0))) + new Scan(new Key(COL_NAME1, 0)) .withOrdering(new Scan.Ordering(COL_NAME4, Scan.Ordering.Order.ASC)); // Act @@ -296,7 +296,7 @@ public void scan_ScanWithOrderDescGiven_ShouldReturnDescendingOrderedResults() t puts = preparePuts(); storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2))); Scan scan = - new Scan(new Key(new IntValue(COL_NAME1, 0))) + new Scan(new Key(COL_NAME1, 0)) .withOrdering(new Scan.Ordering(COL_NAME4, Scan.Ordering.Order.DESC)); // Act @@ -319,7 +319,7 @@ public void scan_ScanWithLimitGiven_ShouldReturnGivenNumberOfResults() throws Ex storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2))); Scan scan = - new Scan(new Key(new IntValue(COL_NAME1, 0))) + new Scan(new Key(COL_NAME1, 0)) .withOrdering(new Scan.Ordering(COL_NAME4, Scan.Ordering.Order.DESC)) .withLimit(1); @@ -340,7 +340,7 @@ public void scannerIterator_ScanWithPartitionKeyGiven_ShouldRetrieveCorrectResul int pKey = 0; // Act - Scan scan = new Scan(new Key(new IntValue(COL_NAME1, pKey))); + Scan scan = new Scan(new Key(COL_NAME1, pKey)); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); scanner.forEach(actual::add); @@ -357,7 +357,7 @@ public void scannerIterator_OneAndIteratorCalled_ShouldRetrieveCorrectResults() int pKey = 0; // Act - Scan scan = new Scan(new Key(new IntValue(COL_NAME1, pKey))); + Scan scan = new Scan(new Key(COL_NAME1, pKey)); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); Optional result = scanner.one(); @@ -379,7 +379,7 @@ public void scannerIterator_AllAndIteratorCalled_ShouldRetrieveCorrectResults() int pKey = 0; // Act - Scan scan = new Scan(new Key(new IntValue(COL_NAME1, pKey))); + Scan scan = new Scan(new Key(COL_NAME1, pKey)); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); List all = scanner.all(); @@ -399,7 +399,7 @@ public void scannerIterator_IteratorCalledMultipleTimes_ShouldRetrieveCorrectRes int pKey = 0; // Act - Scan scan = new Scan(new Key(new IntValue(COL_NAME1, pKey))); + Scan scan = new Scan(new Key(COL_NAME1, pKey)); List actual = new ArrayList<>(); Scanner scanner = storage.scan(scan); actual.add(scanner.iterator().next()); @@ -417,8 +417,8 @@ public void put_SinglePutGiven_ShouldStoreProperly() throws ExecutionException { int pKey = 0; int cKey = 0; puts = preparePuts(); - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, cKey)); + Key partitionKey = new Key(COL_NAME1, pKey); + Key clusteringKey = new Key(COL_NAME4, cKey); Get get = new Get(partitionKey, clusteringKey); // Act @@ -446,13 +446,13 @@ public void put_SinglePutWithIfNotExistsGiven_ShouldStoreProperly() throws Execu int cKey = 0; puts = preparePuts(); puts.get(0).withCondition(new PutIfNotExists()); - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, cKey)); + Key partitionKey = new Key(COL_NAME1, pKey); + Key clusteringKey = new Key(COL_NAME4, cKey); Get get = new Get(partitionKey, clusteringKey); // Act storage.put(puts.get(0)); - puts.get(0).withValue(new IntValue(COL_NAME3, Integer.MAX_VALUE)); + puts.get(0).withValue(COL_NAME3, Integer.MAX_VALUE); assertThatThrownBy(() -> storage.put(puts.get(0))).isInstanceOf(NoMutationException.class); // Assert @@ -476,7 +476,7 @@ public void put_MultiplePutGiven_ShouldStoreProperly() throws Exception { int pKey = 0; int cKey = 0; puts = preparePuts(); - Scan scan = new Scan(new Key(new IntValue(COL_NAME1, pKey))); + Scan scan = new Scan(new Key(COL_NAME1, pKey)); // Act assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) @@ -497,7 +497,7 @@ public void put_MultiplePutWithIfNotExistsGiven_ShouldStoreProperly() throws Exc puts.get(0).withCondition(new PutIfNotExists()); puts.get(1).withCondition(new PutIfNotExists()); puts.get(2).withCondition(new PutIfNotExists()); - Scan scan = new Scan(new Key(new IntValue(COL_NAME1, pKey))); + Scan scan = new Scan(new Key(COL_NAME1, pKey)); // Act assertThatCode(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) @@ -512,8 +512,8 @@ public void put_MultiplePutWithIfNotExistsGiven_ShouldStoreProperly() throws Exc @Test public void put_PutWithoutValuesGiven_ShouldStoreProperly() throws Exception { // Arrange - Key partitionKey = new Key(new IntValue(COL_NAME1, 0)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, 0)); + Key partitionKey = new Key(COL_NAME1, 0); + Key clusteringKey = new Key(COL_NAME4, 0); // Act assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))) @@ -527,8 +527,8 @@ public void put_PutWithoutValuesGiven_ShouldStoreProperly() throws Exception { @Test public void put_PutWithoutValuesGivenTwice_ShouldStoreProperly() throws Exception { // Arrange - Key partitionKey = new Key(new IntValue(COL_NAME1, 0)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, 0)); + Key partitionKey = new Key(COL_NAME1, 0); + Key clusteringKey = new Key(COL_NAME4, 0); // Act assertThatCode(() -> storage.put(new Put(partitionKey, clusteringKey))) @@ -552,7 +552,7 @@ public void put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutati puts.get(0).withCondition(new PutIfNotExists()); puts.get(1).withCondition(new PutIfNotExists()); puts.get(2).withCondition(new PutIfNotExists()); - Scan scan = new Scan(new Key(new IntValue(COL_NAME1, pKey))); + Scan scan = new Scan(new Key(COL_NAME1, pKey)); // Act assertThatThrownBy(() -> storage.put(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) @@ -581,11 +581,11 @@ public void put_MultiplePutWithIfNotExistsGivenWhenOneExists_ShouldThrowNoMutati // Assert List results; - results = scanAll(new Scan(new Key(new IntValue(COL_NAME1, 0)))); + results = scanAll(new Scan(new Key(COL_NAME1, 0))); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(new IntValue(COL_NAME1, 3)))); + results = scanAll(new Scan(new Key(COL_NAME1, 3))); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(new IntValue(COL_NAME1, 6)))); + results = scanAll(new Scan(new Key(COL_NAME1, 6))); assertThat(results.size()).isEqualTo(0); } @@ -601,11 +601,11 @@ public void put_MultiplePutWithDifferentPartitionsGiven_ShouldThrowIllegalArgume // Assert List results; - results = scanAll(new Scan(new Key(new IntValue(COL_NAME1, 0)))); + results = scanAll(new Scan(new Key(COL_NAME1, 0))); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(new IntValue(COL_NAME1, 3)))); + results = scanAll(new Scan(new Key(COL_NAME1, 3))); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(new IntValue(COL_NAME1, 6)))); + results = scanAll(new Scan(new Key(COL_NAME1, 6))); assertThat(results.size()).isEqualTo(0); } @@ -626,7 +626,7 @@ public void put_MultiplePutWithDifferentConditionsGiven_ShouldStoreProperly() th .doesNotThrowAnyException(); // Assert - List results = scanAll(new Scan(new Key(new IntValue(COL_NAME1, 0)))); + List results = scanAll(new Scan(new Key(COL_NAME1, 0))); assertScanResultWithoutOrdering(results, 0, COL_NAME4, Arrays.asList(0, 1)); } @@ -660,7 +660,7 @@ public void put_PutWithIfExistsGivenWhenSuchRecordExists_ShouldUpdateRecord() // Act Assert storage.put(puts.get(0)); puts.get(0).withCondition(new PutIfExists()); - puts.get(0).withValue(new IntValue(COL_NAME3, Integer.MAX_VALUE)); + puts.get(0).withValue(COL_NAME3, Integer.MAX_VALUE); assertThatCode(() -> storage.put(puts.get(0))).doesNotThrowAnyException(); // Assert @@ -689,7 +689,7 @@ public void put_PutWithIfGivenWhenSuchRecordExists_ShouldUpdateRecord() new PutIf( new ConditionalExpression( COL_NAME3, new IntValue(pKey + cKey), ConditionalExpression.Operator.EQ))); - puts.get(0).withValue(new IntValue(COL_NAME3, Integer.MAX_VALUE)); + puts.get(0).withValue(COL_NAME3, Integer.MAX_VALUE); assertThatCode(() -> storage.put(puts.get(0))).doesNotThrowAnyException(); // Assert @@ -718,7 +718,7 @@ public void put_PutWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationException() new PutIf( new ConditionalExpression( COL_NAME3, new IntValue(pKey + cKey + 1), ConditionalExpression.Operator.EQ))); - puts.get(0).withValue(new IntValue(COL_NAME3, Integer.MAX_VALUE)); + puts.get(0).withValue(COL_NAME3, Integer.MAX_VALUE); assertThatThrownBy(() -> storage.put(puts.get(0))).isInstanceOf(NoMutationException.class); // Assert @@ -738,7 +738,7 @@ public void delete_DeleteWithPartitionKeyAndClusteringKeyGiven_ShouldDeleteSingl populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); + Key partitionKey = new Key(COL_NAME1, pKey); // Act Delete delete = prepareDelete(pKey, cKey); @@ -768,8 +768,8 @@ public void delete_DeleteWithIfExistsGivenWhenSuchRecordExists_ShouldDeletePrope populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, cKey)); + Key partitionKey = new Key(COL_NAME1, pKey); + Key clusteringKey = new Key(COL_NAME4, cKey); // Act Delete delete = prepareDelete(pKey, cKey); @@ -788,8 +788,8 @@ public void delete_DeleteWithIfGivenWhenNoSuchRecord_ShouldThrowNoMutationExcept populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, cKey)); + Key partitionKey = new Key(COL_NAME1, pKey); + Key clusteringKey = new Key(COL_NAME4, cKey); // Act Delete delete = prepareDelete(pKey, cKey); @@ -813,8 +813,8 @@ public void delete_DeleteWithIfGivenWhenSuchRecordExists_ShouldDeleteProperly() populateRecords(); int pKey = 0; int cKey = 0; - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, cKey)); + Key partitionKey = new Key(COL_NAME1, pKey); + Key clusteringKey = new Key(COL_NAME4, cKey); // Act Delete delete = prepareDelete(pKey, cKey); @@ -852,7 +852,7 @@ public void delete_MultipleDeleteWithDifferentConditionsGiven_ShouldDeleteProper .doesNotThrowAnyException(); // Assert - List results = scanAll(new Scan(new Key(new IntValue(COL_NAME1, 0)))); + List results = scanAll(new Scan(new Key(COL_NAME1, 0))); assertThat(results.size()).isEqualTo(0); } @@ -862,7 +862,7 @@ public void mutate_MultiplePutGiven_ShouldStoreProperly() throws Exception { int pKey = 0; int cKey = 0; puts = preparePuts(); - Scan scan = new Scan(new Key(new IntValue(COL_NAME1, pKey))); + Scan scan = new Scan(new Key(COL_NAME1, pKey)); // Act assertThatCode(() -> storage.mutate(Arrays.asList(puts.get(0), puts.get(1), puts.get(2)))) @@ -886,11 +886,11 @@ public void mutate_MultiplePutWithDifferentPartitionsGiven_ShouldThrowIllegalArg // Assert List results; - results = scanAll(new Scan(new Key(new IntValue(COL_NAME1, 0)))); + results = scanAll(new Scan(new Key(COL_NAME1, 0))); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(new IntValue(COL_NAME1, 3)))); + results = scanAll(new Scan(new Key(COL_NAME1, 3))); assertThat(results.size()).isEqualTo(0); - results = scanAll(new Scan(new Key(new IntValue(COL_NAME1, 6)))); + results = scanAll(new Scan(new Key(COL_NAME1, 6))); assertThat(results.size()).isEqualTo(0); } @@ -899,14 +899,14 @@ public void mutate_PutAndDeleteGiven_ShouldUpdateAndDeleteRecordsProperly() thro // Arrange populateRecords(); puts = preparePuts(); - puts.get(1).withValue(new IntValue(COL_NAME3, Integer.MAX_VALUE)); - puts.get(2).withValue(new IntValue(COL_NAME3, Integer.MIN_VALUE)); + puts.get(1).withValue(COL_NAME3, Integer.MAX_VALUE); + puts.get(2).withValue(COL_NAME3, Integer.MIN_VALUE); int pKey = 0; int cKey = 0; Delete delete = prepareDelete(pKey, cKey); - Scan scan = new Scan(new Key(new IntValue(COL_NAME1, pKey))); + Scan scan = new Scan(new Key(COL_NAME1, pKey)); // Act assertThatCode(() -> storage.mutate(Arrays.asList(delete, puts.get(1), puts.get(2)))) @@ -924,8 +924,8 @@ public void mutate_SinglePutGiven_ShouldStoreProperly() throws Exception { int pKey = 0; int cKey = 0; puts = preparePuts(); - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, cKey)); + Key partitionKey = new Key(COL_NAME1, pKey); + Key clusteringKey = new Key(COL_NAME4, cKey); Get get = new Get(partitionKey, clusteringKey); // Act @@ -956,8 +956,8 @@ public void mutate_SinglePutGiven_ShouldStoreProperly() throws Exception { int cKey = 0; // Act - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, cKey)); + Key partitionKey = new Key(COL_NAME1, pKey); + Key clusteringKey = new Key(COL_NAME4, cKey); Delete delete = new Delete(partitionKey, clusteringKey); assertThatCode(() -> storage.mutate(Collections.singletonList(delete))) .doesNotThrowAnyException(); @@ -978,7 +978,7 @@ public void mutate_EmptyListGiven_ShouldThrowIllegalArgumentException() { public void put_PutWithoutClusteringKeyGiven_ShouldThrowIllegalArgumentException() { // Arrange int pKey = 0; - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); + Key partitionKey = new Key(COL_NAME1, pKey); Put put = new Put(partitionKey); // Act Assert @@ -990,8 +990,8 @@ public void put_IncorrectPutGiven_ShouldThrowIllegalArgumentException() { // Arrange int pKey = 0; int cKey = 0; - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); - Put put = new Put(partitionKey).withValue(new IntValue(COL_NAME4, cKey)); + Key partitionKey = new Key(COL_NAME1, pKey); + Put put = new Put(partitionKey).withValue(COL_NAME4, cKey); // Act Assert assertThatCode(() -> storage.put(put)).isInstanceOf(IllegalArgumentException.class); @@ -1002,7 +1002,7 @@ public void get_GetGivenForIndexedColumn_ShouldGet() throws ExecutionException { // Arrange storage.put(preparePuts().get(0)); // (0,0) int c3 = 0; - Get get = new Get(new Key(new IntValue(COL_NAME3, c3))); + Get get = new Get(new Key(COL_NAME3, c3)); // Act Optional actual = storage.get(get); @@ -1019,7 +1019,7 @@ public void get_GetGivenForIndexedColumn_ShouldGet() throws ExecutionException { // Arrange populateRecords(); int c3 = 3; - Get get = new Get(new Key(new IntValue(COL_NAME3, c3))); + Get get = new Get(new Key(COL_NAME3, c3)); // Act Assert assertThatThrownBy(() -> storage.get(get)).isInstanceOf(IllegalArgumentException.class); @@ -1030,7 +1030,7 @@ public void scan_ScanGivenForIndexedColumn_ShouldScan() throws Exception { // Arrange populateRecords(); int c3 = 3; - Scan scan = new Scan(new Key(new IntValue(COL_NAME3, c3))); + Scan scan = new Scan(new Key(COL_NAME3, c3)); // Act List actual = scanAll(scan); @@ -1041,8 +1041,8 @@ public void scan_ScanGivenForIndexedColumn_ShouldScan() throws Exception { new ArrayList<>( Arrays.asList(Arrays.asList(1, 2), Arrays.asList(2, 1), Arrays.asList(3, 0))); for (Result result : actual) { - int col1Val = ((IntValue) result.getValue(COL_NAME1).get()).get(); - int col4Val = ((IntValue) result.getValue(COL_NAME4).get()).get(); + int col1Val = result.getValue(COL_NAME1).get().getAsInt(); + int col4Val = result.getValue(COL_NAME4).get().getAsInt(); List col1AndCol4 = Arrays.asList(col1Val, col4Val); assertThat(expectedValues).contains(col1AndCol4); expectedValues.remove(col1AndCol4); @@ -1056,7 +1056,7 @@ public void scan_ScanGivenForNonIndexedColumn_ShouldThrowIllegalArgumentExceptio // Arrange populateRecords(); String c2 = "test"; - Scan scan = new Scan(new Key(new TextValue(COL_NAME2, c2))); + Scan scan = new Scan(new Key(COL_NAME2, c2)); // Act Assert assertThatThrownBy(() -> scanAll(scan)).isInstanceOf(IllegalArgumentException.class); @@ -1068,8 +1068,8 @@ private void populateRecords() { } private Get prepareGet(int pKey, int cKey) { - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, cKey)); + Key partitionKey = new Key(COL_NAME1, pKey); + Key clusteringKey = new Key(COL_NAME4, cKey); return new Get(partitionKey, clusteringKey); } @@ -1082,13 +1082,13 @@ private List preparePuts() { IntStream.range(0, 3) .forEach( j -> { - Key partitionKey = new Key(new IntValue(COL_NAME1, i)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, j)); + Key partitionKey = new Key(COL_NAME1, i); + Key clusteringKey = new Key(COL_NAME4, j); Put put = new Put(partitionKey, clusteringKey) - .withValue(new TextValue(COL_NAME2, Integer.toString(i + j))) - .withValue(new IntValue(COL_NAME3, i + j)) - .withValue(new BooleanValue(COL_NAME5, j % 2 == 0)); + .withValue(COL_NAME2, Integer.toString(i + j)) + .withValue(COL_NAME3, i + j) + .withValue(COL_NAME5, j % 2 == 0); puts.add(put); })); @@ -1096,8 +1096,8 @@ private List preparePuts() { } private Delete prepareDelete(int pKey, int cKey) { - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, cKey)); + Key partitionKey = new Key(COL_NAME1, pKey); + Key clusteringKey = new Key(COL_NAME4, cKey); return new Delete(partitionKey, clusteringKey); } @@ -1110,8 +1110,8 @@ private List prepareDeletes() { IntStream.range(0, 3) .forEach( j -> { - Key partitionKey = new Key(new IntValue(COL_NAME1, i)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, j)); + Key partitionKey = new Key(COL_NAME1, i); + Key clusteringKey = new Key(COL_NAME4, j); Delete delete = new Delete(partitionKey, clusteringKey); deletes.add(delete); })); @@ -1137,7 +1137,7 @@ protected void assertScanResultWithoutOrdering( assertThat(result.getValue(COL_NAME1)) .isEqualTo(Optional.of(new IntValue(COL_NAME1, expectedPartitionKeyValue))); - int actualClusteringKeyValue = ((IntValue) result.getValue(checkedColumn).get()).get(); + int actualClusteringKeyValue = result.getValue(checkedColumn).get().getAsInt(); assertThat(expectedValuesSet).contains(actualClusteringKeyValue); expectedValuesSet.remove(actualClusteringKeyValue); } diff --git a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoWithReservedKeywordIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoWithReservedKeywordIntegrationTest.java index 4830f42f64..ea3586e0a4 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoWithReservedKeywordIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/dynamo/DynamoWithReservedKeywordIntegrationTest.java @@ -12,9 +12,7 @@ import com.scalar.db.api.Scanner; import com.scalar.db.config.DatabaseConfig; import com.scalar.db.exception.storage.ExecutionException; -import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.io.IOException; import java.net.URI; import java.util.ArrayList; @@ -99,8 +97,8 @@ public void get_GetWithReservedKeywordProjection_ShouldReturnWhatsPut() int pKey = 0; int cKey = 0; String status = "s0"; - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, cKey)); + Key partitionKey = new Key(COL_NAME1, pKey); + Key clusteringKey = new Key(COL_NAME2, cKey); dynamo.put(new Put(partitionKey, clusteringKey).withValue(COL_NAME4, status)); // Act @@ -121,15 +119,15 @@ public void get_getWithSecondaryIndexWithReservedKeywordProjection_ShouldReturnW int cKey = 0; String status = "s0"; String col3Value = "value3"; - Key partitionKey = new Key(new IntValue(COL_NAME1, pKey)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, cKey)); + Key partitionKey = new Key(COL_NAME1, pKey); + Key clusteringKey = new Key(COL_NAME2, cKey); dynamo.put( new Put(partitionKey, clusteringKey) .withValue(COL_NAME3, col3Value) .withValue(COL_NAME4, status)); // Act - Get get = new Get(new Key(new TextValue(COL_NAME3, col3Value))).withProjection(COL_NAME4); + Get get = new Get(new Key(COL_NAME3, col3Value)).withProjection(COL_NAME4); Optional result = dynamo.get(get); // Assert @@ -142,9 +140,9 @@ public void get_getWithSecondaryIndexWithReservedKeywordProjection_ShouldReturnW public void scan_ScanWithReservedKeywordProjection_ShouldReturnWhatsPut() throws ExecutionException, IOException { // Arrange - Key partitionKey = new Key(new IntValue(COL_NAME1, 0)); + Key partitionKey = new Key(COL_NAME1, 0); for (int cKey = 0; cKey < 3; cKey++) { - Key clusteringKey = new Key(new IntValue(COL_NAME2, cKey)); + Key clusteringKey = new Key(COL_NAME2, cKey); String status = "s" + cKey; dynamo.put(new Put(partitionKey, clusteringKey).withValue(COL_NAME4, status)); } @@ -170,10 +168,10 @@ public void scan_ScanWithReservedKeywordProjection_ShouldReturnWhatsPut() public void scan_ScanWithSecondaryIndexWithReservedKeywordProjection_ShouldReturnWhatsPut() throws ExecutionException, IOException { // Arrange - Key partitionKey = new Key(new IntValue(COL_NAME1, 0)); + Key partitionKey = new Key(COL_NAME1, 0); String col3Value = "value3"; for (int cKey = 0; cKey < 3; cKey++) { - Key clusteringKey = new Key(new IntValue(COL_NAME2, cKey)); + Key clusteringKey = new Key(COL_NAME2, cKey); String status = "s" + cKey; dynamo.put( new Put(partitionKey, clusteringKey) @@ -182,7 +180,7 @@ public void scan_ScanWithSecondaryIndexWithReservedKeywordProjection_ShouldRetur } // Act - Scan scan = new Scan(new Key(new TextValue(COL_NAME3, col3Value))).withProjection(COL_NAME4); + Scan scan = new Scan(new Key(COL_NAME3, col3Value)).withProjection(COL_NAME4); List results; try (Scanner scanner = dynamo.scan(scan)) { results = scanner.all(); 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 1aceeca409..2fb7e3da4b 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 @@ -12,11 +12,8 @@ import com.scalar.db.api.TableMetadata; 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.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import com.scalar.db.storage.cassandra.Cassandra; import com.scalar.db.storage.jdbc.JdbcDatabase; import com.scalar.db.storage.jdbc.test.TestEnv; @@ -93,13 +90,13 @@ public void whenPutDataIntoTable1_DataShouldBeWrittenIntoCassandra() throws Exec // Arrange String namespace = NAMESPACE1; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, 4)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME4, 4); Put put = new Put(partitionKey, clusteringKey) - .withValue(new TextValue(COL_NAME2, "val2")) - .withValue(new IntValue(COL_NAME3, 3)) - .withValue(new BooleanValue(COL_NAME5, true)) + .withValue(COL_NAME2, "val2") + .withValue(COL_NAME3, 3) + .withValue(COL_NAME5, true) .forNamespace(namespace) .forTable(table); @@ -111,21 +108,19 @@ public void whenPutDataIntoTable1_DataShouldBeWrittenIntoCassandra() throws Exec Optional result = multiStorage.get(get); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((TextValue) result.get().getValue(COL_NAME2).get()).getString().get()) - .isEqualTo("val2"); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(4); - assertThat(((BooleanValue) result.get().getValue(COL_NAME5).get()).get()).isTrue(); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME2).get().getAsString().get()).isEqualTo("val2"); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(4); + assertThat(result.get().getValue(COL_NAME5).get().getAsBoolean()).isTrue(); result = cassandra.get(get); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((TextValue) result.get().getValue(COL_NAME2).get()).getString().get()) - .isEqualTo("val2"); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(4); - assertThat(((BooleanValue) result.get().getValue(COL_NAME5).get()).get()).isTrue(); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME2).get().getAsString().get()).isEqualTo("val2"); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(4); + assertThat(result.get().getValue(COL_NAME5).get().getAsBoolean()).isTrue(); result = mysql.get(get); assertThat(result.isPresent()).isFalse(); @@ -136,13 +131,13 @@ public void whenPutDataIntoTable2_DataShouldBeWrittenIntoMySql() throws Executio // Arrange String namespace = NAMESPACE1; String table = TABLE2; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, 4)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME4, 4); Put put = new Put(partitionKey, clusteringKey) - .withValue(new TextValue(COL_NAME2, "val2")) - .withValue(new IntValue(COL_NAME3, 3)) - .withValue(new BooleanValue(COL_NAME5, true)) + .withValue(COL_NAME2, "val2") + .withValue(COL_NAME3, 3) + .withValue(COL_NAME5, true) .forNamespace(namespace) .forTable(table); @@ -154,24 +149,22 @@ public void whenPutDataIntoTable2_DataShouldBeWrittenIntoMySql() throws Executio Optional result = multiStorage.get(get); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((TextValue) result.get().getValue(COL_NAME2).get()).getString().get()) - .isEqualTo("val2"); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(4); - assertThat(((BooleanValue) result.get().getValue(COL_NAME5).get()).get()).isTrue(); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME2).get().getAsString().get()).isEqualTo("val2"); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(4); + assertThat(result.get().getValue(COL_NAME5).get().getAsBoolean()).isTrue(); result = cassandra.get(get); assertThat(result.isPresent()).isFalse(); result = mysql.get(get); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((TextValue) result.get().getValue(COL_NAME2).get()).getString().get()) - .isEqualTo("val2"); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(4); - assertThat(((BooleanValue) result.get().getValue(COL_NAME5).get()).get()).isTrue(); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME2).get().getAsString().get()).isEqualTo("val2"); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(4); + assertThat(result.get().getValue(COL_NAME5).get().getAsBoolean()).isTrue(); } @Test @@ -180,14 +173,14 @@ public void whenPutDataIntoTable3_DataShouldBeWrittenIntoDefaultStorage() // Arrange String namespace = NAMESPACE1; String table = TABLE3; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, 4)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME4, 4); Put put = new Put(partitionKey, clusteringKey) - .withValue(new TextValue(COL_NAME2, "val2")) - .withValue(new IntValue(COL_NAME3, 3)) - .withValue(new BooleanValue(COL_NAME5, true)) + .withValue(COL_NAME2, "val2") + .withValue(COL_NAME3, 3) + .withValue(COL_NAME5, true) .forNamespace(namespace) .forTable(table); @@ -199,21 +192,19 @@ public void whenPutDataIntoTable3_DataShouldBeWrittenIntoDefaultStorage() Optional result = multiStorage.get(get); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((TextValue) result.get().getValue(COL_NAME2).get()).getString().get()) - .isEqualTo("val2"); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(4); - assertThat(((BooleanValue) result.get().getValue(COL_NAME5).get()).get()).isTrue(); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME2).get().getAsString().get()).isEqualTo("val2"); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(4); + assertThat(result.get().getValue(COL_NAME5).get().getAsBoolean()).isTrue(); result = cassandra.get(get); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((TextValue) result.get().getValue(COL_NAME2).get()).getString().get()) - .isEqualTo("val2"); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(4); - assertThat(((BooleanValue) result.get().getValue(COL_NAME5).get()).get()).isTrue(); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME2).get().getAsString().get()).isEqualTo("val2"); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(4); + assertThat(result.get().getValue(COL_NAME5).get().getAsBoolean()).isTrue(); result = mysql.get(get); assertThat(result.isPresent()).isFalse(); @@ -224,23 +215,23 @@ public void whenScanDataFromTable1_DataShouldBeScannedFromCassandra() throws Exc // Arrange String namespace = NAMESPACE1; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey1 = new Key(new IntValue(COL_NAME4, 0)); - Key clusteringKey2 = new Key(new IntValue(COL_NAME4, 1)); - Key clusteringKey3 = new Key(new IntValue(COL_NAME4, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey1 = new Key(COL_NAME4, 0); + Key clusteringKey2 = new Key(COL_NAME4, 1); + Key clusteringKey3 = new Key(COL_NAME4, 2); cassandra.mutate( Arrays.asList( new Put(partitionKey, clusteringKey1) - .withValue(new IntValue(COL_NAME3, 2)) + .withValue(COL_NAME3, 2) .forNamespace(namespace) .forTable(table), new Put(partitionKey, clusteringKey2) - .withValue(new IntValue(COL_NAME3, 1)) + .withValue(COL_NAME3, 1) .forNamespace(namespace) .forTable(table), new Put(partitionKey, clusteringKey3) - .withValue(new IntValue(COL_NAME3, 0)) + .withValue(COL_NAME3, 0) .forNamespace(namespace) .forTable(table))); @@ -249,15 +240,15 @@ public void whenScanDataFromTable1_DataShouldBeScannedFromCassandra() throws Exc // Assert assertThat(results.size()).isEqualTo(3); - assertThat(((IntValue) results.get(0).getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(0).getValue(COL_NAME3).get()).get()).isEqualTo(2); - assertThat(((IntValue) results.get(0).getValue(COL_NAME4).get()).get()).isEqualTo(0); - assertThat(((IntValue) results.get(1).getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(1).getValue(COL_NAME3).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(1).getValue(COL_NAME4).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(2).getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(2).getValue(COL_NAME3).get()).get()).isEqualTo(0); - assertThat(((IntValue) results.get(2).getValue(COL_NAME4).get()).get()).isEqualTo(2); + assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(results.get(0).getValue(COL_NAME3).get().getAsInt()).isEqualTo(2); + assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(0); + assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(results.get(1).getValue(COL_NAME3).get().getAsInt()).isEqualTo(1); + assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); + assertThat(results.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(results.get(2).getValue(COL_NAME3).get().getAsInt()).isEqualTo(0); + assertThat(results.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); } @Test @@ -265,23 +256,23 @@ public void whenScanDataFromTable2_DataShouldBeScannedFromMySql() throws Excepti // Arrange String namespace = NAMESPACE1; String table = TABLE2; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey1 = new Key(new IntValue(COL_NAME4, 0)); - Key clusteringKey2 = new Key(new IntValue(COL_NAME4, 1)); - Key clusteringKey3 = new Key(new IntValue(COL_NAME4, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey1 = new Key(COL_NAME4, 0); + Key clusteringKey2 = new Key(COL_NAME4, 1); + Key clusteringKey3 = new Key(COL_NAME4, 2); mysql.mutate( Arrays.asList( new Put(partitionKey, clusteringKey1) - .withValue(new IntValue(COL_NAME3, 2)) + .withValue(COL_NAME3, 2) .forNamespace(namespace) .forTable(table), new Put(partitionKey, clusteringKey2) - .withValue(new IntValue(COL_NAME3, 1)) + .withValue(COL_NAME3, 1) .forNamespace(namespace) .forTable(table), new Put(partitionKey, clusteringKey3) - .withValue(new IntValue(COL_NAME3, 0)) + .withValue(COL_NAME3, 0) .forNamespace(namespace) .forTable(table))); @@ -290,15 +281,15 @@ public void whenScanDataFromTable2_DataShouldBeScannedFromMySql() throws Excepti // Assert assertThat(results.size()).isEqualTo(3); - assertThat(((IntValue) results.get(0).getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(0).getValue(COL_NAME3).get()).get()).isEqualTo(2); - assertThat(((IntValue) results.get(0).getValue(COL_NAME4).get()).get()).isEqualTo(0); - assertThat(((IntValue) results.get(1).getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(1).getValue(COL_NAME3).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(1).getValue(COL_NAME4).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(2).getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(2).getValue(COL_NAME3).get()).get()).isEqualTo(0); - assertThat(((IntValue) results.get(2).getValue(COL_NAME4).get()).get()).isEqualTo(2); + assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(results.get(0).getValue(COL_NAME3).get().getAsInt()).isEqualTo(2); + assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(0); + assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(results.get(1).getValue(COL_NAME3).get().getAsInt()).isEqualTo(1); + assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); + assertThat(results.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(results.get(2).getValue(COL_NAME3).get().getAsInt()).isEqualTo(0); + assertThat(results.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); } @Test @@ -306,23 +297,23 @@ public void whenScanDataFromTable3_DataShouldBeScannedFromDefaultStorage() throw // Arrange String namespace = NAMESPACE1; String table = TABLE3; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey1 = new Key(new IntValue(COL_NAME4, 0)); - Key clusteringKey2 = new Key(new IntValue(COL_NAME4, 1)); - Key clusteringKey3 = new Key(new IntValue(COL_NAME4, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey1 = new Key(COL_NAME4, 0); + Key clusteringKey2 = new Key(COL_NAME4, 1); + Key clusteringKey3 = new Key(COL_NAME4, 2); cassandra.mutate( Arrays.asList( new Put(partitionKey, clusteringKey1) - .withValue(new IntValue(COL_NAME3, 2)) + .withValue(COL_NAME3, 2) .forNamespace(namespace) .forTable(table), new Put(partitionKey, clusteringKey2) - .withValue(new IntValue(COL_NAME3, 1)) + .withValue(COL_NAME3, 1) .forNamespace(namespace) .forTable(table), new Put(partitionKey, clusteringKey3) - .withValue(new IntValue(COL_NAME3, 0)) + .withValue(COL_NAME3, 0) .forNamespace(namespace) .forTable(table))); @@ -331,15 +322,15 @@ public void whenScanDataFromTable3_DataShouldBeScannedFromDefaultStorage() throw // Assert assertThat(results.size()).isEqualTo(3); - assertThat(((IntValue) results.get(0).getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(0).getValue(COL_NAME3).get()).get()).isEqualTo(2); - assertThat(((IntValue) results.get(0).getValue(COL_NAME4).get()).get()).isEqualTo(0); - assertThat(((IntValue) results.get(1).getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(1).getValue(COL_NAME3).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(1).getValue(COL_NAME4).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(2).getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(2).getValue(COL_NAME3).get()).get()).isEqualTo(0); - assertThat(((IntValue) results.get(2).getValue(COL_NAME4).get()).get()).isEqualTo(2); + assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(results.get(0).getValue(COL_NAME3).get().getAsInt()).isEqualTo(2); + assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(0); + assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(results.get(1).getValue(COL_NAME3).get().getAsInt()).isEqualTo(1); + assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); + assertThat(results.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(results.get(2).getValue(COL_NAME3).get().getAsInt()).isEqualTo(0); + assertThat(results.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); } private List scanAll(Scan scan) throws Exception { @@ -354,11 +345,11 @@ public void whenDeleteDataFromTable1_DataShouldBeDeletedFromCassandra() // Arrange String namespace = NAMESPACE1; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, 4)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME4, 4); Put put = new Put(partitionKey, clusteringKey) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table); @@ -380,9 +371,9 @@ public void whenDeleteDataFromTable1_DataShouldBeDeletedFromCassandra() result = mysql.get(get); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(4); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(4); } @Test @@ -390,11 +381,11 @@ public void whenDeleteDataFromTable2_DataShouldBeDeletedFromMySql() throws Execu // Arrange String namespace = NAMESPACE1; String table = TABLE2; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, 4)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME4, 4); Put put = new Put(partitionKey, clusteringKey) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table); @@ -413,9 +404,9 @@ public void whenDeleteDataFromTable2_DataShouldBeDeletedFromMySql() throws Execu result = cassandra.get(get); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(4); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(4); result = mysql.get(get); assertThat(result.isPresent()).isFalse(); @@ -427,11 +418,11 @@ public void whenDeleteDataFromTable3_DataShouldBeDeletedFromDefaultStorage() // Arrange String namespace = NAMESPACE1; String table = TABLE3; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, 4)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME4, 4); Put put = new Put(partitionKey, clusteringKey) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table); @@ -453,9 +444,9 @@ public void whenDeleteDataFromTable3_DataShouldBeDeletedFromDefaultStorage() result = mysql.get(get); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(4); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(4); } @Test @@ -463,12 +454,12 @@ public void whenMutateDataToTable1_ShouldExecuteForCassandra() throws ExecutionE // Arrange String namespace = NAMESPACE1; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey1 = new Key(new IntValue(COL_NAME4, 1)); - Key clusteringKey2 = new Key(new IntValue(COL_NAME4, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey1 = new Key(COL_NAME4, 1); + Key clusteringKey2 = new Key(COL_NAME4, 2); Put put = new Put(partitionKey, clusteringKey1) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table); @@ -479,7 +470,7 @@ public void whenMutateDataToTable1_ShouldExecuteForCassandra() throws ExecutionE multiStorage.mutate( Arrays.asList( new Put(partitionKey, clusteringKey2) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table), new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); @@ -492,23 +483,23 @@ public void whenMutateDataToTable1_ShouldExecuteForCassandra() throws ExecutionE assertThat(result.isPresent()).isFalse(); result = multiStorage.get(get2); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(2); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); result = cassandra.get(get1); assertThat(result.isPresent()).isFalse(); result = cassandra.get(get2); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(2); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); result = mysql.get(get1); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); result = mysql.get(get2); assertThat(result.isPresent()).isFalse(); } @@ -518,12 +509,12 @@ public void whenMutateDataToTable2_ShouldExecuteForMySql() throws ExecutionExcep // Arrange String namespace = NAMESPACE1; String table = TABLE2; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey1 = new Key(new IntValue(COL_NAME4, 1)); - Key clusteringKey2 = new Key(new IntValue(COL_NAME4, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey1 = new Key(COL_NAME4, 1); + Key clusteringKey2 = new Key(COL_NAME4, 2); Put put = new Put(partitionKey, clusteringKey1) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table); @@ -534,7 +525,7 @@ public void whenMutateDataToTable2_ShouldExecuteForMySql() throws ExecutionExcep multiStorage.mutate( Arrays.asList( new Put(partitionKey, clusteringKey2) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table), new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); @@ -547,15 +538,15 @@ public void whenMutateDataToTable2_ShouldExecuteForMySql() throws ExecutionExcep assertThat(result.isPresent()).isFalse(); result = multiStorage.get(get2); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(2); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); result = cassandra.get(get1); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); result = cassandra.get(get2); assertThat(result.isPresent()).isFalse(); @@ -563,9 +554,9 @@ public void whenMutateDataToTable2_ShouldExecuteForMySql() throws ExecutionExcep assertThat(result.isPresent()).isFalse(); result = mysql.get(get2); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(2); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); } @Test @@ -573,12 +564,12 @@ public void whenMutateDataToTable3_ShouldExecuteForDefaultStorage() throws Execu // Arrange String namespace = NAMESPACE1; String table = TABLE3; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey1 = new Key(new IntValue(COL_NAME4, 1)); - Key clusteringKey2 = new Key(new IntValue(COL_NAME4, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey1 = new Key(COL_NAME4, 1); + Key clusteringKey2 = new Key(COL_NAME4, 2); Put put = new Put(partitionKey, clusteringKey1) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table); @@ -589,7 +580,7 @@ public void whenMutateDataToTable3_ShouldExecuteForDefaultStorage() throws Execu multiStorage.mutate( Arrays.asList( new Put(partitionKey, clusteringKey2) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table), new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); @@ -602,23 +593,23 @@ public void whenMutateDataToTable3_ShouldExecuteForDefaultStorage() throws Execu assertThat(result.isPresent()).isFalse(); result = multiStorage.get(get2); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(2); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); result = cassandra.get(get1); assertThat(result.isPresent()).isFalse(); result = cassandra.get(get2); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(2); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); result = mysql.get(get1); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); result = mysql.get(get2); assertThat(result.isPresent()).isFalse(); } @@ -629,13 +620,13 @@ public void whenPutDataIntoTable1InNamespace2_DataShouldBeWrittenIntoMySql() // Arrange String namespace = NAMESPACE2; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, 4)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME4, 4); Put put = new Put(partitionKey, clusteringKey) - .withValue(new TextValue(COL_NAME2, "val2")) - .withValue(new IntValue(COL_NAME3, 3)) - .withValue(new BooleanValue(COL_NAME5, true)) + .withValue(COL_NAME2, "val2") + .withValue(COL_NAME3, 3) + .withValue(COL_NAME5, true) .forNamespace(namespace) .forTable(table); @@ -647,24 +638,22 @@ public void whenPutDataIntoTable1InNamespace2_DataShouldBeWrittenIntoMySql() Optional result = multiStorage.get(get); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((TextValue) result.get().getValue(COL_NAME2).get()).getString().get()) - .isEqualTo("val2"); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(4); - assertThat(((BooleanValue) result.get().getValue(COL_NAME5).get()).get()).isTrue(); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME2).get().getAsString().get()).isEqualTo("val2"); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(4); + assertThat(result.get().getValue(COL_NAME5).get().getAsBoolean()).isTrue(); result = cassandra.get(get); assertThat(result.isPresent()).isFalse(); result = mysql.get(get); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((TextValue) result.get().getValue(COL_NAME2).get()).getString().get()) - .isEqualTo("val2"); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(4); - assertThat(((BooleanValue) result.get().getValue(COL_NAME5).get()).get()).isTrue(); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME2).get().getAsString().get()).isEqualTo("val2"); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(4); + assertThat(result.get().getValue(COL_NAME5).get().getAsBoolean()).isTrue(); } @Test @@ -672,23 +661,23 @@ public void whenScanDataFromTable1InNamespace2_DataShouldBeScannedFromMySql() th // Arrange String namespace = NAMESPACE2; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey1 = new Key(new IntValue(COL_NAME4, 0)); - Key clusteringKey2 = new Key(new IntValue(COL_NAME4, 1)); - Key clusteringKey3 = new Key(new IntValue(COL_NAME4, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey1 = new Key(COL_NAME4, 0); + Key clusteringKey2 = new Key(COL_NAME4, 1); + Key clusteringKey3 = new Key(COL_NAME4, 2); mysql.mutate( Arrays.asList( new Put(partitionKey, clusteringKey1) - .withValue(new IntValue(COL_NAME3, 2)) + .withValue(COL_NAME3, 2) .forNamespace(namespace) .forTable(table), new Put(partitionKey, clusteringKey2) - .withValue(new IntValue(COL_NAME3, 1)) + .withValue(COL_NAME3, 1) .forNamespace(namespace) .forTable(table), new Put(partitionKey, clusteringKey3) - .withValue(new IntValue(COL_NAME3, 0)) + .withValue(COL_NAME3, 0) .forNamespace(namespace) .forTable(table))); @@ -697,15 +686,15 @@ public void whenScanDataFromTable1InNamespace2_DataShouldBeScannedFromMySql() th // Assert assertThat(results.size()).isEqualTo(3); - assertThat(((IntValue) results.get(0).getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(0).getValue(COL_NAME3).get()).get()).isEqualTo(2); - assertThat(((IntValue) results.get(0).getValue(COL_NAME4).get()).get()).isEqualTo(0); - assertThat(((IntValue) results.get(1).getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(1).getValue(COL_NAME3).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(1).getValue(COL_NAME4).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(2).getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) results.get(2).getValue(COL_NAME3).get()).get()).isEqualTo(0); - assertThat(((IntValue) results.get(2).getValue(COL_NAME4).get()).get()).isEqualTo(2); + assertThat(results.get(0).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(results.get(0).getValue(COL_NAME3).get().getAsInt()).isEqualTo(2); + assertThat(results.get(0).getValue(COL_NAME4).get().getAsInt()).isEqualTo(0); + assertThat(results.get(1).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(results.get(1).getValue(COL_NAME3).get().getAsInt()).isEqualTo(1); + assertThat(results.get(1).getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); + assertThat(results.get(2).getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(results.get(2).getValue(COL_NAME3).get().getAsInt()).isEqualTo(0); + assertThat(results.get(2).getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); } @Test @@ -714,11 +703,11 @@ public void whenDeleteDataFromTable1InNamespace2_DataShouldBeDeletedFromMySql() // Arrange String namespace = NAMESPACE2; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME4, 4)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME4, 4); Put put = new Put(partitionKey, clusteringKey) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table); @@ -737,9 +726,9 @@ public void whenDeleteDataFromTable1InNamespace2_DataShouldBeDeletedFromMySql() result = cassandra.get(get); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(4); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(4); result = mysql.get(get); assertThat(result.isPresent()).isFalse(); @@ -751,12 +740,12 @@ public void whenMutateDataToTable1InNamespace2_ShouldExecuteForCassandra() // Arrange String namespace = NAMESPACE2; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey1 = new Key(new IntValue(COL_NAME4, 1)); - Key clusteringKey2 = new Key(new IntValue(COL_NAME4, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey1 = new Key(COL_NAME4, 1); + Key clusteringKey2 = new Key(COL_NAME4, 2); Put put = new Put(partitionKey, clusteringKey1) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table); @@ -767,7 +756,7 @@ public void whenMutateDataToTable1InNamespace2_ShouldExecuteForCassandra() multiStorage.mutate( Arrays.asList( new Put(partitionKey, clusteringKey2) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table), new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); @@ -780,15 +769,15 @@ public void whenMutateDataToTable1InNamespace2_ShouldExecuteForCassandra() assertThat(result.isPresent()).isFalse(); result = multiStorage.get(get2); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(2); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); result = cassandra.get(get1); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(1); result = cassandra.get(get2); assertThat(result.isPresent()).isFalse(); @@ -796,9 +785,9 @@ public void whenMutateDataToTable1InNamespace2_ShouldExecuteForCassandra() assertThat(result.isPresent()).isFalse(); result = mysql.get(get2); assertThat(result.isPresent()).isTrue(); - assertThat(((IntValue) result.get().getValue(COL_NAME1).get()).get()).isEqualTo(1); - assertThat(((IntValue) result.get().getValue(COL_NAME3).get()).get()).isEqualTo(3); - assertThat(((IntValue) result.get().getValue(COL_NAME4).get()).get()).isEqualTo(2); + assertThat(result.get().getValue(COL_NAME1).get().getAsInt()).isEqualTo(1); + assertThat(result.get().getValue(COL_NAME3).get().getAsInt()).isEqualTo(3); + assertThat(result.get().getValue(COL_NAME4).get().getAsInt()).isEqualTo(2); } @Test diff --git a/core/src/integration-test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitIntegrationTestBase.java b/core/src/integration-test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitIntegrationTestBase.java index 9f4b986342..2cf61fca45 100644 --- a/core/src/integration-test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitIntegrationTestBase.java +++ b/core/src/integration-test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitIntegrationTestBase.java @@ -838,7 +838,7 @@ public void getAndScan_CommitHappenedInBetween_ShouldReadRepeatably() throws CrudException, CommitException, UnknownTransactionStatusException { // Arrange ConsensusCommit transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); transaction.commit(); ConsensusCommit transaction1 = manager.start(); @@ -846,7 +846,7 @@ public void getAndScan_CommitHappenedInBetween_ShouldReadRepeatably() ConsensusCommit transaction2 = manager.start(); transaction2.get(prepareGet(0, 0, TABLE_1)); - transaction2.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 2))); + transaction2.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 2)); transaction2.commit(); // Act @@ -889,7 +889,7 @@ public void putAndCommit_PutGivenForExistingAfterRead_ShouldUpdateRecord() // Act Optional result = transaction.get(get); - int afterBalance = ((IntValue) result.get().getValue(BALANCE).get()).get() + 100; + int afterBalance = result.get().getValue(BALANCE).get().getAsInt() + 100; IntValue expected = new IntValue(BALANCE, afterBalance); Put put = preparePut(0, 0, TABLE_1).withValue(expected); transaction.put(put); @@ -909,7 +909,7 @@ public void putAndCommit_PutGivenForExistingAndNeverRead_ShouldThrowCommitExcept // Arrange populateRecords(TABLE_1); List puts = preparePuts(TABLE_1); - puts.get(0).withValue(new IntValue(BALANCE, 1100)); + puts.get(0).withValue(BALANCE, 1100); ConsensusCommit transaction = manager.start(); // Act Assert @@ -1436,8 +1436,8 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria // Arrange List puts = Arrays.asList( - preparePut(0, 0, table1).withValue(new IntValue(BALANCE, 1)), - preparePut(0, 1, table2).withValue(new IntValue(BALANCE, 1))); + preparePut(0, 0, table1).withValue(BALANCE, 1), + preparePut(0, 1, table2).withValue(BALANCE, 1)); ConsensusCommit transaction = manager.start(); transaction.put(puts); transaction.commit(); @@ -1449,15 +1449,15 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria Optional result1 = transaction1.get(get1_1); Get get1_2 = prepareGet(0, 0, table1); transaction1.get(get1_2); - int current1 = ((IntValue) result1.get().getValue(BALANCE).get()).get(); + int current1 = result1.get().getValue(BALANCE).get().getAsInt(); Get get2_1 = prepareGet(0, 0, table1); Optional result2 = transaction2.get(get2_1); Get get2_2 = prepareGet(0, 1, table2); transaction2.get(get2_2); - int current2 = ((IntValue) result2.get().getValue(BALANCE).get()).get(); - Put put1 = preparePut(0, 0, table1).withValue(new IntValue(BALANCE, current1 + 1)); + int current2 = result2.get().getValue(BALANCE).get().getAsInt(); + Put put1 = preparePut(0, 0, table1).withValue(BALANCE, current1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, table2).withValue(new IntValue(BALANCE, current2 + 1)); + Put put2 = preparePut(0, 1, table2).withValue(BALANCE, current2 + 1); transaction2.put(put2); transaction1.commit(); transaction2.commit(); @@ -1494,8 +1494,8 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria // Arrange List puts = Arrays.asList( - preparePut(0, 0, table1).withValue(new IntValue(BALANCE, 1)), - preparePut(0, 1, table2).withValue(new IntValue(BALANCE, 1))); + preparePut(0, 0, table1).withValue(BALANCE, 1), + preparePut(0, 1, table2).withValue(BALANCE, 1)); ConsensusCommit transaction = manager.start(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_WRITE); transaction.put(puts); @@ -1510,15 +1510,15 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria Optional result1 = transaction1.get(get1_1); Get get1_2 = prepareGet(0, 0, table1); transaction1.get(get1_2); - int current1 = ((IntValue) result1.get().getValue(BALANCE).get()).get(); + int current1 = result1.get().getValue(BALANCE).get().getAsInt(); Get get2_1 = prepareGet(0, 0, table1); Optional result2 = transaction2.get(get2_1); Get get2_2 = prepareGet(0, 1, table2); transaction2.get(get2_2); - int current2 = ((IntValue) result2.get().getValue(BALANCE).get()).get(); - Put put1 = preparePut(0, 0, table1).withValue(new IntValue(BALANCE, current1 + 1)); + int current2 = result2.get().getValue(BALANCE).get().getAsInt(); + Put put1 = preparePut(0, 0, table1).withValue(BALANCE, current1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, table2).withValue(new IntValue(BALANCE, current2 + 1)); + Put put2 = preparePut(0, 1, table2).withValue(BALANCE, current2 + 1); transaction2.put(put2); transaction1.commit(); Throwable thrown = catchThrowable(transaction2::commit); @@ -1555,8 +1555,8 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria // Arrange List puts = Arrays.asList( - preparePut(0, 0, table1).withValue(new IntValue(BALANCE, 1)), - preparePut(0, 1, table2).withValue(new IntValue(BALANCE, 1))); + preparePut(0, 0, table1).withValue(BALANCE, 1), + preparePut(0, 1, table2).withValue(BALANCE, 1)); ConsensusCommit transaction = manager.start(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ); transaction.put(puts); @@ -1571,15 +1571,15 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria Optional result1 = transaction1.get(get1_1); Get get1_2 = prepareGet(0, 0, table1); transaction1.get(get1_2); - int current1 = ((IntValue) result1.get().getValue(BALANCE).get()).get(); + int current1 = result1.get().getValue(BALANCE).get().getAsInt(); Get get2_1 = prepareGet(0, 0, table1); Optional result2 = transaction2.get(get2_1); Get get2_2 = prepareGet(0, 1, table2); transaction2.get(get2_2); - int current2 = ((IntValue) result2.get().getValue(BALANCE).get()).get(); - Put put1 = preparePut(0, 0, table1).withValue(new IntValue(BALANCE, current1 + 1)); + int current2 = result2.get().getValue(BALANCE).get().getAsInt(); + Put put1 = preparePut(0, 0, table1).withValue(BALANCE, current1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, table2).withValue(new IntValue(BALANCE, current2 + 1)); + Put put2 = preparePut(0, 1, table2).withValue(BALANCE, current2 + 1); transaction2.put(put2); transaction1.commit(); Throwable thrown = catchThrowable(transaction2::commit); @@ -1630,9 +1630,9 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria Get get2_2 = prepareGet(0, 1, table2); transaction2.get(get2_2); int current2 = 0; - Put put1 = preparePut(0, 0, table1).withValue(new IntValue(BALANCE, current1 + 1)); + Put put1 = preparePut(0, 0, table1).withValue(BALANCE, current1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, table2).withValue(new IntValue(BALANCE, current2 + 1)); + Put put2 = preparePut(0, 1, table2).withValue(BALANCE, current2 + 1); transaction2.put(put2); Throwable thrown1 = catchThrowable(transaction1::commit); Throwable thrown2 = catchThrowable(transaction2::commit); @@ -1681,7 +1681,7 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria Get get1_2 = prepareGet(0, 0, table1); Optional result2 = transaction1.get(get1_2); int current1 = 0; - Put put1 = preparePut(0, 0, table1).withValue(new IntValue(BALANCE, current1 + 1)); + Put put1 = preparePut(0, 0, table1).withValue(BALANCE, current1 + 1); transaction1.put(put1); Throwable thrown1 = catchThrowable(transaction1::commit); @@ -1734,9 +1734,9 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria Get get2_2 = prepareGet(0, 1, table2); transaction2.get(get2_2); int current2 = 0; - Put put1 = preparePut(0, 0, table1).withValue(new IntValue(BALANCE, current1 + 1)); + Put put1 = preparePut(0, 0, table1).withValue(BALANCE, current1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, table2).withValue(new IntValue(BALANCE, current2 + 1)); + Put put2 = preparePut(0, 1, table2).withValue(BALANCE, current2 + 1); transaction2.put(put2); Throwable thrown1 = catchThrowable(transaction1::commit); Throwable thrown2 = catchThrowable(transaction2::commit); @@ -1789,9 +1789,9 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria int count1 = results1.size(); List results2 = transaction2.scan(prepareScan(0, 0, 1, TABLE_1)); int count2 = results2.size(); - Put put1 = preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, count1 + 1)); + Put put1 = preparePut(0, 0, TABLE_1).withValue(BALANCE, count1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, TABLE_1).withValue(new IntValue(BALANCE, count2 + 1)); + Put put2 = preparePut(0, 1, TABLE_1).withValue(BALANCE, count2 + 1); transaction2.put(put2); Throwable thrown1 = catchThrowable(transaction1::commit); Throwable thrown2 = catchThrowable(transaction2::commit); @@ -1825,9 +1825,9 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria int count1 = results1.size(); List results2 = transaction2.scan(prepareScan(0, 0, 1, TABLE_1)); int count2 = results2.size(); - Put put1 = preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, count1 + 1)); + Put put1 = preparePut(0, 0, TABLE_1).withValue(BALANCE, count1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, TABLE_1).withValue(new IntValue(BALANCE, count2 + 1)); + Put put2 = preparePut(0, 1, TABLE_1).withValue(BALANCE, count2 + 1); transaction2.put(put2); Throwable thrown1 = catchThrowable(transaction1::commit); Throwable thrown2 = catchThrowable(transaction2::commit); @@ -1855,8 +1855,8 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria // Arrange List puts = Arrays.asList( - preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1)), - preparePut(0, 1, TABLE_1).withValue(new IntValue(BALANCE, 1))); + preparePut(0, 0, TABLE_1).withValue(BALANCE, 1), + preparePut(0, 1, TABLE_1).withValue(BALANCE, 1)); ConsensusCommit transaction = manager.start(Isolation.SERIALIZABLE, SerializableStrategy.EXTRA_READ); transaction.put(puts); @@ -1871,9 +1871,9 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria int count1 = results1.size(); List results2 = transaction2.scan(prepareScan(0, 0, 1, TABLE_1)); int count2 = results2.size(); - Put put1 = preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, count1 + 1)); + Put put1 = preparePut(0, 0, TABLE_1).withValue(BALANCE, count1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, TABLE_1).withValue(new IntValue(BALANCE, count2 + 1)); + Put put2 = preparePut(0, 1, TABLE_1).withValue(BALANCE, count2 + 1); transaction2.put(put2); Throwable thrown1 = catchThrowable(transaction1::commit); Throwable thrown2 = catchThrowable(transaction2::commit); @@ -1895,7 +1895,7 @@ public void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializa throws CrudException, CommitException, UnknownTransactionStatusException { // Arrange ConsensusCommit transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 2))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 2)); transaction.commit(); // Act @@ -1903,9 +1903,9 @@ public void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializa Optional result1 = transaction1.get(prepareGet(0, 0, TABLE_1)); int balance1 = 0; if (result1.isPresent()) { - balance1 = ((IntValue) result1.get().getValue(BALANCE).get()).get(); + balance1 = result1.get().getValue(BALANCE).get().getAsInt(); } - transaction1.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, balance1 + 1))); + transaction1.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, balance1 + 1)); ConsensusCommit transaction2 = manager.start(); transaction2.get(prepareGet(0, 0, TABLE_1)); @@ -1917,9 +1917,9 @@ public void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializa Optional result3 = transaction3.get(prepareGet(0, 0, TABLE_1)); int balance3 = 0; if (result3.isPresent()) { - balance3 = ((IntValue) result3.get().getValue(BALANCE).get()).get(); + balance3 = result3.get().getValue(BALANCE).get().getAsInt(); } - transaction3.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, balance3 + 1))); + transaction3.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, balance3 + 1)); transaction3.commit(); Throwable thrown = catchThrowable(transaction1::commit); @@ -1930,7 +1930,7 @@ public void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializa .hasCauseInstanceOf(NoMutationException.class); transaction = manager.start(); Optional result = transaction.get(prepareGet(0, 0, TABLE_1)); - assertThat(((IntValue) result.get().getValue(BALANCE).get()).get()).isEqualTo(1); + assertThat(result.get().getValue(BALANCE).get().getAsInt()).isEqualTo(1); } @Test @@ -1938,7 +1938,7 @@ public void deleteAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerial throws CrudException, CommitException, UnknownTransactionStatusException { // Arrange ConsensusCommit transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 2))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 2)); transaction.commit(); // Act @@ -1956,9 +1956,9 @@ public void deleteAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerial Optional result3 = transaction3.get(prepareGet(0, 0, TABLE_1)); int balance3 = 0; if (result3.isPresent()) { - balance3 = ((IntValue) result3.get().getValue(BALANCE).get()).get(); + balance3 = result3.get().getValue(BALANCE).get().getAsInt(); } - transaction3.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, balance3 + 1))); + transaction3.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, balance3 + 1)); transaction3.commit(); Throwable thrown = catchThrowable(transaction1::commit); @@ -1969,7 +1969,7 @@ public void deleteAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerial .hasCauseInstanceOf(NoMutationException.class); transaction = manager.start(); Optional result = transaction.get(prepareGet(0, 0, TABLE_1)); - assertThat(((IntValue) result.get().getValue(BALANCE).get()).get()).isEqualTo(1); + assertThat(result.get().getValue(BALANCE).get().getAsInt()).isEqualTo(1); } @Test @@ -1977,7 +1977,7 @@ public void get_DeleteCalledBefore_ShouldReturnEmpty() throws CommitException, UnknownTransactionStatusException, CrudException { // Arrange ConsensusCommit transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); transaction.commit(); // Act @@ -1998,7 +1998,7 @@ public void scan_DeleteCalledBefore_ShouldReturnEmpty() throws CommitException, UnknownTransactionStatusException, CrudException { // Arrange ConsensusCommit transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); transaction.commit(); // Act @@ -2019,14 +2019,14 @@ public void delete_PutCalledBefore_ShouldDelete() throws CommitException, UnknownTransactionStatusException, CrudException { // Arrange ConsensusCommit transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); transaction.commit(); // Act ConsensusCommit transaction1 = manager.start(); Get get = prepareGet(0, 0, TABLE_1); Optional resultBefore = transaction1.get(get); - transaction1.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 2))); + transaction1.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 2)); transaction1.delete(prepareDelete(0, 0, TABLE_1)); assertThatCode(transaction1::commit).doesNotThrowAnyException(); @@ -2043,7 +2043,7 @@ public void put_DeleteCalledBefore_ShouldPut() throws CommitException, UnknownTransactionStatusException, CrudException { // Arrange ConsensusCommit transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); transaction.commit(); // Act @@ -2051,7 +2051,7 @@ public void put_DeleteCalledBefore_ShouldPut() Get get = prepareGet(0, 0, TABLE_1); Optional resultBefore = transaction1.get(get); transaction1.delete(prepareDelete(0, 0, TABLE_1)); - transaction1.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 2))); + transaction1.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 2)); assertThatCode(transaction1::commit).doesNotThrowAnyException(); // Assert @@ -2067,7 +2067,7 @@ public void put_DeleteCalledBefore_ShouldPut() public void scan_OverlappingPutGivenBefore_ShouldThrowCrudRuntimeException() { // Arrange ConsensusCommit transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); // Act Scan scan = prepareScan(0, 0, 0, TABLE_1); @@ -2083,7 +2083,7 @@ public void scan_NonOverlappingPutGivenBefore_ShouldScan() throws CommitException, UnknownTransactionStatusException { // Arrange ConsensusCommit transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); // Act Scan scan = prepareScan(0, 1, 1, TABLE_1); @@ -2130,9 +2130,9 @@ private ConsensusCommit prepareTransfer( Optional toResult = transaction.get(toGets.get(toId)); IntValue fromBalance = - new IntValue(BALANCE, ((IntValue) fromResult.get().getValue(BALANCE).get()).get() - amount); + new IntValue(BALANCE, fromResult.get().getValue(BALANCE).get().getAsInt() - amount); IntValue toBalance = - new IntValue(BALANCE, ((IntValue) toResult.get().getValue(BALANCE).get()).get() + amount); + new IntValue(BALANCE, toResult.get().getValue(BALANCE).get().getAsInt() + amount); List fromPuts = preparePuts(fromTable); List toPuts = differentTables ? preparePuts(toTable) : fromPuts; @@ -2172,13 +2172,13 @@ private void populateRecords(String table) IntStream.range(0, NUM_TYPES) .forEach( j -> { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, i)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, j)); + Key partitionKey = new Key(ACCOUNT_ID, i); + Key clusteringKey = new Key(ACCOUNT_TYPE, j); Put put = new Put(partitionKey, clusteringKey) .forNamespace(NAMESPACE) .forTable(table) - .withValue(new IntValue(BALANCE, INITIAL_BALANCE)); + .withValue(BALANCE, INITIAL_BALANCE); transaction.put(put); })); transaction.commit(); @@ -2191,13 +2191,13 @@ private void populatePreparedRecordAndCoordinatorStateRecord( long preparedAt, TransactionState coordinatorState) throws ExecutionException, CoordinatorException { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, 0)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, 0)); + Key partitionKey = new Key(ACCOUNT_ID, 0); + Key clusteringKey = new Key(ACCOUNT_TYPE, 0); Put put = new Put(partitionKey, clusteringKey) .forNamespace(NAMESPACE) .forTable(table) - .withValue(new IntValue(BALANCE, INITIAL_BALANCE)) + .withValue(BALANCE, INITIAL_BALANCE) .withValue(Attribute.toIdValue(ANY_ID_2)) .withValue(Attribute.toStateValue(recordState)) .withValue(Attribute.toVersionValue(2)) @@ -2217,8 +2217,8 @@ private void populatePreparedRecordAndCoordinatorStateRecord( } private Get prepareGet(int id, int type, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, type)); + Key partitionKey = new Key(ACCOUNT_ID, id); + Key clusteringKey = new Key(ACCOUNT_TYPE, type); return new Get(partitionKey, clusteringKey) .forNamespace(NAMESPACE) .forTable(table) @@ -2234,18 +2234,18 @@ private List prepareGets(String table) { } private Scan prepareScan(int id, int fromType, int toType, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); + Key partitionKey = new Key(ACCOUNT_ID, id); return new Scan(partitionKey) .forNamespace(NAMESPACE) .forTable(table) .withConsistency(Consistency.LINEARIZABLE) - .withStart(new Key(new IntValue(ACCOUNT_TYPE, fromType))) - .withEnd(new Key(new IntValue(ACCOUNT_TYPE, toType))); + .withStart(new Key(ACCOUNT_TYPE, fromType)) + .withEnd(new Key(ACCOUNT_TYPE, toType)); } private Put preparePut(int id, int type, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, type)); + Key partitionKey = new Key(ACCOUNT_ID, id); + Key clusteringKey = new Key(ACCOUNT_TYPE, type); return new Put(partitionKey, clusteringKey) .forNamespace(NAMESPACE) .forTable(table) @@ -2261,8 +2261,8 @@ private List preparePuts(String table) { } private Delete prepareDelete(int id, int type, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, type)); + Key partitionKey = new Key(ACCOUNT_ID, id); + Key clusteringKey = new Key(ACCOUNT_TYPE, type); return new Delete(partitionKey, clusteringKey) .forNamespace(NAMESPACE) .forTable(table) diff --git a/core/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionIntegrationTest.java index ac55472a21..3ad8174af2 100644 --- a/core/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionIntegrationTest.java @@ -132,7 +132,7 @@ public void putAndCommit_PutGivenForExistingAfterRead_ShouldUpdateRecord() // Act Optional result = transaction.get(get); - int afterBalance = ((IntValue) result.get().getValue(BALANCE).get()).get() + 100; + int afterBalance = result.get().getValue(BALANCE).get().getAsInt() + 100; IntValue expected = new IntValue(BALANCE, afterBalance); Put put = preparePut(0, 0, NAMESPACE, TABLE).withValue(expected); transaction.put(put); @@ -205,9 +205,9 @@ private JdbcTransaction prepareTransfer(int fromId, int toId, int amount) Optional result1 = transaction.get(gets.get(fromId)); Optional result2 = transaction.get(gets.get(toId)); IntValue fromBalance = - new IntValue(BALANCE, ((IntValue) result1.get().getValue(BALANCE).get()).get() - amount); + new IntValue(BALANCE, result1.get().getValue(BALANCE).get().getAsInt() - amount); IntValue toBalance = - new IntValue(BALANCE, ((IntValue) result2.get().getValue(BALANCE).get()).get() + amount); + new IntValue(BALANCE, result2.get().getValue(BALANCE).get().getAsInt() + amount); List puts = preparePuts(NAMESPACE, TABLE); puts.get(fromId).withValue(fromBalance); puts.get(toId).withValue(toBalance); @@ -224,13 +224,13 @@ private void populateRecords() throws TransactionException { IntStream.range(0, NUM_TYPES) .forEach( j -> { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, i)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, j)); + Key partitionKey = new Key(ACCOUNT_ID, i); + Key clusteringKey = new Key(ACCOUNT_TYPE, j); Put put = new Put(partitionKey, clusteringKey) .forNamespace(NAMESPACE) .forTable(TABLE) - .withValue(new IntValue(BALANCE, INITIAL_BALANCE)); + .withValue(BALANCE, INITIAL_BALANCE); try { transaction.put(put); } catch (CrudException e) { @@ -241,8 +241,8 @@ private void populateRecords() throws TransactionException { } private Get prepareGet(int id, int type, String namespace, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, type)); + Key partitionKey = new Key(ACCOUNT_ID, id); + Key clusteringKey = new Key(ACCOUNT_TYPE, type); return new Get(partitionKey, clusteringKey) .forNamespace(namespace) .forTable(table) @@ -260,18 +260,18 @@ private List prepareGets(String namespace, String table) { } private Scan prepareScan(int id, int fromType, int toType, String namespace, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); + Key partitionKey = new Key(ACCOUNT_ID, id); return new Scan(partitionKey) .forNamespace(namespace) .forTable(table) .withConsistency(Consistency.LINEARIZABLE) - .withStart(new Key(new IntValue(ACCOUNT_TYPE, fromType))) - .withEnd(new Key(new IntValue(ACCOUNT_TYPE, toType))); + .withStart(new Key(ACCOUNT_TYPE, fromType)) + .withEnd(new Key(ACCOUNT_TYPE, toType)); } private Put preparePut(int id, int type, String namespace, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, type)); + Key partitionKey = new Key(ACCOUNT_ID, id); + Key clusteringKey = new Key(ACCOUNT_TYPE, type); return new Put(partitionKey, clusteringKey) .forNamespace(namespace) .forTable(table) @@ -289,8 +289,8 @@ private List preparePuts(String namespace, String table) { } private Delete prepareDelete(int id, int type, String namespace, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, type)); + Key partitionKey = new Key(ACCOUNT_ID, id); + Key clusteringKey = new Key(ACCOUNT_TYPE, type); return new Delete(partitionKey, clusteringKey) .forNamespace(namespace) .forTable(table) diff --git a/core/src/main/java/com/scalar/db/api/DistributedStorage.java b/core/src/main/java/com/scalar/db/api/DistributedStorage.java index 2e3e07420f..d2d772a81c 100644 --- a/core/src/main/java/com/scalar/db/api/DistributedStorage.java +++ b/core/src/main/java/com/scalar/db/api/DistributedStorage.java @@ -39,15 +39,15 @@ * * // Inserts a new entry which has the primary key value 0 to the storage. * // Assumes that the primary key is composed of a integer value named COL_NAME. - * Put put = new Put(new Key(new IntValue(COL_NAME, 0)); + * Put put = new Put(new Key(COL_NAME, 0); * storage.put(put); * * // Retrieves the entry from the storage. - * Get get = new Get(new Key(new IntValue(COL_NAME, 0)); + * Get get = new Get(new Key(COL_NAME, 0); * Optional result = storage.get(get); * * // Deletes an entry which has the primary key value 1. - * Delete delete = new Delete(new Key(new IntValue(COL_NAME, 1)); + * Delete delete = new Delete(new Key(COL_NAME, 1); * storage.delete(delete); * } * diff --git a/core/src/main/java/com/scalar/db/io/TextValue.java b/core/src/main/java/com/scalar/db/io/TextValue.java index 0183d37b74..41f1f8ba7d 100644 --- a/core/src/main/java/com/scalar/db/io/TextValue.java +++ b/core/src/main/java/com/scalar/db/io/TextValue.java @@ -80,7 +80,8 @@ public Optional get() { * Returns the content of this {@code Value} * * @return an {@code Optional} of the content of this {@code Value} in byte array - * @deprecated As of release 3.2.0, replaced by {@link #get()}. Will be removed in release 4.0.0. + * @deprecated As of release 3.2.0, replaced by {@link #getAsBytes()}. Will be removed in release + * 4.0.0. */ @SuppressWarnings("InlineMeSuggester") @Deprecated diff --git a/core/src/main/java/com/scalar/db/storage/cassandra/ValueBinder.java b/core/src/main/java/com/scalar/db/storage/cassandra/ValueBinder.java index 8d2340435e..9183e6f701 100644 --- a/core/src/main/java/com/scalar/db/storage/cassandra/ValueBinder.java +++ b/core/src/main/java/com/scalar/db/storage/cassandra/ValueBinder.java @@ -99,8 +99,8 @@ public void visit(DoubleValue value) { */ @Override public void visit(TextValue value) { - LOGGER.debug(value.getString() + " is bound to " + i); - value.getString().ifPresent(s -> bound.setString(i, s)); + LOGGER.debug(value.get() + " is bound to " + i); + value.get().ifPresent(s -> bound.setString(i, s)); i++; } diff --git a/core/src/main/java/com/scalar/db/storage/common/ResultImpl.java b/core/src/main/java/com/scalar/db/storage/common/ResultImpl.java index 7b5ec9b8c9..a9b9fffe96 100644 --- a/core/src/main/java/com/scalar/db/storage/common/ResultImpl.java +++ b/core/src/main/java/com/scalar/db/storage/common/ResultImpl.java @@ -5,10 +5,8 @@ import com.scalar.db.api.TableMetadata; import com.scalar.db.io.Key; import com.scalar.db.io.Value; -import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -38,16 +36,16 @@ public Optional getClusteringKey() { } private Optional getKey(LinkedHashSet names) { - List> list = new ArrayList<>(); + Key.Builder builder = Key.newBuilder(); for (String name : names) { Value value = values.get(name); if (value == null) { LOGGER.warn("full key doesn't seem to be projected into the result"); return Optional.empty(); } - list.add(value); + builder.add(value); } - return Optional.of(new Key(list)); + return Optional.of(builder.build()); } @Override diff --git a/core/src/main/java/com/scalar/db/storage/cosmos/ConcatenationVisitor.java b/core/src/main/java/com/scalar/db/storage/cosmos/ConcatenationVisitor.java index 230bd7d4d4..2c7a1a60b2 100644 --- a/core/src/main/java/com/scalar/db/storage/cosmos/ConcatenationVisitor.java +++ b/core/src/main/java/com/scalar/db/storage/cosmos/ConcatenationVisitor.java @@ -88,7 +88,7 @@ public void visit(DoubleValue value) { */ @Override public void visit(TextValue value) { - value.getString().ifPresent(s -> values.add(s)); + value.get().ifPresent(s -> values.add(s)); } /** diff --git a/core/src/main/java/com/scalar/db/storage/cosmos/MapVisitor.java b/core/src/main/java/com/scalar/db/storage/cosmos/MapVisitor.java index f2d147583f..52a8f3ecb9 100644 --- a/core/src/main/java/com/scalar/db/storage/cosmos/MapVisitor.java +++ b/core/src/main/java/com/scalar/db/storage/cosmos/MapVisitor.java @@ -87,7 +87,7 @@ public void visit(DoubleValue value) { */ @Override public void visit(TextValue value) { - value.getString().ifPresent(s -> values.put(value.getName(), s)); + value.get().ifPresent(s -> values.put(value.getName(), s)); } /** diff --git a/core/src/main/java/com/scalar/db/storage/cosmos/ValueBinder.java b/core/src/main/java/com/scalar/db/storage/cosmos/ValueBinder.java index 5e01310739..8fa1751da0 100644 --- a/core/src/main/java/com/scalar/db/storage/cosmos/ValueBinder.java +++ b/core/src/main/java/com/scalar/db/storage/cosmos/ValueBinder.java @@ -85,7 +85,7 @@ public void visit(DoubleValue value) { */ @Override public void visit(TextValue value) { - value.getString().ifPresent(s -> consumer.accept(s)); + value.get().ifPresent(s -> consumer.accept(s)); } /** diff --git a/core/src/main/java/com/scalar/db/storage/dynamo/MapVisitor.java b/core/src/main/java/com/scalar/db/storage/dynamo/MapVisitor.java index 06db35e563..55b381fc40 100644 --- a/core/src/main/java/com/scalar/db/storage/dynamo/MapVisitor.java +++ b/core/src/main/java/com/scalar/db/storage/dynamo/MapVisitor.java @@ -94,9 +94,7 @@ public void visit(DoubleValue value) { */ @Override public void visit(TextValue value) { - value - .getString() - .ifPresent(s -> values.put(value.getName(), AttributeValue.builder().s(s).build())); + value.get().ifPresent(s -> values.put(value.getName(), AttributeValue.builder().s(s).build())); } /** diff --git a/core/src/main/java/com/scalar/db/storage/dynamo/ValueBinder.java b/core/src/main/java/com/scalar/db/storage/dynamo/ValueBinder.java index f862490906..80444b0388 100644 --- a/core/src/main/java/com/scalar/db/storage/dynamo/ValueBinder.java +++ b/core/src/main/java/com/scalar/db/storage/dynamo/ValueBinder.java @@ -105,8 +105,8 @@ public void visit(DoubleValue value) { @Override public void visit(TextValue value) { AttributeValue.Builder builder = AttributeValue.builder(); - if (value.getString().isPresent()) { - builder.s(value.getString().get()); + if (value.get().isPresent()) { + builder.s(value.get().get()); } else { builder.nul(true); } diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/query/PreparedStatementBinder.java b/core/src/main/java/com/scalar/db/storage/jdbc/query/PreparedStatementBinder.java index 5b187c769e..0f29a71f46 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/query/PreparedStatementBinder.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/query/PreparedStatementBinder.java @@ -75,7 +75,7 @@ public void visit(DoubleValue value) { @Override public void visit(TextValue value) { try { - preparedStatement.setString(index++, value.getString().orElse(null)); + preparedStatement.setString(index++, value.get().orElse(null)); } catch (SQLException e) { sqlException = e; } 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 a3645c75a0..83e8f4f611 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 @@ -15,10 +15,7 @@ import com.scalar.db.exception.storage.NoMutationException; import com.scalar.db.exception.transaction.CoordinatorException; import com.scalar.db.exception.transaction.RequiredValueMissingException; -import com.scalar.db.io.BigIntValue; -import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Objects; import java.util.Optional; import java.util.concurrent.TimeUnit; @@ -88,7 +85,7 @@ Put createPutWith(Coordinator.State state) { .getMetadata() .ifPresent( m -> { - put.withValue(new TextValue(Attribute.METADATA, m)); + put.withValue(Attribute.METADATA, m); }); return put; } @@ -126,10 +123,9 @@ public static class State { public State(Result result) { checkNotMissingRequired(result); - id = ((TextValue) result.getValue(Attribute.ID).get()).getString().get(); - state = - TransactionState.getInstance(((IntValue) result.getValue(Attribute.STATE).get()).get()); - createdAt = ((BigIntValue) result.getValue(Attribute.CREATED_AT).get()).get(); + id = result.getValue(Attribute.ID).get().getAsString().get(); + state = TransactionState.getInstance(result.getValue(Attribute.STATE).get().getAsInt()); + createdAt = result.getValue(Attribute.CREATED_AT).get().getAsLong(); } public State(String id, TransactionState state) { @@ -187,15 +183,15 @@ public int hashCode() { private void checkNotMissingRequired(Result result) { if (!result.getValue(Attribute.ID).isPresent() - || !((TextValue) result.getValue(Attribute.ID).get()).getString().isPresent()) { + || !result.getValue(Attribute.ID).get().getAsString().isPresent()) { throw new RequiredValueMissingException("id is missing in the coordinator state"); } if (!result.getValue(Attribute.STATE).isPresent() - || ((IntValue) result.getValue(Attribute.STATE).get()).get() == 0) { + || result.getValue(Attribute.STATE).get().getAsInt() == 0) { throw new RequiredValueMissingException("state is missing in the coordinator state"); } if (!result.getValue(Attribute.CREATED_AT).isPresent() - || ((BigIntValue) result.getValue(Attribute.CREATED_AT).get()).get() == 0) { + || result.getValue(Attribute.CREATED_AT).get().getAsLong() == 0) { throw new RequiredValueMissingException("created_at is missing in the coordinator state"); } } 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 5de879492b..6c7947e352 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 @@ -77,7 +77,7 @@ public void add(Operation base, TransactionResult result) { } TextValue beforeId = (TextValue) latest.getValue(Attribute.BEFORE_ID).get(); - if (beforeId.getString().isPresent()) { + if (beforeId.get().isPresent()) { mutations.add(composePut(base, latest)); } else { // no record to rollback, so it should be deleted diff --git a/core/src/main/java/com/scalar/db/transaction/consensuscommit/TransactionResult.java b/core/src/main/java/com/scalar/db/transaction/consensuscommit/TransactionResult.java index 0960f5cb23..606725ebb7 100644 --- a/core/src/main/java/com/scalar/db/transaction/consensuscommit/TransactionResult.java +++ b/core/src/main/java/com/scalar/db/transaction/consensuscommit/TransactionResult.java @@ -6,10 +6,7 @@ import com.google.common.collect.ImmutableMap; import com.scalar.db.api.Result; import com.scalar.db.api.TransactionState; -import com.scalar.db.io.BigIntValue; -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.Map; import java.util.Objects; @@ -81,23 +78,23 @@ public String toString() { } public String getId() { - return ((TextValue) getValue(Attribute.ID).get()).getString().get(); + return getValue(Attribute.ID).get().getAsString().get(); } public TransactionState getState() { - return TransactionState.getInstance(((IntValue) getValue(Attribute.STATE).get()).get()); + return TransactionState.getInstance(getValue(Attribute.STATE).get().getAsInt()); } public int getVersion() { - return ((IntValue) getValue(Attribute.VERSION).get()).get(); + return getValue(Attribute.VERSION).get().getAsInt(); } public long getPreparedAt() { - return ((BigIntValue) getValue(Attribute.PREPARED_AT).get()).get(); + return getValue(Attribute.PREPARED_AT).get().getAsLong(); } public long getCommittedAt() { - return ((BigIntValue) getValue(Attribute.COMMITTED_AT).get()).get(); + return getValue(Attribute.COMMITTED_AT).get().getAsLong(); } public boolean isCommitted() { diff --git a/core/src/test/java/com/scalar/db/api/DeleteTest.java b/core/src/test/java/com/scalar/db/api/DeleteTest.java index dcaa033d81..fe70e4a547 100644 --- a/core/src/test/java/com/scalar/db/api/DeleteTest.java +++ b/core/src/test/java/com/scalar/db/api/DeleteTest.java @@ -4,7 +4,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import com.scalar.db.io.Value; import java.util.Optional; import org.junit.Test; @@ -17,16 +16,16 @@ public class DeleteTest { private static final String ANY_TEXT_2 = "text2"; private Delete prepareDelete() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Delete(partitionKey, clusteringKey); } @Test public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() { // Arrange - Key expected = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key expected = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Delete del = new Delete(expected, clusteringKey); // Act @@ -39,8 +38,8 @@ public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() { @Test public void getClusteringKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() { // Arrange - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key expected = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key expected = new Key(ANY_NAME_1, ANY_TEXT_2); Delete del = new Delete(partitionKey, expected); // Act @@ -53,7 +52,7 @@ public void getClusteringKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() @Test public void getClusteringKey_ClusteringKeyNotGivenInConstructor_ShouldReturnNull() { // Arrange - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Delete del = new Delete(partitionKey); // Act diff --git a/core/src/test/java/com/scalar/db/api/GetTest.java b/core/src/test/java/com/scalar/db/api/GetTest.java index f9529c9392..bbdc6d6bf8 100644 --- a/core/src/test/java/com/scalar/db/api/GetTest.java +++ b/core/src/test/java/com/scalar/db/api/GetTest.java @@ -4,7 +4,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import com.scalar.db.io.Value; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.Arrays; @@ -22,28 +21,28 @@ public class GetTest { private static final String ANY_TEXT_3 = "text3"; private Get prepareGet() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Get(partitionKey, clusteringKey); } private Get prepareAnotherGet() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_3); return new Get(partitionKey, clusteringKey); } private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Put(partitionKey, clusteringKey); } @Test public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() { // Arrange - Key expected = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key expected = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Get get = new Get(expected, clusteringKey); // Act @@ -56,8 +55,8 @@ public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() { @Test public void getClusteringKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() { // Arrange - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key expected = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key expected = new Key(ANY_NAME_1, ANY_TEXT_2); Get get = new Get(partitionKey, expected); // Act @@ -70,7 +69,7 @@ public void getClusteringKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() @Test public void getClusteringKey_ClusteringKeyNotGivenInConstructor_ShouldReturnNull() { // Arrange - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Get get = new Get(partitionKey); // Act diff --git a/core/src/test/java/com/scalar/db/api/PutTest.java b/core/src/test/java/com/scalar/db/api/PutTest.java index 68ec1d724c..a55dcafcce 100644 --- a/core/src/test/java/com/scalar/db/api/PutTest.java +++ b/core/src/test/java/com/scalar/db/api/PutTest.java @@ -30,16 +30,16 @@ public class PutTest { private static final String ANY_TEXT_4 = "text4"; private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Put(partitionKey, clusteringKey); } @Test public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() { // Arrange - Key expected = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key expected = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Put put = new Put(expected, clusteringKey); // Act @@ -52,8 +52,8 @@ public void getPartitionKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() { @Test public void getClusteringKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() { // Arrange - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key expected = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key expected = new Key(ANY_NAME_1, ANY_TEXT_2); Put put = new Put(partitionKey, expected); // Act @@ -66,7 +66,7 @@ public void getClusteringKey_ProperKeyGivenInConstructor_ShouldReturnWhatsSet() @Test public void getClusteringKey_ClusteringKeyNotGivenInConstructor_ShouldReturnNull() { // Arrange - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Put put = new Put(partitionKey); // Act @@ -232,9 +232,9 @@ public void equals_SamePutWithPutIfNotExistsGiven_ShouldReturnTrue() { public void equals_PutWithDifferentValuesGiven_ShouldReturnFalse() { // Arrange Put put = preparePut(); - put.withValue(new TextValue(ANY_NAME_3, ANY_TEXT_3)); + put.withValue(ANY_NAME_3, ANY_TEXT_3); Put another = preparePut(); - another.withValue(new TextValue(ANY_NAME_3, ANY_TEXT_4)); + another.withValue(ANY_NAME_3, ANY_TEXT_4); // Act boolean ret = put.equals(another); diff --git a/core/src/test/java/com/scalar/db/api/ScanTest.java b/core/src/test/java/com/scalar/db/api/ScanTest.java index b0d7e698bd..6bd577c2dd 100644 --- a/core/src/test/java/com/scalar/db/api/ScanTest.java +++ b/core/src/test/java/com/scalar/db/api/ScanTest.java @@ -4,7 +4,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; 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.Optional; @@ -20,9 +19,9 @@ public class ScanTest { private static final String ANY_TEXT_4 = "text4"; private Scan prepareScan() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key startClusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); - Key endClusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key startClusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); + Key endClusteringKey = new Key(ANY_NAME_2, ANY_TEXT_3); Scan.Ordering ordering = new Scan.Ordering(ANY_NAME_2, Scan.Ordering.Order.ASC); return new Scan(partitionKey) @@ -34,9 +33,9 @@ private Scan prepareScan() { } private Scan prepareAnotherScan() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key startClusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); - Key endClusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_4)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key startClusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); + Key endClusteringKey = new Key(ANY_NAME_2, ANY_TEXT_4); Scan.Ordering ordering = new Scan.Ordering(ANY_NAME_2, Scan.Ordering.Order.ASC); return new Scan(partitionKey) @@ -50,9 +49,9 @@ private Scan prepareAnotherScan() { @Test public void constructorAndSetters_AllSet_ShouldGetWhatsSet() { // Arrange - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key startClusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); - Key endClusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key startClusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); + Key endClusteringKey = new Key(ANY_NAME_2, ANY_TEXT_3); Scan.Ordering ordering = new Scan.Ordering(ANY_NAME_2, Scan.Ordering.Order.ASC); // Act diff --git a/core/src/test/java/com/scalar/db/io/TextValueTest.java b/core/src/test/java/com/scalar/db/io/TextValueTest.java index 4dc475f81d..2fa750a785 100644 --- a/core/src/test/java/com/scalar/db/io/TextValueTest.java +++ b/core/src/test/java/com/scalar/db/io/TextValueTest.java @@ -15,28 +15,13 @@ public class TextValueTest { private static final String ANOTHER_NAME = "another_name"; @Test - public void getBytes_ProperValueGivenInConstructor_ShouldReturnWhatsSet() { - // Arrange - byte[] expected = "some_text".getBytes(StandardCharsets.UTF_8); - TextValue value = new TextValue(ANY_NAME, expected); - - // Act - Optional actual = value.getBytes(); - - // Assert - assertThat(actual.isPresent()).isTrue(); - assertThat(Arrays.equals(expected, actual.get())).isTrue(); - assertThat(expected == actual.get()).isFalse(); - } - - @Test - public void getString_ProperValueGivenInConstructor_ShouldReturnWhatsSet() { + public void get_ProperValueGivenInConstructor_ShouldReturnWhatsSet() { // Arrange String expected = "some_text"; TextValue value = new TextValue(ANY_NAME, expected); // Act - Optional actual = value.getString(); + Optional actual = value.get(); // Assert assertThat(actual.isPresent()).isTrue(); @@ -124,13 +109,13 @@ public void getAsDouble_ProperValueGivenInConstructor_ShouldThrowUnsupportedOper } @Test - public void getStringWithTwoBytesCharacter_ProperValueGivenInConstructor_ShouldReturnWhatsSet() { + public void getWithTwoBytesCharacter_ProperValueGivenInConstructor_ShouldReturnWhatsSet() { // Arrange String expected = "あいうえお"; TextValue value = new TextValue(ANY_NAME, expected); // Act - Optional actual = value.getString(); + Optional actual = value.get(); // Assert assertThat(expected.equals(actual.get())).isTrue(); 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 fec23da59b..92199dc0ec 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,7 @@ import com.scalar.db.api.PutIfNotExists; import com.scalar.db.exception.storage.NoMutationException; import com.scalar.db.exception.storage.RetriableExecutionException; -import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Arrays; import java.util.List; import org.junit.Before; @@ -82,17 +80,17 @@ private void configureBehavior() { } private List prepareNonConditionalPuts() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey1 = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey1 = new Key(ANY_NAME_2, ANY_TEXT_2); Put put1 = new Put(partitionKey, clusteringKey1) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)) + .withValue(ANY_NAME_3, ANY_INT_1) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); - Key clusteringKey2 = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3)); + Key clusteringKey2 = new Key(ANY_NAME_2, ANY_TEXT_3); Put put2 = new Put(partitionKey, clusteringKey2) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)) + .withValue(ANY_NAME_3, ANY_INT_1) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); return Arrays.asList(put1, put2); 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 45a5debd74..2e1dee7365 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 @@ -57,14 +57,14 @@ public void setUp() throws Exception { } private Delete prepareDelete() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Delete del = new Delete(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); return del; } private Delete prepareDeleteWithClusteringKey() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Delete del = new Delete(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) 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 d639b90ac6..925d92d2fe 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 @@ -30,9 +30,7 @@ import com.scalar.db.exception.storage.NoMutationException; import com.scalar.db.exception.storage.ReadRepairableExecutionException; import com.scalar.db.exception.storage.RetriableExecutionException; -import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -64,22 +62,22 @@ public void setUp() throws Exception { } private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Put put = new Put(partitionKey) - .withValue(new IntValue(ANY_NAME_2, ANY_INT_1)) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_2)) + .withValue(ANY_NAME_2, ANY_INT_1) + .withValue(ANY_NAME_3, ANY_INT_2) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); return put; } private Put preparePutWithClusteringKey() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Put put = new Put(partitionKey, clusteringKey) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)) + .withValue(ANY_NAME_3, ANY_INT_1) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); return put; 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 59348f8a31..968e294675 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 @@ -7,7 +7,6 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -24,7 +23,6 @@ import com.scalar.db.api.Scan; import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -60,20 +58,20 @@ public void setUp() throws Exception { } private Get prepareGet() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); return new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); } private Get prepareGetWithClusteringKey() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Get(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); } private Scan prepareScan() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); return new Scan(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); } @@ -204,8 +202,7 @@ public void prepare_ScanOperationWithSingleClusteringKey_ShouldPrepareProperQuer }); configureBehavior(expected); scan = prepareScan(); - scan.withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2))) - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3))); + scan.withStart(new Key(ANY_NAME_2, ANY_TEXT_2)).withEnd(new Key(ANY_NAME_2, ANY_TEXT_3)); // Act handler.prepare(scan); @@ -238,9 +235,15 @@ public void prepare_ScanOperationWithMultipleClusteringKeys_ShouldPrepareProperQ configureBehavior(expected); scan = prepareScan(); scan.withStart( - new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2), new TextValue(ANY_NAME_3, ANY_TEXT_3))) + Key.newBuilder() + .addText(ANY_NAME_2, ANY_TEXT_2) + .addText(ANY_NAME_3, ANY_TEXT_3) + .build()) .withEnd( - new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2), new TextValue(ANY_NAME_3, ANY_TEXT_4))); + Key.newBuilder() + .addText(ANY_NAME_2, ANY_TEXT_2) + .addText(ANY_NAME_3, ANY_TEXT_4) + .build()); // Act handler.prepare(scan); @@ -268,8 +271,8 @@ public void prepare_ScanOperationWithNeitherInclusive_ShouldPrepareProperQuery() }); configureBehavior(expected); scan = prepareScan(); - scan.withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)), false) - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3)), false); + scan.withStart(new Key(ANY_NAME_2, ANY_TEXT_2), false) + .withEnd(new Key(ANY_NAME_2, ANY_TEXT_3), false); // Act handler.prepare(scan); @@ -300,7 +303,7 @@ public void prepare_ScanOperationWithOrderingAndLimit_ShouldPrepareProperQuery() }); configureBehavior(expected); scan = prepareScan(); - scan.withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2))) + scan.withStart(new Key(ANY_NAME_2, ANY_TEXT_2)) .withOrdering(new Scan.Ordering(ANY_NAME_2, ASC_ORDER)) .withLimit(ANY_LIMIT); @@ -334,7 +337,7 @@ public void prepare_ScanOperationWithMultipleOrdering_ShouldPrepareProperQuery() }); configureBehavior(expected); scan = prepareScan(); - scan.withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2))) + scan.withStart(new Key(ANY_NAME_2, ANY_TEXT_2)) .withOrdering(new Scan.Ordering(ANY_NAME_2, ASC_ORDER)) .withOrdering(new Scan.Ordering(ANY_NAME_3, DESC_ORDER)) .withLimit(ANY_LIMIT); @@ -366,9 +369,15 @@ public void bind_ScanOperationWithMultipleClusteringKeysGiven_ShouldBindProperly configureBehavior(null); scan = prepareScan(); scan.withStart( - new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2), new TextValue(ANY_NAME_3, ANY_TEXT_3))) + Key.newBuilder() + .addText(ANY_NAME_2, ANY_TEXT_2) + .addText(ANY_NAME_3, ANY_TEXT_3) + .build()) .withEnd( - new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2), new TextValue(ANY_NAME_3, ANY_TEXT_4))); + Key.newBuilder() + .addText(ANY_NAME_2, ANY_TEXT_2) + .addText(ANY_NAME_3, ANY_TEXT_4) + .build()); // Act handler.bind(prepared, scan); diff --git a/core/src/test/java/com/scalar/db/storage/cassandra/UpdateStatementHandlerTest.java b/core/src/test/java/com/scalar/db/storage/cassandra/UpdateStatementHandlerTest.java index 2fccb5206b..d8890ea93a 100644 --- a/core/src/test/java/com/scalar/db/storage/cassandra/UpdateStatementHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/cassandra/UpdateStatementHandlerTest.java @@ -55,22 +55,22 @@ public void setUp() throws Exception { } private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Put put = new Put(partitionKey) - .withValue(new IntValue(ANY_NAME_2, ANY_INT_1)) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_2)) + .withValue(ANY_NAME_2, ANY_INT_1) + .withValue(ANY_NAME_3, ANY_INT_2) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); return put; } private Put preparePutWithClusteringKey() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Put put = new Put(partitionKey, clusteringKey) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)) + .withValue(ANY_NAME_3, ANY_INT_1) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); return put; diff --git a/core/src/test/java/com/scalar/db/storage/common/checker/OperationCheckerTest.java b/core/src/test/java/com/scalar/db/storage/common/checker/OperationCheckerTest.java index 78d514d10a..fe07d5ec89 100644 --- a/core/src/test/java/com/scalar/db/storage/common/checker/OperationCheckerTest.java +++ b/core/src/test/java/com/scalar/db/storage/common/checker/OperationCheckerTest.java @@ -79,8 +79,8 @@ public void setUp() throws Exception { @Test public void whenCheckingOperationWithWrongTable_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val2")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val2").build(); List projections = Arrays.asList(COL1, COL2, COL3); Get get = new Get(partitionKey, clusteringKey).withProjections(projections); Utility.setTargetToIfNot(get, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -96,8 +96,8 @@ public void whenCheckingOperationWithWrongTable_shouldThrowIllegalArgumentExcept @Test public void whenCheckingGetOperationWithAllValidArguments_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val2")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val2").build(); List projections = Arrays.asList(COL1, COL2, COL3); Get get = new Get(partitionKey, clusteringKey).withProjections(projections); Utility.setTargetToIfNot(get, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -109,8 +109,8 @@ public void whenCheckingGetOperationWithAllValidArguments_shouldNotThrowAnyExcep @Test public void whenCheckingGetOperationWithInvalidProjections_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val2")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val2").build(); List projections = Arrays.asList(COL1, COL2, "v4"); Get get = new Get(partitionKey, clusteringKey).withProjections(projections); Utility.setTargetToIfNot(get, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -124,8 +124,8 @@ public void whenCheckingGetOperationWithInvalidProjections_shouldThrowIllegalArg public void whenCheckingGetOperationWithInvalidPartitionKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue("p3", "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val2")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText("p3", "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val2").build(); List projections = Arrays.asList(COL1, COL2, COL3); Get get = new Get(partitionKey, clusteringKey).withProjections(projections); Utility.setTargetToIfNot(get, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -139,8 +139,8 @@ public void whenCheckingGetOperationWithInvalidProjections_shouldThrowIllegalArg public void whenCheckingGetOperationWithInvalidPartitionKeyType_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new TextValue(PKEY1, "1"), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val2")); + Key partitionKey = Key.newBuilder().addText(PKEY1, "1").addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val2").build(); List projections = Arrays.asList(COL1, COL2, COL3); Get get = new Get(partitionKey, clusteringKey).withProjections(projections); Utility.setTargetToIfNot(get, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -154,8 +154,8 @@ public void whenCheckingGetOperationWithInvalidProjections_shouldThrowIllegalArg public void whenCheckingGetOperationWithInvalidClusteringKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue("c3", "val2")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText("c3", "val2").build(); List projections = Arrays.asList(COL1, COL2, COL3); Get get = new Get(partitionKey, clusteringKey).withProjections(projections); Utility.setTargetToIfNot(get, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -169,8 +169,8 @@ public void whenCheckingGetOperationWithInvalidProjections_shouldThrowIllegalArg public void whenCheckingGetOperationWithInvalidClusteringKeyType_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new TextValue(CKEY1, "2"), new TextValue(CKEY2, "val2")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addText(CKEY1, "2").addText(CKEY2, "val2").build(); List projections = Arrays.asList(COL1, COL2, COL3); Get get = new Get(partitionKey, clusteringKey).withProjections(projections); Utility.setTargetToIfNot(get, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -184,7 +184,7 @@ public void whenCheckingGetOperationWithInvalidProjections_shouldThrowIllegalArg public void whenCheckingGetOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); Key clusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); Get get = new Get(partitionKey, clusteringKey).withProjections(projections); @@ -198,9 +198,9 @@ public void whenCheckingGetOperationWithInvalidProjections_shouldThrowIllegalArg @Test public void whenCheckingScanOperationWithAllValidArguments_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key startClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - Key endClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val9")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key startClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); + Key endClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val9").build(); List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = @@ -220,7 +220,7 @@ public void whenCheckingScanOperationWithAllValidArguments_shouldNotThrowAnyExce @Test public void whenCheckingScanOperationWithoutAnyClusteringKey_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); Key startClusteringKey = null; Key endClusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); @@ -242,9 +242,9 @@ public void whenCheckingScanOperationWithoutAnyClusteringKey_shouldNotThrowAnyEx @Test public void whenCheckingScanOperationWithPartialClusteringKey_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key startClusteringKey = new Key(new IntValue(CKEY1, 1)); - Key endClusteringKey = new Key(new IntValue(CKEY1, 9)); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key startClusteringKey = new Key(CKEY1, 1); + Key endClusteringKey = new Key(CKEY1, 9); List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = @@ -264,8 +264,8 @@ public void whenCheckingScanOperationWithPartialClusteringKey_shouldNotThrowAnyE @Test public void whenCheckingScanOperationWithoutAnyEndClusteringKey_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key startClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key startClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); Key endClusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; @@ -286,9 +286,9 @@ public void whenCheckingScanOperationWithoutAnyEndClusteringKey_shouldNotThrowAn @Test public void whenCheckingScanOperationWithReverseOrderings_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key startClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - Key endClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val9")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key startClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); + Key endClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val9").build(); List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = @@ -308,9 +308,9 @@ public void whenCheckingScanOperationWithReverseOrderings_shouldNotThrowAnyExcep @Test public void whenCheckingScanOperationWithPartialOrdering_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key startClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - Key endClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val9")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key startClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); + Key endClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val9").build(); List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = @@ -329,9 +329,9 @@ public void whenCheckingScanOperationWithPartialOrdering_shouldNotThrowAnyExcept @Test public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key startClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - Key endClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val9")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key startClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); + Key endClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val9").build(); List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = @@ -350,9 +350,9 @@ public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyExceptio public void whenCheckingScanOperationWithInvalidProjections_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key startClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - Key endClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val9")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key startClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); + Key endClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val9").build(); List projections = Arrays.asList(COL1, COL2, "v4"); int limit = 10; Scan scan = @@ -374,9 +374,9 @@ public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyExceptio public void whenCheckingScanOperationWithInvalidPartitionKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue("p3", "val1")); - Key startClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - Key endClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val9")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText("p3", "val1").build(); + Key startClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); + Key endClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val9").build(); List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = @@ -398,9 +398,9 @@ public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyExceptio public void whenCheckingScanOperationWithInvalidClusteringKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key startClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue("c3", "val1")); - Key endClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue("c3", "val9")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key startClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText("c3", "val1").build(); + Key endClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText("c3", "val9").build(); List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = @@ -422,9 +422,9 @@ public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyExceptio public void whenCheckingScanOperationWithInvalidClusteringKeyRange_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key startClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - Key endClusteringKey = new Key(new IntValue(CKEY1, 2)); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key startClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); + Key endClusteringKey = new Key(CKEY1, 2); List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = @@ -446,9 +446,9 @@ public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyExceptio public void whenCheckingScanOperationWithNegativeLimitNumber_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key startClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - Key endClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val9")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key startClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); + Key endClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val9").build(); List projections = Arrays.asList(COL1, COL2, COL3); int limit = -10; Scan scan = @@ -469,9 +469,9 @@ public void whenCheckingScanOperationWithEmptyOrdering_shouldNotThrowAnyExceptio @Test public void whenCheckingScanOperationWithInvalidOrderings_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key startClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - Key endClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val9")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key startClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); + Key endClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val9").build(); List projections = Arrays.asList(COL1, COL2, COL3); int limit = -10; Scan scan = @@ -493,9 +493,9 @@ public void whenCheckingScanOperationWithInvalidOrderings_shouldThrowIllegalArgu public void whenCheckingScanOperationWithInvalidPartialOrdering_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key startClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - Key endClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val9")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key startClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); + Key endClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val9").build(); List projections = Arrays.asList(COL1, COL2, COL3); int limit = -10; Scan scan = @@ -515,8 +515,8 @@ public void whenCheckingScanOperationWithInvalidOrderings_shouldThrowIllegalArgu @Test public void whenCheckingPutOperationWithAllValidArguments_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); @@ -531,8 +531,8 @@ public void whenCheckingPutOperationWithAllValidArguments_shouldNotThrowAnyExcep @Test public void whenCheckingPutOperationWithoutAnyCondition_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); @@ -548,8 +548,8 @@ public void whenCheckingPutOperationWithoutAnyCondition_shouldNotThrowAnyExcepti public void whenCheckingPutOperationWithInvalidPartitionKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue("c3", "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText("c3", "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); @@ -566,8 +566,8 @@ public void whenCheckingPutOperationWithoutAnyCondition_shouldNotThrowAnyExcepti public void whenCheckingPutOperationWithInvalidClusteringKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue("c3", "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText("c3", "val1").build(); List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); @@ -584,7 +584,7 @@ public void whenCheckingPutOperationWithoutAnyCondition_shouldNotThrowAnyExcepti public void whenCheckingPutOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); Key clusteringKey = null; List> values = Arrays.asList( @@ -601,8 +601,8 @@ public void whenCheckingPutOperationWithoutAnyCondition_shouldNotThrowAnyExcepti @Test public void whenCheckingPutOperationWithInvalidValues_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue("v4", true)); @@ -618,8 +618,8 @@ public void whenCheckingPutOperationWithInvalidValues_shouldThrowIllegalArgument @Test public void whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); List> values = Arrays.asList( new TextValue(COL1, "1"), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); @@ -636,8 +636,8 @@ public void whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgum public void whenCheckingPutOperationWithInvalidPutIfCondition_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); @@ -656,8 +656,8 @@ public void whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgum public void whenCheckingPutOperationWithDeleteIfExistsCondition_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); @@ -673,8 +673,8 @@ public void whenCheckingPutOperationWithInvalidValueType_shouldThrowIllegalArgum @Test public void whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); List> values = Arrays.asList( new IntValue(COL1, 1), new DoubleValue(COL2, 0.1), new BooleanValue(COL3, true)); @@ -690,8 +690,8 @@ public void whenCheckingPutOperationWithDeleteIfCondition_shouldThrowIllegalArgu @Test public void whenCheckingDeleteOperationWithAllValidArguments_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); MutationCondition condition = new DeleteIf( new ConditionalExpression(COL1, new IntValue(1), ConditionalExpression.Operator.EQ)); @@ -705,8 +705,8 @@ public void whenCheckingDeleteOperationWithAllValidArguments_shouldNotThrowAnyEx @Test public void whenCheckingDeleteOperationWithoutAnyCondition_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); MutationCondition condition = null; Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition); Utility.setTargetToIfNot(delete, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -719,8 +719,8 @@ public void whenCheckingDeleteOperationWithoutAnyCondition_shouldNotThrowAnyExce public void whenCheckingDeleteOperationWithInvalidPartitionKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue("p3", "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText("p3", "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); MutationCondition condition = new DeleteIfExists(); Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition); Utility.setTargetToIfNot(delete, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -734,8 +734,8 @@ public void whenCheckingDeleteOperationWithoutAnyCondition_shouldNotThrowAnyExce public void whenCheckingDeleteOperationWithInvalidClusteringKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue("c3", "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText("c3", "val1").build(); MutationCondition condition = new DeleteIfExists(); Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition); Utility.setTargetToIfNot(delete, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -749,7 +749,7 @@ public void whenCheckingDeleteOperationWithoutAnyCondition_shouldNotThrowAnyExce public void whenCheckingDeleteOperationWithoutAnyClusteringKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); Key clusteringKey = null; MutationCondition condition = new DeleteIfExists(); Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition); @@ -763,8 +763,8 @@ public void whenCheckingDeleteOperationWithoutAnyCondition_shouldNotThrowAnyExce @Test public void whenCheckingDeleteOperationWithPutIfCondition_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); MutationCondition condition = new PutIf(); Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition); Utility.setTargetToIfNot(delete, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -778,8 +778,8 @@ public void whenCheckingDeleteOperationWithPutIfCondition_shouldThrowIllegalArgu public void whenCheckingDeleteOperationWithPutIfExistsCondition_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); MutationCondition condition = new PutIfExists(); Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition); Utility.setTargetToIfNot(delete, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -793,8 +793,8 @@ public void whenCheckingDeleteOperationWithPutIfCondition_shouldThrowIllegalArgu public void whenCheckingDeleteOperationWithPutIfNotExistsCondition_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); MutationCondition condition = new PutIfNotExists(); Delete delete = new Delete(partitionKey, clusteringKey).withCondition(condition); Utility.setTargetToIfNot(delete, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -808,8 +808,8 @@ public void whenCheckingDeleteOperationWithPutIfCondition_shouldThrowIllegalArgu public void whenCheckingDeleteOperationWithInvalidDeleteIfCondition_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); MutationCondition condition = new DeleteIf( new ConditionalExpression(COL1, new TextValue("1"), ConditionalExpression.Operator.EQ)); @@ -824,9 +824,9 @@ public void whenCheckingDeleteOperationWithPutIfCondition_shouldThrowIllegalArgu @Test public void whenCheckingMutateOperationWithAllValidArguments_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val1")); - Put put = new Put(partitionKey, clusteringKey).withValue(new IntValue(COL1, 1)); + Key partitionKey = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val1").build(); + Put put = new Put(partitionKey, clusteringKey).withValue(COL1, 1); Utility.setTargetToIfNot(put, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); Delete delete = new Delete(partitionKey, clusteringKey); Utility.setTargetToIfNot(delete, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -849,10 +849,10 @@ public void whenCheckingMutateOperationWithEmptyMutations_shouldThrowIllegalArgu public void whenCheckingMutateOperationWithMutationsWithDifferentPartitionKeysWithNotAllowPartitions_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey1 = new Key(new IntValue(PKEY1, 1), new TextValue(PKEY2, "val1")); - Key partitionKey2 = new Key(new IntValue(PKEY1, 2), new TextValue(PKEY2, "val2")); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val3")); - Put put = new Put(partitionKey1, clusteringKey).withValue(new IntValue(COL1, 1)); + Key partitionKey1 = Key.newBuilder().addInt(PKEY1, 1).addText(PKEY2, "val1").build(); + Key partitionKey2 = Key.newBuilder().addInt(PKEY1, 2).addText(PKEY2, "val2").build(); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val3").build(); + Put put = new Put(partitionKey1, clusteringKey).withValue(COL1, 1); Utility.setTargetToIfNot(put, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); Delete delete = new Delete(partitionKey2, clusteringKey); Utility.setTargetToIfNot(delete, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -865,7 +865,7 @@ public void whenCheckingMutateOperationWithEmptyMutations_shouldThrowIllegalArgu @Test public void whenCheckingGetOperationWithIndexedColumnAsPartitionKey_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(COL1, 1)); + Key partitionKey = new Key(COL1, 1); Key clusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); Get get = new Get(partitionKey, clusteringKey).withProjections(projections); @@ -879,7 +879,7 @@ public void whenCheckingGetOperationWithIndexedColumnAsPartitionKey_shouldNotThr public void whenCheckingGetOperationWithNonIndexedColumnAsPartitionKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new DoubleValue(COL2, 0.1)); + Key partitionKey = new Key(COL2, 0.1d); Key clusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); Get get = new Get(partitionKey, clusteringKey).withProjections(projections); @@ -894,7 +894,7 @@ public void whenCheckingGetOperationWithIndexedColumnAsPartitionKey_shouldNotThr public void whenCheckingGetOperationWithIndexedColumnAsPartitionKeyButWrongType_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new TextValue(COL1, "1")); + Key partitionKey = new Key(COL1, "1"); Key clusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); Get get = new Get(partitionKey, clusteringKey).withProjections(projections); @@ -909,8 +909,8 @@ public void whenCheckingGetOperationWithIndexedColumnAsPartitionKey_shouldNotThr public void whenCheckingGetOperationWithIndexedColumnAsPartitionKeyWithClusteringKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(COL1, 1)); - Key clusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue(CKEY2, "val2")); + Key partitionKey = new Key(COL1, 1); + Key clusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText(CKEY2, "val2").build(); List projections = Arrays.asList(COL1, COL2, COL3); Get get = new Get(partitionKey, clusteringKey).withProjections(projections); Utility.setTargetToIfNot(get, NAMESPACE_PREFIX, NAMESPACE, TABLE_NAME); @@ -924,7 +924,7 @@ public void whenCheckingGetOperationWithIndexedColumnAsPartitionKey_shouldNotThr public void whenCheckingScanOperationWithIndexedColumnAsPartitionKey_shouldNotThrowAnyException() { // Arrange - Key partitionKey = new Key(new IntValue(COL1, 1)); + Key partitionKey = new Key(COL1, 1); Key startClusteringKey = null; Key endClusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); @@ -945,7 +945,7 @@ public void whenCheckingGetOperationWithIndexedColumnAsPartitionKey_shouldNotThr public void whenCheckingScanOperationWithNonIndexedColumnAsPartitionKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new DoubleValue(COL2, 0.1)); + Key partitionKey = new Key(COL2, 0.1d); Key startClusteringKey = null; Key endClusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); @@ -967,7 +967,7 @@ public void whenCheckingGetOperationWithIndexedColumnAsPartitionKey_shouldNotThr public void whenCheckingScanOperationWithIndexedColumnAsPartitionKeyButWrongType_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new TextValue(COL1, "1")); + Key partitionKey = new Key(COL1, "1"); Key startClusteringKey = null; Key endClusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); @@ -989,9 +989,9 @@ public void whenCheckingGetOperationWithIndexedColumnAsPartitionKey_shouldNotThr public void whenCheckingScanOperationWithIndexedColumnAsPartitionKeyWithClusteringKey_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(COL1, 1)); - Key startClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue("c3", "val1")); - Key endClusteringKey = new Key(new IntValue(CKEY1, 2), new TextValue("c3", "val9")); + Key partitionKey = new Key(COL1, 1); + Key startClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText("c3", "val1").build(); + Key endClusteringKey = Key.newBuilder().addInt(CKEY1, 2).addText("c3", "val9").build(); List projections = Arrays.asList(COL1, COL2, COL3); int limit = 10; Scan scan = @@ -1011,7 +1011,7 @@ public void whenCheckingGetOperationWithIndexedColumnAsPartitionKey_shouldNotThr public void whenCheckingScanOperationWithIndexedColumnAsPartitionKeyWithOrderings_shouldThrowIllegalArgumentException() { // Arrange - Key partitionKey = new Key(new IntValue(COL1, 1)); + Key partitionKey = new Key(COL1, 1); Key startClusteringKey = null; Key endClusteringKey = null; List projections = Arrays.asList(COL1, COL2, COL3); diff --git a/core/src/test/java/com/scalar/db/storage/cosmos/BatchHandlerTest.java b/core/src/test/java/com/scalar/db/storage/cosmos/BatchHandlerTest.java index 6aff8f9e16..2f748b42f7 100644 --- a/core/src/test/java/com/scalar/db/storage/cosmos/BatchHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/cosmos/BatchHandlerTest.java @@ -26,9 +26,7 @@ import com.scalar.db.api.TableMetadata; import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.storage.NoMutationException; -import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; @@ -75,21 +73,21 @@ public void setUp() throws Exception { } private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Put put = new Put(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)) - .withValue(new IntValue(ANY_NAME_4, ANY_INT_2)); + .withValue(ANY_NAME_3, ANY_INT_1) + .withValue(ANY_NAME_4, ANY_INT_2); return put; } private Delete prepareDelete() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Delete del = new Delete(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) 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 b7fdaaabd8..19d104ffce 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 @@ -13,7 +13,6 @@ import com.scalar.db.api.TableMetadata; import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; @@ -49,21 +48,21 @@ public void setUp() throws Exception { } private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Put put = new Put(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)) - .withValue(new IntValue(ANY_NAME_4, ANY_INT_2)); + .withValue(ANY_NAME_3, ANY_INT_1) + .withValue(ANY_NAME_4, ANY_INT_2); return put; } private Delete prepareDelete() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Delete del = new Delete(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) @@ -125,7 +124,7 @@ public void makeConditionalQuery_MutationWithoutClusteringKeyGiven_ShouldReturnQ when(metadata.getClusteringKeyNames()) .thenReturn(new LinkedHashSet<>(Collections.singletonList(ANY_NAME_2))); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Delete delete = new Delete(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); @@ -149,8 +148,8 @@ public void makeConditionalQuery_MutationWithoutAllClusteringKeyGiven_ShouldRetu when(metadata.getClusteringKeyNames()) .thenReturn(new LinkedHashSet<>(Arrays.asList(ANY_NAME_2, ANY_NAME_3))); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Delete delete = new Delete(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) 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 19dd51d76d..77f35fbba6 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 @@ -12,9 +12,7 @@ import com.scalar.db.api.Operation; import com.scalar.db.api.Put; import com.scalar.db.api.TableMetadata; -import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; @@ -63,7 +61,7 @@ public void isPrimaryKeySpecified_PrimaryKeyWithoutClusteringKeyGiven_ShouldRetu when(metadata.getClusteringKeyNames()).thenReturn(new LinkedHashSet<>()); Key partitionKey = - new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1), new IntValue(ANY_NAME_3, ANY_INT_1)); + Key.newBuilder().addText(ANY_NAME_1, ANY_TEXT_1).addInt(ANY_NAME_3, ANY_INT_1).build(); Get get = new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); CosmosOperation cosmosOperation = new CosmosOperation(get, metadataManager); @@ -81,8 +79,8 @@ public void isPrimaryKeySpecified_PrimaryKeyWithClusteringKeyGiven_ShouldReturnT .thenReturn(new LinkedHashSet<>(Collections.singletonList(ANY_NAME_2))); Key partitionKey = - new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1), new IntValue(ANY_NAME_3, ANY_INT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key.newBuilder().addText(ANY_NAME_1, ANY_TEXT_1).addInt(ANY_NAME_3, ANY_INT_1).build(); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Get get = new Get(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) @@ -103,7 +101,7 @@ public void isPrimaryKeySpecified_NoClusteringKeyGiven_ShouldReturnTrue() { .thenReturn(new LinkedHashSet<>(Collections.singletonList(ANY_NAME_2))); Key partitionKey = - new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1), new IntValue(ANY_NAME_3, ANY_INT_1)); + Key.newBuilder().addText(ANY_NAME_1, ANY_TEXT_1).addInt(ANY_NAME_3, ANY_INT_1).build(); Delete delete = new Delete(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); CosmosOperation cosmosOperation = new CosmosOperation(delete, metadataManager); @@ -122,10 +120,11 @@ public void getConcatenatedPartitionKey_MultipleKeysGiven_ShouldReturnConcatenat .thenReturn(new LinkedHashSet<>(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_NAME_3))); Key partitionKey = - new Key( - new TextValue(ANY_NAME_1, ANY_TEXT_1), - new TextValue(ANY_NAME_2, ANY_TEXT_2), - new IntValue(ANY_NAME_3, ANY_INT_1)); + Key.newBuilder() + .addText(ANY_NAME_1, ANY_TEXT_1) + .addText(ANY_NAME_2, ANY_TEXT_2) + .addInt(ANY_NAME_3, ANY_INT_1) + .build(); Get get = new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); CosmosOperation cosmosOperation = new CosmosOperation(get, metadataManager); @@ -143,10 +142,11 @@ public void getCosmosPartitionKey_MultipleKeysGiven_ShouldReturnPartitionKey() { .thenReturn(new LinkedHashSet<>(Arrays.asList(ANY_NAME_1, ANY_NAME_2, ANY_NAME_3))); Key partitionKey = - new Key( - new TextValue(ANY_NAME_1, ANY_TEXT_1), - new TextValue(ANY_NAME_2, ANY_TEXT_2), - new IntValue(ANY_NAME_3, ANY_INT_1)); + Key.newBuilder() + .addText(ANY_NAME_1, ANY_TEXT_1) + .addText(ANY_NAME_2, ANY_TEXT_2) + .addInt(ANY_NAME_3, ANY_INT_1) + .build(); Get get = new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); CosmosOperation cosmosOperation = new CosmosOperation(get, metadataManager); @@ -166,8 +166,8 @@ public void getId_MultipleKeysGiven_ShouldReturnConcatenatedPartitionKey() { .thenReturn(new LinkedHashSet<>(Collections.singletonList(ANY_NAME_2))); Key partitionKey = - new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1), new IntValue(ANY_NAME_3, ANY_INT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key.newBuilder().addText(ANY_NAME_1, ANY_TEXT_1).addInt(ANY_NAME_3, ANY_INT_1).build(); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Get get = new Get(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) diff --git a/core/src/test/java/com/scalar/db/storage/cosmos/CosmosTableMetadataManagerTest.java b/core/src/test/java/com/scalar/db/storage/cosmos/CosmosTableMetadataManagerTest.java index ed6ccb14f1..be5695655e 100644 --- a/core/src/test/java/com/scalar/db/storage/cosmos/CosmosTableMetadataManagerTest.java +++ b/core/src/test/java/com/scalar/db/storage/cosmos/CosmosTableMetadataManagerTest.java @@ -18,7 +18,6 @@ import com.scalar.db.api.Get; import com.scalar.db.exception.storage.StorageRuntimeException; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Collections; import java.util.LinkedHashSet; import org.junit.Before; @@ -58,7 +57,7 @@ public void getTableMetadata_ProperOperationGivenFirst_ShouldCallReadItem() { .thenReturn(response); when(response.getItem()).thenReturn(metadata); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Get get = new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); // Act @@ -74,9 +73,9 @@ public void getTableMetadata_SameTableGiven_ShouldCallReadItemOnce() { .thenReturn(response); when(response.getItem()).thenReturn(metadata); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Get get1 = new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); - Key partitionKey2 = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_2)); + Key partitionKey2 = new Key(ANY_NAME_1, ANY_TEXT_2); Get get2 = new Get(partitionKey2).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); // Act @@ -94,7 +93,7 @@ public void getTableMetadata_OperationWithoutTableGiven_ShouldThrowIllegalArgume .thenReturn(response); when(response.getItem()).thenReturn(metadata); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Get get = new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME); // Act Assert @@ -113,7 +112,7 @@ public void getTableMetadata_CosmosExceptionThrown_ShouldThrowStorageRuntimeExce .when(container) .readItem(anyString(), any(PartitionKey.class), eq(CosmosTableMetadata.class)); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Get get = new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); // Act Assert 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 1409a0b43f..041f74b133 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 @@ -29,7 +29,6 @@ import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.storage.NoMutationException; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; @@ -76,8 +75,8 @@ public void setUp() throws Exception { } private Delete prepareDelete() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); id = ANY_TEXT_1 + ":" + ANY_TEXT_2; cosmosPartitionKey = new PartitionKey(ANY_TEXT_1); Delete del = @@ -136,7 +135,7 @@ public void handle_DeleteWithoutClusteringKeyGiven_ShouldCallStoredProcedure() { when(storedProcedure.execute(any(List.class), any(CosmosStoredProcedureRequestOptions.class))) .thenReturn(spResponse); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); cosmosPartitionKey = new PartitionKey(ANY_TEXT_1); Delete delete = new Delete(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); 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 e61950bbbb..828091a0ab 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 @@ -25,9 +25,7 @@ import com.scalar.db.api.TableMetadata; import com.scalar.db.exception.storage.NoMutationException; import com.scalar.db.exception.storage.RetriableExecutionException; -import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; @@ -73,14 +71,14 @@ public void setUp() throws Exception { } private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Put put = new Put(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)) - .withValue(new IntValue(ANY_NAME_4, ANY_INT_2)); + .withValue(ANY_NAME_3, ANY_INT_1) + .withValue(ANY_NAME_4, ANY_INT_2); return put; } @@ -126,13 +124,13 @@ public void handle_PutWithoutClusteringKeyGiven_ShouldCallStoredProcedure() { .thenReturn(spResponse); when(spResponse.getResponseAsString()).thenReturn("true"); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Put put = new Put(partitionKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)) - .withValue(new IntValue(ANY_NAME_4, ANY_INT_2)); + .withValue(ANY_NAME_3, ANY_INT_1) + .withValue(ANY_NAME_4, ANY_INT_2); CosmosMutation cosmosMutation = new CosmosMutation(put, metadataManager); Record record = cosmosMutation.makeRecord(); String query = cosmosMutation.makeConditionalQuery(); 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 fbed17c19f..50131b8b43 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.TableMetadata; import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; @@ -78,8 +77,8 @@ public void setUp() throws Exception { } private Get prepareGet() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); id = ANY_TEXT_1 + ":" + ANY_TEXT_2; cosmosPartitionKey = new PartitionKey(ANY_TEXT_1); return new Get(partitionKey, clusteringKey) @@ -88,7 +87,7 @@ private Get prepareGet() { } private Scan prepareScan() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); return new Scan(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); } @@ -119,7 +118,7 @@ public void handle_GetOperationWithIndexGiven_ShouldCallQueryItems() { .thenReturn(responseIterable); Record expected = new Record(); when(responseIterable.iterator()).thenReturn(Arrays.asList(expected).iterator()); - Key indexKey = new Key(new TextValue(ANY_NAME_3, ANY_TEXT_3)); + Key indexKey = new Key(ANY_NAME_3, ANY_TEXT_3); Get get = new Get(indexKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); String query = "select * from Record r where r.values." + ANY_NAME_3 + " = '" + ANY_TEXT_3 + "'"; @@ -202,7 +201,7 @@ public void handle_ScanOperationWithIndexGiven_ShouldCallQueryItems() { Record expected = new Record(); when(responseIterable.iterator()).thenReturn(Arrays.asList(expected).iterator()); - Key indexKey = new Key(new TextValue(ANY_NAME_3, ANY_TEXT_3)); + Key indexKey = new Key(ANY_NAME_3, ANY_TEXT_3); Scan scan = new Scan(indexKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); String query = "select * from Record r where r.values." + ANY_NAME_3 + " = '" + ANY_TEXT_3 + "'"; @@ -247,8 +246,8 @@ public void handle_ScanOperationWithSingleClusteringKey_ShouldCallQueryItemsWith Scan scan = prepareScan() - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2))) - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3))); + .withStart(new Key(ANY_NAME_2, ANY_TEXT_2)) + .withEnd(new Key(ANY_NAME_2, ANY_TEXT_3)); String query = "select * from Record r where (r.concatenatedPartitionKey = '" @@ -285,11 +284,15 @@ public void handle_ScanOperationWithMultipleClusteringKeys_ShouldCallQueryItemsW Scan scan = prepareScan() .withStart( - new Key( - new TextValue(ANY_NAME_2, ANY_TEXT_2), new TextValue(ANY_NAME_3, ANY_TEXT_3))) + Key.newBuilder() + .addText(ANY_NAME_2, ANY_TEXT_2) + .addText(ANY_NAME_3, ANY_TEXT_3) + .build()) .withEnd( - new Key( - new TextValue(ANY_NAME_2, ANY_TEXT_2), new TextValue(ANY_NAME_3, ANY_TEXT_4))); + Key.newBuilder() + .addText(ANY_NAME_2, ANY_TEXT_2) + .addText(ANY_NAME_3, ANY_TEXT_4) + .build()); String query = "select * from Record r where (r.concatenatedPartitionKey = '" @@ -333,8 +336,8 @@ public void handle_ScanOperationWithNeitherInclusive_ShouldCallQueryItemsWithPro Scan scan = prepareScan() - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)), false) - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3)), false); + .withStart(new Key(ANY_NAME_2, ANY_TEXT_2), false) + .withEnd(new Key(ANY_NAME_2, ANY_TEXT_3), false); String query = "select * from Record r where (r.concatenatedPartitionKey = '" @@ -370,7 +373,7 @@ public void handle_ScanOperationWithOrderingAndLimit_ShouldCallQueryItemsWithPro Scan scan = prepareScan() - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2))) + .withStart(new Key(ANY_NAME_2, ANY_TEXT_2)) .withOrdering(new Scan.Ordering(ANY_NAME_2, ASC_ORDER)) .withLimit(ANY_LIMIT); @@ -407,7 +410,7 @@ public void handle_ScanOperationWithMultipleOrdering_ShouldCallQueryItemsWithPro Scan scan = prepareScan() - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2))) + .withStart(new Key(ANY_NAME_2, ANY_TEXT_2)) .withOrdering(new Scan.Ordering(ANY_NAME_2, ASC_ORDER)) .withOrdering(new Scan.Ordering(ANY_NAME_3, DESC_ORDER)) .withLimit(ANY_LIMIT); diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/BatchHandlerTest.java b/core/src/test/java/com/scalar/db/storage/dynamo/BatchHandlerTest.java index 236802a4a9..70886b1e00 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/BatchHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/BatchHandlerTest.java @@ -17,9 +17,7 @@ import com.scalar.db.api.TableMetadata; import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.storage.NoMutationException; -import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -71,21 +69,21 @@ public void setUp() throws Exception { } private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Put put = new Put(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)) - .withValue(new IntValue(ANY_NAME_4, ANY_INT_2)); + .withValue(ANY_NAME_3, ANY_INT_1) + .withValue(ANY_NAME_4, ANY_INT_2); return put; } private Delete prepareDelete() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Delete del = new Delete(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) @@ -166,14 +164,14 @@ public void handle_MultiPartitionOperationsGiven_ShouldCallTransactWriteItems() .thenReturn(transactWriteResponse); Put put1 = preparePut(); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_3)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_3); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_3); Put put2 = new Put(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)) - .withValue(new IntValue(ANY_NAME_4, ANY_INT_2)); + .withValue(ANY_NAME_3, ANY_INT_1) + .withValue(ANY_NAME_4, ANY_INT_2); // Act Assert assertThatCode( diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/DeleteStatementHandlerTest.java b/core/src/test/java/com/scalar/db/storage/dynamo/DeleteStatementHandlerTest.java index bbd3a990fa..f63b78425e 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/DeleteStatementHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/DeleteStatementHandlerTest.java @@ -16,7 +16,6 @@ import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.storage.NoMutationException; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Collections; import java.util.LinkedHashSet; import org.junit.Before; @@ -56,8 +55,8 @@ public void setUp() throws Exception { } private Delete prepareDelete() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Delete del = new Delete(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) @@ -112,7 +111,7 @@ public void handle_DeleteWithoutClusteringKeyGiven_ShouldCallDeleteItem() { .thenReturn(new LinkedHashSet<>(Collections.singletonList(ANY_NAME_2))); when(client.deleteItem(any(DeleteItemRequest.class))).thenReturn(response); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Delete delete = new Delete(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); 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 5eff56b8af..c7a76b9e22 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 @@ -13,7 +13,6 @@ import com.scalar.db.api.TableMetadata; import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashSet; @@ -51,14 +50,14 @@ public void setUp() throws Exception { } private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Put put = new Put(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)) - .withValue(new IntValue(ANY_NAME_4, ANY_INT_2)); + .withValue(ANY_NAME_3, ANY_INT_1) + .withValue(ANY_NAME_4, ANY_INT_2); return put; } 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 88a8c34d09..47f0e7f037 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 @@ -8,7 +8,6 @@ import com.scalar.db.api.Operation; import com.scalar.db.api.TableMetadata; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashSet; @@ -42,8 +41,8 @@ public void setUp() throws Exception { } private Get prepareGet() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Get get = new Get(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoTableMetadataManagerTest.java b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoTableMetadataManagerTest.java index 543ee4a1fc..05fab1f46a 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoTableMetadataManagerTest.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoTableMetadataManagerTest.java @@ -12,7 +12,6 @@ import com.scalar.db.api.Get; import com.scalar.db.exception.storage.StorageRuntimeException; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -73,7 +72,7 @@ public void getTableMetadata_ProperOperationGivenFirst_ShouldCallGetItem() { when(client.getItem(any(GetItemRequest.class))).thenReturn(response); when(response.item()).thenReturn(metadataMap); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Get get = new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); Map expectedKey = new HashMap<>(); expectedKey.put("table", AttributeValue.builder().s(FULLNAME).build()); @@ -96,7 +95,7 @@ public void getTableMetadata_ProperOperationGivenFirstWithPrefix_ShouldCallGetIt when(response.item()).thenReturn(metadataMap); manager = new DynamoTableMetadataManager(client, Optional.of("prefix_")); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Get get = new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); Map expectedKey = new HashMap<>(); expectedKey.put("table", AttributeValue.builder().s(FULLNAME).build()); @@ -118,9 +117,9 @@ public void getTableMetadata_SameTableGiven_ShouldCallReadItemOnce() { when(client.getItem(any(GetItemRequest.class))).thenReturn(response); when(response.item()).thenReturn(metadataMap); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Get get1 = new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); - Key partitionKey2 = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_2)); + Key partitionKey2 = new Key(ANY_NAME_1, ANY_TEXT_2); Get get2 = new Get(partitionKey2).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); // Act @@ -136,7 +135,7 @@ public void getTableMetadata_OperationWithoutTableGiven_ShouldThrowIllegalArgume when(client.getItem(any(GetItemRequest.class))).thenReturn(response); when(response.item()).thenReturn(metadataMap); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Get get = new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME); // Act Assert @@ -153,7 +152,7 @@ public void getTableMetadata_CosmosExceptionThrown_ShouldThrowStorageRuntimeExce DynamoDbException toThrow = mock(DynamoDbException.class); doThrow(toThrow).when(client).getItem(any(GetItemRequest.class)); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Get get = new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); // Act Assert diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/ItemSorterTest.java b/core/src/test/java/com/scalar/db/storage/dynamo/ItemSorterTest.java index 9dbf309f54..58fa3430ac 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/ItemSorterTest.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/ItemSorterTest.java @@ -6,7 +6,6 @@ import com.scalar.db.api.TableMetadata; import com.scalar.db.io.DataType; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; @@ -94,7 +93,7 @@ public void sort_ItemsGivenWithoutOrderingAndLimit_ShouldNotSort() { Map item1 = prepareItemWithSmallValues(); item1.put(ANY_NAME_2, AttributeValue.builder().n(String.valueOf(ANY_LARGE_INT)).build()); Map item2 = prepareItemWithSmallValues(); - Scan scan = new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))); + Scan scan = new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)); List> items = new ArrayList<>(); items.add(item1); items.add(item2); @@ -115,7 +114,7 @@ public void sort_ItemsGivenWithAscOrderingInt_ShouldSortProperly() { item1.put(ANY_NAME_2, AttributeValue.builder().n(String.valueOf(ANY_LARGE_INT)).build()); Map item2 = prepareItemWithSmallValues(); Scan scan = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) .withOrdering(new Scan.Ordering(ANY_NAME_2, Scan.Ordering.Order.ASC)); List> items = new ArrayList<>(); items.add(item1); @@ -137,7 +136,7 @@ public void sort_ItemsGivenWithDescOrderingInt_ShouldSortProperly() { Map item2 = prepareItemWithSmallValues(); item2.put(ANY_NAME_2, AttributeValue.builder().n(String.valueOf(ANY_LARGE_INT)).build()); Scan scan = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) .withOrdering(new Scan.Ordering(ANY_NAME_2, Scan.Ordering.Order.DESC)); List> items = new ArrayList<>(); items.add(item1); @@ -159,7 +158,7 @@ public void sort_ItemsGivenWithDescOrderingBoolean_ShouldSortProperly() { Map item2 = prepareItemWithSmallValues(); item2.put(ANY_NAME_3, AttributeValue.builder().bool(LARGE_BOOLEAN).build()); Scan scan = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) .withOrdering(new Scan.Ordering(ANY_NAME_3, Scan.Ordering.Order.DESC)); List> items = new ArrayList<>(); items.add(item1); @@ -181,7 +180,7 @@ public void sort_ItemsGivenWithDescOrderingBigint_ShouldSortProperly() { Map item2 = prepareItemWithSmallValues(); item2.put(ANY_NAME_4, AttributeValue.builder().n(String.valueOf(ANY_LARGE_BIGINT)).build()); Scan scan = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) .withOrdering(new Scan.Ordering(ANY_NAME_4, Scan.Ordering.Order.DESC)); List> items = new ArrayList<>(); items.add(item1); @@ -203,7 +202,7 @@ public void sort_ItemsGivenWithDescOrderingFloat_ShouldSortProperly() { Map item2 = prepareItemWithSmallValues(); item2.put(ANY_NAME_5, AttributeValue.builder().n(String.valueOf(ANY_LARGE_FLOAT)).build()); Scan scan = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) .withOrdering(new Scan.Ordering(ANY_NAME_5, Scan.Ordering.Order.DESC)); List> items = new ArrayList<>(); items.add(item1); @@ -225,7 +224,7 @@ public void sort_ItemsGivenWithDescOrderingDouble_ShouldSortProperly() { Map item2 = prepareItemWithSmallValues(); item2.put(ANY_NAME_6, AttributeValue.builder().n(String.valueOf(ANY_LARGE_DOUBLE)).build()); Scan scan = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) .withOrdering(new Scan.Ordering(ANY_NAME_6, Scan.Ordering.Order.DESC)); List> items = new ArrayList<>(); items.add(item1); @@ -247,7 +246,7 @@ public void sort_ItemsGivenWithDescOrderingText_ShouldSortProperly() { Map item2 = prepareItemWithSmallValues(); item2.put(ANY_NAME_7, AttributeValue.builder().s(ANY_LARGE_TEXT).build()); Scan scan = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) .withOrdering(new Scan.Ordering(ANY_NAME_7, Scan.Ordering.Order.DESC)); List> items = new ArrayList<>(); items.add(item1); @@ -270,7 +269,7 @@ public void sort_ItemsGivenWithDescOrderingBlob_ShouldSortProperly() { item2.put( ANY_NAME_8, AttributeValue.builder().b(SdkBytes.fromByteArray(ANY_LARGE_BLOB)).build()); Scan scan = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) .withOrdering(new Scan.Ordering(ANY_NAME_8, Scan.Ordering.Order.DESC)); List> items = new ArrayList<>(); items.add(item1); @@ -292,7 +291,7 @@ public void sort_ItemsGivenWithDescOrderingIntAndLimit_ShouldResultLargerOne() { Map item2 = prepareItemWithSmallValues(); item2.put(ANY_NAME_2, AttributeValue.builder().n(String.valueOf(ANY_LARGE_INT)).build()); Scan scan = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) .withOrdering(new Scan.Ordering(ANY_NAME_2, Scan.Ordering.Order.DESC)) .withLimit(1); List> items = new ArrayList<>(); @@ -317,7 +316,7 @@ public void sort_ItemsGivenWithMultipleOrderingIntAndText_ShouldSortProperly() { Map item3 = prepareItemWithSmallValues(); item3.put(ANY_NAME_7, AttributeValue.builder().s(ANY_LARGE_TEXT).build()); Scan scan = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) .withOrdering(new Scan.Ordering(ANY_NAME_2, Scan.Ordering.Order.DESC)) .withOrdering(new Scan.Ordering(ANY_NAME_7, Scan.Ordering.Order.DESC)); List> items = new ArrayList<>(); diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/PutStatementHandlerTest.java b/core/src/test/java/com/scalar/db/storage/dynamo/PutStatementHandlerTest.java index 7eba99318c..57693bfe96 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/PutStatementHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/PutStatementHandlerTest.java @@ -16,9 +16,7 @@ import com.scalar.db.api.TableMetadata; import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.storage.NoMutationException; -import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Collections; import java.util.LinkedHashSet; import java.util.Map; @@ -64,14 +62,14 @@ public void setUp() throws Exception { } private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); Put put = new Put(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)) - .withValue(new IntValue(ANY_NAME_4, ANY_INT_2)); + .withValue(ANY_NAME_3, ANY_INT_1) + .withValue(ANY_NAME_4, ANY_INT_2); return put; } @@ -107,13 +105,13 @@ public void handle_PutWithoutConditionsGiven_ShouldCallUpdateItem() { public void handle_PutWithoutClusteringKeyGiven_ShouldCallUpdateItem() { // Arrange when(client.updateItem(any(UpdateItemRequest.class))).thenReturn(updateResponse); - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); Put put = new Put(partitionKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)) - .withValue(new IntValue(ANY_NAME_4, ANY_INT_2)); + .withValue(ANY_NAME_3, ANY_INT_1) + .withValue(ANY_NAME_4, ANY_INT_2); DynamoMutation dynamoMutation = new DynamoMutation(put, metadataManager); Map expectedKeys = dynamoMutation.getKeyMap(); String updateExpression = dynamoMutation.getUpdateExpressionWithKey(); diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/SelectStatementHandlerTest.java b/core/src/test/java/com/scalar/db/storage/dynamo/SelectStatementHandlerTest.java index 31034a7d85..6e5a9ca092 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/SelectStatementHandlerTest.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/SelectStatementHandlerTest.java @@ -15,7 +15,6 @@ import com.scalar.db.api.TableMetadata; import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -73,15 +72,15 @@ public void setUp() throws Exception { } private Get prepareGet() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Get(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); } private Scan prepareScan() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); return new Scan(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); } @@ -133,7 +132,7 @@ public void handle_GetOperationWithIndexGiven_ShouldCallQuery() { Map expected = new HashMap<>(); when(queryResponse.items()).thenReturn(Arrays.asList(expected)); - Key indexKey = new Key(new TextValue(ANY_NAME_3, ANY_TEXT_3)); + Key indexKey = new Key(ANY_NAME_3, ANY_TEXT_3); Get get = new Get(indexKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); String expectedKeyCondition = ANY_NAME_3 + " = " + DynamoOperation.VALUE_ALIAS + "0"; Map expectedBindMap = new HashMap<>(); @@ -209,7 +208,7 @@ public void handle_ScanOperationWithIndexGiven_ShouldCallQuery() { Map expected = new HashMap<>(); when(queryResponse.items()).thenReturn(Arrays.asList(expected)); - Key indexKey = new Key(new TextValue(ANY_NAME_3, ANY_TEXT_3)); + Key indexKey = new Key(ANY_NAME_3, ANY_TEXT_3); Scan scan = new Scan(indexKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); String expectedKeyCondition = ANY_NAME_3 + " = " + DynamoOperation.VALUE_ALIAS + "0"; Map expectedBindMap = new HashMap<>(); @@ -257,8 +256,8 @@ public void handle_ScanOperationWithSingleClusteringKey_ShouldCallQueryItemsWith Scan scan = prepareScan() - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2))) - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3))); + .withStart(new Key(ANY_NAME_2, ANY_TEXT_2)) + .withEnd(new Key(ANY_NAME_2, ANY_TEXT_3)); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -302,11 +301,15 @@ public void handle_ScanOperationWithMultipleClusteringKeys_ShouldCallQueryItemsW Scan scan = prepareScan() .withStart( - new Key( - new TextValue(ANY_NAME_2, ANY_TEXT_2), new TextValue(ANY_NAME_3, ANY_TEXT_3))) + Key.newBuilder() + .addText(ANY_NAME_2, ANY_TEXT_2) + .addText(ANY_NAME_3, ANY_TEXT_3) + .build()) .withEnd( - new Key( - new TextValue(ANY_NAME_2, ANY_TEXT_2), new TextValue(ANY_NAME_3, ANY_TEXT_4))); + Key.newBuilder() + .addText(ANY_NAME_2, ANY_TEXT_2) + .addText(ANY_NAME_3, ANY_TEXT_4) + .build()); String expectedCondition = DynamoOperation.PARTITION_KEY @@ -365,7 +368,7 @@ public void handle_ScanOperationWithOrderingAndLimit_ShouldCallQueryWithProperRe Scan scan = prepareScan() - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2))) + .withStart(new Key(ANY_NAME_2, ANY_TEXT_2)) .withOrdering(new Scan.Ordering(ANY_NAME_2, ASC_ORDER)) .withLimit(ANY_LIMIT); @@ -413,7 +416,7 @@ public void handle_ScanOperationWithMultipleOrdering_ShouldCallQueryWithProperRe Scan scan = prepareScan() - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2))) + .withStart(new Key(ANY_NAME_2, ANY_TEXT_2)) .withOrdering(new Scan.Ordering(ANY_NAME_2, ASC_ORDER)) .withOrdering(new Scan.Ordering(ANY_NAME_3, DESC_ORDER)) .withLimit(ANY_LIMIT); 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 1c1d2442af..4cda5f4592 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 @@ -15,7 +15,6 @@ import com.scalar.db.exception.storage.ExecutionException; import com.scalar.db.exception.storage.NoMutationException; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -53,7 +52,7 @@ public void whenGetOperationExecuted_shouldCallJdbcService() throws Exception { // Arrange // Act - Get get = new Get(new Key(new TextValue("p1", "val"))); + Get get = new Get(new Key("p1", "val")); jdbcDatabase.get(get); // Assert @@ -71,7 +70,7 @@ public void whenGetOperationExecuted_shouldCallJdbcService() throws Exception { // Act Assert assertThatThrownBy( () -> { - Get get = new Get(new Key(new TextValue("p1", "val"))); + Get get = new Get(new Key("p1", "val")); jdbcDatabase.get(get); }) .isInstanceOf(ExecutionException.class); @@ -85,7 +84,7 @@ public void whenScanOperationExecutedAndScannerClosed_shouldCallJdbcService() th .thenReturn(new ScannerImpl(resultInterpreter, connection, preparedStatement, resultSet)); // Act - Scan scan = new Scan(new Key(new TextValue("p1", "val"))); + Scan scan = new Scan(new Key("p1", "val")); Scanner scanner = jdbcDatabase.scan(scan); scanner.close(); @@ -104,7 +103,7 @@ public void whenScanOperationExecutedAndScannerClosed_shouldCallJdbcService() th // Act Assert assertThatThrownBy( () -> { - Scan scan = new Scan(new Key(new TextValue("p1", "val"))); + Scan scan = new Scan(new Key("p1", "val")); jdbcDatabase.scan(scan); }) .isInstanceOf(ExecutionException.class); @@ -117,7 +116,7 @@ public void whenPutOperationExecuted_shouldCallJdbcService() throws Exception { when(jdbcService.put(any(), any(), any(), any())).thenReturn(true); // Act - Put put = new Put(new Key(new TextValue("p1", "val1"))).withValue(new TextValue("v1", "val2")); + Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2"); jdbcDatabase.put(put); // Assert @@ -136,8 +135,8 @@ public void whenPutOperationExecuted_shouldCallJdbcService() throws Exception { assertThatThrownBy( () -> { Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")) + new Put(new Key("p1", "val1")) + .withValue("v1", "val2") .withCondition(new PutIfNotExists()); jdbcDatabase.put(put); }) @@ -155,9 +154,7 @@ public void whenPutOperationExecuted_shouldCallJdbcService() throws Exception { // Act Assert assertThatThrownBy( () -> { - Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")); + Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2"); jdbcDatabase.put(put); }) .isInstanceOf(ExecutionException.class); @@ -170,7 +167,7 @@ public void whenDeleteOperationExecuted_shouldCallJdbcService() throws Exception when(jdbcService.delete(any(), any(), any(), any())).thenReturn(true); // Act - Delete delete = new Delete(new Key(new TextValue("p1", "val1"))); + Delete delete = new Delete(new Key("p1", "val1")); jdbcDatabase.delete(delete); // Assert @@ -188,9 +185,7 @@ public void whenDeleteOperationExecuted_shouldCallJdbcService() throws Exception // Act Assert assertThatThrownBy( () -> { - Delete delete = - new Delete(new Key(new TextValue("p1", "val1"))) - .withCondition(new DeleteIfExists()); + Delete delete = new Delete(new Key("p1", "val1")).withCondition(new DeleteIfExists()); jdbcDatabase.delete(delete); }) .isInstanceOf(NoMutationException.class); @@ -207,7 +202,7 @@ public void whenDeleteOperationExecuted_shouldCallJdbcService() throws Exception // Act Assert assertThatThrownBy( () -> { - Delete delete = new Delete(new Key(new TextValue("p1", "val1"))); + Delete delete = new Delete(new Key("p1", "val1")); jdbcDatabase.delete(delete); }) .isInstanceOf(ExecutionException.class); @@ -220,8 +215,8 @@ public void whenMutateOperationExecuted_shouldCallJdbcService() throws Exception when(jdbcService.mutate(any(), any(), any(), any())).thenReturn(true); // Act - Put put = new Put(new Key(new TextValue("p1", "val1"))).withValue(new TextValue("v1", "val2")); - Delete delete = new Delete(new Key(new TextValue("p1", "val1"))); + Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2"); + Delete delete = new Delete(new Key("p1", "val1")); jdbcDatabase.mutate(Arrays.asList(put, delete)); // Assert @@ -240,12 +235,10 @@ public void whenMutateOperationExecuted_shouldCallJdbcService() throws Exception assertThatThrownBy( () -> { Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")) + new Put(new Key("p1", "val1")) + .withValue("v1", "val2") .withCondition(new PutIfNotExists()); - Delete delete = - new Delete(new Key(new TextValue("p1", "val1"))) - .withCondition(new DeleteIfExists()); + Delete delete = new Delete(new Key("p1", "val1")).withCondition(new DeleteIfExists()); jdbcDatabase.mutate(Arrays.asList(put, delete)); }) .isInstanceOf(NoMutationException.class); @@ -262,10 +255,8 @@ public void whenMutateOperationExecuted_shouldCallJdbcService() throws Exception // Act Assert assertThatThrownBy( () -> { - Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")); - Delete delete = new Delete(new Key(new TextValue("p1", "val1"))); + Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2"); + Delete delete = new Delete(new Key("p1", "val1")); jdbcDatabase.mutate(Arrays.asList(put, delete)); }) .isInstanceOf(ExecutionException.class); 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 aee6564da3..15242f6d0d 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 @@ -99,7 +99,7 @@ public void whenGetOperationExecuted_shouldCallQueryBuilder() throws Exception { when(resultSet.next()).thenReturn(false); // Act - Get get = new Get(new Key(new TextValue("p1", "val"))); + Get get = new Get(new Key("p1", "val")); jdbcService.get(get, connection, NAMESPACE, TABLE); // Assert @@ -125,7 +125,7 @@ public void whenGetScannerExecuted_shouldCallQueryBuilder() throws Exception { when(resultSet.next()).thenReturn(false); // Act - Scan scan = new Scan(new Key(new TextValue("p1", "val"))); + Scan scan = new Scan(new Key("p1", "val")); jdbcService.getScanner(scan, connection, NAMESPACE, TABLE); // Assert @@ -151,7 +151,7 @@ public void whenScanExecuted_shouldCallQueryBuilder() throws Exception { when(resultSet.next()).thenReturn(false); // Act - Scan scan = new Scan(new Key(new TextValue("p1", "val"))); + Scan scan = new Scan(new Key("p1", "val")); jdbcService.scan(scan, connection, NAMESPACE, TABLE); // Assert @@ -168,7 +168,7 @@ public void whenPutOperationExecuted_shouldReturnTrueAndCallQueryBuilder() throw when(upsertQuery.prepareAndBind(any())).thenReturn(preparedStatement); // Act - Put put = new Put(new Key(new TextValue("p1", "val1"))).withValue(new TextValue("v1", "val2")); + Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2"); boolean ret = jdbcService.put(put, connection, NAMESPACE, TABLE); // Assert @@ -190,8 +190,8 @@ public void whenPutOperationWithPutIfConditionExecuted_shouldReturnTrueAndCallQu // Act Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")) + new Put(new Key("p1", "val1")) + .withValue("v1", "val2") .withCondition( new PutIf( new ConditionalExpression( @@ -217,8 +217,8 @@ public void whenPutOperationWithPutIfConditionFails_shouldReturnFalseAndCallQuer // Act Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")) + new Put(new Key("p1", "val1")) + .withValue("v1", "val2") .withCondition( new PutIf( new ConditionalExpression( @@ -244,9 +244,7 @@ public void whenPutOperationWithPutIfExistsConditionExecuted_shouldReturnTrueAnd // Act Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")) - .withCondition(new PutIfExists()); + new Put(new Key("p1", "val1")).withValue("v1", "val2").withCondition(new PutIfExists()); boolean ret = jdbcService.put(put, connection, NAMESPACE, TABLE); // Assert @@ -268,9 +266,7 @@ public void whenPutOperationWithPutIfExistsConditionFails_shouldReturnFalseAndCa // Act Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")) - .withCondition(new PutIfExists()); + new Put(new Key("p1", "val1")).withValue("v1", "val2").withCondition(new PutIfExists()); boolean ret = jdbcService.put(put, connection, NAMESPACE, TABLE); // Assert @@ -291,9 +287,7 @@ public void whenPutOperationWithPutIfExistsConditionFails_shouldReturnFalseAndCa // Act Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")) - .withCondition(new PutIfNotExists()); + new Put(new Key("p1", "val1")).withValue("v1", "val2").withCondition(new PutIfNotExists()); boolean ret = jdbcService.put(put, connection, NAMESPACE, TABLE); // Assert @@ -316,9 +310,7 @@ public void whenPutOperationWithPutIfExistsConditionFails_shouldReturnFalseAndCa // Act Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")) - .withCondition(new PutIfNotExists()); + new Put(new Key("p1", "val1")).withValue("v1", "val2").withCondition(new PutIfNotExists()); boolean ret = jdbcService.put(put, connection, NAMESPACE, TABLE); // Assert @@ -336,7 +328,7 @@ public void whenDeleteOperationExecuted_shouldReturnTrueAndCallQueryBuilder() th when(deleteQuery.prepareAndBind(any())).thenReturn(preparedStatement); // Act - Delete delete = new Delete(new Key(new TextValue("p1", "val1"))); + Delete delete = new Delete(new Key("p1", "val1")); boolean ret = jdbcService.delete(delete, connection, NAMESPACE, TABLE); // Assert @@ -357,7 +349,7 @@ public void whenDeleteOperationWithDeleteIfConditionExecuted_shouldReturnTrueAnd // Act Delete delete = - new Delete(new Key(new TextValue("p1", "val1"))) + new Delete(new Key("p1", "val1")) .withCondition( new DeleteIf( new ConditionalExpression( @@ -382,7 +374,7 @@ public void whenDeleteOperationWithDeleteIfConditionFails_shouldReturnFalseAndCa // Act Delete delete = - new Delete(new Key(new TextValue("p1", "val1"))) + new Delete(new Key("p1", "val1")) .withCondition( new DeleteIf( new ConditionalExpression( @@ -407,8 +399,7 @@ public void whenDeleteOperationWithDeleteIfConditionFails_shouldReturnFalseAndCa when(preparedStatement.executeUpdate()).thenReturn(1); // Act - Delete delete = - new Delete(new Key(new TextValue("p1", "val1"))).withCondition(new DeleteIfExists()); + Delete delete = new Delete(new Key("p1", "val1")).withCondition(new DeleteIfExists()); boolean ret = jdbcService.delete(delete, connection, NAMESPACE, TABLE); // Assert @@ -429,8 +420,7 @@ public void whenDeleteOperationWithDeleteIfConditionFails_shouldReturnFalseAndCa when(preparedStatement.executeUpdate()).thenReturn(0); // Act - Delete delete = - new Delete(new Key(new TextValue("p1", "val1"))).withCondition(new DeleteIfExists()); + Delete delete = new Delete(new Key("p1", "val1")).withCondition(new DeleteIfExists()); boolean ret = jdbcService.delete(delete, connection, NAMESPACE, TABLE); // Assert @@ -453,8 +443,8 @@ public void whenMutateOperationExecuted_shouldReturnTrueAndCallQueryBuilder() th when(deleteQuery.prepareAndBind(any())).thenReturn(preparedStatement); // Act - Put put = new Put(new Key(new TextValue("p1", "val1"))).withValue(new TextValue("v1", "val2")); - Delete delete = new Delete(new Key(new TextValue("p1", "val1"))); + Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2"); + Delete delete = new Delete(new Key("p1", "val1")); boolean ret = jdbcService.mutate(Arrays.asList(put, delete), connection, NAMESPACE, TABLE); // Assert diff --git a/core/src/test/java/com/scalar/db/storage/jdbc/query/QueryBuilderTest.java b/core/src/test/java/com/scalar/db/storage/jdbc/query/QueryBuilderTest.java index ed2dfbaccf..86b5eee2ec 100644 --- a/core/src/test/java/com/scalar/db/storage/jdbc/query/QueryBuilderTest.java +++ b/core/src/test/java/com/scalar/db/storage/jdbc/query/QueryBuilderTest.java @@ -88,7 +88,7 @@ public void selectQueryTest() { queryBuilder .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) - .where(new Key(new TextValue("p1", "aaa")), Optional.empty()) + .where(new Key("p1", "aaa"), Optional.empty()) .build() .toString()) .isEqualTo(encloseSql("SELECT c1,c2 FROM n1.t1 WHERE p1=?")); @@ -98,7 +98,7 @@ public void selectQueryTest() { .select(Collections.emptyList()) .from(NAMESPACE, TABLE) .where( - new Key(new TextValue("p1", "aaa"), new TextValue("p2", "bbb")), + Key.newBuilder().addText("p1", "aaa").addText("p2", "bbb").build(), Optional.empty()) .build() .toString()) @@ -108,9 +108,7 @@ public void selectQueryTest() { queryBuilder .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) - .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "aaa")))) + .where(new Key("p1", "aaa"), Optional.of(new Key("c1", "aaa"))) .build() .toString()) .isEqualTo(encloseSql("SELECT c1,c2 FROM n1.t1 WHERE p1=? AND c1=?")); @@ -120,8 +118,8 @@ public void selectQueryTest() { .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "aaa"), new TextValue("c2", "bbb")))) + new Key("p1", "aaa"), + Optional.of(Key.newBuilder().addText("c1", "aaa").addText("c2", "bbb").build())) .build() .toString()) .isEqualTo(encloseSql("SELECT c1,c2 FROM n1.t1 WHERE p1=? AND c1=? AND c2=?")); @@ -131,10 +129,10 @@ public void selectQueryTest() { .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "aaa"))), + new Key("p1", "aaa"), + Optional.of(new Key("c1", "aaa")), true, - Optional.of(new Key(new TextValue("c1", "bbb"))), + Optional.of(new Key("c1", "bbb")), true) .build() .toString()) @@ -147,10 +145,10 @@ public void selectQueryTest() { .select(Collections.emptyList()) .from(NAMESPACE, TABLE) .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "aaa"))), + new Key("p1", "aaa"), + Optional.of(new Key("c1", "aaa")), false, - Optional.of(new Key(new TextValue("c1", "bbb"))), + Optional.of(new Key("c1", "bbb")), false) .build() .toString()) @@ -162,10 +160,10 @@ public void selectQueryTest() { .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "aaa"), new TextValue("c2", "aaa"))), + new Key("p1", "aaa"), + Optional.of(Key.newBuilder().addText("c1", "aaa").addText("c2", "aaa").build()), true, - Optional.of(new Key(new TextValue("c1", "aaa"), new TextValue("c2", "bbb"))), + Optional.of(Key.newBuilder().addText("c1", "aaa").addText("c2", "bbb").build()), false) .build() .toString()) @@ -179,10 +177,10 @@ public void selectQueryTest() { .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "aaa"))), + new Key("p1", "aaa"), + Optional.of(new Key("c1", "aaa")), true, - Optional.of(new Key(new TextValue("c1", "bbb"))), + Optional.of(new Key("c1", "bbb")), true) .orderBy( Collections.singletonList(new Scan.Ordering("c1", Scan.Ordering.Order.ASC))) @@ -197,10 +195,10 @@ public void selectQueryTest() { .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "aaa"))), + new Key("p1", "aaa"), + Optional.of(new Key("c1", "aaa")), true, - Optional.of(new Key(new TextValue("c1", "bbb"))), + Optional.of(new Key("c1", "bbb")), true) .orderBy( Arrays.asList( @@ -217,10 +215,10 @@ public void selectQueryTest() { .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "aaa"))), + new Key("p1", "aaa"), + Optional.of(new Key("c1", "aaa")), true, - Optional.of(new Key(new TextValue("c1", "bbb"))), + Optional.of(new Key("c1", "bbb")), true) .orderBy( Collections.singletonList(new Scan.Ordering("c1", Scan.Ordering.Order.DESC))) @@ -235,10 +233,10 @@ public void selectQueryTest() { .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "aaa"))), + new Key("p1", "aaa"), + Optional.of(new Key("c1", "aaa")), true, - Optional.of(new Key(new TextValue("c1", "bbb"))), + Optional.of(new Key("c1", "bbb")), true) .orderBy( Arrays.asList( @@ -275,10 +273,10 @@ public void selectQueryTest() { .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "aaa"))), + new Key("p1", "aaa"), + Optional.of(new Key("c1", "aaa")), true, - Optional.of(new Key(new TextValue("c1", "bbb"))), + Optional.of(new Key("c1", "bbb")), true) .limit(10) .build() @@ -292,7 +290,7 @@ public void selectQueryWithIndexedColumnTest() { queryBuilder .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) - .where(new Key(new TextValue("v1", "aaa")), Optional.empty()) + .where(new Key("v1", "aaa"), Optional.empty()) .build() .toString()) .isEqualTo(encloseSql("SELECT c1,c2 FROM n1.t1 WHERE v1=?")); @@ -301,12 +299,7 @@ public void selectQueryWithIndexedColumnTest() { queryBuilder .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) - .where( - new Key(new TextValue("v1", "aaa")), - Optional.empty(), - false, - Optional.empty(), - false) + .where(new Key("v1", "aaa"), Optional.empty(), false, Optional.empty(), false) .build() .toString()) .isEqualTo(encloseSql("SELECT c1,c2 FROM n1.t1 WHERE v1=?")); @@ -315,7 +308,7 @@ public void selectQueryWithIndexedColumnTest() { queryBuilder .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) - .where(new Key(new TextValue("v2", "aaa")), Optional.empty()) + .where(new Key("v2", "aaa"), Optional.empty()) .build() .toString()) .isEqualTo(encloseSql("SELECT c1,c2 FROM n1.t1 WHERE v2=?")); @@ -324,12 +317,7 @@ public void selectQueryWithIndexedColumnTest() { queryBuilder .select(Arrays.asList("c1", "c2")) .from(NAMESPACE, TABLE) - .where( - new Key(new TextValue("v2", "aaa")), - Optional.empty(), - false, - Optional.empty(), - false) + .where(new Key("v2", "aaa"), Optional.empty(), false, Optional.empty(), false) .build() .toString()) .isEqualTo(encloseSql("SELECT c1,c2 FROM n1.t1 WHERE v2=?")); @@ -345,7 +333,7 @@ public void insertQueryTest() { assertThat( queryBuilder .insertInto(NAMESPACE, TABLE) - .values(new Key(new TextValue("p1", "aaa")), Optional.empty(), values) + .values(new Key("p1", "aaa"), Optional.empty(), values) .build() .toString()) .isEqualTo(encloseSql("INSERT INTO n1.t1 (p1,v1,v2,v3) VALUES (?,?,?,?)")); @@ -353,10 +341,7 @@ public void insertQueryTest() { assertThat( queryBuilder .insertInto(NAMESPACE, TABLE) - .values( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "bbb"))), - values) + .values(new Key("p1", "aaa"), Optional.of(new Key("c1", "bbb")), values) .build() .toString()) .isEqualTo(encloseSql("INSERT INTO n1.t1 (p1,c1,v1,v2,v3) VALUES (?,?,?,?,?)")); @@ -367,8 +352,8 @@ public void insertQueryTest() { queryBuilder .insertInto(NAMESPACE, TABLE) .values( - new Key(new TextValue("p1", "aaa"), new TextValue("p2", "ccc")), - Optional.of(new Key(new TextValue("c1", "bbb"), new TextValue("c2", "ddd"))), + Key.newBuilder().addText("p1", "aaa").addText("p2", "ccc").build(), + Optional.of(Key.newBuilder().addText("c1", "bbb").addText("c2", "ddd").build()), values) .build() .toString()) @@ -387,7 +372,7 @@ public void updateQueryTest() { queryBuilder .update(NAMESPACE, TABLE) .set(values) - .where(new Key(new TextValue("p1", "aaa")), Optional.empty()) + .where(new Key("p1", "aaa"), Optional.empty()) .build() .toString()) .isEqualTo(encloseSql("UPDATE n1.t1 SET v1=?,v2=?,v3=? WHERE p1=?")); @@ -396,9 +381,7 @@ public void updateQueryTest() { queryBuilder .update(NAMESPACE, TABLE) .set(values) - .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "bbb")))) + .where(new Key("p1", "aaa"), Optional.of(new Key("c1", "bbb"))) .build() .toString()) .isEqualTo(encloseSql("UPDATE n1.t1 SET v1=?,v2=?,v3=? WHERE p1=? AND c1=?")); @@ -408,8 +391,8 @@ public void updateQueryTest() { .update(NAMESPACE, TABLE) .set(values) .where( - new Key(new TextValue("p1", "aaa"), new TextValue("p2", "ccc")), - Optional.of(new Key(new TextValue("c1", "bbb"), new TextValue("c2", "ddd")))) + Key.newBuilder().addText("p1", "aaa").addText("p2", "ccc").build(), + Optional.of(Key.newBuilder().addText("c1", "bbb").addText("c2", "ddd").build())) .build() .toString()) .isEqualTo( @@ -420,8 +403,8 @@ public void updateQueryTest() { .update(NAMESPACE, TABLE) .set(values) .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "bbb"))), + new Key("p1", "aaa"), + Optional.of(new Key("c1", "bbb")), Collections.singletonList( new ConditionalExpression("v1", new TextValue("ccc"), Operator.EQ))) .build() @@ -433,8 +416,8 @@ public void updateQueryTest() { .update(NAMESPACE, TABLE) .set(values) .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "bbb"))), + new Key("p1", "aaa"), + Optional.of(new Key("c1", "bbb")), Arrays.asList( new ConditionalExpression("v1", new TextValue("ccc"), Operator.NE), new ConditionalExpression("v2", new TextValue("ddd"), Operator.GT), @@ -451,7 +434,7 @@ public void deleteQueryTest() { assertThat( queryBuilder .deleteFrom(NAMESPACE, TABLE) - .where(new Key(new TextValue("p1", "aaa")), Optional.empty()) + .where(new Key("p1", "aaa"), Optional.empty()) .build() .toString()) .isEqualTo(encloseSql("DELETE FROM n1.t1 WHERE p1=?")); @@ -459,9 +442,7 @@ public void deleteQueryTest() { assertThat( queryBuilder .deleteFrom(NAMESPACE, TABLE) - .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "bbb")))) + .where(new Key("p1", "aaa"), Optional.of(new Key("c1", "bbb"))) .build() .toString()) .isEqualTo(encloseSql("DELETE FROM n1.t1 WHERE p1=? AND c1=?")); @@ -470,8 +451,8 @@ public void deleteQueryTest() { queryBuilder .deleteFrom(NAMESPACE, TABLE) .where( - new Key(new TextValue("p1", "aaa"), new TextValue("p2", "ccc")), - Optional.of(new Key(new TextValue("c1", "bbb"), new TextValue("c2", "ddd")))) + Key.newBuilder().addText("p1", "aaa").addText("p2", "ccc").build(), + Optional.of(Key.newBuilder().addText("c1", "bbb").addText("c2", "ddd").build())) .build() .toString()) .isEqualTo(encloseSql("DELETE FROM n1.t1 WHERE p1=? AND p2=? AND c1=? AND c2=?")); @@ -480,8 +461,8 @@ public void deleteQueryTest() { queryBuilder .deleteFrom(NAMESPACE, TABLE) .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "bbb"))), + new Key("p1", "aaa"), + Optional.of(new Key("c1", "bbb")), Collections.singletonList( new ConditionalExpression("v1", new TextValue("ccc"), Operator.EQ))) .build() @@ -492,8 +473,8 @@ public void deleteQueryTest() { queryBuilder .deleteFrom(NAMESPACE, TABLE) .where( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "bbb"))), + new Key("p1", "aaa"), + Optional.of(new Key("c1", "bbb")), Arrays.asList( new ConditionalExpression("v1", new TextValue("ccc"), Operator.NE), new ConditionalExpression("v2", new TextValue("ddd"), Operator.GTE), @@ -541,7 +522,7 @@ public void upsertQueryTest() { assertThat( queryBuilder .upsertInto(NAMESPACE, TABLE) - .values(new Key(new TextValue("p1", "aaa")), Optional.empty(), values) + .values(new Key("p1", "aaa"), Optional.empty(), values) .build() .toString()) .isEqualTo(encloseSql(expectedQuery)); @@ -576,10 +557,7 @@ public void upsertQueryTest() { assertThat( queryBuilder .upsertInto(NAMESPACE, TABLE) - .values( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "bbb"))), - values) + .values(new Key("p1", "aaa"), Optional.of(new Key("c1", "bbb")), values) .build() .toString()) .isEqualTo(encloseSql(expectedQuery)); @@ -618,8 +596,8 @@ public void upsertQueryTest() { queryBuilder .upsertInto(NAMESPACE, TABLE) .values( - new Key(new TextValue("p1", "aaa"), new TextValue("p2", "ccc")), - Optional.of(new Key(new TextValue("c1", "bbb"), new TextValue("c2", "ddd"))), + Key.newBuilder().addText("p1", "aaa").addText("p2", "ccc").build(), + Optional.of(Key.newBuilder().addText("c1", "bbb").addText("c2", "ddd").build()), values) .build() .toString()) @@ -652,8 +630,7 @@ public void upsertQueryWithoutValuesTest() { assertThat( queryBuilder .upsertInto(NAMESPACE, TABLE) - .values( - new Key(new TextValue("p1", "aaa")), Optional.empty(), Collections.emptyMap()) + .values(new Key("p1", "aaa"), Optional.empty(), Collections.emptyMap()) .build() .toString()) .isEqualTo(encloseSql(expectedQuery)); @@ -683,9 +660,7 @@ public void upsertQueryWithoutValuesTest() { queryBuilder .upsertInto(NAMESPACE, TABLE) .values( - new Key(new TextValue("p1", "aaa")), - Optional.of(new Key(new TextValue("c1", "bbb"))), - Collections.emptyMap()) + new Key("p1", "aaa"), Optional.of(new Key("c1", "bbb")), Collections.emptyMap()) .build() .toString()) .isEqualTo(encloseSql(expectedQuery)); @@ -717,8 +692,8 @@ public void upsertQueryWithoutValuesTest() { queryBuilder .upsertInto(NAMESPACE, TABLE) .values( - new Key(new TextValue("p1", "aaa"), new TextValue("p2", "ccc")), - Optional.of(new Key(new TextValue("c1", "bbb"), new TextValue("c2", "ddd"))), + Key.newBuilder().addText("p1", "aaa").addText("p2", "ccc").build(), + Optional.of(Key.newBuilder().addText("c1", "bbb").addText("c2", "ddd").build()), Collections.emptyMap()) .build() .toString()) 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 d784569133..7b939201e4 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 @@ -11,7 +11,6 @@ import com.scalar.db.api.Put; import com.scalar.db.api.Scan; import com.scalar.db.exception.storage.ExecutionException; -import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; import java.util.Arrays; import java.util.Collections; @@ -58,8 +57,8 @@ public void whenGetDataFromTable1_DataShouldBeGottenFromStorage1() throws Execut // Arrange String namespace = NAMESPACE1; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME2, 2); Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); // Act @@ -74,8 +73,8 @@ public void whenGetDataFromTable2_DataShouldBeGottenFromStorage2() throws Execut // Arrange String namespace = NAMESPACE1; String table = TABLE2; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME2, 2); Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); // Act @@ -91,8 +90,8 @@ public void whenGetDataFromTable3_DataShouldBeGottenFromDefaultStorage() // Arrange String namespace = NAMESPACE1; String table = TABLE3; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME2, 2); Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); // Act @@ -107,7 +106,7 @@ public void whenScanDataFromTable1_DataShouldBeScannedFromStorage1() throws Exec // Arrange String namespace = NAMESPACE1; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); + Key partitionKey = new Key(COL_NAME1, 1); Scan scan = new Scan(partitionKey).forNamespace(namespace).forTable(table); // Act @@ -121,7 +120,7 @@ public void whenScanDataFromTable1_DataShouldBeScannedFromStorage1() throws Exec public void whenScanDataFromTable2_DataShouldBeScannedFromStorage2() throws ExecutionException { String namespace = NAMESPACE1; String table = TABLE2; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); + Key partitionKey = new Key(COL_NAME1, 1); Scan scan = new Scan(partitionKey).forNamespace(namespace).forTable(table); // Act @@ -137,7 +136,7 @@ public void whenScanDataFromTable3_DataShouldBeScannedFromDefaultStorage() // Arrange String namespace = NAMESPACE1; String table = TABLE3; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); + Key partitionKey = new Key(COL_NAME1, 1); Scan scan = new Scan(partitionKey).forNamespace(namespace).forTable(table); // Act @@ -152,11 +151,11 @@ public void whenPutDataIntoTable1_DataShouldBeWrittenIntoStorage1() throws Execu // Arrange String namespace = NAMESPACE1; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME2, 2); Put put = new Put(partitionKey, clusteringKey) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table); @@ -172,11 +171,11 @@ public void whenPutDataIntoTable2_DataShouldBeWrittenIntoStorage2() throws Execu // Arrange String namespace = NAMESPACE1; String table = TABLE2; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME2, 2); Put put = new Put(partitionKey, clusteringKey) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table); @@ -193,11 +192,11 @@ public void whenPutDataIntoTable3_DataShouldBeWrittenIntoDefaultStorage() // Arrange String namespace = NAMESPACE1; String table = TABLE3; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME2, 2); Put put = new Put(partitionKey, clusteringKey) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table); @@ -213,8 +212,8 @@ public void whenDeleteDataFromTable1_DataShouldBeDeletedFromStorage1() throws Ex // Arrange String namespace = NAMESPACE1; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME2, 2); Delete delete = new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); // Act @@ -229,8 +228,8 @@ public void whenDeleteDataFromTable2_DataShouldBeDeletedFromStorage2() throws Ex // Arrange String namespace = NAMESPACE1; String table = TABLE2; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME2, 2); Delete delete = new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); // Act @@ -246,8 +245,8 @@ public void whenDeleteDataFromTable3_DataShouldBeDeletedFromDefaultStorage() // Arrange String namespace = NAMESPACE1; String table = TABLE3; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME2, 2); Delete delete = new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); // Act @@ -262,15 +261,15 @@ public void whenMutateDataToTable1_ShouldExecuteForStorage1() throws ExecutionEx // Arrange String namespace = NAMESPACE1; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey1 = new Key(new IntValue(COL_NAME2, 2)); - Key clusteringKey2 = new Key(new IntValue(COL_NAME2, 3)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey1 = new Key(COL_NAME2, 2); + Key clusteringKey2 = new Key(COL_NAME2, 3); // Act multiStorage.mutate( Arrays.asList( new Put(partitionKey, clusteringKey2) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table), new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); @@ -284,15 +283,15 @@ public void whenMutateDataToTable2_ShouldExecuteForStorage2() throws ExecutionEx // Arrange String namespace = NAMESPACE1; String table = TABLE2; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey1 = new Key(new IntValue(COL_NAME2, 2)); - Key clusteringKey2 = new Key(new IntValue(COL_NAME2, 3)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey1 = new Key(COL_NAME2, 2); + Key clusteringKey2 = new Key(COL_NAME2, 3); // Act multiStorage.mutate( Arrays.asList( new Put(partitionKey, clusteringKey2) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table), new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); @@ -306,15 +305,15 @@ public void whenMutateDataToTable3_ShouldExecuteForDefaultStorage() throws Execu // Arrange String namespace = NAMESPACE1; String table = TABLE3; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey1 = new Key(new IntValue(COL_NAME2, 2)); - Key clusteringKey2 = new Key(new IntValue(COL_NAME2, 3)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey1 = new Key(COL_NAME2, 2); + Key clusteringKey2 = new Key(COL_NAME2, 3); // Act multiStorage.mutate( Arrays.asList( new Put(partitionKey, clusteringKey2) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table), new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); @@ -336,8 +335,8 @@ public void whenGetDataFromTable1InNamespace2_DataShouldBeGottenFromStorage2() // Arrange String namespace = NAMESPACE2; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME2, 2); Get get = new Get(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); // Act @@ -353,7 +352,7 @@ public void whenScanDataFromTable1InNamespace2_DataShouldBeScannedFromStorage2() // Arrange String namespace = NAMESPACE2; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); + Key partitionKey = new Key(COL_NAME1, 1); Scan scan = new Scan(partitionKey).forNamespace(namespace).forTable(table); // Act @@ -369,11 +368,11 @@ public void whenPutDataIntoTable1InNamespace2_DataShouldBeWrittenIntoStorage2() // Arrange String namespace = NAMESPACE2; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME2, 2); Put put = new Put(partitionKey, clusteringKey) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table); @@ -390,8 +389,8 @@ public void whenDeleteDataFromTable1InNamespace2_DataShouldBeDeletedFromStorage1 // Arrange String namespace = NAMESPACE2; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey = new Key(new IntValue(COL_NAME2, 2)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey = new Key(COL_NAME2, 2); Delete delete = new Delete(partitionKey, clusteringKey).forNamespace(namespace).forTable(table); // Act @@ -407,15 +406,15 @@ public void whenMutateDataToTable1InNamespace2_ShouldExecuteForStorage2() // Arrange String namespace = NAMESPACE2; String table = TABLE1; - Key partitionKey = new Key(new IntValue(COL_NAME1, 1)); - Key clusteringKey1 = new Key(new IntValue(COL_NAME2, 2)); - Key clusteringKey2 = new Key(new IntValue(COL_NAME2, 3)); + Key partitionKey = new Key(COL_NAME1, 1); + Key clusteringKey1 = new Key(COL_NAME2, 2); + Key clusteringKey2 = new Key(COL_NAME2, 3); // Act multiStorage.mutate( Arrays.asList( new Put(partitionKey, clusteringKey2) - .withValue(new IntValue(COL_NAME3, 3)) + .withValue(COL_NAME3, 3) .forNamespace(namespace) .forTable(table), new Delete(partitionKey, clusteringKey1).forNamespace(namespace).forTable(table))); 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 5695aed56b..dda3cf4d68 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 @@ -19,9 +19,7 @@ import com.scalar.db.exception.transaction.CommitException; import com.scalar.db.exception.transaction.CoordinatorException; import com.scalar.db.exception.transaction.UnknownTransactionStatusException; -import com.scalar.db.io.IntValue; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.List; import java.util.Optional; import org.junit.Before; @@ -56,30 +54,30 @@ public void setUp() { } private Put preparePut1() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Put(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)); + .withValue(ANY_NAME_3, ANY_INT_1); } private Put preparePut2() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_3)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_4)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_3); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_4); return new Put(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_2)); + .withValue(ANY_NAME_3, ANY_INT_2); } private Put preparePut3() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_3); return new Put(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_2)); + .withValue(ANY_NAME_3, ANY_INT_2); } private Snapshot prepareSnapshotWithDifferentPartitionPut() { 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 b04caa33d6..ba0fa6756b 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 @@ -22,7 +22,6 @@ import com.scalar.db.api.TransactionState; 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.ArrayList; import java.util.List; @@ -54,35 +53,33 @@ public void setUp() { } private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Put(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_1)); + .withValue(ANY_NAME_3, ANY_INT_1); } private Delete prepareDelete() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Delete(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); } private Get prepareGet() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Get(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); } private void configureResult(Result mock, TransactionState state) { - when(mock.getPartitionKey()) - .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)))); - when(mock.getClusteringKey()) - .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)))); + when(mock.getPartitionKey()).thenReturn(Optional.of(new Key(ANY_NAME_1, ANY_TEXT_1))); + when(mock.getClusteringKey()).thenReturn(Optional.of(new Key(ANY_NAME_2, ANY_TEXT_2))); ImmutableMap> values = ImmutableMap.>builder() 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 ffe2983b41..3c27bb5a32 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 @@ -22,7 +22,6 @@ import com.scalar.db.exception.transaction.CrudRuntimeException; import com.scalar.db.exception.transaction.UncommittedRecordException; 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.HashMap; @@ -57,24 +56,22 @@ public void setUp() { } private Get prepareGet() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Get(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); } private Scan prepareScan() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); return new Scan(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); } private void configureResult(Result mock, boolean hasClusteringKey, TransactionState state) { - when(mock.getPartitionKey()) - .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)))); + when(mock.getPartitionKey()).thenReturn(Optional.of(new Key(ANY_NAME_1, ANY_TEXT_1))); if (hasClusteringKey) { - when(mock.getClusteringKey()) - .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)))); + when(mock.getClusteringKey()).thenReturn(Optional.of(new Key(ANY_NAME_2, ANY_TEXT_2))); } else { when(mock.getClusteringKey()).thenReturn(Optional.empty()); } diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/PartitionedMutationsKeyTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/PartitionedMutationsKeyTest.java index 64a3a34974..5d3660cd05 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/PartitionedMutationsKeyTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/PartitionedMutationsKeyTest.java @@ -4,7 +4,6 @@ import com.scalar.db.api.Put; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import org.junit.Test; /** */ @@ -16,12 +15,12 @@ public class PartitionedMutationsKeyTest { private static final String ANY_TEXT_3 = "text3"; private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); return new Put(partitionKey, null).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); } private Put prepareAnotherPut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_3)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_3); return new Put(partitionKey, null).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); } diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/PartitionedMutationsTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/PartitionedMutationsTest.java index e368ab102a..b101a3f29c 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/PartitionedMutationsTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/PartitionedMutationsTest.java @@ -5,7 +5,6 @@ import com.scalar.db.api.Mutation; import com.scalar.db.api.Put; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import java.util.Arrays; import java.util.List; import org.assertj.core.api.Assertions; @@ -35,18 +34,18 @@ private Put preparePut(Key partitionKey, Key clusteringKey) { } private List preparePuts1() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey1 = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); - Key clusteringKey2 = new Key(new TextValue(ANY_NAME_3, ANY_TEXT_3)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey1 = new Key(ANY_NAME_2, ANY_TEXT_2); + Key clusteringKey2 = new Key(ANY_NAME_3, ANY_TEXT_3); Put put1 = preparePut(partitionKey, clusteringKey1); Put put2 = preparePut(partitionKey, clusteringKey2); return Arrays.asList(put1, put2); } private List preparePuts2() { - Key partitionKey = new Key(new TextValue(ANY_NAME_4, ANY_TEXT_4)); - Key clusteringKey1 = new Key(new TextValue(ANY_NAME_5, ANY_TEXT_5)); - Key clusteringKey2 = new Key(new TextValue(ANY_NAME_6, ANY_TEXT_6)); + Key partitionKey = new Key(ANY_NAME_4, ANY_TEXT_4); + Key clusteringKey1 = new Key(ANY_NAME_5, ANY_TEXT_5); + Key clusteringKey2 = new Key(ANY_NAME_6, ANY_TEXT_6); Put put1 = preparePut(partitionKey, clusteringKey1); Put put2 = preparePut(partitionKey, clusteringKey2); return Arrays.asList(put1, put2); 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 260b7908a1..28540662e1 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 @@ -22,7 +22,6 @@ import com.scalar.db.api.TransactionState; 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.ArrayList; import java.util.List; @@ -60,27 +59,25 @@ public void setUp() throws Exception { } private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Put(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_3)); + .withValue(ANY_NAME_3, ANY_INT_3); } private Delete prepareDelete() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Delete(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); } private void configureResult(Result mock) { - when(mock.getPartitionKey()) - .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)))); - when(mock.getClusteringKey()) - .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)))); + when(mock.getPartitionKey()).thenReturn(Optional.of(new Key(ANY_NAME_1, ANY_TEXT_1))); + when(mock.getClusteringKey()).thenReturn(Optional.of(new Key(ANY_NAME_2, ANY_TEXT_2))); ImmutableMap> values = ImmutableMap.>builder() @@ -134,7 +131,7 @@ public void add_PutAndResultGiven_ShouldComposePutWithPutIfCondition() { put.withValue(Attribute.toBeforeIdValue(ANY_ID_2)); put.withValue(Attribute.toBeforeStateValue(TransactionState.COMMITTED)); put.withValue(Attribute.toBeforeVersionValue(2)); - put.withValue(new IntValue(Attribute.BEFORE_PREFIX + ANY_NAME_3, ANY_INT_2)); + put.withValue(Attribute.BEFORE_PREFIX + ANY_NAME_3, ANY_INT_2); assertThat(actual).isEqualTo(put); } @@ -186,7 +183,7 @@ public void delete_DeleteAndResultGiven_ShouldComposePutWithPutIfCondition() { expected.withValue(Attribute.toBeforeIdValue(ANY_ID_2)); expected.withValue(Attribute.toBeforeStateValue(TransactionState.COMMITTED)); expected.withValue(Attribute.toBeforeVersionValue(2)); - expected.withValue(new IntValue(Attribute.BEFORE_PREFIX + ANY_NAME_3, ANY_INT_2)); + expected.withValue(Attribute.BEFORE_PREFIX + ANY_NAME_3, ANY_INT_2); 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 ac4cbc7eb9..c2b363deef 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 @@ -27,7 +27,6 @@ import com.scalar.db.exception.storage.ExecutionException; 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.ArrayList; import java.util.List; @@ -64,8 +63,8 @@ public void setUp() { } private Get prepareGet() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Get(partitionKey, clusteringKey) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) @@ -73,7 +72,7 @@ private Get prepareGet() { } private Scan prepareScan() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); return new Scan(partitionKey) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) @@ -81,20 +80,18 @@ private Scan prepareScan() { } private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Put(partitionKey, clusteringKey) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new IntValue(ANY_NAME_3, ANY_INT_3)); + .withValue(ANY_NAME_3, ANY_INT_3); } private void configureResult(Result mock, TransactionState state) { - when(mock.getPartitionKey()) - .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)))); - when(mock.getClusteringKey()) - .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)))); + when(mock.getPartitionKey()).thenReturn(Optional.of(new Key(ANY_NAME_1, ANY_TEXT_1))); + when(mock.getClusteringKey()).thenReturn(Optional.of(new Key(ANY_NAME_2, ANY_TEXT_2))); ImmutableMap> values = ImmutableMap.>builder() @@ -123,10 +120,8 @@ private TransactionResult prepareResult(TransactionState state) { } private void configureInitialResult(Result mock, String id, TransactionState state) { - when(mock.getPartitionKey()) - .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)))); - when(mock.getClusteringKey()) - .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)))); + when(mock.getPartitionKey()).thenReturn(Optional.of(new Key(ANY_NAME_1, ANY_TEXT_1))); + when(mock.getClusteringKey()).thenReturn(Optional.of(new Key(ANY_NAME_2, ANY_TEXT_2))); ImmutableMap.Builder builder = ImmutableMap.>builder() 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 55ebc6a83f..5357dd58c3 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 @@ -4,7 +4,6 @@ import com.scalar.db.api.Get; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import org.junit.Test; /** */ @@ -19,21 +18,21 @@ public class SnapshotKeyTest { private static final String ANY_TEXT_4 = "text4"; private Get prepareGet() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Get(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); } private Get prepareGetWithoutClusteringKey() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); return new Get(partitionKey).forNamespace(ANY_KEYSPACE_NAME).forTable(ANY_TABLE_NAME); } private Get prepareAnotherGet() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_3)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_4)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_3); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_4); return new Get(partitionKey, clusteringKey) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); 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 e2c5948e8b..c8d4084e1b 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 @@ -86,8 +86,8 @@ private Snapshot prepareSnapshot(Isolation isolation, SerializableStrategy strat } private Get prepareGet() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Get(partitionKey, clusteringKey) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) @@ -95,8 +95,8 @@ private Get prepareGet() { } private Get prepareAnotherGet() { - Key partitionKey = new Key(new TextValue(ANY_NAME_5, ANY_TEXT_5)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_6, ANY_TEXT_6)); + Key partitionKey = new Key(ANY_NAME_5, ANY_TEXT_5); + Key clusteringKey = new Key(ANY_NAME_6, ANY_TEXT_6); return new Get(partitionKey, clusteringKey) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) @@ -104,8 +104,8 @@ private Get prepareAnotherGet() { } private Scan prepareScan() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Scan(partitionKey) .withStart(clusteringKey) .withConsistency(Consistency.LINEARIZABLE) @@ -114,19 +114,19 @@ private Scan prepareScan() { } private Put preparePut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Put(partitionKey, clusteringKey) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new TextValue(ANY_NAME_3, ANY_TEXT_3)) - .withValue(new TextValue(ANY_NAME_4, ANY_TEXT_4)); + .withValue(ANY_NAME_3, ANY_TEXT_3) + .withValue(ANY_NAME_4, ANY_TEXT_4); } private Put prepareAnotherPut() { - Key partitionKey = new Key(new TextValue(ANY_NAME_5, ANY_TEXT_5)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_6, ANY_TEXT_6)); + Key partitionKey = new Key(ANY_NAME_5, ANY_TEXT_5); + Key clusteringKey = new Key(ANY_NAME_6, ANY_TEXT_6); return new Put(partitionKey, clusteringKey) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) @@ -134,18 +134,18 @@ private Put prepareAnotherPut() { } private Put preparePutWithPartitionKeyOnly() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); return new Put(partitionKey) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME) - .withValue(new TextValue(ANY_NAME_3, ANY_TEXT_3)) - .withValue(new TextValue(ANY_NAME_4, ANY_TEXT_4)); + .withValue(ANY_NAME_3, ANY_TEXT_3) + .withValue(ANY_NAME_4, ANY_TEXT_4); } private Delete prepareDelete() { - Key partitionKey = new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)); + Key partitionKey = new Key(ANY_NAME_1, ANY_TEXT_1); + Key clusteringKey = new Key(ANY_NAME_2, ANY_TEXT_2); return new Delete(partitionKey, clusteringKey) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) @@ -153,8 +153,8 @@ private Delete prepareDelete() { } private Delete prepareAnotherDelete() { - Key partitionKey = new Key(new TextValue(ANY_NAME_5, ANY_TEXT_5)); - Key clusteringKey = new Key(new TextValue(ANY_NAME_6, ANY_TEXT_6)); + Key partitionKey = new Key(ANY_NAME_5, ANY_TEXT_5); + Key clusteringKey = new Key(ANY_NAME_6, ANY_TEXT_6); return new Delete(partitionKey, clusteringKey) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) @@ -699,10 +699,10 @@ public void get_ScanGivenAndPutInWriteSetNotOverlappedWithScan_ShouldNotThrowExc Snapshot.Key putKey = new Snapshot.Key(put); snapshot.put(putKey, put); Scan scan = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) // ["text3", "text4"] - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3)), true) - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_4)), true) + .withStart(new Key(ANY_NAME_2, ANY_TEXT_3), true) + .withEnd(new Key(ANY_NAME_2, ANY_TEXT_4), true) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); @@ -741,7 +741,7 @@ public void get_ScanGivenAndPutInWriteSetNotOverlappedWithScan_ShouldNotThrowExc Snapshot.Key putKey = new Snapshot.Key(put); snapshot.put(putKey, put); Scan scan = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) // (-infinite, infinite) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) @@ -766,28 +766,28 @@ public void get_ScanGivenAndPutInWriteSetNotOverlappedWithScan_ShouldNotThrowExc Scan scan1 = prepareScan() // ["text1", "text3"] - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_1)), true) - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3)), true); + .withStart(new Key(ANY_NAME_2, ANY_TEXT_1), true) + .withEnd(new Key(ANY_NAME_2, ANY_TEXT_3), true); Scan scan2 = prepareScan() // ["text2", "text3"] - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)), true) - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3)), true); + .withStart(new Key(ANY_NAME_2, ANY_TEXT_2), true) + .withEnd(new Key(ANY_NAME_2, ANY_TEXT_3), true); Scan scan3 = prepareScan() // ["text1", "text2"] - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_1)), true) - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)), true); + .withStart(new Key(ANY_NAME_2, ANY_TEXT_1), true) + .withEnd(new Key(ANY_NAME_2, ANY_TEXT_2), true); Scan scan4 = prepareScan() // ("text2", "text3"] - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)), false) - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3)), true); + .withStart(new Key(ANY_NAME_2, ANY_TEXT_2), false) + .withEnd(new Key(ANY_NAME_2, ANY_TEXT_3), true); Scan scan5 = prepareScan() // ["text1", "text2") - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_1)), true) - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)), false); + .withStart(new Key(ANY_NAME_2, ANY_TEXT_1), true) + .withEnd(new Key(ANY_NAME_2, ANY_TEXT_2), false); // Act Assert Throwable thrown1 = catchThrowable(() -> snapshot.get(scan1)); @@ -814,23 +814,23 @@ public void get_ScanGivenAndPutInWriteSetNotOverlappedWithScan_ShouldNotThrowExc Snapshot.Key putKey = new Snapshot.Key(put); snapshot.put(putKey, put); Scan scan1 = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) // (-infinite, "text3"] - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_3)), true) + .withEnd(new Key(ANY_NAME_2, ANY_TEXT_3), true) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); Scan scan2 = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) // (-infinite, "text2"] - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)), true) + .withEnd(new Key(ANY_NAME_2, ANY_TEXT_2), true) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); Scan scan3 = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) // (-infinite, "text2") - .withEnd(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)), false) + .withEnd(new Key(ANY_NAME_2, ANY_TEXT_2), false) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); @@ -856,23 +856,23 @@ public void get_ScanGivenAndPutInWriteSetNotOverlappedWithScan_ShouldNotThrowExc Snapshot.Key putKey = new Snapshot.Key(put); snapshot.put(putKey, put); Scan scan1 = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) // ["text1", infinite) - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_1)), true) + .withStart(new Key(ANY_NAME_2, ANY_TEXT_1), true) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); Scan scan2 = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) // ["text2", infinite) - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)), true) + .withStart(new Key(ANY_NAME_2, ANY_TEXT_2), true) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); Scan scan3 = - new Scan(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1))) + new Scan(new Key(ANY_NAME_1, ANY_TEXT_1)) // ("text2", infinite) - .withStart(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)), false) + .withStart(new Key(ANY_NAME_2, ANY_TEXT_2), false) .withConsistency(Consistency.LINEARIZABLE) .forNamespace(ANY_KEYSPACE_NAME) .forTable(ANY_TABLE_NAME); diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/TransactionResultTest.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/TransactionResultTest.java index ab878e7140..a1b70871fd 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/TransactionResultTest.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/TransactionResultTest.java @@ -9,7 +9,6 @@ import com.scalar.db.api.TransactionState; 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.Map; import java.util.Optional; @@ -35,10 +34,8 @@ public class TransactionResultTest { private TransactionResult result; private void configureResult(Result mock) { - when(mock.getPartitionKey()) - .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)))); - when(mock.getClusteringKey()) - .thenReturn(Optional.of(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)))); + when(mock.getPartitionKey()).thenReturn(Optional.of(new Key(ANY_NAME_1, ANY_TEXT_1))); + when(mock.getClusteringKey()).thenReturn(Optional.of(new Key(ANY_NAME_2, ANY_TEXT_2))); ImmutableMap> values = ImmutableMap.>builder() @@ -76,7 +73,7 @@ public void getPartitionKey_ResultGiven_ShouldReturnCorrectKey() { Optional actual = result.getPartitionKey(); // Assert - assertThat(actual).isEqualTo(Optional.of(new Key(new TextValue(ANY_NAME_1, ANY_TEXT_1)))); + assertThat(actual).isEqualTo(Optional.of(new Key(ANY_NAME_1, ANY_TEXT_1))); } @Test @@ -88,7 +85,7 @@ public void getClusteringKey_ResultGiven_ShouldReturnCorrectKey() { Optional actual = result.getClusteringKey(); // Assert - assertThat(actual).isEqualTo(Optional.of(new Key(new TextValue(ANY_NAME_2, ANY_TEXT_2)))); + assertThat(actual).isEqualTo(Optional.of(new Key(ANY_NAME_2, ANY_TEXT_2))); } @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 a44acb98c6..243b0b2bd8 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 @@ -16,7 +16,6 @@ import com.scalar.db.exception.transaction.CrudException; import com.scalar.db.exception.transaction.UnknownTransactionStatusException; import com.scalar.db.io.Key; -import com.scalar.db.io.TextValue; import com.scalar.db.storage.jdbc.JdbcService; import com.scalar.db.storage.jdbc.RdbEngine; import java.sql.Connection; @@ -55,13 +54,13 @@ public void whenSomeOperationsExecutedAndCommit_shouldCallJdbcService() throws E // Act JdbcTransaction transaction = manager.start(); - Get get = new Get(new Key(new TextValue("p1", "val"))); + Get get = new Get(new Key("p1", "val")); transaction.get(get); - Scan scan = new Scan(new Key(new TextValue("p1", "val"))); + Scan scan = new Scan(new Key("p1", "val")); transaction.scan(scan); - Put put = new Put(new Key(new TextValue("p1", "val1"))).withValue(new TextValue("v1", "val2")); + Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2"); transaction.put(put); - Delete delete = new Delete(new Key(new TextValue("p1", "val1"))); + Delete delete = new Delete(new Key("p1", "val1")); transaction.delete(delete); transaction.mutate(Arrays.asList(put, delete)); transaction.commit(); @@ -85,7 +84,7 @@ public void whenGetOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThro assertThatThrownBy( () -> { JdbcTransaction transaction = manager.start(); - Get get = new Get(new Key(new TextValue("p1", "val"))); + Get get = new Get(new Key("p1", "val")); transaction.get(get); }) .isInstanceOf(CrudException.class); @@ -101,7 +100,7 @@ public void whenScanOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThr assertThatThrownBy( () -> { JdbcTransaction transaction = manager.start(); - Scan scan = new Scan(new Key(new TextValue("p1", "val"))); + Scan scan = new Scan(new Key("p1", "val")); transaction.scan(scan); }) .isInstanceOf(CrudException.class); @@ -117,9 +116,7 @@ public void whenPutOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThro assertThatThrownBy( () -> { JdbcTransaction transaction = manager.start(); - Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")); + Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2"); transaction.put(put); }) .isInstanceOf(CrudException.class); @@ -136,7 +133,7 @@ public void whenPutOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThro assertThatThrownBy( () -> { JdbcTransaction transaction = manager.start(); - Delete delete = new Delete(new Key(new TextValue("p1", "val1"))); + Delete delete = new Delete(new Key("p1", "val1")); transaction.delete(delete); }) .isInstanceOf(CrudException.class); @@ -153,10 +150,8 @@ public void whenPutOperationsExecutedAndJdbcServiceThrowsSQLException_shouldThro assertThatThrownBy( () -> { JdbcTransaction transaction = manager.start(); - Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")); - Delete delete = new Delete(new Key(new TextValue("p1", "val1"))); + Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2"); + Delete delete = new Delete(new Key("p1", "val1")); transaction.mutate(Arrays.asList(put, delete)); }) .isInstanceOf(CrudException.class); @@ -171,11 +166,9 @@ public void whenCommitFails_shouldThrowCommitExceptionAndRollback() throws Excep assertThatThrownBy( () -> { JdbcTransaction transaction = manager.start(); - Get get = new Get(new Key(new TextValue("p1", "val"))); + Get get = new Get(new Key("p1", "val")); transaction.get(get); - Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")); + Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2"); transaction.put(put); transaction.commit(); }) @@ -193,11 +186,9 @@ public void whenRollbackFails_shouldThrowAbortException() throws Exception { assertThatThrownBy( () -> { JdbcTransaction transaction = manager.start(); - Get get = new Get(new Key(new TextValue("p1", "val"))); + Get get = new Get(new Key("p1", "val")); transaction.get(get); - Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")); + Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2"); transaction.put(put); transaction.abort(); }) @@ -216,11 +207,9 @@ public void whenCommitAndRollbackFails_shouldThrowUnknownTransactionStatusExcept assertThatThrownBy( () -> { JdbcTransaction transaction = manager.start(); - Get get = new Get(new Key(new TextValue("p1", "val"))); + Get get = new Get(new Key("p1", "val")); transaction.get(get); - Put put = - new Put(new Key(new TextValue("p1", "val1"))) - .withValue(new TextValue("v1", "val2")); + Put put = new Put(new Key("p1", "val1")).withValue("v1", "val2"); transaction.put(put); transaction.commit(); }) diff --git a/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithConsensusCommitIntegrationTest.java b/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithConsensusCommitIntegrationTest.java index abbe5834f0..b78d2dfaac 100644 --- a/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithConsensusCommitIntegrationTest.java +++ b/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithConsensusCommitIntegrationTest.java @@ -145,7 +145,7 @@ public void getAndScan_CommitHappenedInBetween_ShouldReadRepeatably() throws TransactionException { // Arrange GrpcTransaction transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); transaction.commit(); GrpcTransaction transaction1 = manager.start(); @@ -153,7 +153,7 @@ public void getAndScan_CommitHappenedInBetween_ShouldReadRepeatably() GrpcTransaction transaction2 = manager.start(); transaction2.get(prepareGet(0, 0, TABLE_1)); - transaction2.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 2))); + transaction2.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 2)); transaction2.commit(); // Act @@ -197,7 +197,7 @@ public void putAndCommit_PutGivenForExistingAfterRead_ShouldUpdateRecord() // Act Optional result = transaction.get(get); - int afterBalance = ((IntValue) result.get().getValue(BALANCE).get()).get() + 100; + int afterBalance = result.get().getValue(BALANCE).get().getAsInt() + 100; IntValue expected = new IntValue(BALANCE, afterBalance); Put put = preparePut(0, 0, TABLE_1).withValue(expected); transaction.put(put); @@ -218,7 +218,7 @@ public void putAndCommit_PutGivenForExistingAndNeverRead_ShouldThrowCommitExcept // Arrange populateRecords(TABLE_1); List puts = preparePuts(TABLE_1); - puts.get(0).withValue(new IntValue(BALANCE, 1100)); + puts.get(0).withValue(BALANCE, 1100); GrpcTransaction transaction = manager.start(); // Act Assert @@ -684,8 +684,8 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria // Arrange List puts = Arrays.asList( - preparePut(0, 0, table1).withValue(new IntValue(BALANCE, 1)), - preparePut(0, 1, table2).withValue(new IntValue(BALANCE, 1))); + preparePut(0, 0, table1).withValue(BALANCE, 1), + preparePut(0, 1, table2).withValue(BALANCE, 1)); GrpcTransaction transaction = manager.start(); transaction.put(puts); transaction.commit(); @@ -697,15 +697,15 @@ private void commit_WriteSkewOnExistingRecordsWithSnapshot_ShouldProduceNonSeria Optional result1 = transaction1.get(get1_1); Get get1_2 = prepareGet(0, 0, table1); transaction1.get(get1_2); - int current1 = ((IntValue) result1.get().getValue(BALANCE).get()).get(); + int current1 = result1.get().getValue(BALANCE).get().getAsInt(); Get get2_1 = prepareGet(0, 0, table1); Optional result2 = transaction2.get(get2_1); Get get2_2 = prepareGet(0, 1, table2); transaction2.get(get2_2); - int current2 = ((IntValue) result2.get().getValue(BALANCE).get()).get(); - Put put1 = preparePut(0, 0, table1).withValue(new IntValue(BALANCE, current1 + 1)); + int current2 = result2.get().getValue(BALANCE).get().getAsInt(); + Put put1 = preparePut(0, 0, table1).withValue(BALANCE, current1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, table2).withValue(new IntValue(BALANCE, current2 + 1)); + Put put2 = preparePut(0, 1, table2).withValue(BALANCE, current2 + 1); transaction2.put(put2); transaction1.commit(); transaction2.commit(); @@ -741,7 +741,7 @@ public void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializa throws TransactionException { // Arrange GrpcTransaction transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 2))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 2)); transaction.commit(); // Act @@ -749,9 +749,9 @@ public void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializa Optional result1 = transaction1.get(prepareGet(0, 0, TABLE_1)); int balance1 = 0; if (result1.isPresent()) { - balance1 = ((IntValue) result1.get().getValue(BALANCE).get()).get(); + balance1 = result1.get().getValue(BALANCE).get().getAsInt(); } - transaction1.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, balance1 + 1))); + transaction1.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, balance1 + 1)); GrpcTransaction transaction2 = manager.start(); transaction2.get(prepareGet(0, 0, TABLE_1)); @@ -763,9 +763,9 @@ public void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializa Optional result3 = transaction3.get(prepareGet(0, 0, TABLE_1)); int balance3 = 0; if (result3.isPresent()) { - balance3 = ((IntValue) result3.get().getValue(BALANCE).get()).get(); + balance3 = result3.get().getValue(BALANCE).get().getAsInt(); } - transaction3.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, balance3 + 1))); + transaction3.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, balance3 + 1)); transaction3.commit(); Throwable thrown = catchThrowable(transaction1::commit); @@ -775,7 +775,7 @@ public void putAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerializa transaction = manager.start(); Optional result = transaction.get(prepareGet(0, 0, TABLE_1)); transaction.commit(); - assertThat(((IntValue) result.get().getValue(BALANCE).get()).get()).isEqualTo(1); + assertThat(result.get().getValue(BALANCE).get().getAsInt()).isEqualTo(1); } @Test @@ -783,7 +783,7 @@ public void deleteAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerial throws TransactionException { // Arrange GrpcTransaction transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 2))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 2)); transaction.commit(); // Act @@ -801,9 +801,9 @@ public void deleteAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerial Optional result3 = transaction3.get(prepareGet(0, 0, TABLE_1)); int balance3 = 0; if (result3.isPresent()) { - balance3 = ((IntValue) result3.get().getValue(BALANCE).get()).get(); + balance3 = result3.get().getValue(BALANCE).get().getAsInt(); } - transaction3.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, balance3 + 1))); + transaction3.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, balance3 + 1)); transaction3.commit(); Throwable thrown = catchThrowable(transaction1::commit); @@ -813,14 +813,14 @@ public void deleteAndCommit_DeleteGivenInBetweenTransactions_ShouldProduceSerial transaction = manager.start(); Optional result = transaction.get(prepareGet(0, 0, TABLE_1)); transaction.commit(); - assertThat(((IntValue) result.get().getValue(BALANCE).get()).get()).isEqualTo(1); + assertThat(result.get().getValue(BALANCE).get().getAsInt()).isEqualTo(1); } @Test public void get_DeleteCalledBefore_ShouldReturnEmpty() throws TransactionException { // Arrange GrpcTransaction transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); transaction.commit(); // Act @@ -840,7 +840,7 @@ public void get_DeleteCalledBefore_ShouldReturnEmpty() throws TransactionExcepti public void scan_DeleteCalledBefore_ShouldReturnEmpty() throws TransactionException { // Arrange GrpcTransaction transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); transaction.commit(); // Act @@ -860,14 +860,14 @@ public void scan_DeleteCalledBefore_ShouldReturnEmpty() throws TransactionExcept public void delete_PutCalledBefore_ShouldDelete() throws TransactionException { // Arrange GrpcTransaction transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); transaction.commit(); // Act GrpcTransaction transaction1 = manager.start(); Get get = prepareGet(0, 0, TABLE_1); Optional resultBefore = transaction1.get(get); - transaction1.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 2))); + transaction1.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 2)); transaction1.delete(prepareDelete(0, 0, TABLE_1)); assertThatCode(transaction1::commit).doesNotThrowAnyException(); @@ -883,7 +883,7 @@ public void delete_PutCalledBefore_ShouldDelete() throws TransactionException { public void put_DeleteCalledBefore_ShouldPut() throws TransactionException { // Arrange GrpcTransaction transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); transaction.commit(); // Act @@ -891,7 +891,7 @@ public void put_DeleteCalledBefore_ShouldPut() throws TransactionException { Get get = prepareGet(0, 0, TABLE_1); Optional resultBefore = transaction1.get(get); transaction1.delete(prepareDelete(0, 0, TABLE_1)); - transaction1.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 2))); + transaction1.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 2)); assertThatCode(transaction1::commit).doesNotThrowAnyException(); // Assert @@ -908,7 +908,7 @@ public void scan_OverlappingPutGivenBefore_ShouldThrowCrudException() throws TransactionException { // Arrange GrpcTransaction transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); // Act Scan scan = prepareScan(0, 0, 0, TABLE_1); @@ -923,7 +923,7 @@ public void scan_OverlappingPutGivenBefore_ShouldThrowCrudException() public void scan_NonOverlappingPutGivenBefore_ShouldScan() throws TransactionException { // Arrange GrpcTransaction transaction = manager.start(); - transaction.put(preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1))); + transaction.put(preparePut(0, 0, TABLE_1).withValue(BALANCE, 1)); // Act Scan scan = prepareScan(0, 1, 1, TABLE_1); @@ -971,9 +971,9 @@ private GrpcTransaction prepareTransfer( Optional toResult = transaction.get(toGets.get(toId)); IntValue fromBalance = - new IntValue(BALANCE, ((IntValue) fromResult.get().getValue(BALANCE).get()).get() - amount); + new IntValue(BALANCE, fromResult.get().getValue(BALANCE).get().getAsInt() - amount); IntValue toBalance = - new IntValue(BALANCE, ((IntValue) toResult.get().getValue(BALANCE).get()).get() + amount); + new IntValue(BALANCE, toResult.get().getValue(BALANCE).get().getAsInt() + amount); List fromPuts = preparePuts(fromTable); List toPuts = differentTables ? preparePuts(toTable) : fromPuts; @@ -1012,13 +1012,13 @@ private void populateRecords(String table) throws TransactionException { IntStream.range(0, NUM_TYPES) .forEach( j -> { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, i)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, j)); + Key partitionKey = new Key(ACCOUNT_ID, i); + Key clusteringKey = new Key(ACCOUNT_TYPE, j); Put put = new Put(partitionKey, clusteringKey) .forNamespace(NAMESPACE) .forTable(table) - .withValue(new IntValue(BALANCE, INITIAL_BALANCE)); + .withValue(BALANCE, INITIAL_BALANCE); try { transaction.put(put); } catch (TransactionException e) { @@ -1029,8 +1029,8 @@ private void populateRecords(String table) throws TransactionException { } static Get prepareGet(int id, int type, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, type)); + Key partitionKey = new Key(ACCOUNT_ID, id); + Key clusteringKey = new Key(ACCOUNT_TYPE, type); return new Get(partitionKey, clusteringKey) .forNamespace(NAMESPACE) .forTable(table) @@ -1046,18 +1046,18 @@ static List prepareGets(String table) { } static Scan prepareScan(int id, int fromType, int toType, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); + Key partitionKey = new Key(ACCOUNT_ID, id); return new Scan(partitionKey) .forNamespace(NAMESPACE) .forTable(table) .withConsistency(Consistency.LINEARIZABLE) - .withStart(new Key(new IntValue(ACCOUNT_TYPE, fromType))) - .withEnd(new Key(new IntValue(ACCOUNT_TYPE, toType))); + .withStart(new Key(ACCOUNT_TYPE, fromType)) + .withEnd(new Key(ACCOUNT_TYPE, toType)); } static Put preparePut(int id, int type, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, type)); + Key partitionKey = new Key(ACCOUNT_ID, id); + Key clusteringKey = new Key(ACCOUNT_TYPE, type); return new Put(partitionKey, clusteringKey) .forNamespace(NAMESPACE) .forTable(table) @@ -1073,8 +1073,8 @@ static List preparePuts(String table) { } static Delete prepareDelete(int id, int type, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, type)); + Key partitionKey = new Key(ACCOUNT_ID, id); + Key clusteringKey = new Key(ACCOUNT_TYPE, type); return new Delete(partitionKey, clusteringKey) .forNamespace(NAMESPACE) .forTable(table) diff --git a/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithConsensusCommitWithExtraReadIntegrationTest.java b/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithConsensusCommitWithExtraReadIntegrationTest.java index 41d03eaed0..455da7ca1a 100644 --- a/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithConsensusCommitWithExtraReadIntegrationTest.java +++ b/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithConsensusCommitWithExtraReadIntegrationTest.java @@ -68,8 +68,8 @@ public void tearDown() throws Exception { // Arrange List puts = Arrays.asList( - preparePut(0, 0, table1).withValue(new IntValue(BALANCE, 1)), - preparePut(0, 1, table2).withValue(new IntValue(BALANCE, 1))); + preparePut(0, 0, table1).withValue(BALANCE, 1), + preparePut(0, 1, table2).withValue(BALANCE, 1)); GrpcTransaction transaction = manager.start(); transaction.put(puts); transaction.commit(); @@ -81,15 +81,15 @@ public void tearDown() throws Exception { Optional result1 = transaction1.get(get1_1); Get get1_2 = prepareGet(0, 0, table1); transaction1.get(get1_2); - int current1 = ((IntValue) result1.get().getValue(BALANCE).get()).get(); + int current1 = result1.get().getValue(BALANCE).get().getAsInt(); Get get2_1 = prepareGet(0, 0, table1); Optional result2 = transaction2.get(get2_1); Get get2_2 = prepareGet(0, 1, table2); transaction2.get(get2_2); - int current2 = ((IntValue) result2.get().getValue(BALANCE).get()).get(); - Put put1 = preparePut(0, 0, table1).withValue(new IntValue(BALANCE, current1 + 1)); + int current2 = result2.get().getValue(BALANCE).get().getAsInt(); + Put put1 = preparePut(0, 0, table1).withValue(BALANCE, current1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, table2).withValue(new IntValue(BALANCE, current2 + 1)); + Put put2 = preparePut(0, 1, table2).withValue(BALANCE, current2 + 1); transaction2.put(put2); transaction1.commit(); Throwable thrown = catchThrowable(transaction2::commit); @@ -139,9 +139,9 @@ public void tearDown() throws Exception { Get get2_2 = prepareGet(0, 1, table2); transaction2.get(get2_2); int current2 = 0; - Put put1 = preparePut(0, 0, table1).withValue(new IntValue(BALANCE, current1 + 1)); + Put put1 = preparePut(0, 0, table1).withValue(BALANCE, current1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, table2).withValue(new IntValue(BALANCE, current2 + 1)); + Put put2 = preparePut(0, 1, table2).withValue(BALANCE, current2 + 1); transaction2.put(put2); Throwable thrown1 = catchThrowable(transaction1::commit); Throwable thrown2 = catchThrowable(transaction2::commit); @@ -190,9 +190,9 @@ public void tearDown() throws Exception { int count1 = results1.size(); List results2 = transaction2.scan(prepareScan(0, 0, 1, TABLE_1)); int count2 = results2.size(); - Put put1 = preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, count1 + 1)); + Put put1 = preparePut(0, 0, TABLE_1).withValue(BALANCE, count1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, TABLE_1).withValue(new IntValue(BALANCE, count2 + 1)); + Put put2 = preparePut(0, 1, TABLE_1).withValue(BALANCE, count2 + 1); transaction2.put(put2); Throwable thrown1 = catchThrowable(transaction1::commit); Throwable thrown2 = catchThrowable(transaction2::commit); @@ -218,8 +218,8 @@ public void tearDown() throws Exception { // Arrange List puts = Arrays.asList( - preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, 1)), - preparePut(0, 1, TABLE_1).withValue(new IntValue(BALANCE, 1))); + preparePut(0, 0, TABLE_1).withValue(BALANCE, 1), + preparePut(0, 1, TABLE_1).withValue(BALANCE, 1)); GrpcTransaction transaction = manager.start(); transaction.put(puts); transaction.commit(); @@ -231,9 +231,9 @@ public void tearDown() throws Exception { int count1 = results1.size(); List results2 = transaction2.scan(prepareScan(0, 0, 1, TABLE_1)); int count2 = results2.size(); - Put put1 = preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, count1 + 1)); + Put put1 = preparePut(0, 0, TABLE_1).withValue(BALANCE, count1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, TABLE_1).withValue(new IntValue(BALANCE, count2 + 1)); + Put put2 = preparePut(0, 1, TABLE_1).withValue(BALANCE, count2 + 1); transaction2.put(put2); Throwable thrown1 = catchThrowable(transaction1::commit); Throwable thrown2 = catchThrowable(transaction2::commit); diff --git a/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithConsensusCommitWithExtraWriteIntegrationTest.java b/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithConsensusCommitWithExtraWriteIntegrationTest.java index f52fa3c109..4ef74a6786 100644 --- a/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithConsensusCommitWithExtraWriteIntegrationTest.java +++ b/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithConsensusCommitWithExtraWriteIntegrationTest.java @@ -68,8 +68,8 @@ public void tearDown() throws Exception { // Arrange List puts = Arrays.asList( - preparePut(0, 0, table1).withValue(new IntValue(BALANCE, 1)), - preparePut(0, 1, table2).withValue(new IntValue(BALANCE, 1))); + preparePut(0, 0, table1).withValue(BALANCE, 1), + preparePut(0, 1, table2).withValue(BALANCE, 1)); GrpcTransaction transaction = manager.start(); transaction.put(puts); transaction.commit(); @@ -81,15 +81,15 @@ public void tearDown() throws Exception { Optional result1 = transaction1.get(get1_1); Get get1_2 = prepareGet(0, 0, table1); transaction1.get(get1_2); - int current1 = ((IntValue) result1.get().getValue(BALANCE).get()).get(); + int current1 = result1.get().getValue(BALANCE).get().getAsInt(); Get get2_1 = prepareGet(0, 0, table1); Optional result2 = transaction2.get(get2_1); Get get2_2 = prepareGet(0, 1, table2); transaction2.get(get2_2); - int current2 = ((IntValue) result2.get().getValue(BALANCE).get()).get(); - Put put1 = preparePut(0, 0, table1).withValue(new IntValue(BALANCE, current1 + 1)); + int current2 = result2.get().getValue(BALANCE).get().getAsInt(); + Put put1 = preparePut(0, 0, table1).withValue(BALANCE, current1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, table2).withValue(new IntValue(BALANCE, current2 + 1)); + Put put2 = preparePut(0, 1, table2).withValue(BALANCE, current2 + 1); transaction2.put(put2); transaction1.commit(); Throwable thrown = catchThrowable(transaction2::commit); @@ -139,9 +139,9 @@ public void tearDown() throws Exception { Get get2_2 = prepareGet(0, 1, table2); transaction2.get(get2_2); int current2 = 0; - Put put1 = preparePut(0, 0, table1).withValue(new IntValue(BALANCE, current1 + 1)); + Put put1 = preparePut(0, 0, table1).withValue(BALANCE, current1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, table2).withValue(new IntValue(BALANCE, current2 + 1)); + Put put2 = preparePut(0, 1, table2).withValue(BALANCE, current2 + 1); transaction2.put(put2); Throwable thrown1 = catchThrowable(transaction1::commit); Throwable thrown2 = catchThrowable(transaction2::commit); @@ -189,9 +189,9 @@ public void tearDown() throws Exception { int count1 = results1.size(); List results2 = transaction2.scan(prepareScan(0, 0, 1, TABLE_1)); int count2 = results2.size(); - Put put1 = preparePut(0, 0, TABLE_1).withValue(new IntValue(BALANCE, count1 + 1)); + Put put1 = preparePut(0, 0, TABLE_1).withValue(BALANCE, count1 + 1); transaction1.put(put1); - Put put2 = preparePut(0, 1, TABLE_1).withValue(new IntValue(BALANCE, count2 + 1)); + Put put2 = preparePut(0, 1, TABLE_1).withValue(BALANCE, count2 + 1); transaction2.put(put2); Throwable thrown1 = catchThrowable(transaction1::commit); Throwable thrown2 = catchThrowable(transaction2::commit); diff --git a/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithJdbcTransactionIntegrationTest.java b/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithJdbcTransactionIntegrationTest.java index 232dbca0d4..196d1194ef 100644 --- a/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithJdbcTransactionIntegrationTest.java +++ b/server/src/integration-test/java/com/scalar/db/server/DistributedTransactionServiceWithJdbcTransactionIntegrationTest.java @@ -143,7 +143,7 @@ public void putAndCommit_PutGivenForExistingAfterRead_ShouldUpdateRecord() // Act Optional result = transaction.get(get); - int afterBalance = ((IntValue) result.get().getValue(BALANCE).get()).get() + 100; + int afterBalance = result.get().getValue(BALANCE).get().getAsInt() + 100; IntValue expected = new IntValue(BALANCE, afterBalance); Put put = preparePut(0, 0, NAMESPACE, TABLE).withValue(expected); transaction.put(put); @@ -216,9 +216,9 @@ private GrpcTransaction prepareTransfer(int fromId, int toId, int amount) Optional result1 = transaction.get(gets.get(fromId)); Optional result2 = transaction.get(gets.get(toId)); IntValue fromBalance = - new IntValue(BALANCE, ((IntValue) result1.get().getValue(BALANCE).get()).get() - amount); + new IntValue(BALANCE, result1.get().getValue(BALANCE).get().getAsInt() - amount); IntValue toBalance = - new IntValue(BALANCE, ((IntValue) result2.get().getValue(BALANCE).get()).get() + amount); + new IntValue(BALANCE, result2.get().getValue(BALANCE).get().getAsInt() + amount); List puts = preparePuts(NAMESPACE, TABLE); puts.get(fromId).withValue(fromBalance); puts.get(toId).withValue(toBalance); @@ -235,13 +235,13 @@ private void populateRecords() throws TransactionException { IntStream.range(0, NUM_TYPES) .forEach( j -> { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, i)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, j)); + Key partitionKey = new Key(ACCOUNT_ID, i); + Key clusteringKey = new Key(ACCOUNT_TYPE, j); Put put = new Put(partitionKey, clusteringKey) .forNamespace(NAMESPACE) .forTable(TABLE) - .withValue(new IntValue(BALANCE, INITIAL_BALANCE)); + .withValue(BALANCE, INITIAL_BALANCE); try { transaction.put(put); } catch (CrudException e) { @@ -252,8 +252,8 @@ private void populateRecords() throws TransactionException { } private Get prepareGet(int id, int type, String namespace, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, type)); + Key partitionKey = new Key(ACCOUNT_ID, id); + Key clusteringKey = new Key(ACCOUNT_TYPE, type); return new Get(partitionKey, clusteringKey) .forNamespace(namespace) .forTable(table) @@ -271,18 +271,18 @@ private List prepareGets(String namespace, String table) { } private Scan prepareScan(int id, int fromType, int toType, String namespace, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); + Key partitionKey = new Key(ACCOUNT_ID, id); return new Scan(partitionKey) .forNamespace(namespace) .forTable(table) .withConsistency(Consistency.LINEARIZABLE) - .withStart(new Key(new IntValue(ACCOUNT_TYPE, fromType))) - .withEnd(new Key(new IntValue(ACCOUNT_TYPE, toType))); + .withStart(new Key(ACCOUNT_TYPE, fromType)) + .withEnd(new Key(ACCOUNT_TYPE, toType)); } private Put preparePut(int id, int type, String namespace, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, type)); + Key partitionKey = new Key(ACCOUNT_ID, id); + Key clusteringKey = new Key(ACCOUNT_TYPE, type); return new Put(partitionKey, clusteringKey) .forNamespace(namespace) .forTable(table) @@ -300,8 +300,8 @@ private List preparePuts(String namespace, String table) { } private Delete prepareDelete(int id, int type, String namespace, String table) { - Key partitionKey = new Key(new IntValue(ACCOUNT_ID, id)); - Key clusteringKey = new Key(new IntValue(ACCOUNT_TYPE, type)); + Key partitionKey = new Key(ACCOUNT_ID, id); + Key clusteringKey = new Key(ACCOUNT_TYPE, type); return new Delete(partitionKey, clusteringKey) .forNamespace(namespace) .forTable(table)