Examples of ZooKeeper


Examples of org.apache.zookeeper.ZooKeeper

    this.clearUpZK(zk);
    this.clearUpFiles(TestConf.tmpPath);
  }
 
  public void testSetConfigOK() throws Exception {
    ZooKeeper zk = this.initZK();
   
    CountDownLatch connectedSignal = new CountDownLatch(1);
    IService iservice = new IService(TestConf.host,null,null,null,"./src/test/tmp");   
    iservice.setEventHandle(Constants.CONNECT_EVENT, new TestHandler(connectedSignal));
    iservice.init();
    connectedSignal.await();
   
    Config config = iservice.createConfig("/iserviceTest/node1");
    DefaultData data = (DefaultData) config.get("node3", 123);
    Assert.assertEquals("node3", data.getData());
   
   
    CountDownLatch connectedSignal2 = new CountDownLatch(1);
    config.setEventHandle(Constants.DATA_CHANGE_EVENT, new TestHandler(connectedSignal2));
   
    zk.setData("/iserviceTest/node1/node3", "new-node3".getBytes(), -1);
    zk.setData("/iserviceTest/node1", "new-node1".getBytes(), -1);
    connectedSignal2.await();
    DefaultData data2 = (DefaultData) config.get("node3", 123);
    Assert.assertEquals("new-node3", data2.getData());
   
    this.clearUpZK(zk);
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

    this.clearUpFiles(TestConf.tmpPath);
  }
 
  // change local file before update
  public void testSetConfigOK2() throws Exception{
    ZooKeeper zk = this.initZK();
   
    CountDownLatch connectedSignal = new CountDownLatch(1);
    IService iservice = new IService(TestConf.host,null,null,null,"./src/test/tmp");   
    iservice.setEventHandle(Constants.CONNECT_EVENT, new TestHandler(connectedSignal));
    iservice.init();
    connectedSignal.await();
   
    Config config = iservice.createConfig("/iserviceTest/node1");
    DefaultData data = (DefaultData) config.get("node3", 123);
    Assert.assertEquals("node3", data.getData());
   
    FS.dump(TestConf.tmpPath + "/" + Extends.getPid() + "/iserviceTest/node1/node4.data", "version:1\r\nnew-node4");
   
    CountDownLatch connectedSignal2 = new CountDownLatch(1);
    config.setEventHandle(Constants.DUMP_FAIL_EVENT, new TestHandler(connectedSignal2));
   
    zk.setData("/iserviceTest/node1/node3", "new-node3".getBytes(), -1);
    zk.setData("/iserviceTest/node1", "new-node1".getBytes(), -1);
    connectedSignal2.await();
    DefaultData data2 = (DefaultData) config.get("node3", 123);
    Assert.assertEquals("node3", data2.getData());
   
    this.clearUpZK(zk);
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

   
    this.clearUpFiles(TestConf.tmpPath);
  }
 
  public ZooKeeper initZK() throws Exception{
    ZooKeeper zk = new ZooKeeper(TestConf.host, Constants.SESSION_TIMEOUT, null);
    List<ACL> acls = new ArrayList<ACL>();
    acls.add(new ACL(Perms.ALL, Ids.ANYONE_ID_UNSAFE));
    zk.create("/iserviceTest", "root".getBytes(), acls, CreateMode.PERSISTENT);
    zk.create("/iserviceTest/node1", "node1".getBytes(), acls, CreateMode.PERSISTENT);
    zk.create("/iserviceTest/node2", "node2".getBytes(), acls, CreateMode.PERSISTENT);
    zk.create("/iserviceTest/node1/node3", "node3".getBytes(), acls, CreateMode.PERSISTENT);
    zk.create("/iserviceTest/node1/node4", "node4".getBytes(), acls, CreateMode.PERSISTENT);
    return zk;
  }
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

  private ZooKeeper zk;
  private int count;
 
  public ChangeZkTask2(String host, String root) throws IOException{
    this.zk = new ZooKeeper(host + root, Constants.SESSION_TIMEOUT, null);
    this.count = 0;
  }
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

   
  }
 
 
  public void initZk() throws Exception{
    ZooKeeper zk = new ZooKeeper(DemoConf.host + DemoConf.root, Constants.SESSION_TIMEOUT, null);
    List<ACL> acls = new ArrayList<ACL>();
    acls.add(new ACL(Perms.ALL, Ids.ANYONE_ID_UNSAFE));
   
    if(zk.exists("/IserviceDemoTest", false) == null){
      zk.create("/IserviceDemoTest", "".getBytes(), acls, CreateMode.PERSISTENT);
      zk.create("/IserviceDemoTest/group1", "".getBytes(), acls, CreateMode.PERSISTENT);
      zk.create("/IserviceDemoTest/group2", "".getBytes(), acls, CreateMode.PERSISTENT);
      zk.create("/IserviceDemoTest/group1/app1", "".getBytes(), acls, CreateMode.PERSISTENT);
      zk.create("/IserviceDemoTest/group1/app2", "".getBytes(), acls, CreateMode.PERSISTENT);
      zk.create("/IserviceDemoTest/group1/app2/key1", "in group1/app2, i'm key1 version-1".getBytes(), acls, CreateMode.PERSISTENT);
      zk.create("/IserviceDemoTest/group1/app2/key2", "".getBytes(), acls, CreateMode.PERSISTENT);
   

  }
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

  private ZooKeeper zk;
  private int count;
 
  public ChangeZkTask(String host, String root) throws IOException{
    this.zk = new ZooKeeper(host + root, Constants.SESSION_TIMEOUT, null);
    this.count = 0;
  }
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

    timer.schedule(task, 0, 10000);
   
  }
 
  public void initZk() throws Exception{
    ZooKeeper zk = new ZooKeeper(DemoConf.host + DemoConf.root, Constants.SESSION_TIMEOUT, null);
    List<ACL> acls = new ArrayList<ACL>();
    acls.add(new ACL(Perms.ALL, Ids.ANYONE_ID_UNSAFE));
   
    if(zk.exists("/IserviceDemoTest", false) == null){
      zk.create("/IserviceDemoTest", "".getBytes(), acls, CreateMode.PERSISTENT);
      zk.create("/IserviceDemoTest/group1", "".getBytes(), acls, CreateMode.PERSISTENT);
      zk.create("/IserviceDemoTest/group2", "".getBytes(), acls, CreateMode.PERSISTENT);
      zk.create("/IserviceDemoTest/group1/app1", "".getBytes(), acls, CreateMode.PERSISTENT);
      zk.create("/IserviceDemoTest/group1/app2", "".getBytes(), acls, CreateMode.PERSISTENT);
      zk.create("/IserviceDemoTest/group1/app2/key1", "in group1/app2, i'm key1 version-1".getBytes(), acls, CreateMode.PERSISTENT);
      zk.create("/IserviceDemoTest/group1/app2/key2", "".getBytes(), acls, CreateMode.PERSISTENT);
   

  }
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

    if (StringUtils.isNotEmpty(config.getZkServer()))
    {
      try
      {
        AnalyzerZKWatcher<SlaveConfig> analyzerZKWatcher = new AnalyzerZKWatcher<SlaveConfig>(config);
        zk = new ZooKeeper(config.getZkServer(),3000,analyzerZKWatcher);
        analyzerZKWatcher.setZk(zk);
       
        //每次启动时都先检查是否有根目录
        ZKUtil.createGroupNodesIfNotExist(zk,config.getGroupId());
       
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

    {
      try
      {
        AnalyzerZKWatcher<MasterConfig> analyzerZKWatcher =
            new AnalyzerZKWatcher<MasterConfig>(config);
        zk = new ZooKeeper(config.getZkServer(),3000,analyzerZKWatcher);
        analyzerZKWatcher.setZk(zk);
       
        //每次启动时都先检查是否有根目录
        ZKUtil.createGroupNodesIfNotExist(zk,config.getGroupId());
       
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

    {
      try
      {
        AnalyzerZKWatcher<MasterConfig> analyzerZKWatcher =
            new AnalyzerZKWatcher<MasterConfig>(config);
        zk = new ZooKeeper(config.getZkServer(),3000,analyzerZKWatcher);
        analyzerZKWatcher.setZk(zk);
       
        ZKUtil.createGroupNodesIfNotExist(zk,config.getGroupId());
      }
      catch(Exception ex)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.