From c353f7120a1481503ad9bac90614600d4e9109e7 Mon Sep 17 00:00:00 2001
From: nygard_89 <gugly89@gmail.com>
Date: Thu, 14 Apr 2016 17:12:59 +0200
Subject: [PATCH] [travis] Reverted to original version, just added riak as
 service. [riak] Configured RiakKVClientTest.java to work with default
 bucket-type instead of creating a new one.

---
 .travis.yml                                   | 14 ++++-------
 .../com/yahoo/ycsb/db/riak/RiakKVClient.java  | 19 +++++++++++++++
 .../yahoo/ycsb/db/riak/RiakKVClientTest.java  | 24 +++++++++----------
 3 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index ceeab13c..84a79314 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -21,21 +21,17 @@ language: java
 
 jdk:
   - oraclejdk7
-  - openjdk7  
-  
+  - openjdk7
+
 install: mvn install -q -DskipTests=true
 
 script: mvn test -q
 
-# Bucket-type to activate before running Riak KV tests.
-before_script:
-  - sudo riak-admin bucket-type create ycsb '{"props":{"allow_mult":"false"}}'
-  - sudo riak-admin bucket-type activate ycsb
-
 # Services to start for tests.
 services:
   - mongodb
   - riak
 
-# Sudo required for Riak KV test.
-sudo: required
+
+# Use the Container based infrastructure.
+sudo: false
\ No newline at end of file
diff --git a/riak/src/main/java/com/yahoo/ycsb/db/riak/RiakKVClient.java b/riak/src/main/java/com/yahoo/ycsb/db/riak/RiakKVClient.java
index 816d8dda..99a52dfa 100644
--- a/riak/src/main/java/com/yahoo/ycsb/db/riak/RiakKVClient.java
+++ b/riak/src/main/java/com/yahoo/ycsb/db/riak/RiakKVClient.java
@@ -18,6 +18,7 @@
 
 package com.yahoo.ycsb.db.riak;
 
+import com.basho.riak.client.api.commands.buckets.StoreBucketProperties;
 import com.basho.riak.client.api.commands.kv.UpdateValue;
 import com.basho.riak.client.core.RiakFuture;
 import com.yahoo.ycsb.*;
@@ -548,4 +549,22 @@ public final class RiakKVClient extends DB {
       throw new DBException(e);
     }
   }
+
+  /**
+   * Auxiliary function needed for testing. It configures the default bucket-type to take care of the consistency
+   * problem by disallowing the siblings creation. Moreover, it disables strong consistency, as the scan transaction
+   * test would otherwise fail.
+   *
+   * @param bucket     The bucket name.
+   * @throws Exception Thrown if something bad happens.
+     */
+  void setTestEnvironment(String bucket) throws Exception {
+    bucketType = "default";
+    strongConsistency = false;
+
+    Namespace ns = new Namespace(bucketType, bucket);
+    StoreBucketProperties newBucketProperties = new StoreBucketProperties.Builder(ns).withAllowMulti(false).build();
+
+    riakClient.execute(newBucketProperties);
+  }
 }
diff --git a/riak/src/test/java/com/yahoo/ycsb/db/riak/RiakKVClientTest.java b/riak/src/test/java/com/yahoo/ycsb/db/riak/RiakKVClientTest.java
index e8fe23d2..bc1e310e 100644
--- a/riak/src/test/java/com/yahoo/ycsb/db/riak/RiakKVClientTest.java
+++ b/riak/src/test/java/com/yahoo/ycsb/db/riak/RiakKVClientTest.java
@@ -29,8 +29,8 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeNoException;
 import static org.junit.Assume.assumeThat;
 
 /**
@@ -57,10 +57,17 @@ public class RiakKVClientTest {
     riakClient = new RiakKVClient();
     riakClient.init();
 
+    // Set the test bucket environment with the appropriate parameters.
+    try {
+      riakClient.setTestEnvironment(bucket);
+    } catch(Exception e) {
+      assumeNoException("Unable to configure Riak KV for test, aborting.", e);
+    }
+
     // Just add some records to work on...
     for (int i = 0; i < recordsToInsert; i++) {
       // Abort the entire test whenever the dataset population operation fails.
-      assumeThat("Riak KV is NOT RUNNING, aborting test!",
+      assumeThat("Riak KV is NOT RUNNING, aborting test.",
           riakClient.insert(bucket, keyPrefix + String.valueOf(i), StringByteIterator.getByteIteratorMap(
               createExpectedHashMap(i))),
               is(Status.OK));
@@ -129,18 +136,11 @@ public class RiakKVClientTest {
     // Prepare a HashMap vector to store the scan transaction results.
     Vector<HashMap<String, ByteIterator>> scannedValues = new Vector<>();
 
-    // If strong consistency is to be used, then it is not possible to perform a scan transaction  (check
-    // RiakKVClient.java for further info).
-    Status status = riakClient.scan(bucket, keyPrefix + Integer.toString(startScanKeyNumber), recordsToScan, null,
-        scannedValues);
-
-    assumeThat("Scan transaction NOT SUPPORTED when using strong consistency. Test skipped.",
-        status,
-        not(Status.NOT_IMPLEMENTED));
-
+    // Check whether the scan transaction is correctly performed or not.
     assertEquals("Scan transaction FAILED.",
         Status.OK,
-        status);
+        riakClient.scan(bucket, keyPrefix + Integer.toString(startScanKeyNumber), recordsToScan, null,
+            scannedValues));
 
     // After the scan transaction completes, compare the obtained results with the expected ones.
     for (int i = 0; i < recordsToScan; i++) {
-- 
GitLab