Repository: basho/riak-nodejs-client
Pull request #61 (2015-05-20 19:49:03)

Add NVal to StoreIndex command
Fixes issue #60 (CLIENTS-410).


Patch:
diff --git a/lib/commands/yokozuna/storeindex.js b/lib/commands/yokozuna/storeindex.js
index 19b56d1..d16a54e 100644
--- a/lib/commands/yokozuna/storeindex.js
+++ b/lib/commands/yokozuna/storeindex.js
@@ -44,6 +44,7 @@ var RpbYokozunaIndex = require('../../protobuf/riakprotobuf').getProtoFor('RpbYo
  * @param {String} options.indexName The name of the index.
  * @param {String} [options.schemaName=_yz_default] The name of the schema for this index.
  * @param {Number} [options.timeout] Set a timeout for this operation.
+ * @param {Number} [options.nVal] The number of replicas.
  * @param {Function} callback The callback to be executed when the operation completes.
  * @param {String} callback.err An error message. Will be null if no error.
  * @param {Boolean} callback.response The operation either succeeds or errors. This will be true.
@@ -71,6 +72,7 @@ StoreIndex.prototype.constructPbRequest = function() {
     var pbIndex = new RpbYokozunaIndex();
 
     pbIndex.setName(new Buffer(this.options.indexName));
+    pbIndex.setNVal(this.options.nVal > 0 ? this.options.nVal : null );
 
     if (this.options.schemaName) {
         pbIndex.setSchema(new Buffer(this.options.schemaName));
@@ -95,7 +97,8 @@ StoreIndex.prototype.onSuccess = function(RpbPutResp) {
 var schema = Joi.object().keys({
     indexName: Joi.string().required(),
     schemaName: Joi.string().default(null).optional(),
-    timeout: Joi.number().default(null).optional()
+    timeout: Joi.number().default(null).optional(),
+    nVal: Joi.number().optional()
 });
 
 /**
@@ -148,6 +151,16 @@ Builder.prototype = {
         this.timeout = timeout;
         return this;
     },
+    /**
+    * Set the nVal.
+    * @method withNVal
+    * @param {Number} nVal the number of replicas.
+    * @chainable
+    */
+    withNVal : function(nVal) {
+        this.nVal = nVal;
+        return this;
+    },
     /**
      * Set the callback to be executed when the operation completes.
      * @method withCallback
diff --git a/tools b/tools
index 3e32f7c..f8703aa 160000
--- a/tools
+++ b/tools
@@ -1,1 +1,1 @@
-Subproject commit 3e32f7c445a7e7a527607f707f43130790584d27
+Subproject commit f8703aa25fb6ba1eaec603148823d82474d009e0


Test patch:
diff --git a/test/integration/yokozuna/search.js b/test/integration/yokozuna/search.js
index 7937fdd..d7d264a 100644
--- a/test/integration/yokozuna/search.js
+++ b/test/integration/yokozuna/search.js
@@ -165,13 +165,13 @@ describe('Search - Integration', function() {
        
         var count = 0;
         var callback = function(err, resp) {
-            assert(!err, err);
-            count++;
-            if (resp.numFound === 0) {
-                if (count < 6) {
+            if (err || resp.numFound === 0) {
+                count++;
+                if (count < 10) {
                     setTimeout(searchme, 2000 * count);
                 } else {
-                    assert.fail('Search failed; ' + resp);
+                    assert(!err, err);
+                    assert.fail('Search failed: ' + resp);
                 }
             } else {
                done();
diff --git a/test/unit/yokozuna/storeindex.js b/test/unit/yokozuna/storeindex.js
index 1fa8d1c..bbe0feb 100644
--- a/test/unit/yokozuna/storeindex.js
+++ b/test/unit/yokozuna/storeindex.js
@@ -27,6 +27,7 @@ describe('StoreIndex', function() {
             var store = new StoreIndex.Builder()
                     .withIndexName('indexName')
                     .withSchemaName('schemaName')
+                    .withNVal(5)
                     .withTimeout(60000)
                     .withCallback(function(){})
                     .build();
@@ -37,6 +38,7 @@ describe('StoreIndex', function() {
             var index = protobuf.index;
             assert.equal(index.getName().toString('utf8'), 'indexName');
             assert.equal(index.getSchema().toString('utf8'), 'schemaName');
+            assert.equal(index.getNVal(), 5);
             done();
         });