Esempio n. 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);
            }
        }
Esempio n. 2
0
        public virtual void TestSimple()
        {
            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("/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);
            }
            finally
            {
                CloseableUtils.CloseQuietly(reaper);
                CloseableUtils.CloseQuietly(client);
            }
        }
Esempio n. 3
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void Close()
 {
     if (state.CompareAndSet(ChildReaper.State.Started, ChildReaper.State.Closed))
     {
         CloseableUtils.CloseQuietly(reaper);
         task.Cancel(true);
     }
 }
Esempio n. 4
0
        public void testBasic()
        {
            CuratorZookeeperClient client = new CuratorZookeeperClient(ZkDefaultHosts,
                                                                       DefaultSessionTimeout,
                                                                       DefaultConnectionTimeout,
                                                                       null,
                                                                       new RetryOneTime(1));
            SessionFailRetryLoop retryLoop = client.newSessionFailRetryLoop(SessionFailRetryLoop.Mode.FAIL);

            retryLoop.start();
            try
            {
                client.start();
                try
                {
                    while (retryLoop.shouldContinue())
                    {
                        try
                        {
                            RetryLoop.callWithRetry
                            (
                                client,
                                CallableUtils.FromFunc <object>(() =>
                            {
                                Task <Stat> existsTask = client.getZooKeeper().existsAsync("/foo/bar", false);
                                existsTask.Wait();
                                Assert.Null(existsTask.Result);
                                KillSession.kill(client.getZooKeeper(), ZkDefaultHosts, DefaultSessionTimeout);

                                client.getZooKeeper();
                                client.blockUntilConnectedOrTimedOut();
                                existsTask = client.getZooKeeper().existsAsync("/foo/bar", false);
                                existsTask.Wait();
                                Assert.Null(existsTask.Result);
                                return(null);
                            }
                                                                ));
                        }
                        catch (Exception e)
                        {
                            retryLoop.takeException(e);
                        }
                    }
                    Assert.Fail();
                }
                catch (SessionFailRetryLoop.SessionFailedException dummy)
                {
                    // correct
                }
            }
            finally
            {
                retryLoop.Dispose();
                CloseableUtils.closeQuietly(client);
            }
        }
Esempio n. 5
0
        private void closeClient()
        {
            lock (_closeLock)
            {
                if (cleanup != null)
                {
                    cleanup.shutdownNow();
                    cleanup = null;
                }

                if (client != null)
                {
                    CloseableUtils.closeQuietly(client);
                    client = null;
                }
            }
        }
Esempio n. 6
0
        public void Dispose()
        {
            log.Debug("Connection Closing");

            CloseableUtils.closeQuietly(ensembleProvider);
            try
            {
                zooKeeper.closeAndClear();
            }
            catch (Exception e)
            {
                ThreadUtils.checkInterrupted(e);
                throw new IOException("", e);
            }
            finally
            {
                _isConnected.set(false);
            }
        }
Esempio n. 7
0
        public void testRetryStatic()
        {
            CuratorZookeeperClient client = new CuratorZookeeperClient(ZkDefaultHosts,
                                                                       DefaultSessionTimeout,
                                                                       DefaultConnectionTimeout,
                                                                       null,
                                                                       new RetryOneTime(1));
            SessionFailRetryLoop retryLoop = client.newSessionFailRetryLoop(SessionFailRetryLoop.Mode.RETRY);

            retryLoop.start();
            try
            {
                client.start();
                AtomicBoolean secondWasDone = new AtomicBoolean(false);
                AtomicBoolean firstTime     = new AtomicBoolean(true);
                SessionFailRetryLoop.callWithRetry
                (
                    client,
                    SessionFailRetryLoop.Mode.RETRY,
                    CallableUtils.FromFunc <object>(() =>
                {
                    RetryLoop.callWithRetry(
                        client,
                        CallableUtils.FromFunc <object>(() =>
                    {
                        Task <Stat> existsTask;
                        if (firstTime.compareAndSet(true, false))
                        {
                            existsTask = client.getZooKeeper().existsAsync("/foo/bar", false);
                            existsTask.Wait();
                            Assert.Null(existsTask.Result);
                            KillSession.kill(client.getZooKeeper(), ZkDefaultHosts, DefaultSessionTimeout);
                            client.getZooKeeper();
                            client.blockUntilConnectedOrTimedOut();
                        }
                        existsTask = client.getZooKeeper().existsAsync("/foo/bar", false);
                        existsTask.Wait();
                        Assert.Null(existsTask.Result);
                        return(null);
                    }
                                                        ));

                    RetryLoop.callWithRetry
                    (
                        client,
                        CallableUtils.FromFunc <object>(() =>
                    {
                        Assert.False(firstTime.get());
                        Task <Stat> existsTask = client.getZooKeeper().existsAsync("/foo/bar", false);
                        existsTask.Wait();
                        Assert.Null(existsTask.Result);
                        secondWasDone.set(true);
                        return(null);
                    }
                                                        ));
                    return(null);
                }
                                                    ));

                Assert.True(secondWasDone.get());
            }
            finally
            {
                retryLoop.Dispose();
                CloseableUtils.closeQuietly(client);
            }
        }