From 32f898e756025cacdae2ff353a350b90118e970b Mon Sep 17 00:00:00 2001 From: Alex Moore Date: Wed, 2 Mar 2016 15:57:24 -0500 Subject: [PATCH 01/10] Refactor ITestBase, fix flappy ITestFetchOperation test --- .../buckets/itest/ITestListBuckets.java | 4 +- .../indexes/itest/ITestBigIntIndexQuery.java | 4 +- .../indexes/itest/ITestBinIndexQuery.java | 4 +- .../indexes/itest/ITestIntIndexQuery.java | 4 +- .../indexes/itest/ITestRawIndexQuery.java | 4 +- .../itest/ITestBucketKeyMapReduce.java | 4 +- .../commands/itest/ITestBucketMapReduce.java | 4 +- .../api/commands/itest/ITestBucketProps.java | 4 +- .../api/commands/itest/ITestDatatype.java | 4 +- .../api/commands/itest/ITestFetchValue.java | 4 +- .../commands/itest/ITestIndexMapReduce.java | 4 +- .../api/commands/itest/ITestMultiFetch.java | 4 +- .../client/api/commands/itest/ITestORM.java | 4 +- .../api/commands/itest/ITestStoreValue.java | 4 +- .../api/commands/itest/ITestUpdateValue.java | 4 +- .../operations/itest/ISearchTestBase.java | 2 +- .../itest/ITestAutoCleanupBase.java | 130 +++++++++++ .../core/operations/itest/ITestBase.java | 221 +++++------------- .../itest/ITestBucketProperties.java | 4 +- .../core/operations/itest/ITestCrdtApi.java | 2 +- .../itest/ITestDeleteOperation.java | 2 +- .../itest/ITestDtUpdateOperation.java | 2 +- .../operations/itest/ITestFetchOperation.java | 112 ++++++--- .../itest/ITestListBucketsOperation.java | 2 +- .../itest/ITestListKeysOperation.java | 5 +- .../itest/ITestMapReduceOperation.java | 3 +- .../operations/itest/ITestPingOperation.java | 2 +- .../itest/ITestSecondaryIndexQueryOp.java | 2 +- .../operations/itest/ITestStoreOperation.java | 3 +- .../itest/ITestYzAdminOperations.java | 2 +- .../core/operations/itest/ts/ITestTsBase.java | 4 +- 31 files changed, 306 insertions(+), 252 deletions(-) create mode 100644 src/test/java/com/basho/riak/client/core/operations/itest/ITestAutoCleanupBase.java diff --git a/src/test/java/com/basho/riak/client/api/commands/buckets/itest/ITestListBuckets.java b/src/test/java/com/basho/riak/client/api/commands/buckets/itest/ITestListBuckets.java index 2d71142f4..5df90f9c9 100644 --- a/src/test/java/com/basho/riak/client/api/commands/buckets/itest/ITestListBuckets.java +++ b/src/test/java/com/basho/riak/client/api/commands/buckets/itest/ITestListBuckets.java @@ -3,7 +3,7 @@ import com.basho.riak.client.api.RiakClient; import com.basho.riak.client.api.commands.buckets.ListBuckets; import com.basho.riak.client.api.commands.kv.StoreValue; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.core.query.Location; import com.basho.riak.client.core.query.Namespace; import com.basho.riak.client.core.query.RiakObject; @@ -20,7 +20,7 @@ * @author empovit * @since 2.0.3 */ -public class ITestListBuckets extends ITestBase +public class ITestListBuckets extends ITestAutoCleanupBase { private final RiakClient client = new RiakClient(cluster); diff --git a/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestBigIntIndexQuery.java b/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestBigIntIndexQuery.java index 764f3f4fd..402b00419 100644 --- a/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestBigIntIndexQuery.java +++ b/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestBigIntIndexQuery.java @@ -23,7 +23,7 @@ import com.basho.riak.client.api.annotations.RiakVClock; import com.basho.riak.client.api.cap.VClock; import com.basho.riak.client.core.RiakFuture; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.api.commands.indexes.BigIntIndexQuery; import com.basho.riak.client.api.commands.kv.StoreValue; import com.basho.riak.client.core.query.Location; @@ -39,7 +39,7 @@ * * @author Brian Roach */ -public class ITestBigIntIndexQuery extends ITestBase +public class ITestBigIntIndexQuery extends ITestAutoCleanupBase { @Test diff --git a/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestBinIndexQuery.java b/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestBinIndexQuery.java index 4525fc885..612bf4a28 100644 --- a/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestBinIndexQuery.java +++ b/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestBinIndexQuery.java @@ -23,7 +23,7 @@ import com.basho.riak.client.api.annotations.RiakVClock; import com.basho.riak.client.api.cap.VClock; import com.basho.riak.client.core.RiakFuture; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.api.commands.indexes.BinIndexQuery; import com.basho.riak.client.api.commands.kv.StoreValue; import com.basho.riak.client.core.query.Location; @@ -39,7 +39,7 @@ * @author Brian Roach * @since 2.0 */ -public class ITestBinIndexQuery extends ITestBase +public class ITestBinIndexQuery extends ITestAutoCleanupBase { @Test public void testMatchQuery() throws ExecutionException, InterruptedException diff --git a/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestIntIndexQuery.java b/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestIntIndexQuery.java index 96f21dfff..c5feb5852 100644 --- a/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestIntIndexQuery.java +++ b/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestIntIndexQuery.java @@ -23,7 +23,7 @@ import com.basho.riak.client.api.annotations.RiakVClock; import com.basho.riak.client.api.cap.VClock; import com.basho.riak.client.core.RiakFuture; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.api.commands.indexes.IntIndexQuery; import com.basho.riak.client.api.commands.kv.StoreValue; import com.basho.riak.client.core.query.Location; @@ -39,7 +39,7 @@ * @author Brian Roach * @since 2.0 */ -public class ITestIntIndexQuery extends ITestBase +public class ITestIntIndexQuery extends ITestAutoCleanupBase { @Test public void testMatchQuery() throws InterruptedException, ExecutionException diff --git a/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestRawIndexQuery.java b/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestRawIndexQuery.java index b177b5518..2578a12f8 100644 --- a/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestRawIndexQuery.java +++ b/src/test/java/com/basho/riak/client/api/commands/indexes/itest/ITestRawIndexQuery.java @@ -27,7 +27,7 @@ import com.basho.riak.client.api.commands.kv.StoreValue; import com.basho.riak.client.core.RiakFuture; import com.basho.riak.client.core.operations.StoreOperation; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.core.query.Location; import com.basho.riak.client.core.query.Namespace; import com.basho.riak.client.core.query.RiakObject; @@ -43,7 +43,7 @@ * * @author Brian Roach */ -public class ITestRawIndexQuery extends ITestBase +public class ITestRawIndexQuery extends ITestAutoCleanupBase { @Test public void simpleTest() throws InterruptedException, ExecutionException diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketKeyMapReduce.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketKeyMapReduce.java index 290eaeae2..c69facf50 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketKeyMapReduce.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketKeyMapReduce.java @@ -16,7 +16,7 @@ package com.basho.riak.client.api.commands.itest; import com.basho.riak.client.api.RiakClient; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.api.commands.buckets.StoreBucketProperties; import com.basho.riak.client.api.commands.kv.StoreValue; import com.basho.riak.client.api.commands.mapreduce.BucketKeyMapReduce; @@ -45,7 +45,7 @@ * @author Brian Roach * @since 2.0 */ -public class ITestBucketKeyMapReduce extends ITestBase +public class ITestBucketKeyMapReduce extends ITestAutoCleanupBase { RiakClient client = new RiakClient(cluster); diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketMapReduce.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketMapReduce.java index b89d99227..66dfd08ce 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketMapReduce.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketMapReduce.java @@ -18,7 +18,7 @@ import com.basho.riak.client.api.RiakClient; import com.basho.riak.client.core.RiakFuture; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.api.commands.buckets.StoreBucketProperties; import com.basho.riak.client.api.commands.kv.StoreValue; import com.basho.riak.client.api.commands.mapreduce.BucketMapReduce; @@ -48,7 +48,7 @@ * * @author Brian Roach */ -public class ITestBucketMapReduce extends ITestBase +public class ITestBucketMapReduce extends ITestAutoCleanupBase { private final static RiakClient client = new RiakClient(cluster); private final static String mrBucketName = bucketName.toString() + "_mr"; diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketProps.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketProps.java index 46e8b614c..6f1d102e3 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketProps.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketProps.java @@ -20,10 +20,10 @@ import com.basho.riak.client.api.cap.Quorum; import com.basho.riak.client.api.commands.buckets.FetchBucketProperties; import com.basho.riak.client.core.operations.FetchBucketPropsOperation; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.core.query.BucketProperties; import com.basho.riak.client.api.commands.buckets.ResetBucketProperties; import com.basho.riak.client.api.commands.buckets.StoreBucketProperties; -import com.basho.riak.client.core.operations.itest.ITestBase; import com.basho.riak.client.core.query.Namespace; import org.junit.Test; @@ -35,7 +35,7 @@ * * @author Chris Mancini */ -public class ITestBucketProps extends ITestBase +public class ITestBucketProps extends ITestAutoCleanupBase { private final String propsBucketName = bucketName.toString() + "_props"; 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 e20af0ffa..7f1d64a86 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 @@ -13,7 +13,7 @@ import com.basho.riak.client.api.commands.datatypes.FetchMap; import com.basho.riak.client.api.commands.datatypes.UpdateDatatype.Option; import com.basho.riak.client.api.RiakClient; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.api.commands.datatypes.UpdateMap; import com.basho.riak.client.core.query.Location; import com.basho.riak.client.core.query.Namespace; @@ -32,7 +32,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -public class ITestDatatype extends ITestBase +public class ITestDatatype extends ITestAutoCleanupBase { private final String numLogins = "logins"; diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestFetchValue.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestFetchValue.java index f2467085d..5120d4f1b 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestFetchValue.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestFetchValue.java @@ -19,7 +19,7 @@ import com.basho.riak.client.api.cap.ConflictResolver; import com.basho.riak.client.api.cap.ConflictResolverFactory; import com.basho.riak.client.api.cap.UnresolvedConflictException; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.api.commands.kv.FetchValue.Option; import com.basho.riak.client.api.commands.kv.FetchValue; import com.basho.riak.client.api.RiakClient; @@ -49,7 +49,7 @@ * * @author Brian Roach */ -public class ITestFetchValue extends ITestBase +public class ITestFetchValue extends ITestAutoCleanupBase { @Test public void simpleTestDefaultType() diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestIndexMapReduce.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestIndexMapReduce.java index 2128532d5..008c6f7aa 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestIndexMapReduce.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestIndexMapReduce.java @@ -18,7 +18,7 @@ import com.basho.riak.client.api.RiakClient; import com.basho.riak.client.core.RiakFuture; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.api.commands.buckets.StoreBucketProperties; import com.basho.riak.client.api.commands.kv.StoreValue; import com.basho.riak.client.api.commands.mapreduce.IndexMapReduce; @@ -40,7 +40,7 @@ * * @author Brian Roach */ -public class ITestIndexMapReduce extends ITestBase +public class ITestIndexMapReduce extends ITestAutoCleanupBase { private final RiakClient client = new RiakClient(cluster); private final String mrBucketName = bucketName.toString() + "_mr"; diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestMultiFetch.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestMultiFetch.java index e2820499e..28f7293d6 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestMultiFetch.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestMultiFetch.java @@ -18,7 +18,7 @@ import com.basho.riak.client.api.RiakClient; import com.basho.riak.client.core.RiakFuture; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.api.commands.kv.FetchValue; import com.basho.riak.client.api.commands.kv.MultiFetch; import com.basho.riak.client.api.commands.kv.StoreValue; @@ -37,7 +37,7 @@ * * @author Brian Roach */ -public class ITestMultiFetch extends ITestBase +public class ITestMultiFetch extends ITestAutoCleanupBase { @Test diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestORM.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestORM.java index b35206070..7e4a92246 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestORM.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestORM.java @@ -32,7 +32,7 @@ import com.basho.riak.client.api.convert.ConverterFactory; import com.basho.riak.client.api.convert.RiakJacksonModule; import com.basho.riak.client.core.operations.StoreBucketPropsOperation; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.core.query.Location; import com.basho.riak.client.core.query.Namespace; import com.basho.riak.client.core.query.RiakObject; @@ -54,7 +54,7 @@ * * @author Brian Roach */ -public class ITestORM extends ITestBase +public class ITestORM extends ITestAutoCleanupBase { @Before public void resetFactory() diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestStoreValue.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestStoreValue.java index bd678d87d..4d0d87b49 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestStoreValue.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestStoreValue.java @@ -16,7 +16,7 @@ package com.basho.riak.client.api.commands.itest; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.api.commands.kv.FetchValue; import com.basho.riak.client.api.RiakClient; import com.basho.riak.client.api.annotations.RiakVClock; @@ -37,7 +37,7 @@ * * @author Brian Roach */ -public class ITestStoreValue extends ITestBase +public class ITestStoreValue extends ITestAutoCleanupBase { @Test public void simpleTest() throws ExecutionException, InterruptedException diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestUpdateValue.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestUpdateValue.java index e57a69d5f..8060455e4 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestUpdateValue.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestUpdateValue.java @@ -16,7 +16,7 @@ package com.basho.riak.client.api.commands.itest; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.api.RiakClient; import com.basho.riak.client.api.annotations.RiakVClock; import com.basho.riak.client.api.cap.VClock; @@ -34,7 +34,7 @@ * * @author Brian Roach */ -public class ITestUpdateValue extends ITestBase +public class ITestUpdateValue extends ITestAutoCleanupBase { @Test public void simpleTest() throws ExecutionException, InterruptedException diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ISearchTestBase.java b/src/test/java/com/basho/riak/client/core/operations/itest/ISearchTestBase.java index 60fc97918..a85e3b3a4 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ISearchTestBase.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ISearchTestBase.java @@ -23,7 +23,7 @@ * @author Alex Moore * @since 2.0.5 */ -public class ISearchTestBase extends ITestBase +public class ISearchTestBase extends ITestAutoCleanupBase { public static void setupSearchEnvironment(String bucketName, String indexName) throws ExecutionException, InterruptedException { diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestAutoCleanupBase.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestAutoCleanupBase.java new file mode 100644 index 000000000..b53fa878e --- /dev/null +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestAutoCleanupBase.java @@ -0,0 +1,130 @@ +/* + * Copyright 2013 Basho Technologies Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.basho.riak.client.core.operations.itest; + +import com.basho.riak.client.core.RiakFuture; +import com.basho.riak.client.core.RiakFutureListener; +import com.basho.riak.client.core.operations.DeleteOperation; +import com.basho.riak.client.core.operations.ListKeysOperation; +import com.basho.riak.client.core.operations.ResetBucketPropsOperation; +import com.basho.riak.client.core.operations.YzFetchIndexOperation; +import com.basho.riak.client.core.query.Location; +import com.basho.riak.client.core.query.Namespace; +import com.basho.riak.client.core.util.BinaryValue; +import org.junit.After; + +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Semaphore; + +/** + * + * @author Brian Roach + * @since 2.0 + */ +public class ITestAutoCleanupBase extends ITestBase +{ + @After + public void afterTest() throws ExecutionException, InterruptedException + { + resetAndEmptyBucket(bucketName); + if (testBucketType) + { + resetAndEmptyBucket(defaultNamespace()); + } + } + + public static void resetAndEmptyBucket(BinaryValue name) throws InterruptedException, ExecutionException + { + resetAndEmptyBucket(new Namespace(Namespace.DEFAULT_BUCKET_TYPE, name.toString())); + } + + public static void resetAndEmptyBucket(Namespace namespace) throws InterruptedException, ExecutionException + { + ListKeysOperation.Builder keysOpBuilder = new ListKeysOperation.Builder(namespace); + + ListKeysOperation keysOp = keysOpBuilder.build(); + cluster.execute(keysOp); + List keyList = keysOp.get().getKeys(); + final Semaphore semaphore = new Semaphore(NUMBER_OF_PARALLEL_REQUESTS); + final CountDownLatch latch = new CountDownLatch(keyList.size()); + + RiakFutureListener listener = new RiakFutureListener() { + @Override + public void handle(RiakFuture f) + { + try + { + f.get(); + } + catch (Exception ex) + { + if (ex instanceof RuntimeException) + { + throw (RuntimeException)ex; + } + throw new RuntimeException(ex); + } + semaphore.release(); + latch.countDown(); + } + + }; + + for (BinaryValue k : keyList) + { + Location location = new Location(namespace, k); + DeleteOperation delOp = new DeleteOperation.Builder(location).withRw(3).build(); + delOp.addListener(listener); + semaphore.acquire(); + cluster.execute(delOp); + } + + latch.await(); + + ResetBucketPropsOperation.Builder resetOpBuilder = + new ResetBucketPropsOperation.Builder(namespace); + + ResetBucketPropsOperation resetOp = resetOpBuilder.build(); + cluster.execute(resetOp); + resetOp.get(); + + } + + public static boolean assureIndexExists(String indexName) throws InterruptedException + { + for (int x = 0; x < 5; x++) + { + Thread.sleep(2000); + YzFetchIndexOperation fetch = new YzFetchIndexOperation.Builder().withIndexName(indexName).build(); + cluster.execute(fetch); + fetch.await(); + if (fetch.isSuccess()) + { + return true; + } + } + + return false; + } + + public static Namespace defaultNamespace() + { + return new Namespace(testBucketType ? bucketType : BinaryValue.createFromUtf8(Namespace.DEFAULT_BUCKET_TYPE), + bucketName); + } +} 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 51fb88920..5222c7573 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 @@ -1,62 +1,36 @@ -/* - * Copyright 2013 Basho Technologies Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package com.basho.riak.client.core.operations.itest; import com.basho.riak.client.core.RiakCluster; import com.basho.riak.client.core.RiakFuture; -import com.basho.riak.client.core.RiakFutureListener; import com.basho.riak.client.core.RiakNode; import com.basho.riak.client.core.netty.RiakResponseException; -import com.basho.riak.client.core.operations.DeleteOperation; -import com.basho.riak.client.core.operations.ListKeysOperation; -import com.basho.riak.client.core.operations.ResetBucketPropsOperation; -import com.basho.riak.client.core.operations.YzFetchIndexOperation; -import com.basho.riak.client.core.query.Location; -import com.basho.riak.client.core.query.Namespace; import com.basho.riak.client.core.util.BinaryValue; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.rules.TestName; + +import java.io.*; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; -import java.util.List; -import java.util.concurrent.*; -import java.util.logging.Logger; - -import org.junit.*; -import org.junit.rules.TestName; -import org.slf4j.LoggerFactory; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** - * - * @author Brian Roach - * @since 2.0 + * Created by alex on 3/2/16. */ -public abstract class ITestBase +public class ITestBase { + protected static final int NUMBER_OF_PARALLEL_REQUESTS = 10; protected static RiakCluster cluster; protected static boolean testYokozuna; protected static boolean test2i; @@ -74,14 +48,14 @@ public abstract class ITestBase protected static String overrideCert; protected static String hostname; protected static int pbcPort; - protected static final int NUMBER_OF_PARALLEL_REQUESTS = 10; @Rule public TestName testName = new TestName(); @BeforeClass - public static void setUp() throws FileNotFoundException, CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException + public static void setUp() throws FileNotFoundException, CertificateException, IOException, KeyStoreException, + NoSuchAlgorithmException { - bucketName = BinaryValue.unsafeCreate("ITestBase".getBytes()); + bucketName = BinaryValue.unsafeCreate("ITestAutoCleanupBase".getBytes()); /** * Riak security. @@ -92,58 +66,63 @@ public static void setUp() throws FileNotFoundException, CertificateException, I security = Boolean.parseBoolean(System.getProperty("com.basho.riak.security")); overrideCert = System.getProperty("com.basho.riak.security.cacert"); - + /** * Yokozuna. - * + * * You need to create a bucket type in Riak for YZ: - * - * riak-admin bucket-type create jvtest_yz_search '{"props":{}}' - * riak-admin bucket-type activate jvtest_yz_search + * + * riak-admin bucket-type create yokozuna '{"props":{}}' + * riak-admin bucket-type activate yokozuna */ - yokozunaBucketType = BinaryValue.create("jvtest_yz_search"); + yokozunaBucketType = BinaryValue.create("yokozuna"); testYokozuna = Boolean.parseBoolean(System.getProperty("com.basho.riak.yokozuna")); - + /** * Bucket type - * - * you must create the type 'jvtest_test_type' to use this: * - * riak-admin bucket-type create jvtest_test_type '{"props":{}}' - * riak-admin bucket-type activate jvtest_test_type + * you must create the type 'plain' to use this: + * + * riak-admin bucket-type create plain '{"props":{}}' + * riak-admin bucket-type activate plain */ testBucketType = Boolean.parseBoolean(System.getProperty("com.basho.riak.buckettype")); - bucketType = BinaryValue.unsafeCreate("jvtest_test_type".getBytes()); - + bucketType = BinaryValue.unsafeCreate("plain".getBytes()); + /** * Secondary indexes - * + * * The backend must be 'leveldb' in riak config to us this */ test2i = Boolean.parseBoolean(System.getProperty("com.basho.riak.2i")); - - + + legacyRiakSearch = Boolean.parseBoolean(System.getProperty("com.basho.riak.riakSearch")); - - + + /** * In order to run the CRDT itests you must first manually * create the following bucket types in your riak instance * with the corresponding bucket properties. * - * riak-admin bucket-type create jvtest_maps '{"props":{"allow_mult":true, "datatype": "map"}}' - * riak-admin bucket-type create jvtest_sets '{"props":{"allow_mult":true, "datatype": "set"}}' - * riak-admin bucket-type create jvtest_counters '{"props":{"allow_mult":true, "datatype": "counter"}}' - * riak-admin bucket-type activate jvtest_maps - * riak-admin bucket-type activate jvtest_sets - * riak-admin bucket-type activate jvtest_counters + * riak-admin bucket-type create maps '{"props":{"allow_mult":true, "datatype": "map"}}' + * riak-admin bucket-type create sets '{"props":{"allow_mult":true, "datatype": "set"}}' + * riak-admin bucket-type create counters '{"props":{"allow_mult":true, "datatype": "counter"}}' + * riak-admin bucket-type activate maps + * riak-admin bucket-type activate sets + * riak-admin bucket-type activate counters */ - counterBucketType = BinaryValue.create("jvtest_counters"); - setBucketType = BinaryValue.create("jvtest_sets"); - mapBucketType = BinaryValue.create("jvtest_maps"); + counterBucketType = BinaryValue.create("counters"); + setBucketType = BinaryValue.create("sets"); + mapBucketType = BinaryValue.create("maps"); testCrdt = Boolean.parseBoolean(System.getProperty("com.basho.riak.crdt")); testTimeSeries = Boolean.parseBoolean(System.getProperty("com.basho.riak.timeseries")); + /** + * Riak PBC host + * + * In case you want/need to use a custom PBC host you may pass it by using the following system property + */ hostname = System.getProperty("com.basho.riak.host", RiakNode.Builder.DEFAULT_REMOTE_ADDRESS); /** @@ -168,6 +147,12 @@ public static void setUp() throws FileNotFoundException, CertificateException, I cluster.start(); } + @AfterClass + public static void tearDown() throws InterruptedException, ExecutionException, TimeoutException + { + cluster.shutdown().get(2, TimeUnit.SECONDS); + } + private static void setupUsernamePasswordSecurity(RiakNode.Builder builder) throws CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException { InputStream in; @@ -194,101 +179,6 @@ private static void setupUsernamePasswordSecurity(RiakNode.Builder builder) thro builder.withAuth("riakpass", "Test1234", ks); } - @After - public void afterTest() throws ExecutionException, InterruptedException - { - resetAndEmptyBucket(bucketName); - if (testBucketType) - { - resetAndEmptyBucket(defaultNamespace()); - } - } - - @AfterClass - public static void tearDown() throws InterruptedException, ExecutionException, TimeoutException - { - cluster.shutdown().get(2, TimeUnit.SECONDS); - } - - public static void resetAndEmptyBucket(BinaryValue name) throws InterruptedException, ExecutionException - { - resetAndEmptyBucket(new Namespace(Namespace.DEFAULT_BUCKET_TYPE, name.toString())); - } - - protected static void resetAndEmptyBucket(Namespace namespace) throws InterruptedException, ExecutionException - { - ListKeysOperation.Builder keysOpBuilder = new ListKeysOperation.Builder(namespace); - - ListKeysOperation keysOp = keysOpBuilder.build(); - cluster.execute(keysOp); - List keyList = keysOp.get().getKeys(); - final Semaphore semaphore = new Semaphore(NUMBER_OF_PARALLEL_REQUESTS); - final CountDownLatch latch = new CountDownLatch(keyList.size()); - - RiakFutureListener listener = new RiakFutureListener() { - @Override - public void handle(RiakFuture f) - { - try - { - f.get(); - } - catch (Exception ex) - { - if (ex instanceof RuntimeException) - { - throw (RuntimeException)ex; - } - throw new RuntimeException(ex); - } - semaphore.release(); - latch.countDown(); - } - - }; - - for (BinaryValue k : keyList) - { - Location location = new Location(namespace, k); - DeleteOperation.Builder delOpBuilder = new DeleteOperation.Builder(location); - DeleteOperation delOp = delOpBuilder.build(); - delOp.addListener(listener); - semaphore.acquire(); - cluster.execute(delOp); - } - - latch.await(); - - ResetBucketPropsOperation.Builder resetOpBuilder = - new ResetBucketPropsOperation.Builder(namespace); - - ResetBucketPropsOperation resetOp = resetOpBuilder.build(); - cluster.execute(resetOp); - resetOp.get(); - - } - - public static boolean assureIndexExists(String indexName) throws InterruptedException - { - for (int x = 0; x < 5; x++) - { - Thread.sleep(2000); - YzFetchIndexOperation fetch = new YzFetchIndexOperation.Builder().withIndexName(indexName).build(); - cluster.execute(fetch); - fetch.await(); - if (fetch.isSuccess()) - { - return true; - } - } - - return false; - } - - public static Namespace defaultNamespace() { - return new Namespace( testBucketType ? bucketType : BinaryValue.createFromUtf8(Namespace.DEFAULT_BUCKET_TYPE), bucketName); - } - protected static void assertFutureSuccess(RiakFuture resultFuture) { if(resultFuture.cause() == null) @@ -307,5 +197,8 @@ protected static void assertFutureFailure(RiakFuture resultFuture) assertEquals(resultFuture.cause().getClass(), RiakResponseException.class); } - protected void setBucketNameToTestName() {bucketName = BinaryValue.create(testName.getMethodName());} + protected void setBucketNameToTestName() + { + bucketName = BinaryValue.create(testName.getMethodName()); + } } diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestBucketProperties.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestBucketProperties.java index fbad602c3..61677fbf4 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestBucketProperties.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestBucketProperties.java @@ -18,8 +18,6 @@ import com.basho.riak.client.api.cap.Quorum; import com.basho.riak.client.core.operations.FetchBucketPropsOperation; import com.basho.riak.client.core.operations.StoreBucketPropsOperation; -import static com.basho.riak.client.core.operations.itest.ITestBase.bucketName; -import static com.basho.riak.client.core.operations.itest.ITestBase.testBucketType; import com.basho.riak.client.core.query.BucketProperties; import com.basho.riak.client.core.query.Namespace; import java.util.concurrent.ExecutionException; @@ -31,7 +29,7 @@ * * @author Brian Roach */ -public class ITestBucketProperties extends ITestBase +public class ITestBucketProperties extends ITestAutoCleanupBase { @Test diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestCrdtApi.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestCrdtApi.java index 6aabda2eb..dfa7976b1 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestCrdtApi.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestCrdtApi.java @@ -32,7 +32,7 @@ import static org.junit.Assert.*; -public class ITestCrdtApi extends ITestBase +public class ITestCrdtApi extends ITestAutoCleanupBase { @Test diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestDeleteOperation.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestDeleteOperation.java index 35b9fca2d..31a5225b1 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestDeleteOperation.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestDeleteOperation.java @@ -31,7 +31,7 @@ * * @author Brian Roach */ -public class ITestDeleteOperation extends ITestBase +public class ITestDeleteOperation extends ITestAutoCleanupBase { @Test public void testDeleteObjectDefaultType() throws InterruptedException, ExecutionException diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestDtUpdateOperation.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestDtUpdateOperation.java index af35c984e..298891edc 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestDtUpdateOperation.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestDtUpdateOperation.java @@ -34,7 +34,7 @@ import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; -public class ITestDtUpdateOperation extends ITestBase +public class ITestDtUpdateOperation extends ITestAutoCleanupBase { private RiakCounter fetchCounter(BinaryValue type, BinaryValue bucket, BinaryValue key) diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestFetchOperation.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestFetchOperation.java index f17bd99db..da6081a2a 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestFetchOperation.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestFetchOperation.java @@ -15,19 +15,25 @@ */ package com.basho.riak.client.core.operations.itest; +import com.basho.riak.client.core.RiakFuture; +import com.basho.riak.client.core.operations.FetchBucketPropsOperation; import com.basho.riak.client.core.operations.FetchOperation; import com.basho.riak.client.core.operations.StoreBucketPropsOperation; import com.basho.riak.client.core.operations.StoreOperation; -import static com.basho.riak.client.core.operations.itest.ITestBase.bucketName; import com.basho.riak.client.core.query.Location; import com.basho.riak.client.core.query.Namespace; import com.basho.riak.client.core.query.RiakObject; import com.basho.riak.client.core.util.BinaryValue; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + import java.util.List; +import java.util.Random; import java.util.concurrent.ExecutionException; + import static org.junit.Assert.*; import static org.junit.Assume.assumeTrue; -import org.junit.Test; /** * @@ -35,7 +41,25 @@ */ public class ITestFetchOperation extends ITestBase { - + private static long keySeed = new Random().nextLong(); + private static String siblingsBucket = "siblings"; + + @BeforeClass + public static void setupSiblingBuckets() throws ExecutionException, InterruptedException + { + setAllowMultOnBucket(new Namespace(Namespace.DEFAULT_BUCKET_TYPE, siblingsBucket)); + setAllowMultOnBucket(new Namespace(bucketType.toStringUtf8(), siblingsBucket)); + } + + @AfterClass + public static void cleanupBuckets() throws ExecutionException, InterruptedException + { + ITestAutoCleanupBase.resetAndEmptyBucket(new Namespace(Namespace.DEFAULT_BUCKET_TYPE, bucketName.toString())); + ITestAutoCleanupBase.resetAndEmptyBucket(new Namespace(Namespace.DEFAULT_BUCKET_TYPE, siblingsBucket)); + ITestAutoCleanupBase.resetAndEmptyBucket(new Namespace(bucketType.toString(), bucketName.toString())); + ITestAutoCleanupBase.resetAndEmptyBucket(new Namespace(bucketType.toString(), siblingsBucket)); + } + @Test public void testFetchOpNotFoundDefaultType() throws InterruptedException, ExecutionException { @@ -51,11 +75,11 @@ public void testFetchOpNotFoundTestType() throws InterruptedException, Execution private void testFetchOpNotFound(String bucketType) throws InterruptedException, ExecutionException { - final BinaryValue key = BinaryValue.unsafeCreate("my_key_1".getBytes()); - final String value = "{\"value\":\"value\"}"; - Namespace ns = new Namespace(bucketType, bucketName.toString()); - Location location = new Location(ns, key); - FetchOperation fetchOp = + final BinaryValue key = generateKey(); + + Location location = new Location(new Namespace(bucketType, bucketName.toString()), key); + + FetchOperation fetchOp = new FetchOperation.Builder(location).build(); cluster.execute(fetchOp); @@ -80,7 +104,7 @@ public void testFetchOpNoSiblingsTestType() throws InterruptedException, Executi private void testFetchOpNoSiblings(String bucketType) throws InterruptedException, ExecutionException { - final BinaryValue key = BinaryValue.unsafeCreate("my_key_2".getBytes()); + final BinaryValue key = generateKey(); final String value = "{\"value\":\"value\"}"; RiakObject rObj = new RiakObject().setValue(BinaryValue.create(value)); @@ -103,11 +127,13 @@ private void testFetchOpNoSiblings(String bucketType) throws InterruptedExceptio List objectList = response.getObjectList(); assertEquals(1, objectList.size()); RiakObject ro = objectList.get(0); + assertFalse(ro.isDeleted()); assertEquals(ro.getValue().toString(), value); } @Test + public void testFetchOpWithSiblingsDefaultType() throws InterruptedException, ExecutionException { testFetchOpWithSiblings(Namespace.DEFAULT_BUCKET_TYPE); @@ -122,47 +148,57 @@ public void testFetchOpWithSiblingsTestType() throws InterruptedException, Execu private void testFetchOpWithSiblings(String bucketType) throws InterruptedException, ExecutionException { - final BinaryValue key = BinaryValue.unsafeCreate("my_key_3".getBytes()); + final BinaryValue key = generateKey(); final String value = "{\"value\":\"value\"}"; - - Namespace namespace = new Namespace(bucketType, bucketName.toString()); - StoreBucketPropsOperation op = - new StoreBucketPropsOperation.Builder(namespace) - .withAllowMulti(true) - .build(); - cluster.execute(op); - op.get(); - + + Namespace namespace = new Namespace(bucketType, siblingsBucket.toString()); + RiakObject rObj = new RiakObject().setValue(BinaryValue.create(value)); Location location = new Location(namespace, key); - StoreOperation storeOp = - new StoreOperation.Builder(location) - .withContent(rObj) - .build(); + final StoreOperation storeOp = new StoreOperation.Builder(location).withContent(rObj).withDw(3).withW(3).withReturnBody(true).build(); cluster.execute(storeOp); storeOp.get(); assertTrue(storeOp.isSuccess()); - - storeOp = - new StoreOperation.Builder(location) - .withContent(rObj) - .build(); - - cluster.execute(storeOp); - storeOp.get(); - assertTrue(storeOp.isSuccess()); - FetchOperation fetchOp = - new FetchOperation.Builder(location).build(); - + + final StoreOperation storeOp2 = new StoreOperation.Builder(location).withContent(rObj).withDw(3).withW(3).withReturnBody(true).build(); + + cluster.execute(storeOp2); + storeOp2.get(); + assertTrue(storeOp2.isSuccess()); + + FetchOperation fetchOp = + new FetchOperation.Builder(location).withR(3).build(); + System.out.println(key.toStringUtf8()); cluster.execute(fetchOp); FetchOperation.Response response = fetchOp.get(); + assertTrue(response.getObjectList().size() > 1); - RiakObject ro = response.getObjectList().get(0); assertEquals(ro.getValue().toString(), value); - } - + + private static Namespace setAllowMultOnBucket(Namespace namespace) throws InterruptedException, ExecutionException + { + StoreBucketPropsOperation op = + new StoreBucketPropsOperation.Builder(namespace) + .withAllowMulti(true) + .build(); + final RiakFuture storePropsFuture = cluster.execute(op); + storePropsFuture.get(); + + FetchBucketPropsOperation fetchPropsOp = new FetchBucketPropsOperation.Builder(namespace).build(); + final RiakFuture fetchFuture = cluster.execute(fetchPropsOp); + final FetchBucketPropsOperation.Response response = fetchFuture.get(); + assertTrue(response.getBucketProperties().getAllowMulti()); + return namespace; + } + + private BinaryValue generateKey() + { + final String key = testName.getMethodName() + keySeed; + return BinaryValue.unsafeCreate(key.getBytes()); + } + } diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestListBucketsOperation.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestListBucketsOperation.java index dd5fa2a4a..69601c4b5 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestListBucketsOperation.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestListBucketsOperation.java @@ -40,7 +40,7 @@ * * @author Brian Roach */ -public class ITestListBucketsOperation extends ITestBase +public class ITestListBucketsOperation extends ITestAutoCleanupBase { @Test public void testListBucketsDefaultType() throws InterruptedException, ExecutionException diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestListKeysOperation.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestListKeysOperation.java index f6d22b31c..4485b81e1 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestListKeysOperation.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestListKeysOperation.java @@ -19,7 +19,6 @@ import com.basho.riak.client.core.RiakFutureListener; import com.basho.riak.client.core.operations.ListKeysOperation; import com.basho.riak.client.core.operations.StoreOperation; -import static com.basho.riak.client.core.operations.itest.ITestBase.bucketName; import com.basho.riak.client.core.query.Location; import com.basho.riak.client.core.query.Namespace; import com.basho.riak.client.core.query.RiakObject; @@ -38,7 +37,7 @@ * * @author Brian Roach */ -public class ITestListKeysOperation extends ITestBase +public class ITestListKeysOperation extends ITestAutoCleanupBase { @Test public void testListNoKeysDefaultType() throws InterruptedException, ExecutionException @@ -172,7 +171,7 @@ public void handle(RiakFuture f) } latch.await(2, TimeUnit.MINUTES); - ITestBase.resetAndEmptyBucket(ns); + ITestAutoCleanupBase.resetAndEmptyBucket(ns); } } diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestMapReduceOperation.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestMapReduceOperation.java index 2cfa7b413..40e9a3490 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestMapReduceOperation.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestMapReduceOperation.java @@ -17,7 +17,6 @@ import com.basho.riak.client.core.operations.MapReduceOperation; import com.basho.riak.client.core.operations.StoreOperation; -import static com.basho.riak.client.core.operations.itest.ITestBase.bucketName; import com.basho.riak.client.core.query.Location; import com.basho.riak.client.core.query.Namespace; import com.basho.riak.client.core.query.RiakObject; @@ -38,7 +37,7 @@ * @author Brian Roach * @since 2.0 */ -public class ITestMapReduceOperation extends ITestBase +public class ITestMapReduceOperation extends ITestAutoCleanupBase { @Test public void testBasicMRDefaultType() throws InterruptedException, ExecutionException, IOException diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestPingOperation.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestPingOperation.java index c966fedd3..936c02e07 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestPingOperation.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestPingOperation.java @@ -30,7 +30,7 @@ * * @author Brian Roach */ -public class ITestPingOperation extends ITestBase +public class ITestPingOperation extends ITestAutoCleanupBase { @Test public void theMachinethatGoesPing() throws InterruptedException, ExecutionException diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestSecondaryIndexQueryOp.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestSecondaryIndexQueryOp.java index 398578ee8..72d1b784d 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestSecondaryIndexQueryOp.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestSecondaryIndexQueryOp.java @@ -36,7 +36,7 @@ * @author Brian Roach * @author Alex Moore */ -public class ITestSecondaryIndexQueryOp extends ITestBase +public class ITestSecondaryIndexQueryOp extends ITestAutoCleanupBase { @Test public void testSingleQuerySingleResponseDefaultType() throws InterruptedException, ExecutionException diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestStoreOperation.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestStoreOperation.java index ecbe0b56e..9e3e60880 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestStoreOperation.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestStoreOperation.java @@ -18,7 +18,6 @@ import com.basho.riak.client.core.operations.FetchOperation; import com.basho.riak.client.core.operations.StoreBucketPropsOperation; import com.basho.riak.client.core.operations.StoreOperation; -import static com.basho.riak.client.core.operations.itest.ITestBase.bucketName; import com.basho.riak.client.core.query.Location; import com.basho.riak.client.core.query.Namespace; import com.basho.riak.client.core.query.RiakObject; @@ -33,7 +32,7 @@ * @author Brian Roach * @since 2.0 */ -public class ITestStoreOperation extends ITestBase +public class ITestStoreOperation extends ITestAutoCleanupBase { final private BinaryValue key = BinaryValue.unsafeCreate("my_key".getBytes()); final private String value = "{\"value\":\"some value\"}"; diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestYzAdminOperations.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestYzAdminOperations.java index 0c1864247..0f4a15fee 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestYzAdminOperations.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestYzAdminOperations.java @@ -34,7 +34,7 @@ * @author Brian Roach * @since 2.0 */ -public class ITestYzAdminOperations extends ITestBase +public class ITestYzAdminOperations extends ITestAutoCleanupBase { public static final String indexName = "test_index_ITestYzAdminOperations"; diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ts/ITestTsBase.java b/src/test/java/com/basho/riak/client/core/operations/itest/ts/ITestTsBase.java index b5c652670..9c46d80f2 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ts/ITestTsBase.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ts/ITestTsBase.java @@ -3,7 +3,7 @@ import com.basho.riak.client.api.RiakClient; import com.basho.riak.client.api.commands.timeseries.Query; import com.basho.riak.client.core.RiakFuture; -import com.basho.riak.client.core.operations.itest.ITestBase; +import com.basho.riak.client.core.operations.itest.ITestAutoCleanupBase; import com.basho.riak.client.core.operations.ts.QueryOperation; import com.basho.riak.client.core.query.timeseries.Cell; import com.basho.riak.client.core.query.timeseries.QueryResult; @@ -40,7 +40,7 @@ * @author Sergey Galkin * @since 2.0.3 */ -public abstract class ITestTsBase extends ITestBase +public abstract class ITestTsBase extends ITestAutoCleanupBase { protected final static String tableName = "GeoCheckin"; From b682bcda7109d6a47be033df10936b026d6d4291 Mon Sep 17 00:00:00 2001 From: Alex Moore Date: Wed, 2 Mar 2016 15:59:01 -0500 Subject: [PATCH 02/10] Remove extra options that arent needed --- .../client/core/operations/itest/ITestFetchOperation.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestFetchOperation.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestFetchOperation.java index da6081a2a..5e581f123 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestFetchOperation.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestFetchOperation.java @@ -155,21 +155,21 @@ private void testFetchOpWithSiblings(String bucketType) throws InterruptedExcept RiakObject rObj = new RiakObject().setValue(BinaryValue.create(value)); Location location = new Location(namespace, key); - final StoreOperation storeOp = new StoreOperation.Builder(location).withContent(rObj).withDw(3).withW(3).withReturnBody(true).build(); + final StoreOperation storeOp = new StoreOperation.Builder(location).withContent(rObj).build(); cluster.execute(storeOp); storeOp.get(); assertTrue(storeOp.isSuccess()); - final StoreOperation storeOp2 = new StoreOperation.Builder(location).withContent(rObj).withDw(3).withW(3).withReturnBody(true).build(); + final StoreOperation storeOp2 = new StoreOperation.Builder(location).withContent(rObj).build(); cluster.execute(storeOp2); storeOp2.get(); assertTrue(storeOp2.isSuccess()); FetchOperation fetchOp = - new FetchOperation.Builder(location).withR(3).build(); + new FetchOperation.Builder(location).build(); System.out.println(key.toStringUtf8()); cluster.execute(fetchOp); FetchOperation.Response response = fetchOp.get(); From 3db4a7d313d6622614c788be62932a55e01354f1 Mon Sep 17 00:00:00 2001 From: Alex Moore Date: Thu, 3 Mar 2016 10:46:34 -0500 Subject: [PATCH 03/10] Break out ITest cleanup into another base file, move some slower tests to only do one setup + cleanup --- .../itest/ITestBucketKeyMapReduce.java | 59 ++++++------ .../commands/itest/ITestBucketMapReduce.java | 78 +++++++--------- .../operations/itest/ISearchTestBase.java | 2 +- .../itest/ITestAutoCleanupBase.java | 74 --------------- .../core/operations/itest/ITestBase.java | 91 ++++++++++++++++++- .../operations/itest/ITestFetchOperation.java | 9 +- .../itest/ITestListKeysOperation.java | 2 +- .../itest/ITestYzAdminOperations.java | 2 +- 8 files changed, 157 insertions(+), 160 deletions(-) diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketKeyMapReduce.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketKeyMapReduce.java index c69facf50..5f772bec4 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketKeyMapReduce.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketKeyMapReduce.java @@ -21,6 +21,7 @@ import com.basho.riak.client.api.commands.kv.StoreValue; import com.basho.riak.client.api.commands.mapreduce.BucketKeyMapReduce; import com.basho.riak.client.api.commands.mapreduce.MapReduce; +import com.basho.riak.client.core.operations.itest.ITestBase; import com.basho.riak.client.core.query.Location; import com.basho.riak.client.core.query.Namespace; import com.basho.riak.client.core.query.RiakObject; @@ -29,52 +30,59 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; -import org.junit.Test; +import org.junit.*; import java.io.IOException; import java.util.Map; import java.util.concurrent.ExecutionException; -import org.junit.After; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import org.junit.Assume; -import org.junit.Before; /** * @author Brian Roach * @since 2.0 */ -public class ITestBucketKeyMapReduce extends ITestAutoCleanupBase +public class ITestBucketKeyMapReduce extends ITestBase { + private final static RiakClient client = new RiakClient(cluster); + private final static String mrBucketName = "ITestBucketKeyMapReduce"; - RiakClient client = new RiakClient(cluster); - static final String mrBucket = "mr_bucket"; - - @Before - public void changeBucketProps() throws ExecutionException, InterruptedException + @BeforeClass + public static void setup() throws InterruptedException, ExecutionException { + changeBucketProps(); + initValues(Namespace.DEFAULT_BUCKET_TYPE.toString()); if (testBucketType) { - Namespace ns = new Namespace(bucketType.toString(), mrBucket); - StoreBucketProperties op = new StoreBucketProperties.Builder(ns).withAllowMulti(false).build(); - client.execute(op); + initValues(mapReduceBucketType.toString()); } } - - @After - public void clearMrBucket() throws InterruptedException, ExecutionException + + @AfterClass + public static void tearDown() throws ExecutionException, InterruptedException { - Namespace ns = new Namespace(Namespace.DEFAULT_BUCKET_TYPE, mrBucket); + Namespace ns = new Namespace(mrBucketName); resetAndEmptyBucket(ns); + if (testBucketType) { - ns = new Namespace(bucketType.toString(), mrBucket); + ns = new Namespace(mapReduceBucketType.toString(), mrBucketName); resetAndEmptyBucket(ns); } } - private void initValues(String bucketType) throws ExecutionException, InterruptedException + private static void changeBucketProps() throws ExecutionException, InterruptedException + { + if (testBucketType) + { + Namespace ns = new Namespace(mapReduceBucketType.toString(), mrBucketName); + StoreBucketProperties op = new StoreBucketProperties.Builder(ns).withAllowMulti(false).build(); + client.execute(op); + } + } + + private static void initValues(String bucketType) throws ExecutionException, InterruptedException { RiakObject obj = new RiakObject(); @@ -83,7 +91,7 @@ private void initValues(String bucketType) throws ExecutionException, Interrupte "book her sister was reading, but it had no pictures or conversations in " + "it, 'and what is the use of a book,' thought Alice 'without pictures or " + "conversation?'")); - Namespace ns = new Namespace(bucketType, mrBucket); + Namespace ns = new Namespace(bucketType, mrBucketName); Location location = new Location(ns, "p1"); client.execute(new StoreValue.Builder(obj).withLocation(location).build()); @@ -116,14 +124,12 @@ public void JsBucketKeyMRDefaultType() throws InterruptedException, ExecutionExc public void JsBucketKeyMRTestType() throws InterruptedException, ExecutionException, IOException { Assume.assumeTrue(testBucketType); - JsBucketKeyMR(bucketType.toString()); + JsBucketKeyMR(mapReduceBucketType.toString()); } private void JsBucketKeyMR(String bucketType) throws InterruptedException, ExecutionException, IOException { - initValues(bucketType); - - Namespace ns = new Namespace(bucketType, mrBucket); + Namespace ns = new Namespace(bucketType, mrBucketName); MapReduce mr = new BucketKeyMapReduce.Builder() .withLocation(new Location(ns, "p1")) .withLocation(new Location(ns, "p2")) @@ -188,13 +194,12 @@ public void erlangBucketKeyMRDefaultType() throws ExecutionException, Interrupte public void erlangBucketKeyMRTestType() throws ExecutionException, InterruptedException { Assume.assumeTrue(testBucketType); - erlangBucketKeyMR(bucketType.toString()); + erlangBucketKeyMR(mapReduceBucketType.toString()); } private void erlangBucketKeyMR(String bucketType) throws ExecutionException, InterruptedException { - initValues(bucketType); - Namespace ns = new Namespace(bucketType, mrBucket); + Namespace ns = new Namespace(bucketType, mrBucketName); MapReduce mr = new BucketKeyMapReduce.Builder() .withLocation(new Location(ns, "p1")) diff --git a/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketMapReduce.java b/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketMapReduce.java index 66dfd08ce..29447aa15 100644 --- a/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketMapReduce.java +++ b/src/test/java/com/basho/riak/client/api/commands/itest/ITestBucketMapReduce.java @@ -23,6 +23,7 @@ import com.basho.riak.client.api.commands.kv.StoreValue; import com.basho.riak.client.api.commands.mapreduce.BucketMapReduce; import com.basho.riak.client.api.commands.mapreduce.MapReduce; +import com.basho.riak.client.core.operations.itest.ITestBase; import com.basho.riak.client.core.query.Location; import com.basho.riak.client.core.query.Namespace; import com.basho.riak.client.core.query.RiakObject; @@ -35,52 +36,57 @@ import com.basho.riak.client.core.util.BinaryValue; import com.fasterxml.jackson.databind.node.ArrayNode; import java.util.concurrent.ExecutionException; -import org.junit.After; -import org.junit.Test; + +import org.junit.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import org.junit.Assume; -import org.junit.Before; /** * * @author Brian Roach */ -public class ITestBucketMapReduce extends ITestAutoCleanupBase +public class ITestBucketMapReduce extends ITestBase { private final static RiakClient client = new RiakClient(cluster); - private final static String mrBucketName = bucketName.toString() + "_mr"; - - @Before - public void changeBucketProps() throws ExecutionException, InterruptedException + private final static String mrBucketName = "ITestBucketMapReduce"; + + @BeforeClass + public static void setup() throws InterruptedException, ExecutionException { + changeBucketProps(); + initValues(Namespace.DEFAULT_BUCKET_TYPE.toString()); if (testBucketType) { - Namespace ns = new Namespace(bucketType.toString(), mrBucketName); - StoreBucketProperties op = new StoreBucketProperties.Builder(ns).withAllowMulti(false).build(); - client.execute(op); + initValues(mapReduceBucketType.toString()); } } - - @After - public void cleanUp() throws InterruptedException, ExecutionException + + @AfterClass + public static void tearDown() throws ExecutionException, InterruptedException { - // Because some of these tests blow up due to Riak bugs we need - // to clean up the mess here Namespace ns = new Namespace(mrBucketName); resetAndEmptyBucket(ns); - + if (testBucketType) { - ns = new Namespace(bucketType.toString(), mrBucketName); + ns = new Namespace(mapReduceBucketType.toString(), mrBucketName); resetAndEmptyBucket(ns); } - + } + + private static void changeBucketProps() throws ExecutionException, InterruptedException + { + if (testBucketType) + { + Namespace ns = new Namespace(mapReduceBucketType.toString(), mrBucketName); + StoreBucketProperties op = new StoreBucketProperties.Builder(ns).withAllowMulti(false).build(); + client.execute(op); + } } - private void initValues(String bucketType) throws InterruptedException + private static void initValues(String bucketType) throws InterruptedException { // insert 200 items into a bucket @@ -109,12 +115,11 @@ public void erlangBucketMRDefaultType() throws InterruptedException, ExecutionEx public void erlangBucketMRTestType() throws InterruptedException, ExecutionException { Assume.assumeTrue(testBucketType); - erlangBucketMR(bucketType.toString()); + erlangBucketMR(mapReduceBucketType.toString()); } private void erlangBucketMR(String bucketType) throws InterruptedException, ExecutionException { - initValues(bucketType); Namespace ns = new Namespace(bucketType, mrBucketName); BucketMapReduce bmr = new BucketMapReduce.Builder() @@ -134,8 +139,6 @@ private void erlangBucketMR(String bucketType) throws InterruptedException, Exec assertEquals(42, result.get(42).asInt()); assertEquals(199, result.get(199).asInt()); - - resetAndEmptyBucket(ns); } @Test @@ -148,13 +151,11 @@ public void JsBucketMRDefaultType() throws InterruptedException, ExecutionExcept public void JsBucketMRTestType() throws InterruptedException, ExecutionException { Assume.assumeTrue(testBucketType); - JsBucketMR(bucketType.toString()); + JsBucketMR(mapReduceBucketType.toString()); } private void JsBucketMR(String bucketType) throws InterruptedException, ExecutionException { - initValues(bucketType); - Namespace ns = new Namespace(bucketType, mrBucketName); BucketMapReduce bmr = new BucketMapReduce.Builder() @@ -178,15 +179,11 @@ private void JsBucketMR(String bucketType) throws InterruptedException, Executio assertEquals(42, result.get(42).asInt()); assertEquals(199, result.get(199).asInt()); - - resetAndEmptyBucket(ns); } @Test public void multiPhaseResult() throws InterruptedException, ExecutionException { - initValues(Namespace.DEFAULT_BUCKET_TYPE); - Namespace ns = new Namespace(Namespace.DEFAULT_BUCKET_TYPE, mrBucketName); BucketMapReduce bmr = new BucketMapReduce.Builder() @@ -211,14 +208,11 @@ public void multiPhaseResult() throws InterruptedException, ExecutionException assertEquals(42, result.get(42).asInt()); assertEquals(199, result.get(199).asInt()); - - resetAndEmptyBucket(ns); } @Test public void keyFilter() throws InterruptedException, ExecutionException { - initValues(Namespace.DEFAULT_BUCKET_TYPE); Namespace ns = new Namespace(Namespace.DEFAULT_BUCKET_TYPE, mrBucketName); BucketMapReduce bmr = new BucketMapReduce.Builder() @@ -239,8 +233,6 @@ public void keyFilter() throws InterruptedException, ExecutionException assertEquals(4, response.getResultsFromAllPhases().size()); assertEquals(46, response.getResultsFromAllPhases().get(0).asInt()); assertEquals(49, response.getResultsFromAllPhases().get(3).asInt()); - - resetAndEmptyBucket(ns); } @Test @@ -248,8 +240,7 @@ public void differentBucketType() throws InterruptedException, ExecutionExceptio { Assume.assumeTrue(testBucketType); - initValues(bucketType.toString()); - Namespace ns = new Namespace(bucketType.toString(), mrBucketName); + Namespace ns = new Namespace(mapReduceBucketType.toString(), mrBucketName); BucketMapReduce bmr = new BucketMapReduce.Builder() .withNamespace(ns) @@ -266,8 +257,6 @@ public void differentBucketType() throws InterruptedException, ExecutionExceptio MapReduce.Response response = client.execute(bmr); assertEquals(179, response.getResultsFromAllPhases().size()); - - resetAndEmptyBucket(ns); } @Test @@ -275,9 +264,7 @@ public void differentBucketTypeWithFilter() throws InterruptedException, Executi { Assume.assumeTrue(testBucketType); - initValues(bucketType.toString()); - - Namespace ns = new Namespace(bucketType.toString(), mrBucketName); + Namespace ns = new Namespace(mapReduceBucketType.toString(), mrBucketName); BucketMapReduce bmr = new BucketMapReduce.Builder() .withNamespace(ns) @@ -296,8 +283,5 @@ public void differentBucketTypeWithFilter() throws InterruptedException, Executi future.await(); assertTrue(future.isSuccess()); assertEquals(4, future.get().getResultsFromAllPhases().size()); - resetAndEmptyBucket(ns); - } - } diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ISearchTestBase.java b/src/test/java/com/basho/riak/client/core/operations/itest/ISearchTestBase.java index a85e3b3a4..60fc97918 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ISearchTestBase.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ISearchTestBase.java @@ -23,7 +23,7 @@ * @author Alex Moore * @since 2.0.5 */ -public class ISearchTestBase extends ITestAutoCleanupBase +public class ISearchTestBase extends ITestBase { public static void setupSearchEnvironment(String bucketName, String indexName) throws ExecutionException, InterruptedException { diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestAutoCleanupBase.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestAutoCleanupBase.java index b53fa878e..2f0314f5f 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestAutoCleanupBase.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestAutoCleanupBase.java @@ -47,80 +47,6 @@ public void afterTest() throws ExecutionException, InterruptedException resetAndEmptyBucket(defaultNamespace()); } } - - public static void resetAndEmptyBucket(BinaryValue name) throws InterruptedException, ExecutionException - { - resetAndEmptyBucket(new Namespace(Namespace.DEFAULT_BUCKET_TYPE, name.toString())); - } - - public static void resetAndEmptyBucket(Namespace namespace) throws InterruptedException, ExecutionException - { - ListKeysOperation.Builder keysOpBuilder = new ListKeysOperation.Builder(namespace); - - ListKeysOperation keysOp = keysOpBuilder.build(); - cluster.execute(keysOp); - List keyList = keysOp.get().getKeys(); - final Semaphore semaphore = new Semaphore(NUMBER_OF_PARALLEL_REQUESTS); - final CountDownLatch latch = new CountDownLatch(keyList.size()); - - RiakFutureListener listener = new RiakFutureListener() { - @Override - public void handle(RiakFuture f) - { - try - { - f.get(); - } - catch (Exception ex) - { - if (ex instanceof RuntimeException) - { - throw (RuntimeException)ex; - } - throw new RuntimeException(ex); - } - semaphore.release(); - latch.countDown(); - } - - }; - - for (BinaryValue k : keyList) - { - Location location = new Location(namespace, k); - DeleteOperation delOp = new DeleteOperation.Builder(location).withRw(3).build(); - delOp.addListener(listener); - semaphore.acquire(); - cluster.execute(delOp); - } - - latch.await(); - - ResetBucketPropsOperation.Builder resetOpBuilder = - new ResetBucketPropsOperation.Builder(namespace); - - ResetBucketPropsOperation resetOp = resetOpBuilder.build(); - cluster.execute(resetOp); - resetOp.get(); - - } - - public static boolean assureIndexExists(String indexName) throws InterruptedException - { - for (int x = 0; x < 5; x++) - { - Thread.sleep(2000); - YzFetchIndexOperation fetch = new YzFetchIndexOperation.Builder().withIndexName(indexName).build(); - cluster.execute(fetch); - fetch.await(); - if (fetch.isSuccess()) - { - return true; - } - } - - return false; - } public static Namespace defaultNamespace() { 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 5222c7573..25d089bf2 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 @@ -2,8 +2,15 @@ import com.basho.riak.client.core.RiakCluster; import com.basho.riak.client.core.RiakFuture; +import com.basho.riak.client.core.RiakFutureListener; import com.basho.riak.client.core.RiakNode; import com.basho.riak.client.core.netty.RiakResponseException; +import com.basho.riak.client.core.operations.DeleteOperation; +import com.basho.riak.client.core.operations.ListKeysOperation; +import com.basho.riak.client.core.operations.ResetBucketPropsOperation; +import com.basho.riak.client.core.operations.YzFetchIndexOperation; +import com.basho.riak.client.core.query.Location; +import com.basho.riak.client.core.query.Namespace; import com.basho.riak.client.core.util.BinaryValue; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -17,9 +24,8 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import java.util.List; +import java.util.concurrent.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -45,6 +51,7 @@ public class ITestBase protected static BinaryValue mapBucketType; protected static BinaryValue bucketType; protected static BinaryValue yokozunaBucketType; + protected static BinaryValue mapReduceBucketType; protected static String overrideCert; protected static String hostname; protected static int pbcPort; @@ -52,7 +59,7 @@ public class ITestBase public TestName testName = new TestName(); @BeforeClass - public static void setUp() throws FileNotFoundException, CertificateException, IOException, KeyStoreException, + public static void setUp() throws CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException { bucketName = BinaryValue.unsafeCreate("ITestAutoCleanupBase".getBytes()); @@ -115,6 +122,9 @@ public static void setUp() throws FileNotFoundException, CertificateException, I counterBucketType = BinaryValue.create("counters"); setBucketType = BinaryValue.create("sets"); mapBucketType = BinaryValue.create("maps"); + + mapReduceBucketType = BinaryValue.create("mr"); + testCrdt = Boolean.parseBoolean(System.getProperty("com.basho.riak.crdt")); testTimeSeries = Boolean.parseBoolean(System.getProperty("com.basho.riak.timeseries")); @@ -153,6 +163,62 @@ public static void tearDown() throws InterruptedException, ExecutionException, T cluster.shutdown().get(2, TimeUnit.SECONDS); } + public static void resetAndEmptyBucket(BinaryValue name) throws InterruptedException, ExecutionException + { + resetAndEmptyBucket(new Namespace(Namespace.DEFAULT_BUCKET_TYPE, name.toString())); + } + + public static void resetAndEmptyBucket(Namespace namespace) throws InterruptedException, ExecutionException + { + ListKeysOperation.Builder keysOpBuilder = new ListKeysOperation.Builder(namespace); + + ListKeysOperation keysOp = keysOpBuilder.build(); + cluster.execute(keysOp); + List keyList = keysOp.get().getKeys(); + final Semaphore semaphore = new Semaphore(NUMBER_OF_PARALLEL_REQUESTS); + final CountDownLatch latch = new CountDownLatch(keyList.size()); + + RiakFutureListener listener = new RiakFutureListener() { + @Override + public void handle(RiakFuture f) + { + try + { + f.get(); + } + catch (Exception ex) + { + if (ex instanceof RuntimeException) + { + throw (RuntimeException)ex; + } + throw new RuntimeException(ex); + } + semaphore.release(); + latch.countDown(); + } + + }; + + for (BinaryValue k : keyList) + { + Location location = new Location(namespace, k); + DeleteOperation delOp = new DeleteOperation.Builder(location).withRw(3).build(); + delOp.addListener(listener); + semaphore.acquire(); + cluster.execute(delOp); + } + + latch.await(); + + ResetBucketPropsOperation.Builder resetOpBuilder = + new ResetBucketPropsOperation.Builder(namespace); + + ResetBucketPropsOperation resetOp = resetOpBuilder.build(); + cluster.execute(resetOp); + resetOp.get(); + } + private static void setupUsernamePasswordSecurity(RiakNode.Builder builder) throws CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException { InputStream in; @@ -201,4 +267,21 @@ protected void setBucketNameToTestName() { bucketName = BinaryValue.create(testName.getMethodName()); } + + public static boolean assureIndexExists(String indexName) throws InterruptedException + { + for (int x = 0; x < 5; x++) + { + Thread.sleep(2000); + YzFetchIndexOperation fetch = new YzFetchIndexOperation.Builder().withIndexName(indexName).build(); + cluster.execute(fetch); + fetch.await(); + if (fetch.isSuccess()) + { + return true; + } + } + + return false; + } } diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestFetchOperation.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestFetchOperation.java index 5e581f123..5968ab704 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestFetchOperation.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestFetchOperation.java @@ -54,10 +54,10 @@ public static void setupSiblingBuckets() throws ExecutionException, InterruptedE @AfterClass public static void cleanupBuckets() throws ExecutionException, InterruptedException { - ITestAutoCleanupBase.resetAndEmptyBucket(new Namespace(Namespace.DEFAULT_BUCKET_TYPE, bucketName.toString())); - ITestAutoCleanupBase.resetAndEmptyBucket(new Namespace(Namespace.DEFAULT_BUCKET_TYPE, siblingsBucket)); - ITestAutoCleanupBase.resetAndEmptyBucket(new Namespace(bucketType.toString(), bucketName.toString())); - ITestAutoCleanupBase.resetAndEmptyBucket(new Namespace(bucketType.toString(), siblingsBucket)); + resetAndEmptyBucket(new Namespace(Namespace.DEFAULT_BUCKET_TYPE, bucketName.toString())); + resetAndEmptyBucket(new Namespace(Namespace.DEFAULT_BUCKET_TYPE, siblingsBucket)); + resetAndEmptyBucket(new Namespace(bucketType.toString(), bucketName.toString())); + resetAndEmptyBucket(new Namespace(bucketType.toString(), siblingsBucket)); } @Test @@ -170,7 +170,6 @@ private void testFetchOpWithSiblings(String bucketType) throws InterruptedExcept FetchOperation fetchOp = new FetchOperation.Builder(location).build(); - System.out.println(key.toStringUtf8()); cluster.execute(fetchOp); FetchOperation.Response response = fetchOp.get(); diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestListKeysOperation.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestListKeysOperation.java index 4485b81e1..690b1656b 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestListKeysOperation.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestListKeysOperation.java @@ -171,7 +171,7 @@ public void handle(RiakFuture f) } latch.await(2, TimeUnit.MINUTES); - ITestAutoCleanupBase.resetAndEmptyBucket(ns); + resetAndEmptyBucket(ns); } } diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestYzAdminOperations.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestYzAdminOperations.java index 0f4a15fee..0c1864247 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestYzAdminOperations.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestYzAdminOperations.java @@ -34,7 +34,7 @@ * @author Brian Roach * @since 2.0 */ -public class ITestYzAdminOperations extends ITestAutoCleanupBase +public class ITestYzAdminOperations extends ITestBase { public static final String indexName = "test_index_ITestYzAdminOperations"; From ad43ec8e72b907b805bdd8e3d38927030e8971cc Mon Sep 17 00:00:00 2001 From: Alex Moore Date: Thu, 3 Mar 2016 12:52:40 -0500 Subject: [PATCH 04/10] Refactor 2i op tests to use common setup/cleanup. Took execution from 4.5s to 78ms. --- .../itest/ITestSecondaryIndexQueryOp.java | 667 ++++++++---------- 1 file changed, 301 insertions(+), 366 deletions(-) diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestSecondaryIndexQueryOp.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestSecondaryIndexQueryOp.java index 72d1b784d..fa7a6f812 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestSecondaryIndexQueryOp.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestSecondaryIndexQueryOp.java @@ -23,10 +23,9 @@ import com.basho.riak.client.core.query.indexes.LongIntIndex; import com.basho.riak.client.core.query.indexes.StringBinIndex; import com.basho.riak.client.core.util.BinaryValue; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Test; +import org.junit.*; +import java.util.Random; import java.util.concurrent.ExecutionException; import static org.junit.Assert.*; @@ -36,240 +35,347 @@ * @author Brian Roach * @author Alex Moore */ -public class ITestSecondaryIndexQueryOp extends ITestAutoCleanupBase +public class ITestSecondaryIndexQueryOp extends ITestBase { + private static final long bucketSeed = new Random().nextLong(); + private static final String bucketName = "ITestSecondaryIndexQueryOp" + bucketSeed; + + private static final Namespace defaultTypeNamespace = new Namespace(bucketName); + private static final Namespace typedNamespace = new Namespace(bucketType.toString(), bucketName); + private static final String incrementingIndexNameString = "test_index"; + private static final String allFivesIndexNameString = "all_fives_index"; + private static final String regexIndexNameString = "regex_index"; + private static final BinaryValue incrementingIndexName = BinaryValue.create(incrementingIndexNameString + "_int"); + private static final BinaryValue allFivesIndexName = BinaryValue.create(allFivesIndexNameString + "_int"); + private static final BinaryValue regexIndexName = BinaryValue.create(regexIndexNameString + "_bin"); + + private static final String keyBase = "my_key"; + private static final String value = "value"; + + @BeforeClass + public static void setupSiblingBuckets() throws ExecutionException, InterruptedException + { + Assume.assumeTrue(test2i); + + setupIndexTestData(defaultTypeNamespace); + + if(testBucketType) + { + setupIndexTestData(typedNamespace); + } + } + + @AfterClass + public static void cleanupBuckets() throws ExecutionException, InterruptedException + { + resetAndEmptyBucket(defaultTypeNamespace); + resetAndEmptyBucket(typedNamespace); + } + @Test public void testSingleQuerySingleResponseDefaultType() throws InterruptedException, ExecutionException { Assume.assumeTrue(test2i); - testSingleQuerySingleResponse(Namespace.DEFAULT_BUCKET_TYPE); + testSingleQuerySingleResponse(defaultTypeNamespace); } - + @Test public void testSingleQuerySingleResponseTestType() throws InterruptedException, ExecutionException { Assume.assumeTrue(test2i); Assume.assumeTrue(testBucketType); - testSingleQuerySingleResponse(bucketType.toString()); - } - - private void testSingleQuerySingleResponse(String bucketType) throws InterruptedException, ExecutionException - { - setBucketNameToTestName(); - String indexName = "test_index"; - String keyBase = "my_key"; - String value = "value"; - Namespace ns = new Namespace(bucketType, bucketName.toString()); - - setupIndexTestData(ns, indexName, keyBase, value); - + testSingleQuerySingleResponse(typedNamespace); + } + + @Test + public void testSingleQueryMultipleResponseDefaultType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + testSingleQueryMultipleResponse(defaultTypeNamespace); + } + + @Test + public void testSingleQueryMultipleResponseTestType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + Assume.assumeTrue(testBucketType); + testSingleQueryMultipleResponse(typedNamespace); + } + + @Test + public void testRangeQueryDefaultType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + testRangeQuery(defaultTypeNamespace); + } + + @Test + public void testRangeQueryTestType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + Assume.assumeTrue(testBucketType); + testRangeQuery(typedNamespace); + } + + @Test + public void testNoSortWithNoPagingDefaultType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + testNoSortWithNoPaging(defaultTypeNamespace); + } + + @Test + public void testNoSortWithNoPagingTestType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + Assume.assumeTrue(testBucketType); + testNoSortWithNoPaging(typedNamespace); + } + + @Test + public void testSortWithNoPagingDefaultType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + testSortWithNoPaging(defaultTypeNamespace); + } + + @Test + public void testSortWithNoPagingTestType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + Assume.assumeTrue(testBucketType); + testSortWithNoPaging(typedNamespace); + } + + @Test + public void testBucketIndexHack() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + SecondaryIndexQueryOperation.Query query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate((indexName + "_int").getBytes())) + new SecondaryIndexQueryOperation.Query.Builder(defaultTypeNamespace, BinaryValue.unsafeCreate("$bucket".getBytes())) + .withIndexKey(BinaryValue.create(bucketName)) + .withReturnKeyAndIndex(true) + .build(); + + SecondaryIndexQueryOperation queryOp = + new SecondaryIndexQueryOperation.Builder(query) + .build(); + + cluster.execute(queryOp); + SecondaryIndexQueryOperation.Response response = queryOp.get(); + + assertEquals(100, response.getEntryList().size()); + } + + @Test + public void testKeyIndexHack() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + + SecondaryIndexQueryOperation.Query query = + new SecondaryIndexQueryOperation.Query.Builder(defaultTypeNamespace, BinaryValue.unsafeCreate("$key".getBytes())) + .withRangeStart(BinaryValue.create("my_key10")) + .withRangeEnd(BinaryValue.create("my_key19")) + .withReturnKeyAndIndex(true) + .build(); + + SecondaryIndexQueryOperation queryOp = + new SecondaryIndexQueryOperation.Builder(query) + .build(); + + cluster.execute(queryOp); + SecondaryIndexQueryOperation.Response response = queryOp.get(); + + assertEquals(10, response.getEntryList().size()); + } + + @Test + public void testNoSortWithPagingDefaultType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + testNoSortWithPaging(defaultTypeNamespace); + } + + @Test + public void testNoSortWithPagingTestType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + Assume.assumeTrue(testBucketType); + testNoSortWithPaging(typedNamespace); + } + + @Test + public void testSortWithPagingDefaultType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + testSortWithPaging(defaultTypeNamespace); + } + + @Test + public void testSortWithPagingTestType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + Assume.assumeTrue(testBucketType); + testSortWithPaging(typedNamespace); + } + + @Test + public void testRegexTermFilterDefaultType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + testRegexTermFilter(defaultTypeNamespace); + } + + @Test + public void testRegexTermFilterTestType() throws InterruptedException, ExecutionException + { + Assume.assumeTrue(test2i); + Assume.assumeTrue(testBucketType); + testRegexTermFilter(typedNamespace); + } + + @Test + public void testExceptionThrownWhenUsingRegexFilterOnIntIndexesDefaultType() + { + Assume.assumeTrue(test2i); + testExceptionThrownWhenUsingRegexFilterOnIntIndexes(defaultTypeNamespace); + } + + @Test + public void testExceptionThrownWhenUsingRegexFilterOnIntIndexesTestType() + { + Assume.assumeTrue(test2i); + Assume.assumeTrue(testBucketType); + testExceptionThrownWhenUsingRegexFilterOnIntIndexes(typedNamespace); + } + + private void testSingleQuerySingleResponse(Namespace namespace) throws InterruptedException, ExecutionException + { + SecondaryIndexQueryOperation.Query query = + new SecondaryIndexQueryOperation.Query.Builder(namespace, incrementingIndexName) .withIndexKey(BinaryValue.unsafeCreate(String.valueOf(5L).getBytes())) .build(); - - SecondaryIndexQueryOperation queryOp = + + SecondaryIndexQueryOperation queryOp = new SecondaryIndexQueryOperation.Builder(query) .build(); - + cluster.execute(queryOp); SecondaryIndexQueryOperation.Response response = queryOp.get(); - + assertEquals(1, response.getEntryList().size()); assertFalse(response.getEntryList().get(0).hasIndexKey()); - assertEquals(response.getEntryList().get(0).getObjectKey().toString(), keyBase + "5"); - + assertEquals(keyBase + "5", response.getEntryList().get(0).getObjectKey().toString()); + query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate((indexName + "_int").getBytes())) + new SecondaryIndexQueryOperation.Query.Builder(namespace, incrementingIndexName) .withIndexKey(BinaryValue.unsafeCreate(String.valueOf(5L).getBytes())) .withReturnKeyAndIndex(true) .build(); - queryOp = + queryOp = new SecondaryIndexQueryOperation.Builder(query) .build(); - + cluster.execute(queryOp); response = queryOp.get(); - + assertEquals(1, response.getEntryList().size()); assertTrue(response.getEntryList().get(0).hasIndexKey()); - assertEquals(response.getEntryList().get(0).getIndexKey(), BinaryValue.unsafeCreate("5".getBytes())); - assertEquals(response.getEntryList().get(0).getObjectKey().toString(), keyBase + "5"); - } - - @Test - public void testSingleQueryMultipleResponseDefaultType() throws InterruptedException, ExecutionException - { - Assume.assumeTrue(test2i); - testSingleQueryMultipleResponse(Namespace.DEFAULT_BUCKET_TYPE); - } - - @Test - public void testSingleQueryMultipleResponseTestType() throws InterruptedException, ExecutionException - { - Assume.assumeTrue(test2i); - Assume.assumeTrue(testBucketType); - testSingleQueryMultipleResponse(bucketType.toString()); + assertEquals(BinaryValue.unsafeCreate("5".getBytes()), response.getEntryList().get(0).getIndexKey()); + assertEquals(keyBase + "5", response.getEntryList().get(0).getObjectKey().toString()); } - - private void testSingleQueryMultipleResponse(String bucketType) throws InterruptedException, ExecutionException - { - setBucketNameToTestName(); - String indexName = "test_index"; - String keyBase = "my_key"; - String value = "value"; - Namespace ns = new Namespace(bucketType, bucketName.toString()); - - for (long i = 0; i < 100; i++) - { - RiakObject obj = new RiakObject().setValue(BinaryValue.create(value)); - obj.getIndexes().getIndex(LongIntIndex.named(indexName)).add(5L); - Location location = new Location(ns, BinaryValue.unsafeCreate((keyBase + i).getBytes())); - StoreOperation storeOp = - new StoreOperation.Builder(location) - .withContent(obj) - .build(); - - cluster.execute(storeOp); - storeOp.get(); - } - + private void testSingleQueryMultipleResponse(Namespace namespace) throws InterruptedException, ExecutionException + { SecondaryIndexQueryOperation.Query query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate((indexName + "_int").getBytes())) + new SecondaryIndexQueryOperation.Query.Builder(namespace, allFivesIndexName) .withIndexKey(BinaryValue.unsafeCreate(String.valueOf(5L).getBytes())) .withPaginationSort(true) .build(); - - SecondaryIndexQueryOperation queryOp = + + SecondaryIndexQueryOperation queryOp = new SecondaryIndexQueryOperation.Builder(query) .build(); - + cluster.execute(queryOp); SecondaryIndexQueryOperation.Response response = queryOp.get(); - + assertEquals(100, response.getEntryList().size()); assertFalse(response.getEntryList().get(0).hasIndexKey()); - assertEquals(response.getEntryList().get(0).getObjectKey().toString(), keyBase + "0"); - + assertEquals(keyBase + "0", response.getEntryList().get(0).getObjectKey().toString()); + query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate((indexName + "_int").getBytes())) + new SecondaryIndexQueryOperation.Query.Builder(namespace, allFivesIndexName) .withIndexKey(BinaryValue.unsafeCreate(String.valueOf(5L).getBytes())) .withPaginationSort(true) .withReturnKeyAndIndex(true) .build(); - - queryOp = + + queryOp = new SecondaryIndexQueryOperation.Builder(query) .build(); - + cluster.execute(queryOp); response = queryOp.get(); - + assertEquals(100, response.getEntryList().size()); assertTrue(response.getEntryList().get(0).hasIndexKey()); - assertEquals(response.getEntryList().get(0).getIndexKey(), BinaryValue.unsafeCreate("5".getBytes())); - assertEquals(response.getEntryList().get(0).getObjectKey().toString(), keyBase + "0"); - - } - - @Test - public void testRangeQueryDefaultType() throws InterruptedException, ExecutionException - { - Assume.assumeTrue(test2i); - testRangeQuery(Namespace.DEFAULT_BUCKET_TYPE); - - } - - @Test - public void testRangeQueryTestType() throws InterruptedException, ExecutionException - { - Assume.assumeTrue(test2i); - Assume.assumeTrue(testBucketType); - testRangeQuery(bucketType.toString()); - + assertEquals(BinaryValue.unsafeCreate("5".getBytes()), response.getEntryList().get(0).getIndexKey()); + assertEquals(keyBase + "0", response.getEntryList().get(0).getObjectKey().toString()); + } - - private void testRangeQuery(String bucketType) throws InterruptedException, ExecutionException - { - setBucketNameToTestName(); - String indexName = "test_index"; - String keyBase = "my_key"; - String value = "value"; - Namespace ns = new Namespace(bucketType, bucketName.toString()); - - setupIndexTestData(ns, indexName, keyBase, value); - + private void testRangeQuery(Namespace namespace) throws InterruptedException, ExecutionException + { SecondaryIndexQueryOperation.Query query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate((indexName + "_int").getBytes())) + new SecondaryIndexQueryOperation.Query.Builder(namespace, incrementingIndexName) .withRangeStart(BinaryValue.unsafeCreate(String.valueOf(5L).getBytes())) .withRangeEnd(BinaryValue.unsafeCreate(String.valueOf(20L).getBytes())) .withPaginationSort(true) .build(); - - SecondaryIndexQueryOperation queryOp = + + SecondaryIndexQueryOperation queryOp = new SecondaryIndexQueryOperation.Builder(query) .build(); - + cluster.execute(queryOp); SecondaryIndexQueryOperation.Response response = queryOp.get(); - + assertEquals(16, response.getEntryList().size()); assertFalse(response.getEntryList().get(0).hasIndexKey()); - assertEquals(response.getEntryList().get(0).getObjectKey().toString(), keyBase + "5"); - + assertEquals(keyBase + "5", response.getEntryList().get(0).getObjectKey().toString()); + query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate((indexName + "_int").getBytes())) + new SecondaryIndexQueryOperation.Query.Builder(namespace, incrementingIndexName) .withRangeStart(BinaryValue.unsafeCreate(String.valueOf(5L).getBytes())) .withRangeEnd(BinaryValue.unsafeCreate(String.valueOf(20L).getBytes())) .withReturnKeyAndIndex(true) .withPaginationSort(true) .build(); - - queryOp = + + queryOp = new SecondaryIndexQueryOperation.Builder(query) .build(); - + cluster.execute(queryOp); response = queryOp.get(); + assertEquals(16, response.getEntryList().size()); assertTrue(response.getEntryList().get(0).hasIndexKey()); - assertEquals(response.getEntryList().get(0).getIndexKey(), BinaryValue.unsafeCreate("5".getBytes())); - assertEquals(response.getEntryList().get(0).getObjectKey().toString(), keyBase + "5"); + assertEquals(BinaryValue.unsafeCreate("5".getBytes()), response.getEntryList().get(0).getIndexKey()); + assertEquals(keyBase + "5", response.getEntryList().get(0).getObjectKey().toString()); } - @Test - public void testNoSortWithNoPagingDefaultType() throws InterruptedException, ExecutionException + private void testNoSortWithNoPaging(Namespace namespace) throws InterruptedException, ExecutionException { - Assume.assumeTrue(test2i); - testNoSortWithNoPaging(Namespace.DEFAULT_BUCKET_TYPE); - } - - @Test - public void testNoSortWithNoPagingTestType() throws InterruptedException, ExecutionException - { - Assume.assumeTrue(test2i); - Assume.assumeTrue(testBucketType); - testNoSortWithNoPaging(bucketType.toString()); - } - - private void testNoSortWithNoPaging(String bucketType) throws InterruptedException, ExecutionException - { - setBucketNameToTestName(); - String indexName = "test_index_pagination"; - String value = "value"; - Namespace ns = new Namespace(bucketType, bucketName.toString()); - - setupIndexTestData(ns, indexName, "", value); - SecondaryIndexQueryOperation.Query query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate((indexName + "_int").getBytes())) + new SecondaryIndexQueryOperation.Query.Builder(namespace, incrementingIndexName) .withRangeStart(BinaryValue.unsafeCreate(String.valueOf(0L).getBytes())) .withRangeEnd(BinaryValue.unsafeCreate(String.valueOf(100L).getBytes())) .withPaginationSort(false) .build(); - + SecondaryIndexQueryOperation queryOp = new SecondaryIndexQueryOperation.Builder(query) .build(); @@ -280,38 +386,15 @@ private void testNoSortWithNoPaging(String bucketType) throws InterruptedExcepti assertEquals(100, response.getEntryList().size()); } - @Test - public void testSortWithNoPagingDefaultType() throws InterruptedException, ExecutionException - { - Assume.assumeTrue(test2i); - testSortWithNoPaging(Namespace.DEFAULT_BUCKET_TYPE); - } - - @Test - public void testSortWithNoPagingTestType() throws InterruptedException, ExecutionException + private void testSortWithNoPaging(Namespace namespace) throws InterruptedException, ExecutionException { - Assume.assumeTrue(test2i); - Assume.assumeTrue(testBucketType); - testSortWithNoPaging(bucketType.toString()); - } - - private void testSortWithNoPaging(String bucketType) throws InterruptedException, ExecutionException - { - setBucketNameToTestName(); - String indexName = "test_index_pagination"; - String value = "value"; - Namespace ns = new Namespace(bucketType, bucketName.toString()); - - setupIndexTestData(ns, indexName, "", value); - - SecondaryIndexQueryOperation.Query query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate((indexName + "_int").getBytes())) + new SecondaryIndexQueryOperation.Query.Builder(namespace, incrementingIndexName) .withRangeStart(BinaryValue.unsafeCreate(String.valueOf(0L).getBytes())) .withRangeEnd(BinaryValue.unsafeCreate(String.valueOf(100L).getBytes())) .withPaginationSort(true) .build(); - + SecondaryIndexQueryOperation queryOp = new SecondaryIndexQueryOperation.Builder(query) .build(); @@ -324,83 +407,41 @@ private void testSortWithNoPaging(String bucketType) throws InterruptedException AssertLongObjectsInOrder(response); } - @Test - public void testNoSortWithPagingDefaultType() throws InterruptedException, ExecutionException - { - Assume.assumeTrue(test2i); - testNoSortWithPaging(Namespace.DEFAULT_BUCKET_TYPE); - } - - @Test - public void testNoSortWithPagingTestType() throws InterruptedException, ExecutionException - { - Assume.assumeTrue(test2i); - Assume.assumeTrue(testBucketType); - testNoSortWithPaging(bucketType.toString()); - } - - private void testNoSortWithPaging(String bucketType) throws InterruptedException, ExecutionException - { - setBucketNameToTestName(); - String indexName = "test_index_pagination"; - String value = "value"; - Namespace ns = new Namespace(bucketType, bucketName.toString()); - - setupIndexTestData(ns, indexName, "", value); - try + + private void testNoSortWithPaging(Namespace namespace) throws InterruptedException, ExecutionException + { + try { SecondaryIndexQueryOperation.Query query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate((indexName + "_int").getBytes())) + new SecondaryIndexQueryOperation.Query.Builder(namespace, incrementingIndexName) .withRangeStart(BinaryValue.unsafeCreate(String.valueOf(0L).getBytes())) .withRangeEnd(BinaryValue.unsafeCreate(String.valueOf(100L).getBytes())) .withPaginationSort(false) .withMaxResults(20) .build(); - - SecondaryIndexQueryOperation queryOp = - new SecondaryIndexQueryOperation.Builder(query) - .build(); + + new SecondaryIndexQueryOperation.Builder(query).build(); fail("Didn't throw IllegalArgumentException"); } - catch(IllegalArgumentException ex) { + catch(IllegalArgumentException ex) + { assertNotNull(ex); } } - @Test - public void testSortWithPagingDefaultType() throws InterruptedException, ExecutionException - { - Assume.assumeTrue(test2i); - testSortWithPaging(Namespace.DEFAULT_BUCKET_TYPE); - } - - @Test - public void testSortWithPagingTestType() throws InterruptedException, ExecutionException - { - Assume.assumeTrue(test2i); - Assume.assumeTrue(testBucketType); - testSortWithPaging(Namespace.DEFAULT_BUCKET_TYPE); - } - - private void testSortWithPaging(String bucketType) throws InterruptedException, ExecutionException - { - setBucketNameToTestName(); - String indexName = "test_index_pagination"; - String value = "value"; - Namespace ns = new Namespace(bucketType, bucketName.toString()); - setupIndexTestData(ns, indexName, "", value); - + private void testSortWithPaging(Namespace namespace) throws InterruptedException, ExecutionException + { SecondaryIndexQueryOperation.Query query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate((indexName + "_int").getBytes())) + new SecondaryIndexQueryOperation.Query.Builder(namespace, incrementingIndexName) .withRangeStart(BinaryValue.unsafeCreate(String.valueOf(0L).getBytes())) .withRangeEnd(BinaryValue.unsafeCreate(String.valueOf(100L).getBytes())) .withPaginationSort(true) .withMaxResults(20) .build(); - + SecondaryIndexQueryOperation queryOp = new SecondaryIndexQueryOperation.Builder(query) .build(); @@ -413,55 +454,17 @@ private void testSortWithPaging(String bucketType) throws InterruptedException, AssertLongObjectsInOrder(response); } - @Test - public void testRegexTermFilterDefaultType() throws InterruptedException, ExecutionException - { - Assume.assumeTrue(test2i); - testRegexTermFilter(Namespace.DEFAULT_BUCKET_TYPE); - } - - @Test - public void testRegexTermFilterTestType() throws InterruptedException, ExecutionException + private void testRegexTermFilter(Namespace namespace) throws InterruptedException, ExecutionException { - Assume.assumeTrue(test2i); - Assume.assumeTrue(testBucketType); - testRegexTermFilter(bucketType.toString()); - } - - private void testRegexTermFilter(String bucketType) throws InterruptedException, ExecutionException - { - setBucketNameToTestName(); - String indexName = "test_index_regex"; - String value = "value"; - Namespace ns = new Namespace(bucketType, bucketName.toString()); - - for (long i = 0; i < 20; i++) - { - RiakObject obj = new RiakObject().setValue(BinaryValue.create(value)); - - obj.getIndexes().getIndex(StringBinIndex.named(indexName)).add("foo" + String.format("%02d", i)); - - - Location location = new Location(ns, BinaryValue.unsafeCreate(Long.toString(i).getBytes())); - StoreOperation storeOp = - new StoreOperation.Builder(location) - .withContent(obj) - .build(); - - cluster.execute(storeOp); - storeOp.get(); - } - - SecondaryIndexQueryOperation.Query query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate((indexName + "_bin").getBytes())) + new SecondaryIndexQueryOperation.Query.Builder(namespace, regexIndexName) .withRangeStart(BinaryValue.unsafeCreate("foo00".getBytes())) .withRangeEnd(BinaryValue.unsafeCreate("foo19".getBytes())) .withRegexTermFilter(BinaryValue.unsafeCreate("2".getBytes())) .withReturnKeyAndIndex(true) .withPaginationSort(true) .build(); - + SecondaryIndexQueryOperation queryOp = new SecondaryIndexQueryOperation.Builder(query) .build(); @@ -470,117 +473,45 @@ private void testRegexTermFilter(String bucketType) throws InterruptedException, SecondaryIndexQueryOperation.Response response = queryOp.get(); assertEquals(2, response.getEntryList().size()); - assertEquals(response.getEntryList().get(0).getIndexKey(), BinaryValue.unsafeCreate("foo02".getBytes())); - assertEquals(response.getEntryList().get(0).getObjectKey().toString(), "2"); - assertEquals(response.getEntryList().get(1).getIndexKey(), BinaryValue.unsafeCreate("foo12".getBytes())); - assertEquals(response.getEntryList().get(1).getObjectKey().toString(), "12"); - } + assertEquals(BinaryValue.unsafeCreate("foo02".getBytes()), response.getEntryList().get(0).getIndexKey()); + assertEquals("my_key2", response.getEntryList().get(0).getObjectKey().toString()); - @Test - public void testExceptionThrownWhenUsingRegexFilterOnIntIndexesDefaultType() - { - Assume.assumeTrue(test2i); - testExceptionThrownWhenUsingRegexFilterOnIntIndexes(Namespace.DEFAULT_BUCKET_TYPE); + assertEquals(BinaryValue.unsafeCreate("foo12".getBytes()), response.getEntryList().get(1).getIndexKey()); + assertEquals("my_key12", response.getEntryList().get(1).getObjectKey().toString()); } - - @Test - public void testExceptionThrownWhenUsingRegexFilterOnIntIndexesTestType() - { - Assume.assumeTrue(test2i); - Assume.assumeTrue(testBucketType); - testExceptionThrownWhenUsingRegexFilterOnIntIndexes(bucketType.toString()); - } - - private void testExceptionThrownWhenUsingRegexFilterOnIntIndexes(String bucketType) + + private void testExceptionThrownWhenUsingRegexFilterOnIntIndexes(Namespace namespace) { - setBucketNameToTestName(); - try { - Namespace ns = new Namespace(bucketType, bucketName.toString()); - + try + { SecondaryIndexQueryOperation.Query query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate(("foo_int").getBytes())) + new SecondaryIndexQueryOperation.Query.Builder(namespace, incrementingIndexName) .withRangeStart(BinaryValue.unsafeCreate("0".getBytes())) .withRangeEnd(BinaryValue.unsafeCreate("100".getBytes())) .withRegexTermFilter(BinaryValue.unsafeCreate("2".getBytes())) .build(); - + new SecondaryIndexQueryOperation.Builder(query) .build(); fail("Didn't throw IllegalArgumentException"); } - catch(IllegalArgumentException ex) { + catch(IllegalArgumentException ex) + { assertNotNull(ex); } } - @Test - public void testBucketIndexHack() throws InterruptedException, ExecutionException - { - Assume.assumeTrue(test2i); - setBucketNameToTestName(); - String indexName = "test_index_bucket"; - String keyBase = "my_key"; - String value = "value"; - - Namespace ns = new Namespace(bucketName.toString()); - - setupIndexTestData(ns, indexName, keyBase, value); - - SecondaryIndexQueryOperation.Query query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate("$bucket".getBytes())) - .withIndexKey(bucketName) - .withReturnKeyAndIndex(true) - .build(); - - SecondaryIndexQueryOperation queryOp = - new SecondaryIndexQueryOperation.Builder(query) - .build(); - - cluster.execute(queryOp); - SecondaryIndexQueryOperation.Response response = queryOp.get(); - - Assert.assertTrue(response.getEntryList().size() == 100); - } - - @Test - public void testKeyIndexHack() throws InterruptedException, ExecutionException - { - Assume.assumeTrue(test2i); - setBucketNameToTestName(); - String indexName = "test_index_bucket"; - String keyBase = "my_key"; - String value = "value"; - - Namespace ns = new Namespace(bucketName.toString()); - - setupIndexTestData(ns, indexName, keyBase, value); - - SecondaryIndexQueryOperation.Query query = - new SecondaryIndexQueryOperation.Query.Builder(ns, BinaryValue.unsafeCreate("$key".getBytes())) - .withRangeStart(BinaryValue.create("my_key10")) - .withRangeEnd(BinaryValue.create("my_key19")) - .withReturnKeyAndIndex(true) - .build(); - - SecondaryIndexQueryOperation queryOp = - new SecondaryIndexQueryOperation.Builder(query) - .build(); - - cluster.execute(queryOp); - SecondaryIndexQueryOperation.Response response = queryOp.get(); - - Assert.assertTrue(response.getEntryList().size() == 10); - } - - private void setupIndexTestData(Namespace ns, String indexName, String keyBase, String value) + private static void setupIndexTestData(Namespace ns) throws InterruptedException, ExecutionException { for (long i = 0; i < 100; i++) { RiakObject obj = new RiakObject().setValue(BinaryValue.create(value)); - obj.getIndexes().getIndex(LongIntIndex.named(indexName)).add(i); + obj.getIndexes().getIndex(LongIntIndex.named(incrementingIndexNameString)).add(i); + obj.getIndexes().getIndex(LongIntIndex.named(allFivesIndexNameString)).add(5L); + obj.getIndexes().getIndex(StringBinIndex.named(regexIndexNameString)).add("foo" + String.format("%02d", i)); Location location = new Location(ns, keyBase + i); StoreOperation storeOp = @@ -593,13 +524,17 @@ private void setupIndexTestData(Namespace ns, String indexName, String keyBase, } } - private void AssertLongObjectsInOrder(SecondaryIndexQueryOperation.Response response) { - Long previousKey = Long.parseLong(response.getEntryList().get(0).getObjectKey().toString()); - for (int j = 1; j < response.getEntryList().size(); j++) { - Long currentKey = Long.parseLong(response.getEntryList().get(j).getObjectKey().toString()); + private void AssertLongObjectsInOrder(SecondaryIndexQueryOperation.Response response) + { + final String firstKey = response.getEntryList().get(0).getObjectKey().toString(); + Long previousKey = Long.parseLong(firstKey.substring(keyBase.length())); + + for (int j = 1; j < response.getEntryList().size(); j++) + { + String fullKey = response.getEntryList().get(j).getObjectKey().toString(); + Long currentKey = Long.parseLong(fullKey.substring(keyBase.length())); assertTrue(previousKey <= currentKey); previousKey = currentKey; } } } - From a8f0696a7ff599f1b7fdbca37cc76a13a828c41f Mon Sep 17 00:00:00 2001 From: Alex Moore Date: Thu, 3 Mar 2016 12:53:54 -0500 Subject: [PATCH 05/10] Bump tools submodule version --- tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools b/tools index 21622932a..68e892487 160000 --- a/tools +++ b/tools @@ -1 +1 @@ -Subproject commit 21622932aba15175ade9e346a06815689761111e +Subproject commit 68e892487918d63175295dba5ab77ed36c9fd85a From 5ef4b916d76fdbbb3b5422fa94f8d1c1571701b3 Mon Sep 17 00:00:00 2001 From: Alex Moore Date: Thu, 3 Mar 2016 13:04:00 -0500 Subject: [PATCH 06/10] Remove unnecessary imports --- .../core/operations/itest/ITestAutoCleanupBase.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/test/java/com/basho/riak/client/core/operations/itest/ITestAutoCleanupBase.java b/src/test/java/com/basho/riak/client/core/operations/itest/ITestAutoCleanupBase.java index 2f0314f5f..cebaaa785 100644 --- a/src/test/java/com/basho/riak/client/core/operations/itest/ITestAutoCleanupBase.java +++ b/src/test/java/com/basho/riak/client/core/operations/itest/ITestAutoCleanupBase.java @@ -15,21 +15,11 @@ */ package com.basho.riak.client.core.operations.itest; -import com.basho.riak.client.core.RiakFuture; -import com.basho.riak.client.core.RiakFutureListener; -import com.basho.riak.client.core.operations.DeleteOperation; -import com.basho.riak.client.core.operations.ListKeysOperation; -import com.basho.riak.client.core.operations.ResetBucketPropsOperation; -import com.basho.riak.client.core.operations.YzFetchIndexOperation; -import com.basho.riak.client.core.query.Location; import com.basho.riak.client.core.query.Namespace; import com.basho.riak.client.core.util.BinaryValue; import org.junit.After; -import java.util.List; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Semaphore; /** * From 24977f1ff332f91c83c676afdffcb2b0e92c6aa5 Mon Sep 17 00:00:00 2001 From: Alex Moore Date: Thu, 3 Mar 2016 13:52:01 -0500 Subject: [PATCH 07/10] Bumping tools version again. --- tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools b/tools index 68e892487..b7f86da7c 160000 --- a/tools +++ b/tools @@ -1 +1 @@ -Subproject commit 68e892487918d63175295dba5ab77ed36c9fd85a +Subproject commit b7f86da7cae523794716bb88a2d72e639897220d From f629f35ad85d7b2d8ef8d20c3a20e9e3f98f75b4 Mon Sep 17 00:00:00 2001 From: Alex Moore Date: Fri, 4 Mar 2016 10:50:55 -0500 Subject: [PATCH 08/10] Switch to master branch of tools --- tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools b/tools index b7f86da7c..922cf68d1 160000 --- a/tools +++ b/tools @@ -1 +1 @@ -Subproject commit b7f86da7cae523794716bb88a2d72e639897220d +Subproject commit 922cf68d129c367c2c56a14f2ae4c97a2df34d50 From 73360e62cfd7eba4b827a7279381c415c8c29e60 Mon Sep 17 00:00:00 2001 From: Alex Moore Date: Mon, 7 Mar 2016 10:52:36 -0500 Subject: [PATCH 09/10] Bump tools to latest version --- tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools b/tools index 922cf68d1..ba1d7bd87 160000 --- a/tools +++ b/tools @@ -1 +1 @@ -Subproject commit 922cf68d129c367c2c56a14f2ae4c97a2df34d50 +Subproject commit ba1d7bd879b856f3ee268567311c10b6e0076ba5 From 977f893c5ddb7ed8d0acc09c3d98195867816149 Mon Sep 17 00:00:00 2001 From: Alex Moore Date: Mon, 7 Mar 2016 11:03:37 -0500 Subject: [PATCH 10/10] Bump it up --- tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools b/tools index ba1d7bd87..82d238596 160000 --- a/tools +++ b/tools @@ -1 +1 @@ -Subproject commit ba1d7bd879b856f3ee268567311c10b6e0076ba5 +Subproject commit 82d238596d43e01d42f101220e0751eab0e7d645