Пример #1
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);
            }
        }
 /// <exception cref="System.IO.IOException"/>
 public override void StartThreads()
 {
     if (!isExternalClient)
     {
         try
         {
             zkClient.Start();
         }
         catch (Exception e)
         {
             throw new IOException("Could not start Curator Framework", e);
         }
     }
     else
     {
         // If namespace parents are implicitly created, they won't have ACLs.
         // So, let's explicitly create them.
         CuratorFramework nullNsFw = zkClient.UsingNamespace(null);
         EnsurePath       ensureNs = nullNsFw.NewNamespaceAwareEnsurePath("/" + zkClient.GetNamespace
                                                                              ());
         try
         {
             ensureNs.Ensure(nullNsFw.GetZookeeperClient());
         }
         catch (Exception e)
         {
             throw new IOException("Could not create namespace", e);
         }
     }
     listenerThreadPool = Executors.NewSingleThreadExecutor();
     try
     {
         delTokSeqCounter = new SharedCount(zkClient, ZkDtsmSeqnumRoot, 0);
         if (delTokSeqCounter != null)
         {
             delTokSeqCounter.Start();
         }
     }
     catch (Exception e)
     {
         throw new IOException("Could not start Sequence Counter", e);
     }
     try
     {
         keyIdSeqCounter = new SharedCount(zkClient, ZkDtsmKeyidRoot, 0);
         if (keyIdSeqCounter != null)
         {
             keyIdSeqCounter.Start();
         }
     }
     catch (Exception e)
     {
         throw new IOException("Could not start KeyId Counter", e);
     }
     try
     {
         CreatePersistentNode(ZkDtsmMasterKeyRoot);
         CreatePersistentNode(ZkDtsmTokensRoot);
     }
     catch (Exception)
     {
         throw new RuntimeException("Could not create ZK paths");
     }
     try
     {
         keyCache = new PathChildrenCache(zkClient, ZkDtsmMasterKeyRoot, true);
         if (keyCache != null)
         {
             keyCache.Start(PathChildrenCache.StartMode.BuildInitialCache);
             keyCache.GetListenable().AddListener(new _PathChildrenCacheListener_340(this), listenerThreadPool
                                                  );
         }
     }
     catch (Exception e)
     {
         throw new IOException("Could not start PathChildrenCache for keys", e);
     }
     try
     {
         tokenCache = new PathChildrenCache(zkClient, ZkDtsmTokensRoot, true);
         if (tokenCache != null)
         {
             tokenCache.Start(PathChildrenCache.StartMode.BuildInitialCache);
             tokenCache.GetListenable().AddListener(new _PathChildrenCacheListener_368(this),
                                                    listenerThreadPool);
         }
     }
     catch (Exception e)
     {
         throw new IOException("Could not start PathChildrenCache for tokens", e);
     }
     base.StartThreads();
 }