From 56baee9d69a938f25f5bad7a4c758b8ffd17a20f Mon Sep 17 00:00:00 2001 From: "Daniel B. Garcia" Date: Fri, 12 Mar 2021 14:00:15 +0800 Subject: [PATCH 01/12] Fix for 'Exception in thread main java.lang.NoSuchMethodError: com.basho.riak.client.api.commands.datatypes.SetUpdate.add(Ljava/lang/String;) Lcom/basho/riak/client/api/commands/datatypes/SetUpdate;' --- .../client/api/commands/datatypes/SetUpdate.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/basho/riak/client/api/commands/datatypes/SetUpdate.java b/src/main/java/com/basho/riak/client/api/commands/datatypes/SetUpdate.java index 5fc064ed2..6357e35c6 100644 --- a/src/main/java/com/basho/riak/client/api/commands/datatypes/SetUpdate.java +++ b/src/main/java/com/basho/riak/client/api/commands/datatypes/SetUpdate.java @@ -42,6 +42,20 @@ public SetUpdate() { } + @Override + public SetUpdate add(BinaryValue value) + { + super.add(value); + return this; + } + + @Override + public SetUpdate add(String value) + { + super.add(value); + return this; + } + /** * Remove the provided value from the set in Riak. * @param value the value to be removed. From 0e167459bcea07c143849dfe6448ce78fc23f2c5 Mon Sep 17 00:00:00 2001 From: "Daniel B. Garcia" Date: Fri, 16 Apr 2021 14:36:45 +0800 Subject: [PATCH 02/12] Added parameter to Maven's javadoc plugin to allow comments containing scripts --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 74d39e7c4..6dff834cf 100755 --- a/pom.xml +++ b/pom.xml @@ -205,6 +205,7 @@ maven-javadoc-plugin -Xdoclint:none + --allow-script-in-comments com.basho.riak.protobuf.util From 5d64ca39f26dfa4b7929ea476c90e76e802aee68 Mon Sep 17 00:00:00 2001 From: "Daniel B. Garcia" Date: Fri, 22 Oct 2021 13:53:41 +0800 Subject: [PATCH 03/12] Added javax.xml.bind dependency. --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 6dff834cf..835112c05 100755 --- a/pom.xml +++ b/pom.xml @@ -470,5 +470,10 @@ commons-codec 1.10 + + javax.xml.bind + jaxb-api + 2.3.1 + From 7a2f9234aad02f7b9d9d19f8a47e14c00798f8f5 Mon Sep 17 00:00:00 2001 From: "Daniel B. Garcia" Date: Wed, 10 Nov 2021 13:02:46 +0800 Subject: [PATCH 04/12] Updated animal-sniffer plugin to fix IllegalArgumentException. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 835112c05..a8a30d6e3 100755 --- a/pom.xml +++ b/pom.xml @@ -370,7 +370,7 @@ org.codehaus.mojo animal-sniffer-maven-plugin - 1.15 + 1.20 org.codehaus.mojo.signature From 858abd09e13c49d7a3826824cbc55dd1002fc802 Mon Sep 17 00:00:00 2001 From: "Daniel B. Garcia" Date: Mon, 28 Mar 2022 09:44:41 +0800 Subject: [PATCH 05/12] Test codes (unfinished). --- notes.txt | 8 ++++ .../api/commands/itest/ITestDatatype.java | 38 +++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 notes.txt diff --git a/notes.txt b/notes.txt new file mode 100644 index 000000000..25dcbbf8d --- /dev/null +++ b/notes.txt @@ -0,0 +1,8 @@ +mvn clean +mvn -Pjar-with-dependencies assembly:single + +mvn -Pitest,default -Dcom.basho.riak.host=192.168.33.11 -Dcom.basho.riak.pbcport=8087 verify +mvn -Pitest -Dcom.basho.riak.host=192.168.33.11 -Dcom.basho.riak.pbcport=8087 verify +mvn -Pdefault -Dcom.basho.riak.host=192.168.33.11 -Dcom.basho.riak.pbcport=8087 verify + +mvn -Pitest,default -Dcom.basho.riak.host=192.168.33.11 -Dcom.basho.riak.pbcport=8087 -DskipTests verify diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java index 2b887da0f..a3fe8e2c8 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java @@ -11,11 +11,9 @@ import org.junit.Assume; import org.junit.Test; +import javax.swing.*; import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Random; -import java.util.Set; +import java.util.*; import java.util.concurrent.ExecutionException; import static org.junit.Assert.*; @@ -124,6 +122,38 @@ public void simpleTest() throws ExecutionException, InterruptedException } assertTrue(setView.containsAll(expectedSet)); assertTrue(expectedSet.containsAll(setView)); + + // cart - asSet - item removal + ByteBuffer b = ByteBuffer.allocate(4); + b.putInt(5); + + // - remove item '5' + SetUpdate su = new SetUpdate().remove(BinaryValue.create(b.array())); + MapUpdate mu = new MapUpdate().update(shoppingCart, su); + MapUpdate muUser = new MapUpdate().update(username, mu); + UpdateMap updateEntry = new UpdateMap.Builder(carts, muUser).build(); + UpdateMap.Response res = client.execute(updateEntry); + +// // - fetch updated map +// FetchMap fetchMap = new FetchMap.Builder(loc).build(); +// FetchMap.Response fetchMapResponse = client.execute(fetchMap); +// RiakMap updatedUsersMap = fetchMapResponse.getDatatype(); +// RiakMap updatedUsernameMap = updatedUsersMap.getMap(username); +// RiakSet updatedShoppingCartSet = updatedUsernameMap.getSet(shoppingCart); +// Set updatedSetView = updatedShoppingCartSet.view(); +// +// // - build expected set +// int[] iArray = {0, 1, 2, 3, 4, 6, 7, 8, 9}; +// Set updatedExpectedSet = new HashSet<>(); +// for (int i = 0; i < iArray.length; i++) { +// ByteBuffer buf = ByteBuffer.allocate(4); +// buf.putInt(iArray[i]); +// updatedExpectedSet.add(BinaryValue.create(buf.array())); +// } +// +// // - compare sets +// assertTrue(updatedSetView.containsAll(updatedExpectedSet)); +// assertTrue(updatedExpectedSet.containsAll(updatedSetView)); } public void testConflict() throws ExecutionException, InterruptedException From 3aaf1625aa5899c3f8e30577b9b4aedf74d24a8c Mon Sep 17 00:00:00 2001 From: "Daniel B. Garcia" Date: Fri, 21 Oct 2022 16:22:35 +0800 Subject: [PATCH 06/12] Test codes (unfinished). --- notes.txt | 8 ++++ .../api/commands/itest/ITestDatatype.java | 42 +++++++++++-------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/notes.txt b/notes.txt index 25dcbbf8d..6052af898 100644 --- a/notes.txt +++ b/notes.txt @@ -6,3 +6,11 @@ mvn -Pitest -Dcom.basho.riak.host=192.168.33.11 -Dcom.basho.riak.pbcport=8087 ve mvn -Pdefault -Dcom.basho.riak.host=192.168.33.11 -Dcom.basho.riak.pbcport=8087 verify mvn -Pitest,default -Dcom.basho.riak.host=192.168.33.11 -Dcom.basho.riak.pbcport=8087 -DskipTests verify + + + + + + +sudo riak-admin bucket-type create maps '{"props":{"datatype":"map"}}' +sudo riak-admin bucket-type create plain '' diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java index a3fe8e2c8..051e9e1c8 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java @@ -129,10 +129,14 @@ public void simpleTest() throws ExecutionException, InterruptedException // - remove item '5' SetUpdate su = new SetUpdate().remove(BinaryValue.create(b.array())); - MapUpdate mu = new MapUpdate().update(shoppingCart, su); - MapUpdate muUser = new MapUpdate().update(username, mu); - UpdateMap updateEntry = new UpdateMap.Builder(carts, muUser).build(); - UpdateMap.Response res = client.execute(updateEntry); + for (BinaryValue item : expectedSet) { + System.out.println(" - " + item.getClass()); + } + System.out.println("\n\n"); +// MapUpdate mu = new MapUpdate().update(shoppingCart, su); +// MapUpdate muUser = new MapUpdate().update(username, mu); +// UpdateMap updateEntry = new UpdateMap.Builder(carts, muUser).build(); +// UpdateMap.Response res = client.execute(updateEntry); // // - fetch updated map // FetchMap fetchMap = new FetchMap.Builder(loc).build(); @@ -225,6 +229,8 @@ public void testNotFoundHyperLogLog() throws ExecutionException, InterruptedExce public void testGSet() throws ExecutionException , InterruptedException { Assume.assumeTrue(testGSetDataType); + resetAndEmptyBucket(uniqueUsers); + final Location location = new Location(uniqueUsers, "site-2017-01-01-" + new Random().nextLong()); FetchSet fetchSet = new FetchSet.Builder(location).build(); @@ -239,20 +245,20 @@ public void testGSet() throws ExecutionException , InterruptedException final UpdateSet.Response updateResponse = client.execute(us); final Set updatedSet = updateResponse.getDatatype().view(); - assertFalse(updatedSet.isEmpty()); - assertTrue(updatedSet.contains(BinaryValue.create("user1"))); - assertTrue(updatedSet.contains(BinaryValue.create("user2"))); - assertTrue(updatedSet.contains(BinaryValue.create("user3"))); - assertFalse(updateResponse.hasContext()); - - final FetchSet.Response loadedFetchResponse = client.execute(fetchSet); +// assertFalse(updatedSet.isEmpty()); +// assertTrue(updatedSet.contains(BinaryValue.create("user1"))); +// assertTrue(updatedSet.contains(BinaryValue.create("user2"))); +// assertTrue(updatedSet.contains(BinaryValue.create("user3"))); +// assertFalse(updateResponse.hasContext()); - final Set loadedSet = loadedFetchResponse.getDatatype().view(); - - assertFalse(loadedSet.isEmpty()); - assertTrue(loadedSet.contains(BinaryValue.create("user1"))); - assertTrue(loadedSet.contains(BinaryValue.create("user2"))); - assertTrue(loadedSet.contains(BinaryValue.create("user3"))); - assertFalse(loadedFetchResponse.hasContext()); +// final FetchSet.Response loadedFetchResponse = client.execute(fetchSet); +// +// final Set loadedSet = loadedFetchResponse.getDatatype().view(); +// +// assertFalse(loadedSet.isEmpty()); +// assertTrue(loadedSet.contains(BinaryValue.create("user1"))); +// assertTrue(loadedSet.contains(BinaryValue.create("user2"))); +// assertTrue(loadedSet.contains(BinaryValue.create("user3"))); +// assertFalse(loadedFetchResponse.hasContext()); } } From 24da4a239845602cac3a61b95f12535798f0c32e Mon Sep 17 00:00:00 2001 From: "Daniel B. Garcia" Date: Wed, 9 Nov 2022 13:05:47 +0800 Subject: [PATCH 07/12] Test codes (unfinished). --- .../api/commands/itest/ITestDatatype.java | 50 +++++++++++-------- .../core/operations/itest/ITestBase.java | 2 + 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java index 051e9e1c8..2e43d62fa 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java @@ -123,16 +123,9 @@ public void simpleTest() throws ExecutionException, InterruptedException assertTrue(setView.containsAll(expectedSet)); assertTrue(expectedSet.containsAll(setView)); - // cart - asSet - item removal - ByteBuffer b = ByteBuffer.allocate(4); - b.putInt(5); - - // - remove item '5' - SetUpdate su = new SetUpdate().remove(BinaryValue.create(b.array())); - for (BinaryValue item : expectedSet) { - System.out.println(" - " + item.getClass()); - } - System.out.println("\n\n"); +// // cart - asSet - item removal ByteBuffer b = ByteBuffer.allocate(4); b.putInt(5); // - remove item '5' +// SetUpdate su = new SetUpdate().remove(BinaryValue.create(b.array())); for (BinaryValue item : +// expectedSet) { System.out.println(" - " + item.getClass()); } System.out.println("\n\n"); // MapUpdate mu = new MapUpdate().update(shoppingCart, su); // MapUpdate muUser = new MapUpdate().update(username, mu); // UpdateMap updateEntry = new UpdateMap.Builder(carts, muUser).build(); @@ -226,24 +219,37 @@ public void testNotFoundHyperLogLog() throws ExecutionException, InterruptedExce } @Test - public void testGSet() throws ExecutionException , InterruptedException - { - Assume.assumeTrue(testGSetDataType); - resetAndEmptyBucket(uniqueUsers); + public void testSet() throws ExecutionException, InterruptedException { + Assume.assumeTrue(testSetDataType); +// resetAndEmptyBucket(uniqueUsers); - final Location location = new Location(uniqueUsers, "site-2017-01-01-" + new Random().nextLong()); + final Location location = new Location(uniqueUsers, "users-" + new Random().nextLong()); - FetchSet fetchSet = new FetchSet.Builder(location).build(); - final FetchSet.Response initialFetchResponse = client.execute(fetchSet); + FetchSet fetchSet = new FetchSet.Builder(location).build(); + final FetchSet.Response initialFetchResponse = client.execute(fetchSet); final RiakSet initialSet = initialFetchResponse.getDatatype(); assertTrue(initialSet.view().isEmpty()); + } - GSetUpdate gsu = new GSetUpdate().add("user1").add("user2").add("user3"); - UpdateSet us = new UpdateSet.Builder(location, gsu).withReturnDatatype(true).build(); - - final UpdateSet.Response updateResponse = client.execute(us); - final Set updatedSet = updateResponse.getDatatype().view(); + @Test + public void testGSet() throws ExecutionException, InterruptedException { + Assume.assumeTrue(testGSetDataType); + resetAndEmptyBucket(uniqueUsers); +// +// final Location location = new Location(uniqueUsers, "site-2017-01-01-" + new Random().nextLong()); +// +// FetchSet fetchSet = new FetchSet.Builder(location).build(); +// final FetchSet.Response initialFetchResponse = client.execute(fetchSet); +// +// final RiakSet initialSet = initialFetchResponse.getDatatype(); +// assertTrue(initialSet.view().isEmpty()); +// +// GSetUpdate gsu = new GSetUpdate().add("user1").add("user2").add("user3"); +// UpdateSet us = new UpdateSet.Builder(location, gsu).withReturnDatatype(true).build(); +// +// final UpdateSet.Response updateResponse = client.execute(us); +// final Set updatedSet = updateResponse.getDatatype().view(); // assertFalse(updatedSet.isEmpty()); // assertTrue(updatedSet.contains(BinaryValue.create("user1"))); diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestBase.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestBase.java index 264216794..95bf66e37 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestBase.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestBase.java @@ -62,6 +62,7 @@ public abstract class ITestBase protected static boolean testBucketType; protected static boolean testCrdt; protected static boolean testHllDataType; + protected static boolean testSetDataType; protected static boolean testGSetDataType; protected static boolean testTimeSeries; protected static boolean testCoveragePlan; @@ -193,6 +194,7 @@ public static void setUp() cluster.start(); testHllDataType = testCrdt && checkExistanceOfBucketType(hllBucketType); + testSetDataType = testCrdt && checkExistanceOfBucketType(setBucketType); testGSetDataType = testCrdt && checkExistanceOfBucketType(gsetBucketType); } From bf3f4b04ca5c4bea0a27f72e0613dace77db1780 Mon Sep 17 00:00:00 2001 From: "Daniel B. Garcia" Date: Wed, 16 Nov 2022 10:42:34 +0800 Subject: [PATCH 08/12] Sets test. --- .../api/commands/itest/ITestDatatype.java | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java index 2e43d62fa..03bd34fbe 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java @@ -30,6 +30,7 @@ public class ITestDatatype extends ITestAutoCleanupBase private final Namespace carts = new Namespace(mapBucketType, bucketName); private final Namespace uniqueUsersCount = new Namespace(hllBucketType, BinaryValue.create("uniqueUsersCount")); + private final Namespace uniqueUsersSet = new Namespace(setBucketType, BinaryValue.create("uniqueUsersSet")); private final Namespace uniqueUsers = new Namespace(gsetBucketType, BinaryValue.create("uniqueUsers")); private final RiakClient client = new RiakClient(cluster); @@ -122,35 +123,6 @@ public void simpleTest() throws ExecutionException, InterruptedException } assertTrue(setView.containsAll(expectedSet)); assertTrue(expectedSet.containsAll(setView)); - -// // cart - asSet - item removal ByteBuffer b = ByteBuffer.allocate(4); b.putInt(5); // - remove item '5' -// SetUpdate su = new SetUpdate().remove(BinaryValue.create(b.array())); for (BinaryValue item : -// expectedSet) { System.out.println(" - " + item.getClass()); } System.out.println("\n\n"); -// MapUpdate mu = new MapUpdate().update(shoppingCart, su); -// MapUpdate muUser = new MapUpdate().update(username, mu); -// UpdateMap updateEntry = new UpdateMap.Builder(carts, muUser).build(); -// UpdateMap.Response res = client.execute(updateEntry); - -// // - fetch updated map -// FetchMap fetchMap = new FetchMap.Builder(loc).build(); -// FetchMap.Response fetchMapResponse = client.execute(fetchMap); -// RiakMap updatedUsersMap = fetchMapResponse.getDatatype(); -// RiakMap updatedUsernameMap = updatedUsersMap.getMap(username); -// RiakSet updatedShoppingCartSet = updatedUsernameMap.getSet(shoppingCart); -// Set updatedSetView = updatedShoppingCartSet.view(); -// -// // - build expected set -// int[] iArray = {0, 1, 2, 3, 4, 6, 7, 8, 9}; -// Set updatedExpectedSet = new HashSet<>(); -// for (int i = 0; i < iArray.length; i++) { -// ByteBuffer buf = ByteBuffer.allocate(4); -// buf.putInt(iArray[i]); -// updatedExpectedSet.add(BinaryValue.create(buf.array())); -// } -// -// // - compare sets -// assertTrue(updatedSetView.containsAll(updatedExpectedSet)); -// assertTrue(updatedExpectedSet.containsAll(updatedSetView)); } public void testConflict() throws ExecutionException, InterruptedException @@ -221,15 +193,44 @@ public void testNotFoundHyperLogLog() throws ExecutionException, InterruptedExce @Test public void testSet() throws ExecutionException, InterruptedException { Assume.assumeTrue(testSetDataType); -// resetAndEmptyBucket(uniqueUsers); + resetAndEmptyBucket(uniqueUsersSet); - final Location location = new Location(uniqueUsers, "users-" + new Random().nextLong()); + final Location location = new Location(uniqueUsersSet, "users-" + new Random().nextLong()); - FetchSet fetchSet = new FetchSet.Builder(location).build(); - final FetchSet.Response initialFetchResponse = client.execute(fetchSet); + FetchSet fetchSet = new FetchSet.Builder(location).build(); + final FetchSet.Response initialFetchResponse = client.execute(fetchSet); final RiakSet initialSet = initialFetchResponse.getDatatype(); assertTrue(initialSet.view().isEmpty()); + + SetUpdate su = new SetUpdate() + .add("user1") + .add("user2") + .add("user3"); + UpdateSet update = new UpdateSet.Builder(location, su).build(); + client.execute(update); + + final FetchSet.Response newItemsResponse = client.execute(fetchSet); + Set updatedSet = newItemsResponse.getDatatype().view(); + assertFalse(updatedSet.isEmpty()); + assertTrue(updatedSet.contains(BinaryValue.create("user1"))); + assertTrue(updatedSet.contains(BinaryValue.create("user2"))); + assertTrue(updatedSet.contains(BinaryValue.create("user3"))); + assertFalse(updatedSet.contains(BinaryValue.create("user4"))); + + final FetchSet.Response removeItemResponse = client.execute(fetchSet); + Context ctx = removeItemResponse.getContext(); + SetUpdate suRemoveItem = new SetUpdate().remove("user2"); + UpdateSet updateRemove = new UpdateSet.Builder(location, suRemoveItem).withContext(ctx).build(); + client.execute(updateRemove); + + final FetchSet.Response removedResponse = client.execute(fetchSet); + Set removedItemSet = removedResponse.getDatatype().view(); + assertFalse(removedItemSet.isEmpty()); + assertTrue(removedItemSet.contains(BinaryValue.create("user1"))); + assertFalse(removedItemSet.contains(BinaryValue.create("user2"))); + assertTrue(removedItemSet.contains(BinaryValue.create("user3"))); + assertFalse(removedItemSet.contains(BinaryValue.create("user4"))); } @Test From 6cde8a43c7369098879c0e5ec4ae96b7da0bdfdd Mon Sep 17 00:00:00 2001 From: "Daniel B. Garcia" Date: Tue, 29 Nov 2022 11:51:24 +0800 Subject: [PATCH 09/12] GSets test --- .../api/commands/itest/ITestDatatype.java | 59 ++++++++----------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java index 03bd34fbe..f20001ef1 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java @@ -11,7 +11,6 @@ import org.junit.Assume; import org.junit.Test; -import javax.swing.*; import java.nio.ByteBuffer; import java.util.*; import java.util.concurrent.ExecutionException; @@ -31,7 +30,7 @@ public class ITestDatatype extends ITestAutoCleanupBase private final Namespace carts = new Namespace(mapBucketType, bucketName); private final Namespace uniqueUsersCount = new Namespace(hllBucketType, BinaryValue.create("uniqueUsersCount")); private final Namespace uniqueUsersSet = new Namespace(setBucketType, BinaryValue.create("uniqueUsersSet")); - private final Namespace uniqueUsers = new Namespace(gsetBucketType, BinaryValue.create("uniqueUsers")); + private final Namespace uniqueUsersGSet = new Namespace(gsetBucketType, BinaryValue.create("uniqueUsersGSet")); private final RiakClient client = new RiakClient(cluster); @@ -236,36 +235,30 @@ public void testSet() throws ExecutionException, InterruptedException { @Test public void testGSet() throws ExecutionException, InterruptedException { Assume.assumeTrue(testGSetDataType); - resetAndEmptyBucket(uniqueUsers); -// -// final Location location = new Location(uniqueUsers, "site-2017-01-01-" + new Random().nextLong()); -// -// FetchSet fetchSet = new FetchSet.Builder(location).build(); -// final FetchSet.Response initialFetchResponse = client.execute(fetchSet); -// -// final RiakSet initialSet = initialFetchResponse.getDatatype(); -// assertTrue(initialSet.view().isEmpty()); -// -// GSetUpdate gsu = new GSetUpdate().add("user1").add("user2").add("user3"); -// UpdateSet us = new UpdateSet.Builder(location, gsu).withReturnDatatype(true).build(); -// -// final UpdateSet.Response updateResponse = client.execute(us); -// final Set updatedSet = updateResponse.getDatatype().view(); - -// assertFalse(updatedSet.isEmpty()); -// assertTrue(updatedSet.contains(BinaryValue.create("user1"))); -// assertTrue(updatedSet.contains(BinaryValue.create("user2"))); -// assertTrue(updatedSet.contains(BinaryValue.create("user3"))); -// assertFalse(updateResponse.hasContext()); - -// final FetchSet.Response loadedFetchResponse = client.execute(fetchSet); -// -// final Set loadedSet = loadedFetchResponse.getDatatype().view(); -// -// assertFalse(loadedSet.isEmpty()); -// assertTrue(loadedSet.contains(BinaryValue.create("user1"))); -// assertTrue(loadedSet.contains(BinaryValue.create("user2"))); -// assertTrue(loadedSet.contains(BinaryValue.create("user3"))); -// assertFalse(loadedFetchResponse.hasContext()); + resetAndEmptyBucket(uniqueUsersGSet); + + final Location location = new Location(uniqueUsersGSet, "users-" + new Random().nextLong()); + + FetchSet fetchSet = new FetchSet.Builder(location).build(); + final FetchSet.Response initialFetchResponse = client.execute(fetchSet); + + final RiakSet initialSet = initialFetchResponse.getDatatype(); + assertTrue(initialSet.view().isEmpty()); + + GSetUpdate gsu = new GSetUpdate() + .add("user1") + .add("user2") + .add("user3"); + UpdateSet us = new UpdateSet.Builder(location, gsu).build(); + + final UpdateSet.Response updateResponse = client.execute(us); + final FetchSet.Response newItemResponse = client.execute(fetchSet); + final Set updatedSet = newItemResponse.getDatatype().view(); + + assertFalse(updatedSet.isEmpty()); + assertTrue(updatedSet.contains(BinaryValue.create("user1"))); + assertTrue(updatedSet.contains(BinaryValue.create("user2"))); + assertTrue(updatedSet.contains(BinaryValue.create("user3"))); + assertFalse(updatedSet.contains(BinaryValue.create("user4"))); } } From e18330179e000097dc7ca921895f16153bb0ea52 Mon Sep 17 00:00:00 2001 From: "Daniel B. Garcia" Date: Thu, 1 Dec 2022 13:10:22 +0800 Subject: [PATCH 10/12] GSets exception test when removing an item. --- .../client/api/commands/itest/ITestDatatype.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java index f20001ef1..c36b3e794 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java @@ -232,7 +232,7 @@ public void testSet() throws ExecutionException, InterruptedException { assertFalse(removedItemSet.contains(BinaryValue.create("user4"))); } - @Test + @Test(expected = java.lang.Error.class) public void testGSet() throws ExecutionException, InterruptedException { Assume.assumeTrue(testGSetDataType); resetAndEmptyBucket(uniqueUsersGSet); @@ -260,5 +260,19 @@ public void testGSet() throws ExecutionException, InterruptedException { assertTrue(updatedSet.contains(BinaryValue.create("user2"))); assertTrue(updatedSet.contains(BinaryValue.create("user3"))); assertFalse(updatedSet.contains(BinaryValue.create("user4"))); + + final FetchSet.Response removeItemResponse = client.execute(fetchSet); + Context ctx = removeItemResponse.getContext(); + GSetUpdate suRemoveItem = new GSetUpdate().remove("user2"); + UpdateSet updateRemove = new UpdateSet.Builder(location, suRemoveItem).withContext(ctx).build(); + client.execute(updateRemove); + + final FetchSet.Response removedResponse = client.execute(fetchSet); + Set removedItemSet = removedResponse.getDatatype().view(); + assertTrue(removedItemSet.isEmpty()); + assertTrue(removedItemSet.contains(BinaryValue.create("user1"))); + assertTrue(removedItemSet.contains(BinaryValue.create("user2"))); + assertTrue(removedItemSet.contains(BinaryValue.create("user3"))); + assertFalse(removedItemSet.contains(BinaryValue.create("user4"))); } } From 79e83eaba0775d3719b2800c59d8cca59cfee8fc Mon Sep 17 00:00:00 2001 From: "Daniel B. Garcia" Date: Fri, 9 Dec 2022 15:10:43 +0800 Subject: [PATCH 11/12] GSet remov item test redesigned. --- .../api/commands/itest/ITestDatatype.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java index c36b3e794..19a9061b7 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java @@ -232,7 +232,7 @@ public void testSet() throws ExecutionException, InterruptedException { assertFalse(removedItemSet.contains(BinaryValue.create("user4"))); } - @Test(expected = java.lang.Error.class) + @Test public void testGSet() throws ExecutionException, InterruptedException { Assume.assumeTrue(testGSetDataType); resetAndEmptyBucket(uniqueUsersGSet); @@ -250,11 +250,10 @@ public void testGSet() throws ExecutionException, InterruptedException { .add("user2") .add("user3"); UpdateSet us = new UpdateSet.Builder(location, gsu).build(); + client.execute(us); - final UpdateSet.Response updateResponse = client.execute(us); final FetchSet.Response newItemResponse = client.execute(fetchSet); final Set updatedSet = newItemResponse.getDatatype().view(); - assertFalse(updatedSet.isEmpty()); assertTrue(updatedSet.contains(BinaryValue.create("user1"))); assertTrue(updatedSet.contains(BinaryValue.create("user2"))); @@ -263,13 +262,17 @@ public void testGSet() throws ExecutionException, InterruptedException { final FetchSet.Response removeItemResponse = client.execute(fetchSet); Context ctx = removeItemResponse.getContext(); - GSetUpdate suRemoveItem = new GSetUpdate().remove("user2"); - UpdateSet updateRemove = new UpdateSet.Builder(location, suRemoveItem).withContext(ctx).build(); - client.execute(updateRemove); + try { + SetUpdate suRemoveItem = new SetUpdate().remove("user2"); + UpdateSet updateRemove = new UpdateSet.Builder(location, suRemoveItem).withContext(ctx).build(); + client.execute(updateRemove); + } catch (Exception e) { + // We are expecting the error. If the error occurs, the test is good. + } final FetchSet.Response removedResponse = client.execute(fetchSet); Set removedItemSet = removedResponse.getDatatype().view(); - assertTrue(removedItemSet.isEmpty()); + assertFalse(removedItemSet.isEmpty()); assertTrue(removedItemSet.contains(BinaryValue.create("user1"))); assertTrue(removedItemSet.contains(BinaryValue.create("user2"))); assertTrue(removedItemSet.contains(BinaryValue.create("user3"))); From 9ff0016df43b34365a54d1e05736ff04f784daab Mon Sep 17 00:00:00 2001 From: "Daniel B. Garcia" Date: Mon, 12 Dec 2022 15:00:34 +0800 Subject: [PATCH 12/12] Force a fail assertion if the expected exception is not thrown. --- .../basho/riak/client/api/commands/itest/ITestDatatype.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java index 19a9061b7..83f9d92bf 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestDatatype.java @@ -266,7 +266,8 @@ public void testGSet() throws ExecutionException, InterruptedException { SetUpdate suRemoveItem = new SetUpdate().remove("user2"); UpdateSet updateRemove = new UpdateSet.Builder(location, suRemoveItem).withContext(ctx).build(); client.execute(updateRemove); - } catch (Exception e) { + fail("Expected exception was not thrown."); + } catch (IllegalArgumentException e) { // We are expecting the error. If the error occurs, the test is good. }