示例#1
0
        public void TestDelete()
        {
            using (var requestHandler = new TestRequestHandler())
                using (var client = new RingMasterClient(requestHandler))
                {
                    string path    = this.GetRandomString();
                    var    version = this.GetRandomInt();

                    requestHandler.Implementation = request =>
                    {
                        Assert.IsTrue(request is RequestDelete);
                        var deleteRequest = (RequestDelete)request;
                        Assert.AreEqual(path, deleteRequest.Path);
                        Assert.AreEqual(version, deleteRequest.Version);

                        return(new RequestResponse()
                        {
                            ResultCode = (deleteRequest.DeleteMode == DeleteMode.None) ? (int)RingMasterException.Code.Ok : (int)RingMasterException.Code.Nonode
                        });
                    };

                    bool result = client.Delete(path, version, isRecursive: false).Result;
                    Assert.IsTrue(result);

                    result = client.Delete(path, version, isRecursive: true).Result;
                    Assert.IsFalse(result);
                }
        }
示例#2
0
 private async Task DeleteChild(string root, int childCount)
 {
     using (var client = new RingMasterClient(serverAddress, null, null, 10000))
     {
         for (int count = 0; count < childCount; count++)
         {
             var path = $"/{root}/{count}";
             await client.Delete(path, -1, DeleteMode.SuccessEvenIfNodeDoesntExist);
         }
     }
 }
示例#3
0
        /// <summary>
        /// Creates the VNET base data before multi-thread operation is started.
        /// </summary>
        private static async Task CreateBaseData()
        {
            var client = new RingMasterClient(
                connectionString: serverAddress,
                clientCerts: null,
                serverCerts: null,
                requestTimeout: requestTimeout,
                watcher: null);

            var createMode = CreateMode.PersistentAllowPathCreation | CreateMode.SuccessEvenIfNodeExistsFlag;

            for (int vnetId = 0; vnetId < VnetCount; vnetId++)
            {
                await client.Delete($"/vnets-{vnetId}", -1, true);

                await client.Multi(
                    Enumerable.Range(0, MinNodeCount)
                    .Select(n => Op.Create($"/vnets-{vnetId}/lnms/dn-{vnetId}-{n}", null, null, createMode))
                    .ToList(),
                    true);
            }
        }
示例#4
0
        public void TestConcurrentDelete()
        {
            TestAsync().GetAwaiter().GetResult();

            async Task TestAsync()
            {
                const int    ChildrenCount = 1000;
                const string RootName      = nameof(this.TestConcurrentDelete);
                const int    threadCount   = 64;

                using (var client = new RingMasterClient(serverAddress, null, null, 10000))
                {
                    await client.Create($"/{RootName}", null, null, CreateMode.PersistentAllowPathCreation).ConfigureAwait(false);

                    var ops = new List <Op>(ChildrenCount);
                    for (int count = 0; count < ChildrenCount; count++)
                    {
                        ops.Add(Op.Create($"/{RootName}/{count}", null, null, CreateMode.PersistentAllowPathCreation));
                    }

                    await client.Batch(ops).ConfigureAwait(false);
                }

                for (int i = 0; i < threadCount; i++)
                {
                    var deleteChildTask = this.DeleteChild(RootName, ChildrenCount);
                    var deleteParent    = Task.Run(async() =>
                    {
                        using (var client = new RingMasterClient(serverAddress, null, null, 10000))
                        {
                            await client.Delete($"/{RootName}", -1, DeleteMode.None);
                        }
                    });
                }
            }
        }
示例#5
0
        public void TestConflictingCreateDeleteExists()
        {
            TestConflictingCreateDeleteExistsAsync().GetAwaiter().GetResult();

            async Task TestConflictingCreateDeleteExistsAsync()
            {
                const string path  = "/$rmbvt/test";
                var          stop  = false;
                var          taskW = Task.Run(async() =>
                {
                    while (!stop)
                    {
                        try
                        {
                            using (var rm = new RingMasterClient(serverAddress, null, null, 10000))
                            {
                                while (!stop)
                                {
                                    await rm.Create(path, null, null, CreateMode.PersistentAllowPathCreation | CreateMode.SuccessEvenIfNodeExistsFlag);
                                    await rm.Delete(path, -1, DeleteMode.SuccessEvenIfNodeDoesntExist);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            var rmException = ex as RingMasterException;
                            if (rmException != null && rmException.ErrorCode == RingMasterException.Code.Operationtimeout)
                            {
                                // Do thing. Continue test.
                            }
                            else
                            {
                                stop = true;
                                throw;
                            }
                        }
                    }
                });

                var taskR = Task.Run(async() =>
                {
                    while (!stop)
                    {
                        try
                        {
                            using (var rm = new RingMasterClient(serverAddress, null, null, 10000))
                            {
                                while (!stop)
                                {
                                    await Task.WhenAll(
                                        rm.Exists(path, null, true));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            var rmException = ex as RingMasterException;
                            if (rmException != null && rmException.ErrorCode == RingMasterException.Code.Operationtimeout)
                            {
                                // Do thing. Continue test.
                            }
                            else
                            {
                                stop = true;
                                throw;
                            }
                        }
                    }
                });

                var clock = Stopwatch.StartNew();

                SpinWait.SpinUntil(() => clock.Elapsed.TotalSeconds >= 3600 || stop);

                stop = true;
                await Task.WhenAll(taskW, taskR).ContinueWith(t => log(t.Exception?.ToString()));
            }
        }