Permalink
Browse files

NCBC-163: Implement Remove with Observe

Change-Id: I2b46381c83e9653de7a4c99b72610fc079dc1112
Reviewed-on: http://review.couchbase.org/22836
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 Nov 27, 2012
1 parent 11fc31f commit f828a51b56ec1d46e981883c42b3d72f922e6b3c
@@ -9,6 +9,7 @@
using Couchbase.Tests.Utils;
using Couchbase.Tests.Factories;
using System.IO;
+using System.Threading;
namespace Couchbase.Tests
{
@@ -85,7 +86,7 @@ public void When_Storing_A_New_Key_Observe_Will_Fail_With_Master_Persistence_And
{
var kv = KeyValueUtils.GenerateKeyAndValue("observe");
var storeResult = _Client.ExecuteStore(StoreMode.Set, kv.Item1, kv.Item2);
- var observeResult = _Client.Observe(kv.Item2, storeResult.Cas-1, PersistTo.One, ReplicateTo.Zero);
+ var observeResult = _Client.Observe(kv.Item2, storeResult.Cas - 1, PersistTo.One, ReplicateTo.Zero);
Assert.That(observeResult.Success, Is.False);
Assert.That(observeResult.Message, Is.StringMatching(ObserveOperationConstants.MESSAGE_MODIFIED));
}
@@ -131,26 +132,90 @@ public void When_Storing_A_New_Key_With_Master_Persistence_That_Key_Is_In_View_W
var deleteDesignDocResult = cluster.DeleteDesignDocument("default", "cities");
Assert.That(deleteDesignDocResult, Is.True);
}
+
+ [Test]
+ public void When_Observing_A_Removed_Key_Operation_Is_Successful_With_Master_Node_Persistence()
+ {
+ var key = GetUniqueKey("observe");
+ var value = GetRandomString();
+
+ var storeResult = Store(StoreMode.Set, key, value);
+ StoreAssertPass(storeResult);
+
+ var removeResult = _Client.ExecuteRemove(key, PersistTo.One);
+ Assert.That(removeResult.Success, Is.True);
+
+ var getResult = _Client.ExecuteGet(key);
+ GetAssertFail(getResult);
+ }
+
+ [Test]
+ public void When_Observing_A_Removed_Key_Operation_Is_Successful_With_Master_And_Replication_Persistence()
+ {
+ var key = GetUniqueKey("observe");
+ var value = GetRandomString();
+
+ var storeResult = _Client.ExecuteStore(StoreMode.Set, key, PersistTo.One, ReplicateTo.Two);
+ StoreAssertPass(storeResult);
+
+ var removeResult = _Client.ExecuteRemove(key, PersistTo.One, ReplicateTo.Two);
+ Assert.That(removeResult.Success, Is.True);
+
+ var getResult = _Client.ExecuteGet(key);
+ GetAssertFail(getResult);
+ }
+
+ [Test]
+ public void When_Observing_A_Removed_Key_Operation_Is_Successful_With_Replication_Only()
+ {
+ var key = GetUniqueKey("observe");
+ var value = GetRandomString();
+
+ var storeResult = _Client.ExecuteStore(StoreMode.Set, key, PersistTo.One, ReplicateTo.Two);
+ StoreAssertPass(storeResult);
+
+ var removeResult = _Client.ExecuteRemove(key, PersistTo.Zero, ReplicateTo.Two);
+ Assert.That(removeResult.Success, Is.True);
+
+ var getResult = _Client.ExecuteGet(key);
+ GetAssertFail(getResult);
+ }
+
+ [Test]
+ public void When_Observing_A_Removed_Key_Operation_Is_Successful_With_Multi_Node_Persistence()
+ {
+ var key = GetUniqueKey("observe");
+ var value = GetRandomString();
+
+ var storeResult = _Client.ExecuteStore(StoreMode.Set, key, PersistTo.One, ReplicateTo.Two);
+ StoreAssertPass(storeResult);
+
+ var removeResult = _Client.ExecuteRemove(key, PersistTo.Two);
+ Assert.That(removeResult.Success, Is.True);
+
+ var getResult = _Client.ExecuteGet(key);
+ GetAssertFail(getResult);
+ }
}
}
-#region [ License information ]
+#region [ License information ]
/* ************************************************************
*
- * @author Couchbase <info@couchbase.com>
- * @copyright 2012 Couchbase, Inc.
- *
- * 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.
- *
+ * @author Couchbase <info@couchbase.com>
+ * @copyright 2012 Couchbase, Inc.
+ *
+ * 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
@@ -18,7 +18,7 @@
namespace Couchbase
{
- /// <summary>
+ /// <summary>D:\dev\couchbase-net-client\src\Couchbase\CouchbaseViewBase.cs
/// Client which can be used to connect to Couchbase servers.
/// </summary>
public class CouchbaseClient : MemcachedClient, IHttpClientLocator, ICouchbaseClient
@@ -554,7 +554,42 @@ public IStoreOperationResult ExecuteStore(StoreMode mode, string key, object val
return storeResult;
}
- public IObserveOperationResult Observe(string key, ulong cas, PersistTo persistTo, ReplicateTo replicateTo)
+ public IRemoveOperationResult ExecuteRemove(string key, PersistTo persistTo, ReplicateTo replciateTo)
+ {
+ var removeResult = base.ExecuteRemove(key);
+
+ if (persistTo == PersistTo.Zero && replciateTo == ReplicateTo.Zero)
+ {
+ return removeResult;
+ }
+
+ var observeResult = Observe(key, 0, persistTo, replciateTo, ObserveKeyState.NotFound, ObserveKeyState.LogicallyDeleted);
+
+ if (observeResult.Success)
+ {
+ observeResult.Combine(removeResult);
+ }
+ else
+ {
+ observeResult.Combine(removeResult);
+ }
+
+ return removeResult;
+ }
+
+ public IRemoveOperationResult ExecuteRemove(string key, PersistTo persistTo)
+ {
+ return ExecuteRemove(key, persistTo, ReplicateTo.Zero);
+ }
+
+ public IRemoveOperationResult ExecuteRemove(string key, ReplicateTo replicateTo)
+ {
+ return ExecuteRemove(key, PersistTo.Zero, replicateTo);
+ }
+
+ public IObserveOperationResult Observe(string key, ulong cas, PersistTo persistTo, ReplicateTo replicateTo,
+ ObserveKeyState persistedKeyState = ObserveKeyState.FoundPersisted,
+ ObserveKeyState replicatedState = ObserveKeyState.FoundNotPersisted)
{
var hashedKey = this.KeyTransformer.Transform(key);
var vbucket = this.poolInstance.GetVBucket(key);
@@ -572,11 +607,11 @@ public IObserveOperationResult Observe(string key, ulong cas, PersistTo persistT
//Master only persistence
if (replicateTo == ReplicateTo.Zero && persistTo == PersistTo.One)
{
- return runner.HandleMasterPersistence(poolInstance);
+ return runner.HandleMasterPersistence(poolInstance, persistedKeyState);
}
else
{
- return runner.HandleMasterPersistenceWithReplication(poolInstance);
+ return runner.HandleMasterPersistenceWithReplication(poolInstance, persistedKeyState, replicatedState);
}
}
@@ -743,7 +778,7 @@ private void getViewSetup(ref string designName, ref string viewName)
designName = this.documentNameTransformer.Transform(designName);
}
- #region [ IHttpClientLocator ]
+ #region [ IHttpClientLocator ]
IHttpClient IHttpClientLocator.Locate(string designDocument)
{
@@ -760,7 +795,7 @@ IHttpClient IHttpClientLocator.Locate(string designDocument)
#endregion
- #region [ parameter helpers ]
+ #region [ parameter helpers ]
private static T ThrowIfNull<T>(T input, string parameterName)
where T : class
@@ -781,24 +816,24 @@ private static T If<T>(T input, Action<T> check)
}
}
-#region [ License information ]
+#region [ License information ]
/* ************************************************************
*
- * @author Couchbase <info@couchbase.com>
- * @copyright 2012 Couchbase, Inc.
- * @copyright 2010 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.
- *
+ * @author Couchbase <info@couchbase.com>
+ * @copyright 2012 Couchbase, Inc.
+ * @copyright 2010 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
@@ -10,27 +10,33 @@
namespace Couchbase
{
- public interface ICouchbaseResultsClient : IMemcachedResultsClient
- {
- IGetOperationResult ExecuteGet(string key, DateTime newExpiration);
- IGetOperationResult<T> ExecuteGet<T>(string key, DateTime newExpiration);
- IGetOperationResult ExecuteTryGet(string key, DateTime newExpiration, out object value);
+ public interface ICouchbaseResultsClient : IMemcachedResultsClient
+ {
+ IGetOperationResult ExecuteGet(string key, DateTime newExpiration);
+ IGetOperationResult<T> ExecuteGet<T>(string key, DateTime newExpiration);
+ IGetOperationResult ExecuteTryGet(string key, DateTime newExpiration, out object value);
- IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, PersistTo persistTo, ReplicateTo replicateTo);
- IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, ReplicateTo replicateTo);
- IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, PersistTo persistTo);
+ IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, PersistTo persistTo, ReplicateTo replicateTo);
+ IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, ReplicateTo replicateTo);
+ IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, PersistTo persistTo);
- IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, DateTime expiresAt, PersistTo persistTo, ReplicateTo replicateTo);
- IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, DateTime expiresAt, PersistTo persistTo);
- IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, DateTime expiresAt, ReplicateTo replicateTo);
+ IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, DateTime expiresAt, PersistTo persistTo, ReplicateTo replicateTo);
+ IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, DateTime expiresAt, PersistTo persistTo);
+ IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, DateTime expiresAt, ReplicateTo replicateTo);
- IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, TimeSpan validFor, PersistTo persistTo, ReplicateTo replicateTo);
- IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, TimeSpan validFor, PersistTo persistTo);
- IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, TimeSpan validFor, ReplicateTo replicateTo);
+ IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, TimeSpan validFor, PersistTo persistTo, ReplicateTo replicateTo);
+ IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, TimeSpan validFor, PersistTo persistTo);
+ IStoreOperationResult ExecuteStore(StoreMode mode, string key, object value, TimeSpan validFor, ReplicateTo replicateTo);
- IObserveOperationResult Observe(string key, ulong cas, PersistTo persistTo, ReplicateTo replicateTo);
+ IRemoveOperationResult ExecuteRemove(string key, PersistTo persisTo, ReplicateTo replicateTo);
+ IRemoveOperationResult ExecuteRemove(string key, PersistTo persisTo);
+ IRemoveOperationResult ExecuteRemove(string key, ReplicateTo replicateTo);
- }
+ IObserveOperationResult Observe(string key, ulong cas, PersistTo persistTo, ReplicateTo replicateTo,
+ ObserveKeyState persistedKeyState = ObserveKeyState.FoundPersisted,
+ ObserveKeyState replicatedState = ObserveKeyState.FoundNotPersisted);
+
+ }
}
#region [ License information ]
Oops, something went wrong.

0 comments on commit f828a51

Please sign in to comment.