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 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 void When_Key_Exists_Append_Succeeds()
        {
            const string key = "Hello";
            const string expected = "Hello!";

            //clean up old keys
            var deleteOperation = new Delete(key, GetVBucket(), Converter, Serializer);
            IOStrategy.Execute(deleteOperation);

            deleteOperation = new Delete(key + "!", GetVBucket(),  Converter, Serializer);
            IOStrategy.Execute(deleteOperation);

            //create the key
            var set = new Set<string>(key, "Hello", GetVBucket(), Converter);
            var addResult = IOStrategy.Execute(set);
            Assert.IsTrue(addResult.Success);

            var append = new Append<string>(key, "!", Serializer, GetVBucket(), Converter);
            var result = IOStrategy.Execute(append);

            
            Assert.IsTrue(result.Success);
            Assert.AreEqual(string.Empty, result.Value);

            var get = new Get<string>(key, GetVBucket(),  Converter, Serializer);
            var getResult = IOStrategy.Execute(get);
            Assert.AreEqual(expected, getResult.Value);
        }
Пример #4
0
 public override IOperation Clone()
 {
     var cloned = new Delete(Key, VBucket, Transcoder, Timeout)
     {
         Attempts = Attempts,
         Cas = Cas,
         CreationTime = CreationTime,
         Opaque = Opaque
     };
     return cloned;
 }
Пример #5
0
        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);
        }
Пример #6
0
        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);
            IOStrategy.Execute(delete);

            var set = new Set<string>(key, "boo", GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result = IOStrategy.Execute(set);
            Assert.IsTrue(result.Success);
        }
Пример #7
0
        public void When_Key_Does_Not_Exist_Set_Succeeds()
        {
            const string key = "Replace.When_Document_Exists_Replace_Succeeds";

            //delete the value if it exists
            var delete = new Delete(key, GetVBucket(), Converter, Serializer);
            IOStrategy.Execute(delete);

            var set = new Set<string>(key, "boo", GetVBucket(), Converter);
            var result = IOStrategy.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(), new AutoByteConverter(), new TypeSerializer(new ManualByteConverter()));
            var result1 = IOStrategy.Execute(deleteOperation);
            Console.WriteLine(result1.Message);

            var operation = new Add<dynamic>(key, new {foo = "foo"}, GetVBucket(), new AutoByteConverter(), new TypeSerializer(new ManualByteConverter()));
            var result = IOStrategy.Execute(operation);
            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);
        }
Пример #10
0
 public override IOperation Clone()
 {
     var cloned = new Delete(Key, VBucket, Transcoder, Timeout)
     {
         Attempts = Attempts,
         Cas = Cas,
         CreationTime = CreationTime,
         Opaque = Opaque,
         MutationToken = MutationToken,
         LastConfigRevisionTried = LastConfigRevisionTried
     };
     return cloned;
 }
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        public void When_Key_Exists_Get_Returns_Value()
        {
            var key = "When_Key_Exists_Get_Returns_Value";

            //delete the value if it exists
            var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            IOStrategy.Execute(delete);

            //Add the key
            var add = new Add<dynamic>(key, new { foo = "foo" }, GetVBucket(), Transcoder, OperationLifespanTimeout);
            Assert.IsTrue(IOStrategy.Execute(add).Success);

            var get = new Get<dynamic>(key, GetVBucket(), Transcoder, OperationLifespanTimeout);

            var result = IOStrategy.Execute(get);
            Assert.IsTrue(result.Success);

            var expected = new {foo = "foo"};
            Assert.AreEqual(result.Value.foo.Value, expected.foo);
        }
Пример #14
0
        public void When_Key_Exists_Get_Returns_Value()
        {
            var key = "When_Key_Exists_Get_Returns_Value";

            //delete the value if it exists
            var delete = new Delete(key, GetVBucket(), new AutoByteConverter(), new TypeSerializer(new ManualByteConverter()));
            IOStrategy.Execute(delete);

            //Add the key
            var add = new Add<dynamic>(key, new { foo = "foo" }, GetVBucket(), new AutoByteConverter(), new TypeSerializer(new ManualByteConverter()));
            Assert.IsTrue(IOStrategy.Execute(add).Success);
            
            var get = new Get<dynamic>(key, GetVBucket(), new AutoByteConverter(),
                new TypeSerializer(new AutoByteConverter()));

            var result = IOStrategy.Execute(get);
            Assert.IsTrue(result.Success);

            var expected = new {foo = "foo"};
            Assert.AreEqual(result.Value.foo.Value, expected.foo);
        }
        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);
        }
        public void Test_Observe2()
        {
            const string key = "Test_Observe2";
            var remove = new Delete(key, GetVBucket(), Converter, Serializer);

            var set = new Set<int>(key, 10, GetVBucket(), Converter);
            var result = IOStrategy.Execute(set);
            Assert.IsTrue(result.Success);

            var get = new Get<dynamic>(key, GetVBucket(), Converter, Serializer);
            var result1 = IOStrategy.Execute(get);
            Assert.IsTrue(result1.Success);
            Assert.AreEqual(result.Cas, result1.Cas);

            var operation = new Observe(key, GetVBucket(), new AutoByteConverter());
            var result2 = IOStrategy.Execute(operation);
            Assert.AreEqual(result1.Cas, result2.Value.Cas);

            Assert.AreEqual(KeyState.FoundPersisted, result2.Value.KeyState);
            Assert.IsTrue(result2.Success);
        }
        public void Test_IncrementOperation()
        {
            const string key = "Test_IncrementOperation";

            var delete = new Delete(key, GetVBucket(), Converter, Serializer);
            var result = IOStrategy.Execute(delete);
            Console.WriteLine("Deleting key {0}: {1}", key, result.Success);

            var increment = new Increment(key, 0, 1, 0, GetVBucket(), Converter, Serializer);
            var result1 = IOStrategy.Execute(increment);
            Assert.IsTrue(result1.Success);
            Assert.AreEqual(result1.Value, uint.MinValue);

            var result2 = IOStrategy.Execute(increment);
            Assert.IsTrue(result2.Success);
            Assert.AreEqual(1, result2.Value);

            var getOperation = new Get<string>(key, GetVBucket(), Converter, Serializer);
            var result3 = IOStrategy.Execute(getOperation);
            var value = result3.Value;
            Assert.AreEqual(result2.Value.ToString(CultureInfo.InvariantCulture), result3.Value);
        }
        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);
        }
Пример #19
0
        public void When_Type_Is_Object_DataFormat_Json_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);
            IOStrategy.Execute(delete);

            //Add the key
            var add = new Add<dynamic>(key, new { foo = "foo" }, GetVBucket(), Transcoder, OperationLifespanTimeout);
            Assert.IsTrue(IOStrategy.Execute(add).Success);

            var get = new Get<dynamic>(key, GetVBucket(), Transcoder, OperationLifespanTimeout);

            get.CreateExtras();
            Assert.AreEqual(DataFormat.Json, get.Format);

            var result = IOStrategy.Execute(get);
            Assert.IsTrue(result.Success);

            Assert.AreEqual(DataFormat.Json, get.Format);
        }
        public async Task 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 When_Type_Is_ByteArray_DataFormat_Binary_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<byte[]>(key, new byte[] { 0x0 }, GetVBucket(), Transcoder, OperationLifespanTimeout);
            Assert.IsTrue(IOService.Execute(add).Success);

            var getK = new GetK<byte[]>(key, GetVBucket(), Transcoder, OperationLifespanTimeout);

            getK.CreateExtras();
            Assert.AreEqual(DataFormat.Binary, getK.Format);

            var result = IOService.Execute(getK);
            Assert.IsTrue(result.Success);

            Assert.AreEqual(DataFormat.Binary, getK.Format);
        }