Search in sources :

Example 1 with RetryNTimes

use of org.apache.curator.retry.RetryNTimes in project storm by apache.

the class ZkState method newCurator.

private CuratorFramework newCurator(Map stateConf) throws Exception {
    Integer port = (Integer) stateConf.get(Config.TRANSACTIONAL_ZOOKEEPER_PORT);
    String serverPorts = "";
    for (String server : (List<String>) stateConf.get(Config.TRANSACTIONAL_ZOOKEEPER_SERVERS)) {
        serverPorts = serverPorts + server + ":" + port + ",";
    }
    return CuratorFrameworkFactory.newClient(serverPorts, Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT)), Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_CONNECTION_TIMEOUT)), new RetryNTimes(Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_RETRY_TIMES)), Utils.getInt(stateConf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL))));
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) List(java.util.List)

Example 2 with RetryNTimes

use of org.apache.curator.retry.RetryNTimes in project camel by apache.

the class GroupTest method testJoinBeforeConnect.

@Test
public void testJoinBeforeConnect() throws Exception {
    int port = findFreePort();
    CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
    curator.start();
    Group<NodeState> group = new ZooKeeperGroup<NodeState>(curator, "/singletons/test" + System.currentTimeMillis(), NodeState.class);
    group.add(listener);
    group.start();
    GroupCondition groupCondition = new GroupCondition();
    group.add(groupCondition);
    assertFalse(group.isConnected());
    assertFalse(group.isMaster());
    group.update(new NodeState("foo"));
    NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
    assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
    group.close();
    curator.close();
    cnxnFactory.shutdown();
    cnxnFactory.join();
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) ZooKeeperGroup(org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) Test(org.junit.Test)

Example 3 with RetryNTimes

use of org.apache.curator.retry.RetryNTimes in project camel by apache.

the class GroupTest method testJoinAfterConnect.

@Test
public void testJoinAfterConnect() throws Exception {
    int port = findFreePort();
    CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
    curator.start();
    final Group<NodeState> group = new ZooKeeperGroup<NodeState>(curator, "/singletons/test" + System.currentTimeMillis(), NodeState.class);
    group.add(listener);
    group.start();
    assertFalse(group.isConnected());
    assertFalse(group.isMaster());
    GroupCondition groupCondition = new GroupCondition();
    group.add(groupCondition);
    NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
    assertFalse(group.isMaster());
    group.update(new NodeState("foo"));
    assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
    group.close();
    curator.close();
    cnxnFactory.shutdown();
    cnxnFactory.join();
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) ZooKeeperGroup(org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) Test(org.junit.Test)

Example 4 with RetryNTimes

use of org.apache.curator.retry.RetryNTimes in project camel by apache.

the class GroupTest method testGroupClose.

//Tests that if close() is executed right after start(), there are no left over entries.
//(see  https://github.com/jboss-fuse/fuse/issues/133)
@Test
public void testGroupClose() throws Exception {
    int port = findFreePort();
    NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + port).connectionTimeoutMs(6000).sessionTimeoutMs(6000).retryPolicy(new RetryNTimes(10, 100));
    CuratorFramework curator = builder.build();
    curator.start();
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    String groupNode = "/singletons/test" + System.currentTimeMillis();
    curator.create().creatingParentsIfNeeded().forPath(groupNode);
    for (int i = 0; i < 100; i++) {
        ZooKeeperGroup<NodeState> group = new ZooKeeperGroup<NodeState>(curator, groupNode, NodeState.class);
        group.add(listener);
        group.update(new NodeState("foo"));
        group.start();
        group.close();
        List<String> entries = curator.getChildren().forPath(groupNode);
        assertTrue(entries.isEmpty() || group.isUnstable());
        if (group.isUnstable()) {
            // let's wait for session timeout
            curator.close();
            curator = builder.build();
            curator.start();
            curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
        }
    }
    curator.close();
    cnxnFactory.shutdown();
    cnxnFactory.join();
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZooKeeperGroup(org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup) Test(org.junit.Test)

Example 5 with RetryNTimes

use of org.apache.curator.retry.RetryNTimes in project camel by apache.

the class GroupTest method testRejoinAfterDisconnect.

@Test
public void testRejoinAfterDisconnect() throws Exception {
    int port = findFreePort();
    CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
    curator.start();
    NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
    Group<NodeState> group = new ZooKeeperGroup<NodeState>(curator, "/singletons/test" + System.currentTimeMillis(), NodeState.class);
    group.add(listener);
    group.update(new NodeState("foo"));
    group.start();
    GroupCondition groupCondition = new GroupCondition();
    group.add(groupCondition);
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
    assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
    cnxnFactory.shutdown();
    cnxnFactory.join();
    groupCondition.waitForDisconnected(5, TimeUnit.SECONDS);
    group.remove(groupCondition);
    assertFalse(group.isConnected());
    assertFalse(group.isMaster());
    groupCondition = new GroupCondition();
    group.add(groupCondition);
    cnxnFactory = startZooKeeper(port);
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
    assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
    group.close();
    curator.close();
    cnxnFactory.shutdown();
    cnxnFactory.join();
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZooKeeperGroup(org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup) Test(org.junit.Test)

Aggregations

RetryNTimes (org.apache.curator.retry.RetryNTimes)68 CuratorFramework (org.apache.curator.framework.CuratorFramework)51 Test (org.junit.Test)20 RetryPolicy (org.apache.curator.RetryPolicy)12 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)12 Test (org.testng.annotations.Test)11 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)8 IOException (java.io.IOException)6 ZooKeeperGroup (org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup)6 Before (org.junit.Before)6 ArrayList (java.util.ArrayList)5 TestingServer (org.apache.curator.test.TestingServer)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ConnectionState (org.apache.curator.framework.state.ConnectionState)4 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 BackgroundCallback (org.apache.curator.framework.api.BackgroundCallback)3 CuratorEvent (org.apache.curator.framework.api.CuratorEvent)3