Permalink
Browse files

NCBC-192: Handle NRE when executing ops against down node

Change-Id: I2978a6507ead6b867b98f213405ebf486d252fd0
Reviewed-on: http://review.couchbase.org/23671
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: John C. Zablocki <john@couchbase.com>
  • Loading branch information...
johnzablocki authored and John C. Zablocki committed Jan 3, 2013
1 parent 32b2bab commit 81ee6531cf022d41cd57d7a2b6cb1bd55ce17894
@@ -4,6 +4,8 @@
using System.Text;
using NUnit.Framework;
using Enyim.Caching.Memcached.Results.StatusCodes;
+using Couchbase.Configuration;
+using Couchbase.Constants;
namespace Couchbase.Tests
{
@@ -175,6 +177,20 @@ public void When_Generic_Getting_Existing_Item_With_Expiration_Value_Is_Not_Null
Assert.That(getResult.Value, Is.EqualTo(value), "Actual value was not expected value: " + getResult.Value);
Assert.That(getResult.Value, Is.InstanceOf<string>(), "Value was not a string");
}
+
+ [Test]
+ public void When_Getting_A_Key_From_A_Down_Node_No_Exception_Is_Thrown_And_Success_Is_False()
+ {
+ var config = new CouchbaseClientConfiguration();
+ config.Urls.Add(new Uri("http://doesnotexist:8091/pools/"));
+ config.Bucket = "default";
+
+ var client = new CouchbaseClient(config);
+ var getResult = client.ExecuteGet("foo");
+
+ Assert.That(getResult.Success, Is.False);
+ Assert.That(getResult.Message, Is.StringContaining(ClientErrors.FAILURE_NODE_NOT_FOUND));
+ }
}
}
@@ -3,6 +3,9 @@
using System.Linq;
using System.Text;
using NUnit.Framework;
+using Couchbase.Configuration;
+using Enyim.Caching.Memcached;
+using Couchbase.Constants;
namespace Couchbase.Tests
{
@@ -44,6 +47,20 @@ public void When_Removing_An_Invalid_Key_Result_Is_Not_Successful()
var removeResult = _Client.ExecuteRemove(key);
Assert.That(removeResult.Success, Is.False, "Success was true");
}
+
+ [Test]
+ public void When_Removing_A_Key_From_A_Down_Node_No_Exception_Is_Thrown_And_Success_Is_False()
+ {
+ var config = new CouchbaseClientConfiguration();
+ config.Urls.Add(new Uri("http://doesnotexist:8091/pools/"));
+ config.Bucket = "default";
+
+ var client = new CouchbaseClient(config);
+ var removeResult = client.ExecuteRemove("foo");
+
+ Assert.That(removeResult.Success, Is.False);
+ Assert.That(removeResult.Message, Is.StringContaining(ClientErrors.FAILURE_NODE_NOT_FOUND));
+ }
}
}
@@ -5,6 +5,8 @@
using NUnit.Framework;
using Enyim.Caching.Memcached;
using Enyim.Caching.Memcached.Results;
+using Couchbase.Configuration;
+using Couchbase.Constants;
namespace Couchbase.Tests
{
@@ -101,6 +103,20 @@ public void When_Storing_Item_With_Existing_Key_And_StoreMode_Set_Result_Is_Succ
result = Store(StoreMode.Set, key);
StoreAssertPass(result);
}
+
+ [Test]
+ public void When_Storing_A_Key_From_A_Down_Node_No_Exception_Is_Thrown_And_Success_Is_False()
+ {
+ var config = new CouchbaseClientConfiguration();
+ config.Urls.Add(new Uri("http://doesnotexist:8091/pools/"));
+ config.Bucket = "default";
+
+ var client = new CouchbaseClient(config);
+ var storeResult = client.ExecuteStore(StoreMode.Set, "foo", "bar");
+
+ Assert.That(storeResult.Success, Is.False);
+ Assert.That(storeResult.Message, Is.StringContaining(ClientErrors.FAILURE_NODE_NOT_FOUND));
+ }
}
}
@@ -14,7 +14,8 @@
using Couchbase.Results;
using Enyim.Caching.Memcached.Protocol.Binary;
using System.Threading.Tasks;
-using Couchbase.Settings;
+using Couchbase.Settings;
+using Couchbase.Constants;
namespace Couchbase
{
@@ -132,9 +133,9 @@ protected override IGetOperationResult PerformTryGet(string key, out ulong cas,
value = null;
cas = 0;
- if (this.PerformanceMonitor != null) this.PerformanceMonitor.Get(1, false);
-
- result.Fail("Unable to locate node");
+ if (this.PerformanceMonitor != null) this.PerformanceMonitor.Get(1, false);
+
+ result.Fail(ClientErrors.FAILURE_NODE_NOT_FOUND);
return result;
}
@@ -170,7 +171,7 @@ protected override IMutateOperationResult PerformMutate(MutationMode mode, strin
if (this.PerformanceMonitor != null) this.PerformanceMonitor.Mutate(mode, 1, false);
result.Value = defaultValue;
- result.Fail("Failed to locate node");
+ result.Fail(ClientErrors.FAILURE_NODE_NOT_FOUND);
return result;
}
@@ -201,9 +202,9 @@ protected override IConcatOperationResult PerformConcatenate(ConcatenationMode m
return result;
}
- if (this.PerformanceMonitor != null) this.PerformanceMonitor.Concatenate(mode, 1, false);
-
- result.Fail("Failed to locate node");
+ if (this.PerformanceMonitor != null) this.PerformanceMonitor.Concatenate(mode, 1, false);
+
+ result.Fail(ClientErrors.FAILURE_NODE_NOT_FOUND);
return result;
}
@@ -247,9 +248,9 @@ protected override IStoreOperationResult PerformStore(StoreMode mode, string key
return result;
}
- if (this.PerformanceMonitor != null) this.PerformanceMonitor.Store(mode, 1, false);
-
- result.Fail("Failed to locate node");
+ if (this.PerformanceMonitor != null) this.PerformanceMonitor.Store(mode, 1, false);
+
+ result.Fail(ClientErrors.FAILURE_NODE_NOT_FOUND);
return result;
}
@@ -450,9 +451,9 @@ protected IGetOperationResult PerformTryGetAndTouch(string key, uint nextExpirat
value = null;
cas = 0;
- if (this.PerformanceMonitor != null) this.PerformanceMonitor.Get(1, false);
-
- result.Fail("Unable to locate node");
+ if (this.PerformanceMonitor != null) this.PerformanceMonitor.Get(1, false);
+
+ result.Fail(ClientErrors.FAILURE_NODE_NOT_FOUND);
return result;
}
@@ -469,6 +469,11 @@ private void ReinitializeLocator(InternalState previousState)
IMemcachedNode IServerPool.Locate(string key)
{
+ if (this.state == null) {
+ if (log.IsDebugEnabled) log.Debug("this.state was null, returning null node for key '" + key + "'");
+ return null;
+ }
+
return this.state.Locator.Locate(key);
}

0 comments on commit 81ee653

Please sign in to comment.