Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #106 from jzablocki/master

Operation results were swallowing cache misses and other status codes
  • Loading branch information...
commit 08283d67c0c9485c86137d7efe3a8ee4fb68744a 2 parents 94c5f30 + 278d842
@enyim enyim authored
View
2  Enyim.Caching.Tests/MemcachedClientGetTests.cs
@@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using NUnit.Framework;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching.Tests
{
@@ -28,6 +29,7 @@ public void When_Getting_Item_For_Invalid_Key_HasValue_Is_False_And_Result_Is_No
var key = GetUniqueKey("get");
var getResult = _Client.ExecuteGet(key);
+ Assert.That(getResult.StatusCode, Is.EqualTo((int)StatusCodeEnums.NotFound), "Invalid status code");
GetAssertFail(getResult);
}
View
2  Enyim.Caching.Tests/MemcachedClientStoreTests.cs
@@ -5,6 +5,7 @@
using NUnit.Framework;
using Enyim.Caching.Memcached;
using Enyim.Caching.Memcached.Results;
+using Enyim.Caching.Memcached.Results.StatusCodes;
namespace Enyim.Caching.Tests
{
@@ -36,6 +37,7 @@ public void When_Storing_Item_With_Existing_Key_And_StoreMode_Add_Result_Is_Not_
public void When_Storing_Item_With_New_Key_And_StoreMode_Replace_Result_Is_Not_Successful()
{
var result = Store(StoreMode.Replace);
+ Assert.That(result.StatusCode, Is.EqualTo((int)StatusCodeEnums.NotFound), "Invalid status code");
StoreAssertFail(result);
}
View
2  Enyim.Caching/Enyim.Caching.csproj
@@ -273,6 +273,8 @@
<Compile Include="Memcached\Results\IStoreOperationResult.cs" />
<Compile Include="Memcached\Results\MutateOperationResult.cs" />
<Compile Include="Memcached\Results\OperationResultBase.cs" />
+ <Compile Include="Memcached\Results\StatusCodes\StatusCodeEnums.cs" />
+ <Compile Include="Memcached\Results\StatusCodes\StatusCodeMessages.cs" />
<Compile Include="Memcached\Results\StoreOperationResult.cs" />
<Compile Include="Memcached\Results\TextOperationResult.cs" />
<Compile Include="Memcached\ServerStats.cs">
View
3  Enyim.Caching/Memcached/MemcachedNode.cs
@@ -529,8 +529,7 @@ protected virtual IPooledSocketResult ExecuteOperation(IOperation op)
}
else
{
- result.InnerResult = readResult;
- result.Fail("Failed to read response, see inner result for details");
+ readResult.Combine(result);
}
return result;
}
View
2  Enyim.Caching/Memcached/Protocol/Binary/BinarySingleItemOperation.cs
@@ -37,7 +37,7 @@ protected internal override IOperationResult ReadResponse(PooledSocket socket)
if (! (responseResult = this.ProcessResponse(response)).Success)
{
result.InnerResult = responseResult;
- result.Fail("Failed to process response, see StatusCode or InnerResult for details");
+ responseResult.Combine(result);
}
return result;
View
2  Enyim.Caching/Memcached/Protocol/Binary/DeleteOperation.cs
@@ -38,7 +38,7 @@ protected override IOperationResult ProcessResponse(BinaryResponse response)
}
else
{
- var message = ResultHelper.ProcessResponseData("Delete failed for key " + Key, response.Data);
+ var message = ResultHelper.ProcessResponseData(response.Data);
return result.Fail(message);
}
}
View
2  Enyim.Caching/Memcached/Protocol/Binary/GetOperation.cs
@@ -52,7 +52,7 @@ protected override IOperationResult ProcessResponse(BinaryResponse response)
log.DebugFormat("Get failed for key '{0}'. Reason: {1}", this.Key, Encoding.ASCII.GetString(response.Data.Array, response.Data.Offset, response.Data.Count));
#endif
- var message = ResultHelper.ProcessResponseData("Get failed for key " + Key, response.Data);
+ var message = ResultHelper.ProcessResponseData(response.Data);
return result.Fail(message);
}
View
2  Enyim.Caching/Memcached/Protocol/Binary/MutatorOperation.cs
@@ -69,7 +69,7 @@ protected override IOperationResult ProcessResponse(BinaryResponse response)
return result.Pass();
}
- var message = ResultHelper.ProcessResponseData("Mutate failed for key " + Key, response.Data);
+ var message = ResultHelper.ProcessResponseData(response.Data);
return result.Fail(message);
}
View
2  Enyim.Caching/Memcached/Protocol/Binary/StoreOperation.cs
@@ -69,7 +69,7 @@ protected override IOperationResult ProcessResponse(BinaryResponse response)
}
else
{
- var message = ResultHelper.ProcessResponseData("Store failed for key " + Key, response.Data);
+ var message = ResultHelper.ProcessResponseData(response.Data);
return result.Fail(message);
}
}
View
13 Enyim.Caching/Memcached/Results/Extensions/OperationResultExtensions.cs
@@ -57,6 +57,19 @@ public static IOperationResult PassOrFail(this IOperationResult source, bool suc
{
return success ? Pass(source) : Fail(source, message, ex);
}
+
+ /// <summary>
+ /// Combine will attempt to minimize the depth of InnerResults and maintain status codes
+ /// </summary>
+ /// <param name="target"></param>
+ public static void Combine(this IOperationResult source, IOperationResult target)
+ {
+ target.Message = source.Message;
+ target.Success = source.Success;
+ target.Exception = source.Exception;
+ target.StatusCode = source.StatusCode ?? target.StatusCode;
+ target.InnerResult = source.InnerResult ?? source;
+ }
}
}
View
6 Enyim.Caching/Memcached/Results/Helpers/ResultHelper.cs
@@ -10,14 +10,16 @@ namespace Enyim.Caching.Memcached.Results.Helpers
public static class ResultHelper
{
- public static string ProcessResponseData(string message, ArraySegment<byte> data)
+ public static string ProcessResponseData(ArraySegment<byte> data, string message = "")
{
if (data != null && data.Count > 0)
{
try
{
- return message + ": " + Encoding.ASCII.GetString(data.Array, data.Offset, data.Count);
+ return message +
+ (! string.IsNullOrEmpty(message) ? ": " : "") +
+ Encoding.ASCII.GetString(data.Array, data.Offset, data.Count);
}
catch (Exception ex)
{
View
35 Enyim.Caching/Memcached/Results/StatusCodes/StatusCodeEnums.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Enyim.Caching.Memcached.Results.StatusCodes
+{
+ public enum StatusCodeEnums
+ {
+ Success = 0,
+ NotFound
+ }
+}
+
+#region [ License information ]
+/* ************************************************************
+ *
+ * @author Couchbase <info@couchbase.com>
+ * @copyright 2012 Couchbase, Inc.
+ * @copyright 2012 Attila Kiskó, enyim.com
+ *
+ * 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.
+ *
+ * ************************************************************/
+#endregion
View
34 Enyim.Caching/Memcached/Results/StatusCodes/StatusCodeMessages.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Enyim.Caching.Memcached.Results.StatusCodes
+{
+ public static class StatusCodeMessages
+ {
+ public const string NOT_FOUND = "Not found";
+ }
+}
+
+#region [ License information ]
+/* ************************************************************
+ *
+ * @author Couchbase <info@couchbase.com>
+ * @copyright 2012 Couchbase, Inc.
+ * @copyright 2012 Attila Kiskó, enyim.com
+ *
+ * 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.
+ *
+ * ************************************************************/
+#endregion
View
2  Enyim.Caching/MemcachedClient.Results.cs
@@ -174,7 +174,7 @@ public IGetOperationResult<T> ExecuteGet<T>(string key)
}
return result;
}
- result.Fail("Get failed. See InnerException or StatusCode for details");
+ tryGetResult.Combine(result);
return result;
}
View
15 Enyim.Caching/MemcachedClient.cs
@@ -182,6 +182,9 @@ protected virtual IGetOperationResult PerformTryGet(string key, out ulong cas, o
var node = this.pool.Locate(hashedKey);
var result = GetOperationResultFactory.Create();
+ cas = 0;
+ value = null;
+
if (node != null)
{
var command = this.pool.OperationFactory.Get(hashedKey);
@@ -199,16 +202,13 @@ protected virtual IGetOperationResult PerformTryGet(string key, out ulong cas, o
}
else
{
- result.Value = value = null;
- result.Cas = cas = 0;
- result.InnerResult = commandResult;
- result.Fail("Get operation failed. See InnerResult or StatusCode for details");
+ commandResult.Combine(result);
return result;
}
}
- result.Value = value = null;
- result.Cas = cas = 0;
+ result.Value = value;
+ result.Cas = cas;
if (this.performanceMonitor != null) this.performanceMonitor.Get(1, false);
@@ -376,8 +376,7 @@ protected virtual IStoreOperationResult PerformStore(StoreMode mode, string key,
return result;
}
- result.InnerResult = commandResult;
- result.Fail("Store operation failed, see InnerResult or StatusCode for details");
+ commandResult.Combine(result);
return result;
}
Please sign in to comment.
Something went wrong with that request. Please try again.