Esempio n. 1
0
 internal SessionFailRetryLoop(CuratorZookeeperClient client, Mode mode)
 {
     this.client = client;
     this.mode   = mode;
     retryLoop   = client.newRetryLoop();
     watcher     = new SessionFailWatcher(this);
 }
Esempio n. 2
0
        public void testRetryLoop()
        {
            CuratorZookeeperClient client = new CuratorZookeeperClient(ZkDefaultHosts,
                                                                        DefaultSessionTimeout,
                                                                        DefaultConnectionTimeout,
                                                                        null,
                                                                        new RetryOneTime(1));
            client.start();
            try
            {
                int loopCount = 0;
                RetryLoop retryLoop = client.newRetryLoop();
                while ( retryLoop.shouldContinue()  )
                {
                    if ( ++loopCount > 2 )
                    {
                        Assert.Fail();
                        break;
                    }

                    try
                    {
                        client.getZooKeeper().createAsync("/test",
                                                            new byte[]{1,2,3},
                                                            ZooDefs.Ids.OPEN_ACL_UNSAFE,
                                                            CreateMode.EPHEMERAL)
                                             .Wait();
                        retryLoop.markComplete();
                    }
                    catch ( Exception e )
                    {
                        retryLoop.takeException(e);
                    }
                }

                Assert.True(loopCount > 0);
            }
            finally
            {
                client.Dispose();
            }
        }
Esempio n. 3
0
        /**
         * Convenience utility: creates a retry loop calling the given proc and retrying if needed
         *
         * @param client Zookeeper
         * @param proc procedure to call with retry
         * @param <T> return type
         * @return procedure result
         * @throws Exception any non-retriable errors
         */
        public static T callWithRetry <T>(CuratorZookeeperClient client,
                                          ICallable <T> proc)
        {
            T         result    = default(T);
            RetryLoop retryLoop = client.newRetryLoop();

            while (retryLoop.shouldContinue())
            {
                try
                {
                    client.internalBlockUntilConnectedOrTimedOut();

                    result = proc.call();
                    retryLoop.markComplete();
                }
                catch (Exception e)
                {
                    ThreadUtils.checkInterrupted(e);
                    retryLoop.takeException(e);
                }
            }
            return(result);
        }
Esempio n. 4
0
        public void testRetryLoopWithFailure()
        {
            CuratorZookeeperClient client = new CuratorZookeeperClient(ZkDefaultHosts,
                                                                        DefaultSessionTimeout,
                                                                        DefaultConnectionTimeout,
                                                                        null,
                                                                        new RetryOneTime(1));
            client.start();
            try
            {
                int loopCount = 0;
                RetryLoop retryLoop = client.newRetryLoop();
                while ( retryLoop.shouldContinue()  )
                {
                    ++loopCount;
                    switch ( loopCount )
                    {
                        case 1:
                        {
            //                            retryLoop.takeException();
                            break;
                        }

                        case 2:
                        {
                            retryLoop.markComplete();
                            break;
                        }

                        case 3:
                        case 4:
                        {
                            // ignore
                            break;
                        }

                        default:
                        {
                            Assert.Fail();
                            break;
                        }
                    }
                }

                Assert.True(loopCount >= 2);
            }
            finally
            {
                client.Dispose();
            }
        }