Repository: basho/riak-nodejs-client
Pull request #85 (2015-07-07 22:32:05)

Fix a bug when constructing a RiakObject out of a tombstone.


Patch:
diff --git a/lib/commands/commandbase.js b/lib/commands/commandbase.js
index 5b038f4..09bcd62 100644
--- a/lib/commands/commandbase.js
+++ b/lib/commands/commandbase.js
@@ -99,7 +99,7 @@ CommandBase.prototype.getRiakMessage = function() {
     var pbRequest = this.constructPbRequest();
 
     if (pbRequest) {
-        encoded = this.constructPbRequest().encode().toBuffer();
+        encoded = pbRequest.encode().toBuffer();
         this.header.writeInt32BE(encoded.length + 1, 0);
     } else {
         this.header.writeInt32BE(1, 0);
diff --git a/lib/commands/kv/fetchvalue.js b/lib/commands/kv/fetchvalue.js
index 865e4ee..ad3b487 100644
--- a/lib/commands/kv/fetchvalue.js
+++ b/lib/commands/kv/fetchvalue.js
@@ -126,9 +126,9 @@ FetchValue.prototype._parseResponse = function(rpbGetResp) {
             riakObject = new RiakObject();
 
             riakObject.isTombstone = true;
-            riakObject.key = this.key;
-            riakObject.bucket = this.bucket;
-            riakObject.bucketType = this.bucketType;
+            riakObject.bucketType = this.options.bucketType;
+            riakObject.bucket = this.options.bucket;
+            riakObject.key = this.options.key;
 
             response = { isNotFound : false, isUnchanged : unchanged, vclock: vclock, values : [riakObject] };
 
@@ -140,8 +140,8 @@ FetchValue.prototype._parseResponse = function(rpbGetResp) {
 
                 riakObject = RiakObject.createFromRpbContent(pbContentArray[i], this.options.convertToJs);
                 riakObject.vclock = vclock;
-                riakObject.bucket = this.options.bucket;
                 riakObject.bucketType = this.options.bucketType;
+                riakObject.bucket = this.options.bucket;
                 riakObject.key = this.options.key;
 
                 values[i] = riakObject;
diff --git a/lib/commands/kv/riakobject.js b/lib/commands/kv/riakobject.js
index 0fc7be0..443d006 100644
--- a/lib/commands/kv/riakobject.js
+++ b/lib/commands/kv/riakobject.js
@@ -327,10 +327,10 @@ RiakObject.prototype = {
     },
     /**
      * Returns whether or not this RiakObject is marked as being deleted (a tombstone)
-     * @method isTombstone
+     * @method getIsTombstone
      * @return {Boolean} true if this is a tombstone.
      */
-    isTombstone : function() {
+    getIsTombstone : function() {
         return this.isTombstone;
     },
     /**
@@ -511,6 +511,5 @@ module.exports.populateRpbContentFromRiakObject = function(ro) {
         }
     }
     return rpbContent;
-        
 };
 
diff --git a/lib/core/riakcluster.js b/lib/core/riakcluster.js
index 896f8ef..2425a09 100644
--- a/lib/core/riakcluster.js
+++ b/lib/core/riakcluster.js
@@ -149,6 +149,7 @@ RiakCluster.prototype._shutdown = function () {
     for (var i = 0; i < this.nodes.length; i++) {
         if (this.nodes[i].state !== RiakNode.State.SHUTDOWN) {
             allStopped = false;
+            break;
         }
     }
 


Test patch:
diff --git a/test/unit/kv/deletevalue.js b/test/unit/kv/deletevalue.js
index eec2c8d..b84ac71 100644
--- a/test/unit/kv/deletevalue.js
+++ b/test/unit/kv/deletevalue.js
@@ -23,7 +23,7 @@ var assert = require('assert');
 
 describe('DeleteValue', function() {
     describe('Build', function() {
-        it('should build a RpbGetReq correctly', function(done) {
+        it('should build a RpbDelReq correctly', function(done) {
    
             var deleteValue = new DeleteValue.Builder()
                .withBucketType('bucket_type')
diff --git a/test/unit/kv/fetchvalue.js b/test/unit/kv/fetchvalue.js
index 2150606..65a5ea0 100644
--- a/test/unit/kv/fetchvalue.js
+++ b/test/unit/kv/fetchvalue.js
@@ -92,7 +92,7 @@ describe('FetchValue', function() {
 
         it('should take a RpbGetResp and call the users callback with the response', function(done) {
 
-            var rpbContent = generateTestRpbContent('this is a value', "application/json" );
+            var rpbContent = generateTestRpbContent('this is a value', "application/json");
 
             var rpbGetResp = new RpbGetResp();
             rpbGetResp.setContent(rpbContent);
@@ -123,14 +123,42 @@ describe('FetchValue', function() {
             };
 
             var fetchCommand = new FetchValue.Builder()
-               .withBucketType('bucket_type')
-               .withBucket('bucket_name')
-               .withKey('key')
-               .withCallback(callback)
-               .build();
+                .withBucketType('bucket_type')
+                .withBucket('bucket_name')
+                .withKey('key')
+                .withCallback(callback)
+                .build();
 
             fetchCommand.onSuccess(rpbGetResp);
-       });
+        });
+
+        it('should take a RpbGetResp and create a tombstone RiakObject correctly', function(done) {
+
+            var rpbGetResp = new RpbGetResp();
+            rpbGetResp.setUnchanged(true);
+            rpbGetResp.setVclock(new Buffer('1234'));
+
+            var callback = function(err, response) {
+                assert(!err, err);
+                assert(response, 'expected a response!');
+                assert.equal(response.values.length, 1);
+                var riakObject = response.values[0];
+                assert(riakObject.getIsTombstone());
+                assert.equal(riakObject.getBucketType(), 'bucket_type');
+                assert.equal(riakObject.getBucket(), 'bucket_name');
+                assert.equal(riakObject.getKey(), 'key');
+                done();
+            };
+
+            var fetchCommand = new FetchValue.Builder()
+                .withBucketType('bucket_type')
+                .withBucket('bucket_name')
+                .withKey('key')
+                .withCallback(callback)
+                .build();
+
+            fetchCommand.onSuccess(rpbGetResp);
+        });
 
         describe('when convertToJs provided as true', function(){