BinaryValue key = BinaryValue.create("key");
resetAndEmptyBucket(new Namespace(setBucketType, bucketName));
RiakSet set = fetchSet(setBucketType, bucketName, key);
assertTrue(set.view().isEmpty());
Set<BinaryValue> testValues = new HashSet<BinaryValue>(iterations);
Location location = new Location(new Namespace(setBucketType, bucketName), key);
BinaryValue ctx = null;
for (int i = 0; i < iterations; ++i)
{
ByteBuffer buff = (ByteBuffer) ByteBuffer.allocate(8).putInt(i).rewind();
BinaryValue wrapped = BinaryValue.create(buff.array());
testValues.add(wrapped);
DtUpdateOperation update =
new DtUpdateOperation.Builder(location)
.withOp(new SetOp().add(wrapped))
.withReturnBody(true)
.build();
cluster.execute(update);
DtUpdateOperation.Response resp = update.get();
ctx = resp.getContext();
set = resp.getCrdtElement().getAsSet();
}
assertEquals(iterations, set.view().size());
assertEquals(testValues, set.view());
for (BinaryValue setElement : testValues)
{
DtUpdateOperation update =
new DtUpdateOperation.Builder(location)
.withOp(new SetOp().remove(setElement))
.withContext(ctx)
.build();
cluster.execute(update);
update.get();
}
set = fetchSet(setBucketType, bucketName, key);
assertTrue(set.view().isEmpty());
resetAndEmptyBucket(new Namespace(setBucketType, bucketName));
}