Skip to content
This repository has been archived by the owner on Jul 7, 2019. It is now read-only.

Commit

Permalink
Fixed CAS support of Append/Prepend.
Browse files Browse the repository at this point in the history
  • Loading branch information
enyim committed Jul 19, 2011
1 parent 055cd89 commit 16d9e64
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Enyim.Caching/MemcachedClient.cs
Expand Up @@ -619,7 +619,7 @@ protected virtual bool PerformConcatenate(ConcatenationMode mode, string key, re

if (node != null)
{
var command = this.pool.OperationFactory.Concat(mode, hashedKey, 0, data);
var command = this.pool.OperationFactory.Concat(mode, hashedKey, cas, data);
var retval = node.Execute(command);

cas = command.CasValue;
Expand Down
2 changes: 1 addition & 1 deletion Membase/MembaseClient.cs
Expand Up @@ -143,7 +143,7 @@ protected override bool PerformConcatenate(ConcatenationMode mode, string key, r

if (node != null)
{
var command = this.Pool.OperationFactory.Concat(mode, hashedKey, 0, data);
var command = this.Pool.OperationFactory.Concat(mode, hashedKey, cas, data);
var retval = this.ExecuteWithRedirect(node, command);

cas = command.CasValue;
Expand Down
52 changes: 52 additions & 0 deletions MemcachedTest/BinaryMemcachedClientTest.cs
Expand Up @@ -84,6 +84,58 @@ public virtual void CASTest()
Assert.AreEqual(r5.Result, "baz", "Invalid data returned; excpected 'baz'.");
}
}

[TestCase]
public void AppendCASTest()
{
using (MemcachedClient client = GetClient())
{
// store the item
var r1 = client.Cas(StoreMode.Set, "CasAppend", "foo");

Assert.IsTrue(r1.Result, "Initial set failed.");
Assert.AreNotEqual(r1.Cas, 0, "No cas value was returned.");

var r2 = client.Append("CasAppend", r1.Cas, new System.ArraySegment<byte>(new byte[] { (byte)'l' }));

Assert.IsTrue(r2.Result, "Append should have succeeded.");

// get back the item and check the cas value (it should match the cas from the set)
var r3 = client.GetWithCas<string>("CasAppend");

Assert.AreEqual(r3.Result, "fool", "Invalid data returned; expected 'fool'.");
Assert.AreEqual(r2.Cas, r3.Cas, "Cas values r2:r3 do not match.");

var r4 = client.Append("CasAppend", r1.Cas, new System.ArraySegment<byte>(new byte[] { (byte)'l' }));
Assert.IsFalse(r4.Result, "Append with invalid CAS should have failed.");
}
}

[TestCase]
public void PrependCASTest()
{
using (MemcachedClient client = GetClient())
{
// store the item
var r1 = client.Cas(StoreMode.Set, "CasPrepend", "ool");

Assert.IsTrue(r1.Result, "Initial set failed.");
Assert.AreNotEqual(r1.Cas, 0, "No cas value was returned.");

var r2 = client.Prepend("CasPrepend", r1.Cas, new System.ArraySegment<byte>(new byte[] { (byte)'f' }));

Assert.IsTrue(r2.Result, "Prepend should have succeeded.");

// get back the item and check the cas value (it should match the cas from the set)
var r3 = client.GetWithCas<string>("CasPrepend");

Assert.AreEqual(r3.Result, "fool", "Invalid data returned; expected 'fool'.");
Assert.AreEqual(r2.Cas, r3.Cas, "Cas values r2:r3 do not match.");

var r4 = client.Prepend("CasPrepend", r1.Cas, new System.ArraySegment<byte>(new byte[] { (byte)'l' }));
Assert.IsFalse(r4.Result, "Prepend with invalid CAS should have failed.");
}
}
}
}

Expand Down

0 comments on commit 16d9e64

Please sign in to comment.