Search in sources :

Example 1 with RetryOneTime

use of org.apache.curator.retry.RetryOneTime in project hadoop by apache.

the class TestChildReaper method testNamespace.

@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);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) Stat(org.apache.zookeeper.data.Stat) Timing(org.apache.curator.test.Timing) Test(org.junit.Test)

Example 2 with RetryOneTime

use of org.apache.curator.retry.RetryOneTime in project hadoop by apache.

the class TestChildReaper method testMultiPath.

@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);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) Stat(org.apache.zookeeper.data.Stat) Timing(org.apache.curator.test.Timing) Test(org.junit.Test)

Example 3 with RetryOneTime

use of org.apache.curator.retry.RetryOneTime in project hadoop by apache.

the class TestChildReaper method testSomeNodes.

@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);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) Stat(org.apache.zookeeper.data.Stat) Random(java.util.Random) Timing(org.apache.curator.test.Timing) Test(org.junit.Test)

Example 4 with RetryOneTime

use of org.apache.curator.retry.RetryOneTime in project hadoop by apache.

the class TestChildReaper method testSimple.

@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);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) Stat(org.apache.zookeeper.data.Stat) Timing(org.apache.curator.test.Timing) Test(org.junit.Test)

Example 5 with RetryOneTime

use of org.apache.curator.retry.RetryOneTime in project hive by apache.

the class TestZookeeperLockManager method setup.

@Before
public void setup() {
    conf = new HiveConf();
    lockObjData = new HiveLockObjectData("1", "10", "SHARED", "show tables");
    hiveLock = new HiveLockObject(TABLE, lockObjData);
    zLock = new ZooKeeperHiveLock(TABLE_LOCK_PATH, hiveLock, HiveLockMode.SHARED);
    while (server == null) {
        try {
            server = new TestingServer();
            CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
            client = builder.connectString(server.getConnectString()).retryPolicy(new RetryOneTime(1)).build();
            client.start();
        } catch (Exception e) {
            System.err.println("Getting bind exception - retrying to allocate server");
            server = null;
        }
    }
}
Also used : TestingServer(org.apache.curator.test.TestingServer) HiveLockObject(org.apache.hadoop.hive.ql.lockmgr.HiveLockObject) RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) HiveLockObjectData(org.apache.hadoop.hive.ql.lockmgr.HiveLockObject.HiveLockObjectData) HiveConf(org.apache.hadoop.hive.conf.HiveConf) KeeperException(org.apache.zookeeper.KeeperException) Before(org.junit.Before)

Aggregations

RetryOneTime (org.apache.curator.retry.RetryOneTime)25 CuratorFramework (org.apache.curator.framework.CuratorFramework)16 Test (org.junit.Test)10 Timing (org.apache.curator.test.Timing)8 TestingServer (org.apache.curator.test.TestingServer)6 Stat (org.apache.zookeeper.data.Stat)4 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)2 TestingCluster (org.apache.curator.test.TestingCluster)2 ElectionCandidate (com.dangdang.ddframe.job.reg.base.ElectionCandidate)1 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)1 CuratorZKClientBridge (com.netflix.curator.x.zkclientbridge.CuratorZKClientBridge)1 PotentiallyGzippedCompressionProvider (io.druid.curator.PotentiallyGzippedCompressionProvider)1 Random (java.util.Random)1 NodeState (org.apache.camel.component.zookeepermaster.group.NodeState)1