Search in sources :

Example 6 with ChildData

use of io.fabric8.groups.internal.ChildData in project fabric8 by jboss-fuse.

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(io.fabric8.groups.internal.ChildData) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZooKeeperGroup(io.fabric8.groups.internal.ZooKeeperGroup) Test(org.junit.Test)

Aggregations

ServiceDTO (io.fabric8.gateway.ServiceDTO)3 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 ChildData (org.apache.curator.framework.recipes.cache.ChildData)3 NodeState (io.fabric8.groups.NodeState)2 PathChildrenCacheEvent (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ChildData (io.fabric8.groups.internal.ChildData)1 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 Type (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent.Type)1 RetryNTimes (org.apache.curator.retry.RetryNTimes)1 Stat (org.apache.zookeeper.data.Stat)1 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)1 Test (org.junit.Test)1