本文整理汇总了Java中org.apache.curator.test.Timing类的典型用法代码示例。如果您正苦于以下问题:Java Timing类的具体用法?Java Timing怎么用?Java Timing使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Timing类属于org.apache.curator.test包,在下文中一共展示了Timing类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: testZKWatcher
import org.apache.curator.test.Timing; //导入依赖的package包/类
@Test
public void testZKWatcher() throws Exception
{
Timing timing = new Timing();
CountZKWatcher watcher = new CountZKWatcher();
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
示例3: testCuratorCallbackOnError
import org.apache.curator.test.Timing; //导入依赖的package包/类
/**
* Attempt a background operation while Zookeeper server is down.
* Return code must be {@link org.apache.zookeeper.KeeperException.Code#CONNECTIONLOSS}
*/
@Test
public void testCuratorCallbackOnError() throws Exception
{
Timing timing = new Timing();
final CountDownLatch latch = new CountDownLatch(1);
try ( CuratorFramework client = CuratorFrameworkFactory.builder().connectString(server.getConnectString()).sessionTimeoutMs(timing.session()).connectionTimeoutMs(timing.connection()).retryPolicy(new RetryOneTime(1000)).build() )
{
client.start();
AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
// Stop the Zookeeper server
server.stop();
// Attempt to retrieve children list
async.getChildren().forPath("/").handle((children, e) -> {
if ( e instanceof KeeperException.ConnectionLossException )
{
latch.countDown();
}
return null;
});
// Check if the callback has been called with a correct return code
Assert.assertTrue(timing.awaitLatch(latch), "Callback has not been called by curator !");
}
}
开发者ID:apache,项目名称:curator,代码行数:28,代码来源:TestFrameworkBackground.java
示例4: testGetSequentialChildren
import org.apache.curator.test.Timing; //导入依赖的package包/类
@Test
public void testGetSequentialChildren() throws Exception
{
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
client.start();
try
{
Semaphore semaphore = new Semaphore(0);
AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
async.create().forPath("/head").thenRun(() -> {
for ( int i = 0; i < 10; ++i )
{
async.create().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath("/head/child").thenRun(semaphore::release);
}
});
Assert.assertTrue(new Timing().acquireSemaphore(semaphore, 10));
List<String> children = async.getChildren().forPath("/head").toCompletableFuture().get();
Assert.assertEquals(children.size(), 10);
}
finally
{
CloseableUtils.closeQuietly(client);
}
}
开发者ID:apache,项目名称:curator,代码行数:26,代码来源:TestFramework.java
示例5: 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
示例6: 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
示例7: testModes
import org.apache.curator.test.Timing; //导入依赖的package包/类
@Test
public void testModes() throws Exception
{
Timing timing = new Timing();
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
client.start();
try
{
client.create().forPath("/test");
for ( boolean cacheData : new boolean[]{false, true} )
{
internalTestMode(client, cacheData);
client.delete().forPath("/test/one");
client.delete().forPath("/test/two");
}
}
finally
{
TestCleanState.closeAndTestClean(client);
}
}
开发者ID:apache,项目名称:curator,代码行数:24,代码来源:TestPathChildrenCache.java
示例8: testBasic
import org.apache.curator.test.Timing; //导入依赖的package包/类
@Test
public void testBasic() throws Exception
{
Timing timing = new Timing();
DistributedDelayQueue<Long> queue = null;
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
client.start();
try
{
BlockingQueueConsumer<Long> consumer = new BlockingQueueConsumer<Long>(Mockito.mock(ConnectionStateListener.class));
queue = QueueBuilder.builder(client, consumer, new LongSerializer(), "/test").buildDelayQueue();
queue.start();
queue.put(1L, System.currentTimeMillis() + 1000);
Thread.sleep(100);
Assert.assertEquals(consumer.size(), 0); // delay hasn't been reached
Long value = consumer.take(timing.forWaiting().seconds(), TimeUnit.SECONDS);
Assert.assertEquals(value, Long.valueOf(1));
}
finally
{
CloseableUtils.closeQuietly(queue);
CloseableUtils.closeQuietly(client);
}
}
开发者ID:apache,项目名称:curator,代码行数:27,代码来源:TestDistributedDelayQueue.java
示例9: testSimple
import org.apache.curator.test.Timing; //导入依赖的package包/类
@Test
public void testSimple() throws Exception
{
Timing timing = new Timing();
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
client.start();
try
{
InterProcessSemaphoreV2 semaphore = new InterProcessSemaphoreV2(client, "/test", 1);
Assert.assertNotNull(semaphore.acquire(timing.forWaiting().seconds(), TimeUnit.SECONDS));
Assert.assertNull(semaphore.acquire(timing.forWaiting().seconds(), TimeUnit.SECONDS));
}
finally
{
TestCleanState.closeAndTestClean(client);
}
}
开发者ID:apache,项目名称:curator,代码行数:18,代码来源:TestInterProcessSemaphore.java
示例10: 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
示例11: testSomeNodes
import org.apache.curator.test.Timing; //导入依赖的package包/类
@Test
public void testSomeNodes() throws Exception
{
Timing timing = new Timing();
ChildReaper reaper = null;
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
try
{
client.start();
Random r = new Random();
int nonEmptyNodes = 0;
for ( int i = 0; i < 10; ++i )
{
client.create().creatingParentsIfNeeded().forPath("/test/" + Integer.toString(i));
if ( r.nextBoolean() )
{
client.create().forPath("/test/" + Integer.toString(i) + "/foo");
++nonEmptyNodes;
}
}
reaper = new ChildReaper(client, "/test", Reaper.Mode.REAP_UNTIL_DELETE, 1);
reaper.start();
timing.forWaiting().sleepABit();
Stat stat = client.checkExists().forPath("/test");
Assert.assertEquals(stat.getNumChildren(), nonEmptyNodes);
}
finally
{
CloseableUtils.closeQuietly(reaper);
CloseableUtils.closeQuietly(client);
}
}
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:38,代码来源:TestChildReaper.java
示例12: testSimple
import org.apache.curator.test.Timing; //导入依赖的package包/类
@Test
public void testSimple() throws Exception
{
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/" + Integer.toString(i));
}
reaper = new ChildReaper(client, "/test", Reaper.Mode.REAP_UNTIL_DELETE, 1);
reaper.start();
timing.forWaiting().sleepABit();
Stat stat = client.checkExists().forPath("/test");
Assert.assertEquals(stat.getNumChildren(), 0);
}
finally
{
CloseableUtils.closeQuietly(reaper);
CloseableUtils.closeQuietly(client);
}
}
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:30,代码来源:TestChildReaper.java
示例13: testMultiPath
import org.apache.curator.test.Timing; //导入依赖的package包/类
@Test
public void testMultiPath() throws Exception
{
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("/test1/" + Integer.toString(i));
client.create().creatingParentsIfNeeded().forPath("/test2/" + Integer.toString(i));
client.create().creatingParentsIfNeeded().forPath("/test3/" + Integer.toString(i));
}
reaper = new ChildReaper(client, "/test2", Reaper.Mode.REAP_UNTIL_DELETE, 1);
reaper.start();
reaper.addPath("/test1");
timing.forWaiting().sleepABit();
Stat stat = client.checkExists().forPath("/test1");
Assert.assertEquals(stat.getNumChildren(), 0);
stat = client.checkExists().forPath("/test2");
Assert.assertEquals(stat.getNumChildren(), 0);
stat = client.checkExists().forPath("/test3");
Assert.assertEquals(stat.getNumChildren(), 10);
}
finally
{
CloseableUtils.closeQuietly(reaper);
CloseableUtils.closeQuietly(client);
}
}
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:37,代码来源:TestChildReaper.java
示例14: testNamespace
import org.apache.curator.test.Timing; //导入依赖的package包/类
@Test
public void testNamespace() throws Exception
{
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/" + Integer.toString(i));
}
reaper = new ChildReaper(client, "/test", Reaper.Mode.REAP_UNTIL_DELETE, 1);
reaper.start();
timing.forWaiting().sleepABit();
Stat stat = client.checkExists().forPath("/test");
Assert.assertEquals(stat.getNumChildren(), 0);
stat = client.usingNamespace(null).checkExists().forPath("/foo/test");
Assert.assertNotNull(stat);
Assert.assertEquals(stat.getNumChildren(), 0);
}
finally
{
CloseableUtils.closeQuietly(reaper);
CloseableUtils.closeQuietly(client);
}
}
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:40,代码来源:TestChildReaper.java
示例15: setup
import org.apache.curator.test.Timing; //导入依赖的package包/类
@BeforeMethod
public void setup() throws Exception
{
timing = new Timing();
cluster = new TestingCluster(3);
cluster.start();
client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
client.start();
}
开发者ID:dcos,项目名称:exhibitor,代码行数:11,代码来源:TestZookeeperConfigProvider.java
示例16: 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
示例17: testSameCuratorWatcherPerZKDocs
import org.apache.curator.test.Timing; //导入依赖的package包/类
@Test
public void testSameCuratorWatcherPerZKDocs() throws Exception
{
CountCuratorWatcher actualWatcher = new CountCuratorWatcher();
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
示例18: testOverrideCreateParentContainers
import org.apache.curator.test.Timing; //导入依赖的package包/类
@Test
public void testOverrideCreateParentContainers() throws Exception
{
if ( !checkForContainers() )
{
return;
}
CuratorFramework client = CuratorFrameworkFactory.builder()
.connectString(server.getConnectString())
.retryPolicy(new RetryOneTime(1))
.dontUseContainerParents()
.build();
try
{
client.start();
client.create().creatingParentContainersIfNeeded().forPath("/one/two/three", "foo".getBytes());
byte[] data = client.getData().forPath("/one/two/three");
Assert.assertEquals(data, "foo".getBytes());
client.delete().forPath("/one/two/three");
new Timing().sleepABit();
Assert.assertNotNull(client.checkExists().forPath("/one/two"));
new Timing().sleepABit();
Assert.assertNotNull(client.checkExists().forPath("/one"));
}
finally
{
CloseableUtils.closeQuietly(client);
}
}
开发者ID:apache,项目名称:curator,代码行数:33,代码来源:TestFramework.java
示例19: testCreateParentContainers
import org.apache.curator.test.Timing; //导入依赖的package包/类
@Test
public void testCreateParentContainers() throws Exception
{
if ( !checkForContainers() )
{
return;
}
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
CuratorFramework client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).build();
try
{
client.start();
client.create().creatingParentContainersIfNeeded().forPath("/one/two/three", "foo".getBytes());
byte[] data = client.getData().forPath("/one/two/three");
Assert.assertEquals(data, "foo".getBytes());
client.delete().forPath("/one/two/three");
new Timing().sleepABit();
Assert.assertNull(client.checkExists().forPath("/one/two"));
new Timing().sleepABit();
Assert.assertNull(client.checkExists().forPath("/one"));
}
finally
{
CloseableUtils.closeQuietly(client);
}
}
开发者ID:apache,项目名称:curator,代码行数:30,代码来源:TestFramework.java
示例20: testSameWatcherDifferentPaths1Triggered
import org.apache.curator.test.Timing; //导入依赖的package包/类
@Test
public void testSameWatcherDifferentPaths1Triggered() 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.checkExists().usingWatcher(watcher).forPath("/a/b/c");
removerClient.checkExists().usingWatcher(watcher).forPath("/d/e/f");
removerClient.create().creatingParentsIfNeeded().forPath("/d/e/f");
Timing timing = new Timing();
Assert.assertTrue(timing.awaitLatch(latch));
timing.sleepABit();
removerClient.removeWatchers();
}
finally
{
TestCleanState.closeAndTestClean(client);
}
}
开发者ID:apache,项目名称:curator,代码行数:33,代码来源:TestWatcherRemovalManager.java
注:本文中的org.apache.curator.test.Timing类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论