コード例 #1
0
        public virtual void TestSomeNodes()
        {
            Timing           timing = new Timing();
            ChildReaper      reaper = null;
            CuratorFramework client = CuratorFrameworkFactory.NewClient(server.GetConnectString
                                                                            (), timing.Session(), timing.Connection(), new RetryOneTime(1));

            try
            {
                client.Start();
                Random r             = new Random();
                int    nonEmptyNodes = 0;
                for (int i = 0; i < 10; ++i)
                {
                    client.Create().CreatingParentsIfNeeded().ForPath("/test/" + Extensions.ToString
                                                                          (i));
                    if (r.NextBoolean())
                    {
                        client.Create().ForPath("/test/" + Extensions.ToString(i) + "/foo");
                        ++nonEmptyNodes;
                    }
                }
                reaper = new ChildReaper(client, "/test", Reaper.Mode.ReapUntilDelete, 1);
                reaper.Start();
                timing.ForWaiting().SleepABit();
                Stat stat = client.CheckExists().ForPath("/test");
                Assert.Equal(stat.GetNumChildren(), nonEmptyNodes);
            }
            finally
            {
                CloseableUtils.CloseQuietly(reaper);
                CloseableUtils.CloseQuietly(client);
            }
        }
コード例 #2
0
 /// <exception cref="System.Exception"/>
 private void CreatePersistentNode(string nodePath)
 {
     try
     {
         zkClient.Create().WithMode(CreateMode.Persistent).ForPath(nodePath);
     }
     catch (KeeperException.NodeExistsException)
     {
         Log.Debug(nodePath + " znode already exists !!");
     }
     catch (Exception e)
     {
         throw new IOException(nodePath + " znode could not be created !!", e);
     }
 }
コード例 #3
0
        public virtual void TestNamespace()
        {
            Timing           timing = new Timing();
            ChildReaper      reaper = null;
            CuratorFramework client = CuratorFrameworkFactory.Builder().ConnectString(server.
                                                                                      GetConnectString()).SessionTimeoutMs(timing.Session()).ConnectionTimeoutMs(timing
                                                                                                                                                                 .Connection()).RetryPolicy(new RetryOneTime(1)).Namespace("foo").Build();

            try
            {
                client.Start();
                for (int i = 0; i < 10; ++i)
                {
                    client.Create().CreatingParentsIfNeeded().ForPath("/test/" + Extensions.ToString
                                                                          (i));
                }
                reaper = new ChildReaper(client, "/test", Reaper.Mode.ReapUntilDelete, 1);
                reaper.Start();
                timing.ForWaiting().SleepABit();
                Stat stat = client.CheckExists().ForPath("/test");
                Assert.Equal(stat.GetNumChildren(), 0);
                stat = client.UsingNamespace(null).CheckExists().ForPath("/foo/test");
                NUnit.Framework.Assert.IsNotNull(stat);
                Assert.Equal(stat.GetNumChildren(), 0);
            }
            finally
            {
                CloseableUtils.CloseQuietly(reaper);
                CloseableUtils.CloseQuietly(client);
            }
        }
コード例 #4
0
ファイル: CuratorService.cs プロジェクト: orf53975/hadoop.net
 /// <summary>Create a directory.</summary>
 /// <remarks>Create a directory. It is not an error if it already exists</remarks>
 /// <param name="path">path to create</param>
 /// <param name="mode">mode for path</param>
 /// <param name="createParents">flag to trigger parent creation</param>
 /// <param name="acls">ACL for path</param>
 /// <exception cref="System.IO.IOException">any problem</exception>
 public virtual bool ZkMkPath(string path, CreateMode mode, bool createParents, IList
                              <ACL> acls)
 {
     CheckServiceLive();
     path = CreateFullPath(path);
     if (acls == null || acls.IsEmpty())
     {
         throw new NoPathPermissionsException(path, "Empty ACL list");
     }
     try
     {
         RegistrySecurity.AclListInfo aclInfo = new RegistrySecurity.AclListInfo(acls);
         if (Log.IsDebugEnabled())
         {
             Log.Debug("Creating path {} with mode {} and ACL {}", path, mode, aclInfo);
         }
         CreateBuilder createBuilder = curator.Create();
         createBuilder.WithMode(mode).WithACL(acls);
         if (createParents)
         {
             createBuilder.CreatingParentsIfNeeded();
         }
         createBuilder.ForPath(path);
     }
     catch (KeeperException.NodeExistsException e)
     {
         if (Log.IsDebugEnabled())
         {
             Log.Debug("path already present: {}", path, e);
         }
         return(false);
     }
     catch (Exception e)
     {
         throw OperationFailure(path, "mkdir() ", e, acls);
     }
     return(true);
 }
コード例 #5
0
        public virtual void TestMultiPath()
        {
            Timing           timing = new Timing();
            ChildReaper      reaper = null;
            CuratorFramework client = CuratorFrameworkFactory.NewClient(server.GetConnectString
                                                                            (), timing.Session(), timing.Connection(), new RetryOneTime(1));

            try
            {
                client.Start();
                for (int i = 0; i < 10; ++i)
                {
                    client.Create().CreatingParentsIfNeeded().ForPath("/test1/" + Extensions.ToString
                                                                          (i));
                    client.Create().CreatingParentsIfNeeded().ForPath("/test2/" + Extensions.ToString
                                                                          (i));
                    client.Create().CreatingParentsIfNeeded().ForPath("/test3/" + Extensions.ToString
                                                                          (i));
                }
                reaper = new ChildReaper(client, "/test2", Reaper.Mode.ReapUntilDelete, 1);
                reaper.Start();
                reaper.AddPath("/test1");
                timing.ForWaiting().SleepABit();
                Stat stat = client.CheckExists().ForPath("/test1");
                Assert.Equal(stat.GetNumChildren(), 0);
                stat = client.CheckExists().ForPath("/test2");
                Assert.Equal(stat.GetNumChildren(), 0);
                stat = client.CheckExists().ForPath("/test3");
                Assert.Equal(stat.GetNumChildren(), 10);
            }
            finally
            {
                CloseableUtils.CloseQuietly(reaper);
                CloseableUtils.CloseQuietly(client);
            }
        }