Esempio n. 1
0
        public void TestSetACL()
        {
            using (var requestHandler = new TestRequestHandler())
                using (var client = new RingMasterClient(requestHandler))
                {
                    string path    = this.GetRandomString();
                    var    version = this.GetRandomInt();
                    var    acl     = new List <Acl>()
                    {
                        new Acl((int)Acl.Perm.ALL, new Id(AuthSchemes.Digest, this.GetRandomString()))
                    };
                    var expectedStat = new Stat()
                    {
                        Version = this.GetRandomInt()
                    };

                    requestHandler.Implementation = request =>
                    {
                        Assert.IsTrue(request is RequestSetAcl);
                        var setAclRequest = (RequestSetAcl)request;
                        Assert.AreEqual(path, setAclRequest.Path);
                        Assert.AreEqual(acl.Count, setAclRequest.Acl.Count);
                        Assert.IsTrue(Acl.AreEqual(acl[0], setAclRequest.Acl[0]));

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

                    var stat = client.SetACL(path, acl, version).Result;
                    Assert.AreEqual(expectedStat.Version, stat.Version);
                }
        }
Esempio n. 2
0
        public void TestCreateDontThrowIfNodeExists()
        {
            using (var requestHandler = new TestRequestHandler())
                using (var client = new RingMasterClient(requestHandler))
                {
                    string path = this.GetRandomString();
                    byte[] data = this.GetRandomData();
                    var    acl  = new List <Acl>()
                    {
                        new Acl((int)Acl.Perm.ALL, new Id(AuthSchemes.Digest, this.GetRandomString()))
                    };
                    var createMode     = CreateMode.Persistent;
                    var expectedResult = this.GetRandomString();

                    requestHandler.Implementation = request =>
                    {
                        Assert.IsTrue(request is RequestCreate);
                        var createRequest = (RequestCreate)request;
                        Assert.AreEqual(path, createRequest.Path);
                        Assert.AreEqual(data, createRequest.Data);
                        Assert.AreEqual(acl.Count, createRequest.Acl.Count);
                        Assert.IsTrue(Acl.AreEqual(acl[0], createRequest.Acl[0]));
                        Assert.AreEqual(createMode, createRequest.CreateMode);

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

                    client.Create(path, data, acl, createMode, throwIfNodeExists: false).Wait();
                }
        }
 /// <summary>
 /// Verify that the given Acl lists are equal.
 /// </summary>
 /// <param name="expected">Expected Acl list</param>
 /// <param name="actual">Actual Acl list</param>
 internal static void VerifyAclListsAreEqual(IReadOnlyList <Acl> expected, IReadOnlyList <Acl> actual)
 {
     Assert.AreEqual(expected.Count, actual.Count);
     for (int i = 0; i < expected.Count; i++)
     {
         Assert.IsTrue(Acl.AreEqual(expected[i], actual[i]));
     }
 }
Esempio n. 4
0
        public void TestCreateAndGetStat()
        {
            using (var requestHandler = new TestRequestHandler())
                using (var client = new RingMasterClient(requestHandler))
                {
                    string path = this.GetRandomString();
                    byte[] data = this.GetRandomData();
                    var    acl  = new List <Acl>()
                    {
                        new Acl((int)Acl.Perm.ALL, new Id(AuthSchemes.Digest, this.GetRandomString()))
                    };
                    var createMode   = CreateMode.Persistent;
                    var expectedStat = new Stat()
                    {
                        Version = this.GetRandomInt()
                    };

                    requestHandler.Implementation = request =>
                    {
                        Assert.IsTrue(request is RequestCreate);
                        var createRequest = (RequestCreate)request;
                        Assert.AreEqual(path, createRequest.Path);
                        Assert.AreEqual(data, createRequest.Data);
                        Assert.AreEqual(acl.Count, createRequest.Acl.Count);
                        Assert.IsTrue(Acl.AreEqual(acl[0], createRequest.Acl[0]));
                        Assert.AreEqual(createMode, createRequest.CreateMode);

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

                    IStat stat = client.CreateAndGetStat(path, data, acl, createMode).Result;
                    Assert.AreEqual(expectedStat.Version, stat.Version);
                }
        }