From 2797f9a02649a57d287346a146add8425d052c17 Mon Sep 17 00:00:00 2001 From: nygard_89 <gugly89@gmail.com> Date: Tue, 12 Apr 2016 00:54:13 +0200 Subject: [PATCH] [riak] Removed test unit as it only works with a local cluster installation (there is no Riak test or mock utility). [riak] Packaged into com.yahoo.ycsb.db.riak. [riak] Removed unused dependencies. [riak] Bugfix for update() function that returned positive even with no nodes in the cluster. --- riak/pom.xml | 7 +- .../ycsb/db/{ => riak}/RiakKVClient.java | 13 +- .../yahoo/ycsb/db/{ => riak}/RiakUtils.java | 2 +- .../ycsb/db/{ => riak}/package-info.java | 6 +- .../com/yahoo/ycsb/db/RiakKVClientTest.java | 125 ------------------ 5 files changed, 13 insertions(+), 140 deletions(-) rename riak/src/main/java/com/yahoo/ycsb/db/{ => riak}/RiakKVClient.java (97%) rename riak/src/main/java/com/yahoo/ycsb/db/{ => riak}/RiakUtils.java (99%) rename riak/src/main/java/com/yahoo/ycsb/db/{ => riak}/package-info.java (93%) delete mode 100644 riak/src/test/java/com/yahoo/ycsb/db/RiakKVClientTest.java diff --git a/riak/pom.xml b/riak/pom.xml index b3feb39e..2d80d86d 100644 --- a/riak/pom.xml +++ b/riak/pom.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- Copyright (c) 2016 YCSB contributors. All rights reserved. +Copyright 2014 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 @@ -47,12 +48,6 @@ LICENSE file. <artifactId>google-collections</artifactId> <version>1.0</version> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.12</version> - <scope>test</scope> - </dependency> </dependencies> </project> \ No newline at end of file diff --git a/riak/src/main/java/com/yahoo/ycsb/db/RiakKVClient.java b/riak/src/main/java/com/yahoo/ycsb/db/riak/RiakKVClient.java similarity index 97% rename from riak/src/main/java/com/yahoo/ycsb/db/RiakKVClient.java rename to riak/src/main/java/com/yahoo/ycsb/db/riak/RiakKVClient.java index c2da947f..2a176ee8 100644 --- a/riak/src/main/java/com/yahoo/ycsb/db/RiakKVClient.java +++ b/riak/src/main/java/com/yahoo/ycsb/db/riak/RiakKVClient.java @@ -16,7 +16,7 @@ * LICENSE file. */ -package com.yahoo.ycsb.db; +package com.yahoo.ycsb.db.riak; import com.basho.riak.client.api.commands.kv.UpdateValue; import com.basho.riak.client.core.RiakFuture; @@ -43,9 +43,9 @@ import com.basho.riak.client.core.query.RiakObject; import com.basho.riak.client.core.query.indexes.LongIntIndex; import com.basho.riak.client.core.util.BinaryValue; -import static com.yahoo.ycsb.db.RiakUtils.deserializeTable; -import static com.yahoo.ycsb.db.RiakUtils.getKeyAsLong; -import static com.yahoo.ycsb.db.RiakUtils.serializeTable; +import static com.yahoo.ycsb.db.riak.RiakUtils.deserializeTable; +import static com.yahoo.ycsb.db.riak.RiakUtils.getKeyAsLong; +import static com.yahoo.ycsb.db.riak.RiakUtils.serializeTable; /** * Riak KV 2.0.x client for YCSB framework. @@ -479,7 +479,10 @@ public final class RiakKVClient extends DB { RiakFuture<UpdateValue.Response, Location> future = riakClient.executeAsync(update); try { - future.get(transactionTimeLimit, TimeUnit.SECONDS); + // For some reason, the update transaction doesn't throw any exception when no cluster has been started, so one + // needs to check whether it was done or not. When calling the wasUpdated() function with no nodes available, a + // NullPointerException is thrown. + future.get(transactionTimeLimit, TimeUnit.SECONDS).wasUpdated(); } catch (TimeoutException e) { if (debug) { System.err.println("Unable to update key " + key + ". Reason: TIME OUT"); diff --git a/riak/src/main/java/com/yahoo/ycsb/db/RiakUtils.java b/riak/src/main/java/com/yahoo/ycsb/db/riak/RiakUtils.java similarity index 99% rename from riak/src/main/java/com/yahoo/ycsb/db/RiakUtils.java rename to riak/src/main/java/com/yahoo/ycsb/db/riak/RiakUtils.java index 4c072028..2b271fd2 100644 --- a/riak/src/main/java/com/yahoo/ycsb/db/RiakUtils.java +++ b/riak/src/main/java/com/yahoo/ycsb/db/riak/RiakUtils.java @@ -16,7 +16,7 @@ * LICENSE file. */ -package com.yahoo.ycsb.db; +package com.yahoo.ycsb.db.riak; import java.io.*; import java.util.Map; diff --git a/riak/src/main/java/com/yahoo/ycsb/db/package-info.java b/riak/src/main/java/com/yahoo/ycsb/db/riak/package-info.java similarity index 93% rename from riak/src/main/java/com/yahoo/ycsb/db/package-info.java rename to riak/src/main/java/com/yahoo/ycsb/db/riak/package-info.java index 3f517a5d..dbaafb96 100644 --- a/riak/src/main/java/com/yahoo/ycsb/db/package-info.java +++ b/riak/src/main/java/com/yahoo/ycsb/db/riak/package-info.java @@ -17,7 +17,7 @@ */ /** - * The YCSB binding for <a href="http://basho.com/products/riak-kv/">Riak KV</a> - * 2.0.x. + * The YCSB binding for <a href="http://basho.com/products/riak-kv/">Riak KV</a> 2.0.x. + * */ -package com.yahoo.ycsb.db; \ No newline at end of file +package com.yahoo.ycsb.db.riak; \ No newline at end of file diff --git a/riak/src/test/java/com/yahoo/ycsb/db/RiakKVClientTest.java b/riak/src/test/java/com/yahoo/ycsb/db/RiakKVClientTest.java deleted file mode 100644 index 72092eff..00000000 --- a/riak/src/test/java/com/yahoo/ycsb/db/RiakKVClientTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * Copyright (c) 2016 YCSB contributors All rights reserved. - * Copyright 2014 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. See accompanying - * LICENSE file. - */ - -package com.yahoo.ycsb.db; - -import java.util.*; - -import com.yahoo.ycsb.ByteIterator; -import com.yahoo.ycsb.Status; -import com.yahoo.ycsb.StringByteIterator; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Integration tests for the Riak KV client. All tests are configured to return positive. - */ -public class RiakKVClientTest { - private static RiakKVClient riakClient; - private static String bucket = "testBucket"; - private static String startKey = "testKey"; - private static int recordsToInitiallyInsert = 10; - - /** - * Creates a cluster for testing purposes. - */ - @BeforeClass - public static void setUpClass() throws Exception { - riakClient = new RiakKVClient(); - riakClient.init(); - - HashMap<String, String> values = new HashMap<>(); - - // Just add some random values to work on... - for (int i = 0; i < recordsToInitiallyInsert; i++) { - values.put("testRecord_1", "testValue_1"); - values.put("testRecord_2", "testValue_2"); - - riakClient.insert(bucket, startKey + String.valueOf(i), StringByteIterator.getByteIteratorMap(values)); - } - } - - /** - * Shuts down the cluster created. - */ - @AfterClass - public static void tearDownClass() throws Exception { - riakClient.cleanup(); - } - - /** - * Test method for read transaction. - */ - @Test - public void testRead() { - Set<String> fields = new HashSet<>(); - fields.add("testRecord_1"); - fields.add("testRecord_2"); - - HashMap<String, ByteIterator> results = new HashMap<>(); - - assertEquals(Status.OK, riakClient.read(bucket, startKey + "1", fields, results)); - } - - /** - * Test method for scan transaction. - */ - @Test - public void testScan() { - Vector<HashMap<String, ByteIterator>> results = new Vector<>(); - - assertEquals(Status.OK, riakClient.scan(bucket, startKey + "1", recordsToInitiallyInsert - 1, null, results)); - } - - /** - * Test method for update transaction. - */ - @Test - public void testUpdate() { - HashMap<String, String> values = new HashMap<>(); - values.put("testRecord_1", "testValue_1_updated"); - values.put("testRecord_2", "testValue_2_updated"); - - assertEquals(Status.OK, riakClient.update(bucket, startKey + "0", StringByteIterator.getByteIteratorMap(values))); - } - - /** - * Test method for insert transaction. - */ - @Test - public void testInsert() { - HashMap<String, String> values = new HashMap<>(); - values.put("testRecord_1", "testValue_1"); - values.put("testRecord_2", "testValue_2"); - - assertEquals(Status.OK, riakClient.insert(bucket, startKey + Integer.toString(recordsToInitiallyInsert), - StringByteIterator.getByteIteratorMap(values))); - } - - /** - * Test method for delete transaction. - */ - @Test - public void testDelete() { - assertEquals(Status.OK, riakClient.delete(bucket, startKey + "0")); - } -} -- GitLab