public void Test_Timed_Execution_Parallel() { var options = new ParallelOptions { MaxDegreeOfParallelism = 4 }; var converter = new DefaultConverter(); var transcoder = new DefaultTranscoder(converter); var vbucket = GetVBucket(); var n = 1000;//set to a higher # if needed using (new OperationTimer()) { Parallel.For(0, n, options, i => { var key = string.Format("key{0}", i); var set = new Set <int?>(key, i, vbucket, transcoder, OperationLifespanTimeout); var result = IOService.Execute(set); Assert.IsTrue(result.Success); var get = new Get <int?>(key, vbucket, transcoder, OperationLifespanTimeout); var result1 = IOService.Execute(get); Assert.IsTrue(result1.Success); Assert.AreEqual(i, result1.Value); }); } }
public void When_Key_Exists_GetT_Returns_Value() { var key = "When_Key_Exists_GetT_Returns_Value"; //delete the value if it exists var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); IOService.Execute(delete); //Add the key var add = new Add <dynamic>(key, new { foo = "foo" }, GetVBucket(), Transcoder, OperationLifespanTimeout); Assert.IsTrue(IOService.Execute(add).Success); var get = new GetT <dynamic>(key, GetVBucket(), Transcoder, OperationLifespanTimeout) { Expires = new TimeSpan(0, 0, 0, 1).ToTtl() }; var result = IOService.Execute(get); Assert.IsTrue(result.Success); var expected = new { foo = "foo" }; Assert.AreEqual(result.Value.foo.Value, expected.foo); }
public void When_Type_Is_Object_DataFormat_Json_Is_Used() { var key = "When_Type_Is_Object_GetK_Uses_DataFormat_Json"; //delete the value if it exists var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); IOService.Execute(delete); //Add the key var add = new Add <dynamic>(key, new { foo = "foo" }, GetVBucket(), Transcoder, OperationLifespanTimeout); Assert.IsTrue(IOService.Execute(add).Success); var getK = new GetK <dynamic>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); getK.CreateExtras(); Assert.AreEqual(DataFormat.Json, getK.Format); var result = IOService.Execute(getK); Assert.IsTrue(result.Success); Assert.AreEqual(DataFormat.Json, getK.Format); }
public void Test_Config() { var config = new Config(Transcoder, OperationLifespanTimeout, EndPoint); var result = IOService.Execute(config); Assert.IsTrue(result.Success); }
public void When_Key_Exists_Append_Succeeds() { const string key = "Hello"; const string expected = "Hello!"; //clean up old keys var deleteOperation = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); IOService.Execute(deleteOperation); deleteOperation = new Delete(key + "!", GetVBucket(), Transcoder, OperationLifespanTimeout); IOService.Execute(deleteOperation); //create the key var set = new Set <string>(key, "Hello", GetVBucket(), Transcoder, OperationLifespanTimeout); var addResult = IOService.Execute(set); Assert.IsTrue(addResult.Success); var append = new Append <string>(key, "!", GetVBucket(), Transcoder, OperationLifespanTimeout); var result = IOService.Execute(append); Assert.IsTrue(result.Success); Assert.AreEqual(string.Empty, result.Value); var get = new Get <string>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var getResult = IOService.Execute(get); Assert.AreEqual(expected, getResult.Value); }
public void Test_NoOp() { var noop = new Noop(new DefaultTranscoder(), OperationLifespanTimeout); var result = IOService.Execute(noop); Assert.IsTrue(result.Success); }
public void When_Type_Is_String_DataFormat_String_Is_Used() { var key = "When_Type_Is_String_DataFormat_String_Is_Used"; //delete the value if it exists var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); IOService.Execute(delete); //Add the key var add = new Add <string>(key, "foo", GetVBucket(), Transcoder, OperationLifespanTimeout); Assert.IsTrue(IOService.Execute(add).Success); var getK = new GetK <string>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); getK.CreateExtras(); Assert.AreEqual(DataFormat.String, getK.Format); var result = IOService.Execute(getK); Assert.IsTrue(result.Success); Assert.AreEqual(DataFormat.String, getK.Format); }
public void When_Type_Is_ByteArray_DataFormat_Binary_Is_Used() { var key = "When_Type_Is_Object_DataFormat_Json_Is_Used"; //delete the value if it exists var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); IOService.Execute(delete); //Add the key var add = new Add <byte[]>(key, new byte[] { 0x0 }, GetVBucket(), Transcoder, OperationLifespanTimeout); Assert.IsTrue(IOService.Execute(add).Success); var get = new Get <byte[]>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); get.CreateExtras(); Assert.AreEqual(DataFormat.Binary, get.Format); var result = IOService.Execute(get); Assert.IsTrue(result.Success); Assert.AreEqual(DataFormat.Binary, get.Format); }
public void When_Document_Exists_Replace_Succeeds() { const string key = "Replace.When_Document_Exists_Replace_Succeeds"; //delete the value if it exists var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var result = IOService.Execute(delete); Console.WriteLine(result.Message); //add the new doc var add = new Add <dynamic>(key, new { foo = "foo" }, GetVBucket(), Transcoder, OperationLifespanTimeout); var result1 = IOService.Execute(add); Assert.IsTrue(result1.Success); //replace it the old doc with a new one var replace = new Replace <dynamic>(key, new { bar = "bar" }, GetVBucket(), Transcoder, OperationLifespanTimeout); var result2 = IOService.Execute(replace); Assert.IsTrue(result2.Success); //check that doc has been updated var get = new Get <dynamic>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var result3 = IOService.Execute(get); Assert.IsTrue(result3.Success); Assert.AreEqual(result3.Value.bar.Value, "bar"); }
public async void Test_Observe2() { const string key = "Test_Observe2"; var remove = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var set = new Set <int?>(key, 10, GetVBucket(), Transcoder, OperationLifespanTimeout); var result = IOService.Execute(set); Assert.IsTrue(result.Success); var get = new Get <dynamic>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var result1 = IOService.Execute(get); Assert.IsTrue(result1.Success); Assert.AreEqual(result.Cas, result1.Cas); await Task.Delay(100); var operation = new Observe(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var result2 = IOService.Execute(operation); Assert.AreEqual(result1.Cas, result2.Value.Cas); Assert.AreEqual(KeyState.FoundPersisted, result2.Value.KeyState); Assert.IsTrue(result2.Success); }
public void Test_DecrementOperation() { const string key = "Test_DecrementOperation"; //delete key if exists var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var result = IOService.Execute(delete); Console.WriteLine("Deleting key {0}: {1}", key, result.Success); //increment the key var operation = new Increment(key, 1, 1, 0, GetVBucket(), Transcoder, OperationLifespanTimeout); var result1 = IOService.Execute(operation); Assert.IsTrue(result1.Success); Assert.AreEqual(result1.Value, 1); //key should be 1 var get = new Get <string>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var result3 = IOService.Execute(get); Assert.AreEqual(result1.Value.ToString(CultureInfo.InvariantCulture), result3.Value); //decrement the key var decrement = new Decrement(key, 1, 1, 0, GetVBucket(), Transcoder, OperationLifespanTimeout); var result2 = IOService.Execute(decrement); Assert.IsTrue(result2.Success); Assert.AreEqual(result2.Value, 0); //key should be 0 get = new Get <string>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); result3 = IOService.Execute(get); Assert.AreEqual(0.ToString(CultureInfo.InvariantCulture), result3.Value); }
public void Test_IncrementOperation() { const string key = "Test_IncrementOperation"; var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var result = IOService.Execute(delete); Console.WriteLine("Deleting key {0}: {1}", key, result.Success); var increment = new Increment(key, 0, 1, GetVBucket(), Transcoder, OperationLifespanTimeout); var result1 = IOService.Execute(increment); Assert.IsTrue(result1.Success); Assert.AreEqual(result1.Value, uint.MinValue); increment.Reset(); var result2 = IOService.Execute(increment); Assert.IsTrue(result2.Success); Assert.AreEqual(1, result2.Value); var getOperation = new Get <string>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var result3 = IOService.Execute(getOperation); var value = result3.Value; Assert.AreEqual(result2.Value.ToString(CultureInfo.InvariantCulture), result3.Value); }
public void Test_Timed_Execution() { var converter = new DefaultConverter(); var transcoder = new DefaultTranscoder(converter); var vbucket = GetVBucket(); int n = 1000; //set to a higher # if needed using (new OperationTimer()) { var key = string.Format("key{0}", 111); for (var i = 0; i < n; i++) { var set = new Set <int?>(key, 111, vbucket, transcoder, OperationLifespanTimeout); var get = new Get <int?>(key, vbucket, transcoder, OperationLifespanTimeout); var result = IOService.Execute(set); Assert.IsTrue(result.Success); var result1 = IOService.Execute(get); Assert.IsTrue(result1.Success); Assert.AreEqual(111, result1.Value); } } }
public void When_Key_Exists_Exist_Operation_Fails() { var operation = new Add <dynamic>("keythatdoesntexist", new { foo = "foo" }, GetVBucket(), Transcoder, OperationLifespanTimeout); var result = IOService.Execute(operation); Assert.IsFalse(result.Success); Assert.AreEqual(ResponseStatus.KeyExists, result.Status); }
public void Test_Hello_No_Features_Set() { var features = new List <short>(); var hello = new Hello("couchbase-net-sdk/2.1.4", features.ToArray(), Transcoder, 0, 0); var result = IOService.Execute(hello); Assert.IsTrue(result.Success); }
public void Test_Observe() { const string key = "Test_Observe"; var operation = new Observe(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var result = IOService.Execute(operation); Console.WriteLine(result.Message); Assert.IsTrue(result.Success); }
public void Test_Hello_With_Features_MutationSeqno_And_TcpNodelay_Set() { var features = new List <short>(); features.Add((short)ServerFeatures.MutationSeqno); features.Add((short)ServerFeatures.TcpNoDelay); var hello = new Hello("couchbase-net-sdk/2.1.4", features.ToArray(), Transcoder, 0, 0); var result = IOService.Execute(hello); Assert.IsTrue(result.Success); }
public void When_MutationSeqno_Is_Not_Set_MutationToken_Is_The_Same_For_All_Instances() { var key = "bar"; var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var deleteResult = IOService.Execute(delete); var add = new Add <string>(key, "foo", GetVBucket(), Transcoder, OperationLifespanTimeout); var addResult = IOService.Execute(add); Assert.IsNotNull(addResult.Token); Assert.AreEqual(deleteResult.Token, addResult.Token); }
public void When_Key_Does_Not_Exist_Set_Succeeds2() { const string key = "Replace.When_Document_Exists_Replace_Succeeds"; //delete the value if it exists var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); IOService.Execute(delete); var set = new Set <string>(key, "boo", GetVBucket(), Transcoder, OperationLifespanTimeout); var result = IOService.Execute(set); Assert.IsTrue(result.Success); }
public void When_Key_Doesnt_Exist_Operation_Succeeds() { const string key = "keythatdoesntexist"; //delete the value if it exists var deleteOperation = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var result1 = IOService.Execute(deleteOperation); Console.WriteLine(result1.Message); var operation = new Add <dynamic>(key, new { foo = "foo" }, GetVBucket(), Transcoder, OperationLifespanTimeout); var result = IOService.Execute(operation); Assert.IsTrue(result.Success); }
public void When_Type_Is_String_DateFormat_Is_String() { const string key = "OperationBaseTests.When_Type_Is_String_DateFormat_Is_String"; var set = new Set <string>(key, "somestring", GetVBucket(), Transcoder, OperationLifespanTimeout); var result = IOService.Execute(set); Assert.IsTrue(result.Success); Assert.AreEqual(set.Format, DataFormat.String); var get = new Get <string>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var getResult = IOService.Execute(get); Assert.IsTrue(getResult.Success); Assert.AreEqual(DataFormat.String, get.Format); Assert.AreEqual(Compression.None, get.Compression); }
public void Test_When_Type_Is_Json_Integrated() { var key = "jsonkey"; var value = new { x = "hi", y = 14 }; var set = new Set <dynamic>(key, value, GetVBucket(), Transcoder, OperationLifespanTimeout); var setResult = IOService.Execute(set); Assert.IsTrue(setResult.Success); Assert.AreEqual(DataFormat.Json, set.Format); var get = new Get <dynamic>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var getResult = IOService.Execute(get); Assert.AreEqual(DataFormat.Json, get.Format); Assert.IsTrue(getResult.Success); }
public void When_Document_Does_Not_Exist_Replace_Fails() { const string key = "Replace.When_Document_Does_Not_Exist_Replace_Fails"; //delete the value if it exists var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var result = IOService.Execute(delete); Console.WriteLine(result.Message); //replace it the old doc with a new one var replace = new Replace <dynamic>(key, new { bar = "bar" }, GetVBucket(), Transcoder, OperationLifespanTimeout); var result2 = IOService.Execute(replace); Assert.IsFalse(result2.Success); Assert.AreEqual(ResponseStatus.KeyNotFound, result2.Status); }
public void Test_When_Type_Is_String_Integrated() { var key = "stringkey"; var value = "hiho"; var set = new Set <string>(key, value, GetVBucket(), Transcoder, OperationLifespanTimeout); var setResult = IOService.Execute(set); Assert.IsTrue(setResult.Success); Assert.AreEqual(DataFormat.String, set.Format); var get = new Get <string>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var getResult = IOService.Execute(get); Assert.AreEqual(DataFormat.String, get.Format); Assert.IsTrue(getResult.Success); }
public void Test_When_Type_Is_Number_Integrated() { var key = "intkey"; var value = 14.666m; var set = new Set <decimal?>(key, value, GetVBucket(), Transcoder, OperationLifespanTimeout); var setResult = IOService.Execute(set); Assert.IsTrue(setResult.Success); Assert.AreEqual(DataFormat.Json, set.Format); var get = new Get <decimal?>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var getResult = IOService.Execute(get); Assert.AreEqual(DataFormat.Json, get.Format); Assert.IsTrue(getResult.Success); }
public void Test_When_Type_Is_Binary_Integrated() { var key = "binkey"; var value = new byte[] { 1, 2, 3, 4 }; var set = new Set <byte[]>(key, value, GetVBucket(), Transcoder, OperationLifespanTimeout); var setResult = IOService.Execute(set); Assert.IsTrue(setResult.Success); Assert.AreEqual(DataFormat.Binary, set.Format); var get = new Get <byte[]>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var getResult = IOService.Execute(get); Assert.IsTrue(getResult.Success); Assert.AreEqual(DataFormat.Binary, get.Format); }
public void Test_Hello_With_Feature_MutationSeqno_Set() { var features = new List <short>(); features.Add((short)ServerFeatures.MutationSeqno); var hello = new Hello("couchbase-net-sdk/2.1.4", features.ToArray(), Transcoder, 0, 0); var result = IOService.Execute(hello); Assert.IsTrue(result.Success); var key = "bar"; var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var deleteResult = IOService.Execute(delete); var add = new Add <string>(key, "foo", GetVBucket(), Transcoder, OperationLifespanTimeout); var result2 = IOService.Execute(add); Assert.IsNotNull(result2.Token); }
public void When_Type_Object_Int_DateFormat_Is_Json() { const string key = "OperationBaseTests.When_Type_Object_Int_DateFormat_Is_Json"; var value = new { Name = "name", Foo = "foo" }; var set = new Set <dynamic>(key, value, GetVBucket(), Transcoder, OperationLifespanTimeout); var result = IOService.Execute(set); Assert.IsTrue(result.Success); Assert.AreEqual(set.Format, DataFormat.Json); var get = new Get <dynamic>(key, GetVBucket(), Transcoder, OperationLifespanTimeout); var getResult = IOService.Execute(get); Assert.IsTrue(getResult.Success); Assert.AreEqual(DataFormat.Json, get.Format); Assert.AreEqual(Compression.None, get.Compression); }
public void When_Key_Exists_Touch_Returns_Success() { var key = "When_Key_Exists_Touch_Returns_Success"; //delete the value if it exists var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout); IOService.Execute(delete); //Add the key var add = new Add <dynamic>(key, new { foo = "foo" }, GetVBucket(), Transcoder, OperationLifespanTimeout); Assert.IsTrue(IOService.Execute(add).Success); var touch = new Touch(key, GetVBucket(), Transcoder, OperationLifespanTimeout) { Expires = new TimeSpan(0, 0, 0, 3).ToTtl() }; var result = IOService.Execute(touch); Console.WriteLine(result.Message); Assert.IsTrue(result.Success); }