protected void StoreAssertFail(IStoreOperationResult result)
		{
			Assert.That(result.Success, Is.False, "Success was true");
			Assert.That(result.Cas, Is.EqualTo(0), "Cas value was not 0");
			Assert.That(result.StatusCode, Is.GreaterThan(0), "StatusCode not greater than 0");
			Assert.That(result.InnerResult, Is.Not.Null, "InnerResult was null");
		}
示例#2
0
 protected void StoreAssertFail(IStoreOperationResult result)
 {
     Assert.False(result.Success, "Success was true");
     Assert.Equal((ulong)0, result.Cas);
     Assert.True(result.StatusCode > 0, "StatusCode not greater than 0");
     Assert.NotNull(result.InnerResult);
 }
 protected void StoreAssertFail(IStoreOperationResult result)
 {
     Assert.That(result.Success, Is.False, "Success was true");
     Assert.That(result.Cas, Is.EqualTo(0), "Cas value was not 0");
     Assert.That(result.StatusCode, Is.GreaterThan(0), "StatusCode not greater than 0");
     Assert.That(result.InnerResult, Is.Not.Null, "InnerResult was null");
 }
        public void When_Storing_A_New_Key_Observe_Will_Fail_With_Persistence_More_Than_Available_Nodes()
        {
            var kv = KeyValueUtils.GenerateKeyAndValue("observe");
            IStoreOperationResult storeResult = null;
            var availableNodesCount           = getWorkingNodes().Count();

            switch (availableNodesCount)
            {
            case 1:
            {
                storeResult = _Client.ExecuteStore(StoreMode.Set, kv.Item1, kv.Item2, PersistTo.Two);
                break;
            }

            case 2:
            {
                storeResult = _Client.ExecuteStore(StoreMode.Set, kv.Item1, kv.Item2, PersistTo.Three);
                break;
            }

            case 3:
            {
                storeResult = _Client.ExecuteStore(StoreMode.Set, kv.Item1, kv.Item2, PersistTo.Four);
                break;
            }

            default:
            {
                storeResult = _Client.ExecuteStore(StoreMode.Set, kv.Item1, kv.Item2, PersistTo.Four);
                break;
            }
            }

            Assert.That(storeResult.Success, Is.False);
        }
        public void When_Storing_A_New_Key_Observe_Will_Pass_With_Replication_More_Than_Available_Nodes()
        {
            var kv = KeyValueUtils.GenerateKeyAndValue("observe");
            IStoreOperationResult storeResult = null;

            var availableNodesCount = getWorkingNodes().Count();

            switch (availableNodesCount)
            {
            case 1:
            {
                storeResult = _Client.ExecuteStore(StoreMode.Set, kv.Item1, kv.Item2, ReplicateTo.Two);
                break;
            }

            case 2:
            {
                storeResult = _Client.ExecuteStore(StoreMode.Set, kv.Item1, kv.Item2, ReplicateTo.Three);
                break;
            }

            default:
            {
                storeResult = _Client.ExecuteStore(StoreMode.Set, kv.Item1, kv.Item2, ReplicateTo.Three);
                break;
            }
            }

            StoreAssertPass(storeResult);
        }
示例#6
0
        /// <summary>
        /// 根据KEY键获取转化成指定的对象,指示获取转化是否成功的返回值
        /// </summary>
        /// <param name="key">KEY键</param>
        /// <param name="obj">需要转化返回的对象</param>
        /// <returns>是否成功</returns>
        /// <remarks>
        ///     <para>创建:范亮</para>
        ///     <para>日期:2016/4/7</para>
        /// </remarks>
        public void Remove(string key)
        {
            IStoreOperationResult result = null;
            var node      = GetRedisNode(key);
            var couchbase = GetCouchbaseClient(new CouchBaseEndpoint()
            {
                Db             = node.Db,
                Host           = node.Host,
                BucketPassword = node.Password,
                BucketName     = node.UserName,
                Port           = int.Parse(node.Port),
                MaxSize        = int.Parse(node.MaxSize),
                MinSize        = int.Parse(node.MinSize)
            });

            couchbase.Remove(GetKeySuffix(key));
        }
示例#7
0
        public IStoreOperationResult Set(string key, object value, int tries)
        {
            var backoffExp = 0;
            IStoreOperationResult result = null;

            try
            {
                var tryAgain = false;
                do
                {
                    if (backoffExp > tries)
                    {
                        throw new ApplicationException(string.Format("尝试{0}次均无法执行。", tries));
                    }

                    result = _client.ExecuteStore(StoreMode.Set, key, value);
                    if (result.Success)
                    {
                        break;
                    }

                    if (backoffExp > 0)
                    {
                        var backoffMillis = Math.Pow(2, backoffExp);
                        backoffMillis = Math.Min(1000, backoffMillis);
                        Thread.Sleep((int)backoffMillis);
                    }
                    backoffExp++;
                    if (!result.Success)
                    {
                        var message = result.InnerResult != null ? result.InnerResult.Message : result.Message;
                        Console.WriteLine("错误信息:" + message);
                    }

                    tryAgain = (result.Message != null && result.Message.Contains("Temporary failure") ||
                                result.InnerResult != null && result.InnerResult.Message.Contains("Temporary failure"));
                } while (tryAgain);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
            return(result);
        }
示例#8
0
        public bool Update(string key, object value, long numOfMinutes = -1L)
        {
            IStoreOperationResult result = null;
            var node      = GetRedisNode(key);
            var couchBase = GetCouchbaseClient(new CouchBaseEndpoint()
            {
                Db             = node.Db,
                Host           = node.Host,
                BucketPassword = node.Password,
                BucketName     = node.UserName,
                Port           = int.Parse(node.Port),
                MaxSize        = int.Parse(node.MaxSize),
                MinSize        = int.Parse(node.MinSize)
            });

            var keySuffix = GetKeySuffix(key);

            if (numOfMinutes < 0L)
            {
                result = couchBase.ExecuteStore(StoreMode.Set, keySuffix, value);
            }
            else
            {
                var validFor = new TimeSpan(0, (int)numOfMinutes, 0);
                result = couchBase.ExecuteStore(StoreMode.Set, keySuffix, value, validFor);
            }

            if (result.Success)
            {
                return(true);
            }
            if (result.Exception != null)
            {
                throw result.Exception;
            }
            throw new Exception(string.Format("Couchbase Error Code: {0}", result.StatusCode));
        }
示例#9
0
 protected void StoreAssertPass(IStoreOperationResult result)
 {
     Assert.True(result.Success, "Success was false");
     Assert.True(result.Cas > 0, "Cas value was 0");
     Assert.Equal(0, result.StatusCode);
 }
 protected void StoreAssertPass(IStoreOperationResult result)
 {
     Assert.That(result.Success, Is.True, "Success was false");
     Assert.That(result.Cas, Is.GreaterThan(0), "Cas value was 0");
     Assert.That(result.StatusCode, Is.EqualTo(0), "StatusCode was not 0");
 }
示例#11
0
 public static void StoreAssertPass(IStoreOperationResult result)
 {
     Assert.That(result.Success, Is.True, "Success was false");
     Assert.That(result.Cas, Is.GreaterThan(0), "Cas value was 0");
     Assert.That(result.StatusCode, Is.EqualTo(0), "StatusCode was not 0");
 }