Beispiel #1
0
        public void TestRequestInMultiReturnCorrectly()
        {
            TestRequestInMultiReturnCorrectlyAsync().GetAwaiter().GetResult();

            async Task TestRequestInMultiReturnCorrectlyAsync()
            {
                const string RootName = nameof(this.TestRequestInMultiReturnCorrectly);

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

                    await rm.Create($"/{RootName}/child2", null, null, CreateMode.PersistentAllowPathCreation);

                    await rm.Create($"/{RootName}/child3", null, null, CreateMode.PersistentAllowPathCreation);

                    var ops = new List <Op>
                    {
                        Op.Check($"/{RootName}", -1),
                        Op.GetChildren($"/{RootName}"),
                    };

                    var multiResult = await rm.Multi(ops);

                    Assert.AreEqual(multiResult.Count, ops.Count);

                    var checkResult       = multiResult[0] as OpResult.CheckResult;
                    var getChildrenResult = multiResult[1] as OpResult.GetChildrenResult;

                    Assert.AreEqual(3, checkResult.Stat.NumChildren);
                    Assert.AreEqual(RingMasterException.Code.Ok, getChildrenResult.ErrCode);
                    Assert.AreEqual(3, getChildrenResult.Children.Count);
                    Assert.AreEqual(3, getChildrenResult.Stat.NumChildren);
                }
            }
        }
Beispiel #2
0
        public void TestWrongChildrenCountAfterFailedMulti()
        {
            TestWrongNumChildrenInStastAsync().GetAwaiter().GetResult();

            async Task TestWrongNumChildrenInStastAsync()
            {
                const string path = "/$rmbvt/test";
                var          stop = false;

                // Create a parent node with 3 children. During the test, the number of children is not expected
                // to change.
                using (var rm = new RingMasterClient(serverAddress, null, null, 10000))
                {
                    var ops = new List <Op>
                    {
                        Op.Create($"{path}/parent/child1", null, null, CreateMode.PersistentAllowPathCreation),
                        Op.Create($"{path}/parent/child2", null, null, CreateMode.PersistentAllowPathCreation),
                        Op.Create($"{path}/parent/child3", null, null, CreateMode.PersistentAllowPathCreation),
                    };

                    await rm.Multi(ops);
                }

                // Start multiple threads to stress the backend
                var tasks = Enumerable.Range(0, 2).Select(_ => Task.Run(async() =>
                {
                    using (var rm = new RingMasterClient(serverAddress, null, null, 10000))
                    {
                        var ops = new List <Op>();

                        while (!stop)
                        {
                            // Randomly add or delete children in Multi
                            ops.Clear();
                            ops.AddRange(
                                Enumerable.Range(1, 3).Select(
                                    x => Op.Delete($"{path}/parent/child{x}", -1, false)));

                            // Add one more operation to fail the multi, so nothing get committed, in other words the
                            // locklist will always abort.
                            ops.Add(Op.GetData(
                                        $"{path}/parent/nonexisting/node",
                                        Azure.Networking.Infrastructure.RingMaster.Requests.RequestGetData.GetDataOptions.None,
                                        null));
                            var result = (await rm.Multi(ops)).Last();
                            Assert.AreEqual(OpCode.Error, result.ResultType);
                            Assert.AreEqual(RingMasterException.Code.Nonode, result.ErrCode);

                            var children = await rm.GetChildren($"{path}/parent", null);
                            var stat     = await rm.Exists($"{path}/parent", null);

                            Assert.AreEqual(
                                children.Count,
                                stat.NumChildren,
                                $"Children count {children.Count} should be consistent with Stat {stat.NumChildren}");
                            Assert.AreEqual(
                                3,
                                stat.NumChildren,
                                "Number of children returned by Exists should not change");
                        }
                    }
                })).ToArray();

                var clock = Stopwatch.StartNew();

                while (clock.Elapsed.TotalMinutes < 60)
                {
                    await Task.Delay(1000);

                    if (tasks.Any(t => t.IsCompleted))
                    {
                        break;
                    }
                }

                stop = true;
                await Task.WhenAll(tasks);
            }
        }