Пример #1
0
        public void TestGetChildren()
        {
            using (var requestHandler = new TestRequestHandler())
                using (var client = new RingMasterClient(requestHandler))
                {
                    string path = this.GetRandomString();
                    string retrievalCondition = this.GetRandomString();
                    var    watcher            = new TestWatcher(this.GetRandomInt());
                    IReadOnlyList <string> expectedChildren = new string[] { this.GetRandomString(), this.GetRandomString() };

                    requestHandler.Implementation = request =>
                    {
                        Assert.IsTrue(request is RequestGetChildren);
                        var getChildrenRequest = (RequestGetChildren)request;
                        Assert.AreEqual(path, getChildrenRequest.Path);
                        Assert.AreEqual(watcher.Id, getChildrenRequest.Watcher.Id);

                        return(new RequestResponse()
                        {
                            ResultCode = (int)RingMasterException.Code.Ok,
                            Content = expectedChildren
                        });
                    };

                    client.SetWatcher(watcher);

                    var children = client.GetChildren(path, watch: true, retrievalCondition: retrievalCondition).Result;
                    Assert.AreEqual(expectedChildren.Count, children.Count);
                    for (int i = 0; i < expectedChildren.Count; i++)
                    {
                        Assert.AreEqual(expectedChildren[i], children[i]);
                    }
                }
        }
Пример #2
0
        public void TestGetData()
        {
            using (var requestHandler = new TestRequestHandler())
                using (var client = new RingMasterClient(requestHandler))
                {
                    string path         = this.GetRandomString();
                    var    watcher      = new TestWatcher(this.GetRandomInt());
                    byte[] expectedData = this.GetRandomData();

                    requestHandler.Implementation = request =>
                    {
                        Assert.IsTrue(request is RequestGetData);
                        var getDataRequest = (RequestGetData)request;
                        Assert.AreEqual(path, getDataRequest.Path);
                        Assert.AreEqual(watcher.Id, getDataRequest.Watcher.Id);

                        return(new RequestResponse()
                        {
                            ResultCode = (int)RingMasterException.Code.Ok,
                            Content = expectedData
                        });
                    };

                    client.SetWatcher(watcher);

                    var data = client.GetData(path, watch: true).Result;
                    CollectionAssert.AreEqual(expectedData, data);
                }
        }
Пример #3
0
        public void TestExists()
        {
            using (var requestHandler = new TestRequestHandler())
                using (var client = new RingMasterClient(requestHandler))
                {
                    string path         = this.GetRandomString();
                    var    version      = this.GetRandomInt();
                    var    watcher      = new TestWatcher(this.GetRandomInt());
                    var    expectedStat = new Stat()
                    {
                        Version = this.GetRandomInt()
                    };

                    requestHandler.Implementation = request =>
                    {
                        Assert.IsTrue(request is RequestExists);
                        var existsRequest = (RequestExists)request;
                        Assert.AreEqual(path, existsRequest.Path);
                        Assert.AreEqual(watcher.Id, existsRequest.Watcher.Id);

                        return(new RequestResponse()
                        {
                            ResultCode = (int)RingMasterException.Code.Ok,
                            Content = expectedStat
                        });
                    };

                    client.SetWatcher(watcher);

                    IStat stat = client.Exists(path, watch: true).Result;
                    Assert.IsNotNull(stat);
                    Assert.AreEqual(expectedStat.Version, stat.Version);
                }
        }