Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
        public async Task 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
                    {
                        var path = "/test";
                        if (await client.getZooKeeper().existsAsync(path, false) != null)
                        {
                            client.getZooKeeper().deleteAsync(path).Wait();
                        }

                        client.getZooKeeper().createAsync(path,
                                                          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();
            }
        }
Exemplo n.º 3
0
 internal RetryLoop newRetryLoop()
 {
     return(client.newRetryLoop());
 }