Search in sources :

Example 36 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework 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 37 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework 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 38 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework 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)

Example 39 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project camel by apache.

the class GroupTest method testAddFieldIgnoredOnParse.

@Test
public void testAddFieldIgnoredOnParse() throws Exception {
    int port = findFreePort();
    NIOServerCnxnFactory cnxnFactory = startZooKeeper(port);
    CuratorFramework curator = CuratorFrameworkFactory.builder().connectString("localhost:" + port).retryPolicy(new RetryNTimes(10, 100)).build();
    curator.start();
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    String groupNode = "/singletons/test" + System.currentTimeMillis();
    curator.create().creatingParentsIfNeeded().forPath(groupNode);
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    final ZooKeeperGroup<NodeState> group = new ZooKeeperGroup<NodeState>(curator, groupNode, NodeState.class);
    group.add(listener);
    group.start();
    GroupCondition groupCondition = new GroupCondition();
    group.add(groupCondition);
    group.update(new NodeState("foo"));
    assertTrue(groupCondition.waitForConnected(5, TimeUnit.SECONDS));
    assertTrue(groupCondition.waitForMaster(5, TimeUnit.SECONDS));
    ChildData currentData = group.getCurrentData().get(0);
    final int version = currentData.getStat().getVersion();
    NodeState lastState = group.getLastState();
    String json = lastState.toString();
    System.err.println("JSON:" + json);
    String newValWithNewField = json.substring(0, json.lastIndexOf('}')) + ",\"Rubbish\":\"Rubbish\"}";
    curator.getZookeeperClient().getZooKeeper().setData(group.getId(), newValWithNewField.getBytes(), version);
    assertTrue(group.isMaster());
    int attempts = 0;
    while (attempts++ < 5 && version == group.getCurrentData().get(0).getStat().getVersion()) {
        TimeUnit.SECONDS.sleep(1);
    }
    assertNotEquals("We see the updated version", version, group.getCurrentData().get(0).getStat().getVersion());
    System.err.println("CurrentData:" + group.getCurrentData());
    group.close();
    curator.close();
    cnxnFactory.shutdown();
    cnxnFactory.join();
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) ChildData(org.apache.camel.component.zookeepermaster.group.internal.ChildData) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZooKeeperGroup(org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup) Test(org.junit.Test)

Example 40 with CuratorFramework

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFramework in project flink by apache.

the class Kafka08ITCase method testInvalidOffset.

@Test(timeout = 60000)
public void testInvalidOffset() throws Exception {
    final int parallelism = 1;
    // write 20 messages into topic:
    final String topic = writeSequence("invalidOffsetTopic", 20, parallelism, 1);
    // set invalid offset:
    CuratorFramework curatorClient = ((KafkaTestEnvironmentImpl) kafkaServer).createCuratorClient();
    ZookeeperOffsetHandler.setOffsetInZooKeeper(curatorClient, standardProps.getProperty("group.id"), topic, 0, 1234);
    curatorClient.close();
    // read from topic
    final int valuesCount = 20;
    final int startFrom = 0;
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.createRemoteEnvironment("localhost", flinkPort);
    env.getConfig().disableSysoutLogging();
    readSequence(env, StartupMode.GROUP_OFFSETS, null, standardProps, parallelism, topic, valuesCount, startFrom);
    deleteTestTopic(topic);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Test(org.junit.Test)

Aggregations

CuratorFramework (org.apache.curator.framework.CuratorFramework)924 Test (org.testng.annotations.Test)290 RetryOneTime (org.apache.curator.retry.RetryOneTime)271 Test (org.junit.Test)199 Timing (org.apache.curator.test.Timing)147 CountDownLatch (java.util.concurrent.CountDownLatch)124 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)114 KeeperException (org.apache.zookeeper.KeeperException)93 IOException (java.io.IOException)79 ConnectionState (org.apache.curator.framework.state.ConnectionState)71 CuratorEvent (org.apache.curator.framework.api.CuratorEvent)58 ExecutorService (java.util.concurrent.ExecutorService)55 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)53 ArrayList (java.util.ArrayList)51 RetryNTimes (org.apache.curator.retry.RetryNTimes)51 RetryPolicy (org.apache.curator.RetryPolicy)41 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)38 Cleanup (lombok.Cleanup)37 BackgroundCallback (org.apache.curator.framework.api.BackgroundCallback)37 Stat (org.apache.zookeeper.data.Stat)36