本文整理汇总了Java中org.apache.curator.test.Timing类的典型用法代码示例。如果您正苦于以下问题:Java Timing类的具体用法?Java Timing怎么用?Java Timing使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Timing类属于org.apache.curator.test包,在下文中一共展示了Timing类的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);
}
}
示例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);
}
}
示例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 !");
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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();
}