当前位置: 首页>>代码示例>>Java>>正文


Java Timing.session方法代码示例

本文整理汇总了Java中org.apache.curator.test.Timing.session方法的典型用法代码示例。如果您正苦于以下问题:Java Timing.session方法的具体用法?Java Timing.session怎么用?Java Timing.session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.curator.test.Timing的用法示例。


在下文中一共展示了Timing.session方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSimple

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void     testSimple() throws Exception
{
    Exhibitors                  exhibitors = new Exhibitors(Lists.newArrayList("foo", "bar"), 1000, dummyConnectionStringProvider);
    ExhibitorRestClient         mockRestClient = new ExhibitorRestClient()
    {
        @Override
        public String getRaw(String hostname, int port, String uriPath, String mimeType) throws Exception
        {
            return "count=1&port=" + server.getPort() + "&server0=localhost";
        }
    };
    ExhibitorEnsembleProvider   provider = new ExhibitorEnsembleProvider(exhibitors, mockRestClient, "/foo", 10, new RetryOneTime(1));
    provider.pollForInitialEnsemble();

    Timing                      timing = new Timing();
    CuratorZookeeperClient      client = new CuratorZookeeperClient(provider, timing.session(), timing.connection(), null, new ExponentialBackoffRetry(timing.milliseconds(), 3));
    client.start();
    try
    {
        client.blockUntilConnectedOrTimedOut();
        client.getZooKeeper().exists("/", false);
    }
    catch ( Exception e )
    {
        Assert.fail("provider.getConnectionString(): " + provider.getConnectionString() + " server.getPort(): " + server.getPort(), e);
    }
    finally
    {
        client.close();
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:33,代码来源:TestExhibitorEnsembleProvider.java

示例2: testChanging

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void     testChanging() throws Exception
{
    TestingServer               secondServer = new TestingServer();
    try
    {
        String                          mainConnectionString = "count=1&port=" + server.getPort() + "&server0=localhost";
        String                          secondConnectionString = "count=1&port=" + secondServer.getPort() + "&server0=localhost";

        final Semaphore                 semaphore = new Semaphore(0);
        final AtomicReference<String>   connectionString = new AtomicReference<String>(mainConnectionString);
        Exhibitors                      exhibitors = new Exhibitors(Lists.newArrayList("foo", "bar"), 1000, dummyConnectionStringProvider);
        ExhibitorRestClient             mockRestClient = new ExhibitorRestClient()
        {
            @Override
            public String getRaw(String hostname, int port, String uriPath, String mimeType) throws Exception
            {
                semaphore.release();
                return connectionString.get();
            }
        };
        ExhibitorEnsembleProvider   provider = new ExhibitorEnsembleProvider(exhibitors, mockRestClient, "/foo", 10, new RetryOneTime(1));
        provider.pollForInitialEnsemble();

        Timing                          timing = new Timing().multiple(4);
        final CuratorZookeeperClient    client = new CuratorZookeeperClient(provider, timing.session(), timing.connection(), null, new RetryOneTime(2));
        client.start();
        try
        {
            RetryLoop.callWithRetry
            (
                client,
                new Callable<Object>()
                {
                    @Override
                    public Object call() throws Exception
                    {
                        client.getZooKeeper().create("/test", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                        return null;
                    }
                }
            );

            connectionString.set(secondConnectionString);
            semaphore.drainPermits();
            semaphore.acquire();

            server.stop();  // create situation where the current zookeeper gets a sys-disconnected

            Stat        stat = RetryLoop.callWithRetry
            (
                client,
                new Callable<Stat>()
                {
                    @Override
                    public Stat call() throws Exception
                    {
                        return client.getZooKeeper().exists("/test", false);
                    }
                }
            );
            Assert.assertNull(stat);    // it's a different server so should be null
        }
        finally
        {
            client.close();
        }
    }
    finally
    {
        CloseableUtils.closeQuietly(secondServer);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:74,代码来源:TestExhibitorEnsembleProvider.java

示例3: testRetry

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void     testRetry() throws Exception
{
    Timing                          timing = new Timing();
    final CuratorZookeeperClient    client = new CuratorZookeeperClient(server.getConnectString(), timing.session(), timing.connection(), null, new ExponentialBackoffRetry(100, 3));
    SessionFailRetryLoop            retryLoop = client.newSessionFailRetryLoop(SessionFailRetryLoop.Mode.RETRY);
    retryLoop.start();
    try
    {
        client.start();
        final AtomicBoolean     secondWasDone = new AtomicBoolean(false);
        final AtomicBoolean     firstTime = new AtomicBoolean(true);
        while ( retryLoop.shouldContinue() )
        {
            try
            {
                RetryLoop.callWithRetry
                (
                    client,
                    new Callable<Void>()
                    {
                        @Override
                        public Void call() throws Exception
                        {
                            if ( firstTime.compareAndSet(true, false) )
                            {
                                Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                                KillSession2.kill(client.getZooKeeper());
                                client.getZooKeeper();
                                client.blockUntilConnectedOrTimedOut();
                            }

                            Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                            return null;
                        }
                    }
                );

                RetryLoop.callWithRetry
                (
                    client,
                    new Callable<Void>()
                    {
                        @Override
                        public Void call() throws Exception
                        {
                            Assert.assertFalse(firstTime.get());
                            Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                            secondWasDone.set(true);
                            return null;
                        }
                    }
                );
            }
            catch ( Exception e )
            {
                retryLoop.takeException(e);
            }
        }

        Assert.assertTrue(secondWasDone.get());
    }
    finally
    {
        retryLoop.close();
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:69,代码来源:TestSessionFailRetryLoop.java

示例4: testRetryStatic

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void     testRetryStatic() throws Exception
{
    Timing                          timing = new Timing();
    final CuratorZookeeperClient    client = new CuratorZookeeperClient(server.getConnectString(), timing.session(), timing.connection(), null, new ExponentialBackoffRetry(100, 3));
    SessionFailRetryLoop            retryLoop = client.newSessionFailRetryLoop(SessionFailRetryLoop.Mode.RETRY);
    retryLoop.start();
    try
    {
        client.start();
        final AtomicBoolean     secondWasDone = new AtomicBoolean(false);
        final AtomicBoolean     firstTime = new AtomicBoolean(true);
        SessionFailRetryLoop.callWithRetry
        (
            client,
            SessionFailRetryLoop.Mode.RETRY,
            new Callable<Object>()
            {
                @Override
                public Object call() throws Exception
                {
                    RetryLoop.callWithRetry
                    (
                        client,
                        new Callable<Void>()
                        {
                            @Override
                            public Void call() throws Exception
                            {
                                if ( firstTime.compareAndSet(true, false) )
                                {
                                    Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                                    KillSession2.kill(client.getZooKeeper());
                                    client.getZooKeeper();
                                    client.blockUntilConnectedOrTimedOut();
                                }

                                Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                                return null;
                            }
                        }
                    );

                    RetryLoop.callWithRetry
                    (
                        client,
                        new Callable<Void>()
                        {
                            @Override
                            public Void call() throws Exception
                            {
                                Assert.assertFalse(firstTime.get());
                                Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                                secondWasDone.set(true);
                                return null;
                            }
                        }
                    );
                    return null;
                }
            }
        );

        Assert.assertTrue(secondWasDone.get());
    }
    finally
    {
        retryLoop.close();
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:72,代码来源:TestSessionFailRetryLoop.java

示例5: testBasic

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void     testBasic() throws Exception
{
    final Timing                          timing = new Timing();
    final CuratorZookeeperClient    client = new CuratorZookeeperClient(server.getConnectString(), timing.session(), timing.connection(), null, new ExponentialBackoffRetry(100, 3));
    SessionFailRetryLoop            retryLoop = client.newSessionFailRetryLoop(SessionFailRetryLoop.Mode.FAIL);
    retryLoop.start();
    try
    {
        client.start();
        try
        {
            while ( retryLoop.shouldContinue() )
            {
                try
                {
                    RetryLoop.callWithRetry
                    (
                        client,
                        new Callable<Void>()
                        {
                            @Override
                            public Void call() throws Exception
                            {
                                Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                                KillSession2.kill(client.getZooKeeper());

                                timing.sleepABit();

                                client.getZooKeeper();
                                client.blockUntilConnectedOrTimedOut();
                                Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                                return null;
                            }
                        }
                    );
                }
                catch ( Exception e )
                {
                    retryLoop.takeException(e);
                }
            }

            Assert.fail();
        }
        catch ( SessionFailRetryLoop.SessionFailedException dummy )
        {
            // correct
        }
    }
    finally
    {
        retryLoop.close();
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:57,代码来源:TestSessionFailRetryLoop.java

示例6: testBasicStatic

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void     testBasicStatic() throws Exception
{
    Timing                          timing = new Timing();
    final CuratorZookeeperClient    client = new CuratorZookeeperClient(server.getConnectString(), timing.session(), timing.connection(), null, new ExponentialBackoffRetry(100, 3));
    SessionFailRetryLoop            retryLoop = client.newSessionFailRetryLoop(SessionFailRetryLoop.Mode.FAIL);
    retryLoop.start();
    try
    {
        client.start();
        try
        {
            SessionFailRetryLoop.callWithRetry
            (
                client,
                SessionFailRetryLoop.Mode.FAIL,
                new Callable<Object>()
                {
                    @Override
                    public Object call() throws Exception
                    {
                        RetryLoop.callWithRetry
                        (
                            client,
                            new Callable<Void>()
                            {
                                @Override
                                public Void call() throws Exception
                                {
                                    Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                                    KillSession2.kill(client.getZooKeeper());

                                    client.getZooKeeper();
                                    client.blockUntilConnectedOrTimedOut();
                                    Assert.assertNull(client.getZooKeeper().exists("/foo/bar", false));
                                    return null;
                                }
                            }
                        );
                        return null;
                    }
                }
            );
        }
        catch ( SessionFailRetryLoop.SessionFailedException dummy )
        {
            // correct
        }
    }
    finally
    {
        retryLoop.close();
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:56,代码来源:TestSessionFailRetryLoop.java

示例7: testExpiredSession

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void     testExpiredSession() throws Exception
{
    // see http://wiki.apache.org/hadoop/ZooKeeper/FAQ#A4

    final Timing                  timing = new Timing();

    final CountDownLatch    latch = new CountDownLatch(1);
    Watcher                 watcher = new Watcher()
    {
        @Override
        public void process(WatchedEvent event)
        {
            if ( event.getState() == Event.KeeperState.Expired )
            {
                latch.countDown();
            }
        }
    };

    final CuratorZookeeperClient client = new CuratorZookeeperClient(server.getConnectString(), timing.session(), timing.connection(), watcher, new RetryOneTime(2));
    client.start();
    try
    {
        final AtomicBoolean     firstTime = new AtomicBoolean(true);
        RetryLoop.callWithRetry
        (
            client,
            new Callable<Object>()
            {
                @Override
                public Object call() throws Exception
                {
                    if ( firstTime.compareAndSet(true, false) )
                    {
                        try
                        {
                            client.getZooKeeper().create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                        }
                        catch ( KeeperException.NodeExistsException ignore )
                        {
                            // ignore
                        }

                        KillSession2.kill(client.getZooKeeper());

                        Assert.assertTrue(timing.awaitLatch(latch));
                    }
                    ZooKeeper zooKeeper = client.getZooKeeper();
                    client.blockUntilConnectedOrTimedOut();
                    Assert.assertNotNull(zooKeeper.exists("/foo", false));
                    return null;
                }
            }
        );
    }
    finally
    {
        client.close();
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:62,代码来源:BasicTests.java


注:本文中的org.apache.curator.test.Timing.session方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。