Search in sources :

Example 1 with ChildData

use of org.apache.camel.component.zookeepermaster.group.internal.ChildData 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)

Aggregations

ChildData (org.apache.camel.component.zookeepermaster.group.internal.ChildData)1 ZooKeeperGroup (org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 RetryNTimes (org.apache.curator.retry.RetryNTimes)1 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)1 Test (org.junit.Test)1