Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for Sets and GSets. #728

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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






sudo riak-admin bucket-type create maps '{"props":{"datatype":"map"}}'
sudo riak-admin bucket-type create plain ''
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
<additionalparam>--allow-script-in-comments</additionalparam>
<excludePackageNames>com.basho.riak.protobuf.util</excludePackageNames>
</configuration>
</plugin>
Expand Down Expand Up @@ -369,7 +370,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.15</version>
<version>1.20</version>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
Expand Down Expand Up @@ -469,5 +470,10 @@
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import org.junit.Test;

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.*;
Expand All @@ -32,7 +29,8 @@ 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 uniqueUsers = new Namespace(gsetBucketType, BinaryValue.create("uniqueUsers"));
private final Namespace uniqueUsersSet = new Namespace(setBucketType, BinaryValue.create("uniqueUsersSet"));
private final Namespace uniqueUsersGSet = new Namespace(gsetBucketType, BinaryValue.create("uniqueUsersGSet"));

private final RiakClient client = new RiakClient(cluster);

Expand Down Expand Up @@ -192,37 +190,93 @@ public void testNotFoundHyperLogLog() throws ExecutionException, InterruptedExce
}

@Test
public void testGSet() throws ExecutionException , InterruptedException
{
Assume.assumeTrue(testGSetDataType);
final Location location = new Location(uniqueUsers, "site-2017-01-01-" + new Random().nextLong());
public void testSet() throws ExecutionException, InterruptedException {
Assume.assumeTrue(testSetDataType);
resetAndEmptyBucket(uniqueUsersSet);

final Location location = new Location(uniqueUsersSet, "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).withReturnDatatype(true).build();

final UpdateSet.Response updateResponse = client.execute(us);
final Set<BinaryValue> updatedSet = updateResponse.getDatatype().view();
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<BinaryValue> 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(updateResponse.hasContext());
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<BinaryValue> 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
public void testGSet() throws ExecutionException, InterruptedException {
Assume.assumeTrue(testGSetDataType);
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());

final FetchSet.Response loadedFetchResponse = client.execute(fetchSet);
GSetUpdate gsu = new GSetUpdate()
.add("user1")
.add("user2")
.add("user3");
UpdateSet us = new UpdateSet.Builder(location, gsu).build();
client.execute(us);

final Set<BinaryValue> loadedSet = loadedFetchResponse.getDatatype().view();
final FetchSet.Response newItemResponse = client.execute(fetchSet);
final Set<BinaryValue> 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")));

final FetchSet.Response removeItemResponse = client.execute(fetchSet);
Context ctx = removeItemResponse.getContext();
try {
SetUpdate suRemoveItem = new SetUpdate().remove("user2");
UpdateSet updateRemove = new UpdateSet.Builder(location, suRemoveItem).withContext(ctx).build();
client.execute(updateRemove);
fail("Expected exception was not thrown.");
} catch (IllegalArgumentException e) {
// We are expecting the error. If the error occurs, the test is good.
}

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 removedResponse = client.execute(fetchSet);
Set<BinaryValue> removedItemSet = removedResponse.getDatatype().view();
assertFalse(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")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -193,6 +194,7 @@ public static void setUp()
cluster.start();

testHllDataType = testCrdt && checkExistanceOfBucketType(hllBucketType);
testSetDataType = testCrdt && checkExistanceOfBucketType(setBucketType);
testGSetDataType = testCrdt && checkExistanceOfBucketType(gsetBucketType);
}

Expand Down