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();
}
Aggregations