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


Java Timing.sleepABit方法代码示例

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


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

示例1: testCuratorWatcher

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void testCuratorWatcher() throws Exception
{
    Timing timing = new Timing();
    CountCuratorWatcher watcher = new CountCuratorWatcher();
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
    try
    {
        client.start();
        client.create().forPath(PATH);
        // Add twice the same watcher on the same path
        client.getData().usingWatcher(watcher).forPath(PATH);
        client.getData().usingWatcher(watcher).forPath(PATH);
        // Ok, let's test it
        client.setData().forPath(PATH, new byte[]{});
        timing.sleepABit();
        Assert.assertEquals(1, watcher.count.get());
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:24,代码来源:TestWatcherIdentity.java

示例2: testQuickClose

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void testQuickClose() throws Exception
{
    Timing timing = new Timing();
    PersistentNode pen = null;
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
    try
    {
        client.start();
        pen = new PersistentNode(client, CreateMode.PERSISTENT, false, "/test/one/two", new byte[0]);
        pen.start();
        pen.close();
        timing.sleepABit();
        Assert.assertNull(client.checkExists().forPath("/test/one/two"));
    }
    finally
    {
        CloseableUtils.closeQuietly(pen);
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:22,代码来源:TestPersistentNode.java

示例3: testQuickCloseNodeExists

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void testQuickCloseNodeExists() throws Exception
{
    Timing timing = new Timing();
    PersistentNode pen = null;
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
    try
    {
        client.start();
        client.create().creatingParentsIfNeeded().forPath("/test/one/two");

        pen = new PersistentNode(client, CreateMode.PERSISTENT, false, "/test/one/two", new byte[0]);
        pen.start();
        pen.close();
        timing.sleepABit();
        Assert.assertNull(client.checkExists().forPath("/test/one/two"));
    }
    finally
    {
        CloseableUtils.closeQuietly(pen);
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:24,代码来源:TestPersistentNode.java

示例4: testBasic

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
private void testBasic(String namespace) throws Exception
{
    Timing timing = new Timing();
    Reaper reaper = null;
    CuratorFramework client = makeClient(timing, namespace);
    try
    {
        client.start();
        client.create().creatingParentsIfNeeded().forPath("/one/two/three");

        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));

        reaper = new Reaper(client, 100);
        reaper.start();

        reaper.addPath("/one/two/three");
        timing.sleepABit();

        Assert.assertNull(client.checkExists().forPath("/one/two/three"));
    }
    finally
    {
        CloseableUtils.closeQuietly(reaper);
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:27,代码来源:TestReaper.java

示例5: testSameWatcherPerZKDocs

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void testSameWatcherPerZKDocs() throws Exception
{
    CountZKWatcher actualWatcher = new CountZKWatcher();
    Timing timing = new Timing();
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
    try
    {
        client.start();
        client.create().forPath("/test");

        // per ZK docs, this watcher should only trigger once
        client.checkExists().usingWatcher(actualWatcher).forPath("/test");
        client.getData().usingWatcher(actualWatcher).forPath("/test");

        client.setData().forPath("/test", "foo".getBytes());
        client.delete().forPath("/test");
        timing.sleepABit();
        Assert.assertEquals(actualWatcher.count.getAndSet(0), 1);

        client.create().forPath("/test");
        client.checkExists().usingWatcher(actualWatcher).forPath("/test");
        client.delete().forPath("/test");
        timing.sleepABit();
        Assert.assertEquals(actualWatcher.count.get(), 1);
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:32,代码来源:TestWatcherIdentity.java

示例6: outdatedRemovalTest

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void outdatedRemovalTest() throws Exception {
  Timing timing = new Timing();

  OperationsNodeInfo endpointNodeInfo = buildOperationsNodeInfo();
  BootstrapNodeInfo bootstrapNodeInfo = buildBootstrapNodeInfo();

  BootstrapNode bootstrapNode = new BootstrapNode(bootstrapNodeInfo, zkClient);
  OperationsNodeListener mockListener = mock(OperationsNodeListener.class);
  bootstrapNode.addListener(mockListener);
  bootstrapNode.start();

  OperationsNode endpointNode = new OperationsNode(endpointNodeInfo, zkClient);

  endpointNode.start();
  timing.sleepABit();
  verify(mockListener).onNodeAdded(endpointNodeInfo);

  OperationsNodeInfo endpointNodeInfoWithGreaterTimeStarted = buildOperationsNodeInfo();
  OperationsNode endpointNodeWithGreaterTimeStarted = new OperationsNode(endpointNodeInfoWithGreaterTimeStarted, zkClient);

  endpointNodeWithGreaterTimeStarted.start();
  timing.sleepABit();

  endpointNode.close();
  timing.sleepABit();
  verify(mockListener, never()).onNodeRemoved(endpointNodeInfo);

  endpointNodeWithGreaterTimeStarted.close();
  timing.sleepABit();
  verify(mockListener).onNodeRemoved(endpointNodeInfoWithGreaterTimeStarted);

  bootstrapNode.close();
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:35,代码来源:OperationsNodeIT.java

示例7: testNull

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void testNull() throws InterruptedException
{
    Timing timing = new Timing();
    AutoCleanerHolder holder = new AutoCleanerHolder(null, Duration.ofDays(10));
    Assert.assertFalse(holder.shouldRun());
    Assert.assertFalse(holder.shouldRun());
    timing.sleepABit();
    Assert.assertFalse(holder.shouldRun());
    Assert.assertFalse(holder.shouldRun());

    Assert.assertNotNull(holder.getRunPeriod());
}
 
开发者ID:NirmataOSS,项目名称:workflow,代码行数:14,代码来源:TestAutoCleanerHolder.java

示例8: testSameWatcherDifferentKinds1Triggered

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void testSameWatcherDifferentKinds1Triggered() throws Exception
{
    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    try
    {
        client.start();
        WatcherRemovalFacade removerClient = (WatcherRemovalFacade)client.newWatcherRemoveCuratorFramework();
        final CountDownLatch latch = new CountDownLatch(1);
        Watcher watcher = new Watcher()
        {
            @Override
            public void process(WatchedEvent event)
            {
                latch.countDown();
            }
        };

        removerClient.create().creatingParentsIfNeeded().forPath("/a/b/c");
        removerClient.checkExists().usingWatcher(watcher).forPath("/a/b/c");
        removerClient.getData().usingWatcher(watcher).forPath("/a/b/c");
        removerClient.setData().forPath("/a/b/c", "new".getBytes());

        Timing timing = new Timing();
        Assert.assertTrue(timing.awaitLatch(latch));
        timing.sleepABit();

        removerClient.removeWatchers();
    }
    finally
    {
        TestCleanState.closeAndTestClean(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:35,代码来源:TestWatcherRemovalManager.java

示例9: testRemoveUnregisteredWatcherQuietly

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
/**
 * Test the case where we try and remove an unregistered watcher but have the quietly flag set. In this case we expect success. 
 * @throws Exception
 */
@Test
public void testRemoveUnregisteredWatcherQuietly() throws Exception
{
    Timing timing = new Timing();
    CuratorFramework client = CuratorFrameworkFactory.builder().
            connectString(server.getConnectString()).
            retryPolicy(new RetryOneTime(1)).
            build();
    try
    {
        client.start();
        
        final AtomicBoolean watcherRemoved = new AtomicBoolean(false);
        
        final String path = "/";            
        Watcher watcher = new BooleanWatcher(path, watcherRemoved, EventType.DataWatchRemoved);
        
        client.watches().remove(watcher).quietly().forPath(path);
        
        timing.sleepABit();
        
        //There should be no watcher removed as none were registered.
        Assert.assertEquals(watcherRemoved.get(), false);
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:34,代码来源:TestRemoveWatches.java

示例10: testEnsurePath

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void testEnsurePath() throws Exception
{
    Timing timing = new Timing();

    CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
    client.start();
    try
    {
        try ( PathChildrenCache cache = new PathChildrenCache(client, "/one/two/three", false) )
        {
            cache.start();
            timing.sleepABit();

            try
            {
                client.create().forPath("/one/two/three/four");
            }
            catch ( KeeperException.NoNodeException e )
            {
                Assert.fail("Path should exist", e);
            }
        }
        timing.sleepABit();
    }
    finally
    {
        TestCleanState.closeAndTestClean(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:31,代码来源:TestPathChildrenCache.java

示例11: waitForALeader

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
private ClientAndLatch waitForALeader(List<ClientAndLatch> latches, Timing timing) throws InterruptedException
{
    for ( int i = 0; i < MAX_LOOPS; ++i )
    {
        List<ClientAndLatch> leaders = getLeaders(latches);
        if ( leaders.size() != 0 )
        {
            return leaders.get(0);
        }
        timing.sleepABit();
    }
    return null;
}
 
开发者ID:apache,项目名称:curator,代码行数:14,代码来源:TestLeaderLatchCluster.java

示例12: testReapUntilDelete

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
private void testReapUntilDelete(String namespace) throws Exception
{
    Timing timing = new Timing();
    Reaper reaper = null;
    CuratorFramework client = makeClient(timing, namespace);
    try
    {
        client.start();
        client.create().creatingParentsIfNeeded().forPath("/one/two/three");

        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));

        reaper = new Reaper(client, 100);
        reaper.start();

        reaper.addPath("/one/two/three", Reaper.Mode.REAP_UNTIL_DELETE);
        timing.sleepABit();

        Assert.assertNull(client.checkExists().forPath("/one/two/three"));

        client.create().forPath("/one/two/three");
        timing.sleepABit();
        Assert.assertNotNull(client.checkExists().forPath("/one/two/three"));
    }
    finally
    {
        CloseableUtils.closeQuietly(reaper);
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:31,代码来源:TestReaper.java

示例13: testShutdown

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
/**
 * CURATOR-126
 * Shutdown the Curator client while there are still background operations running.
 */
@Test
public void testShutdown() throws Exception
{
    Timing timing = new Timing();
    CuratorFramework client = CuratorFrameworkFactory
        .builder()
        .connectString(server.getConnectString())
        .sessionTimeoutMs(timing.session())
        .connectionTimeoutMs(timing.connection()).retryPolicy(new RetryOneTime(1))
        .maxCloseWaitMs(timing.forWaiting().milliseconds())
        .build();
    try
    {
        final AtomicBoolean hadIllegalStateException = new AtomicBoolean(false);
        ((CuratorFrameworkImpl)client).debugUnhandledErrorListener = new UnhandledErrorListener()
        {
            @Override
            public void unhandledError(String message, Throwable e)
            {
                if ( e instanceof IllegalStateException )
                {
                    hadIllegalStateException.set(true);
                }
            }
        };
        client.start();

        final CountDownLatch operationReadyLatch = new CountDownLatch(1);
        ((CuratorFrameworkImpl)client).debugListener = new CuratorFrameworkImpl.DebugBackgroundListener()
        {
            @Override
            public void listen(OperationAndData<?> data)
            {
                try
                {
                    operationReadyLatch.await();
                }
                catch ( InterruptedException e )
                {
                    Thread.currentThread().interrupt();
                }
            }
        };

        // queue a background operation that will block due to the debugListener
        client.create().inBackground().forPath("/hey");
        timing.sleepABit();

        // close the client while the background is still blocked
        client.close();

        // unblock the background
        operationReadyLatch.countDown();
        timing.sleepABit();

        // should not generate an exception
        Assert.assertFalse(hadIllegalStateException.get());
    }
    finally
    {
        CloseableUtils.closeQuietly(client);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:68,代码来源:TestFrameworkBackground.java

示例14: testLargeNodes

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void testLargeNodes() throws Exception
{
    server.close();

    final int LARGE_QTY = 10000;
    final int SMALL_QTY = 100;

    System.setProperty("jute.maxbuffer", "" + LARGE_QTY);
    server = new TestingServer();
    try
    {
        Timing timing = new Timing();
        ChildReaper reaper = null;
        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new ExponentialBackoffRetry(100, 3));
        try
        {
            client.start();

            for ( int i = 0; i < LARGE_QTY; ++i )
            {
                if ( (i % 1000) == 0 )
                {
                    System.out.println(i);
                }
                client.create().creatingParentsIfNeeded().forPath("/big/node-" + i);

                if ( i < SMALL_QTY )
                {
                    client.create().creatingParentsIfNeeded().forPath("/small/node-" + i);
                }
            }

            reaper = new ChildReaper(client, "/foo", Reaper.Mode.REAP_UNTIL_DELETE, 1);
            reaper.start();

            reaper.addPath("/big");
            reaper.addPath("/small");

            int count = -1;
            for ( int i = 0; (i < 10) && (count != 0); ++i )
            {
                timing.sleepABit();
                count = client.checkExists().forPath("/small").getNumChildren();
            }
            Assert.assertEquals(count, 0);
        }
        finally
        {
            CloseableUtils.closeQuietly(reaper);
            CloseableUtils.closeQuietly(client);
        }
    }
    finally
    {
        System.clearProperty("jute.maxbuffer");
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:59,代码来源:TestChildReaper.java

示例15: testMultiClientVersioned

import org.apache.curator.test.Timing; //导入方法依赖的package包/类
@Test
public void testMultiClientVersioned() throws Exception
{
    Timing timing = new Timing();
    CuratorFramework client1 = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    CuratorFramework client2 = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
    SharedCount count1 = new SharedCount(client1, "/count", 0);
    SharedCount count2 = new SharedCount(client2, "/count", 0);
    try
    {
        client1.start();
        client2.start();
        count1.start();
        count2.start();

        VersionedValue<Integer> versionedValue = count1.getVersionedValue();
        Assert.assertTrue(count1.trySetCount(versionedValue, 10));
        timing.sleepABit();
        versionedValue = count2.getVersionedValue();
        Assert.assertTrue(count2.trySetCount(versionedValue, 20));
        timing.sleepABit();

        final CountDownLatch setLatch = new CountDownLatch(2);
        SharedCountListener listener = new SharedCountListener()
        {
            @Override
            public void countHasChanged(SharedCountReader sharedCount, int newCount) throws Exception
            {
                setLatch.countDown();
            }

            @Override
            public void stateChanged(CuratorFramework client, ConnectionState newState)
            {
                // nop
            }
        };
        count1.addListener(listener);
        VersionedValue<Integer> versionedValue1 = count1.getVersionedValue();
        VersionedValue<Integer> versionedValue2 = count2.getVersionedValue();
        Assert.assertTrue(count2.trySetCount(versionedValue2, 30));
        Assert.assertFalse(count1.trySetCount(versionedValue1, 40));

        versionedValue1 = count1.getVersionedValue();
        Assert.assertTrue(count1.trySetCount(versionedValue1, 40));
        Assert.assertTrue(timing.awaitLatch(setLatch));
    }
    finally
    {
        CloseableUtils.closeQuietly(count2);
        CloseableUtils.closeQuietly(count1);
        TestCleanState.closeAndTestClean(client2);
        TestCleanState.closeAndTestClean(client1);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:56,代码来源:TestSharedCount.java


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