Examples of ZooKeeper


Examples of org.apache.zookeeper.ZooKeeper

    String slave2 = "slave2";
    String slave3 = "slave3";
    String config1 = "config1";
   
    TestZookeeper tz = new TestZookeeper();
    ZooKeeper zk = new ZooKeeper(servers,3000,tz);
    tz.zk = zk;
   
    //每次启动时都先检查是否有根目录
    createGroupNodesIfNotExist(zk,groupId);
   
    updateOrCreateNode(zk,getGroupMasterZKPath(groupId)+"/"+master1,"master1value".getBytes("UTF-8"));
    updateOrCreateNode(zk,getGroupMasterZKPath(groupId)+"/"+master2,"master2value".getBytes("UTF-8"));
    updateOrCreateNode(zk,getGroupSlaveZKPath(groupId)+"/"+slave1,"slave1value".getBytes("UTF-8"));
    updateOrCreateNode(zk,getGroupSlaveZKPath(groupId)+"/"+slave2,"slave2value".getBytes("UTF-8"));
    updateOrCreateNode(zk,getGroupSlaveZKPath(groupId)+"/"+slave3,"slave3value".getBytes("UTF-8"));
    updateOrCreateNode(zk,getGroupConfigZKPath(groupId)+"/"+config1,"config1value".getBytes("UTF-8"));
   
    List<String> groups = zk.getChildren(AnalysisConstants.ZK_ROOT, false);
   
    List<String> master = zk.getChildren(getGroupMasterZKPath(groups.get(0)), false);
       
    List<String> slave = zk.getChildren(getGroupSlaveZKPath(groups.get(0)), false);
   
    List<String> config = zk.getChildren(getGroupConfigZKPath(groups.get(0)), false);
   
    System.out.println(new String(zk.getData(getGroupConfigZKPath(groups.get(0)) + "/" + config.get(0), false,null),"utf-8"));
   
    Thread.sleep(200000);

  }
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

    public TSOState buildState()
    throws LoggerException {
        try{
            CountDownLatch latch = new CountDownLatch(1);
           
            this.zk = new ZooKeeper(config.getZkServers(),
                                            Integer.parseInt(System.getProperty("SESSIONTIMEOUT", Integer.toString(10000))),
                                            new LoggerWatcher(latch));
           
            latch.await();
        } catch (Exception e) {
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

      Assert.assertEquals(Constants.ZK_OK, ts.type);
    }
  }
 
  public void testGetTree() throws Exception {
    ZooKeeper zk = this.initZk();
   
    ZkCtl zkCtl = new ZkCtl(TestConf.host, TestConf.root, "", "", null);
    HashMap<String, String> map = zkCtl.getTree("/iserviceTest/node1");
    Assert.assertEquals("version:0\r\nnode1-node1", map.get("/iserviceTest/node1"));
    Assert.assertEquals("version:0\r\nnode1-node1-node1", map.get("/iserviceTest/node1/node1"));
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

   
    this.clearUpZk(zk);
  }
 
  public void testWatch() throws Exception{
    ZooKeeper zk = this.initZk();
   
    CountDownLatch connectedSignal = new CountDownLatch(1);
    TestStore ts = new TestStore("","","","","");
    ts.setSignal(connectedSignal);
    ZkCtl zkCtl = new ZkCtl(TestConf.host, TestConf.root, "", "", ts);
    zkCtl.watch("/iserviceTest/node1");
    zk.setData("/iserviceTest/node1", "node1-node1-new".getBytes(), 0);

    connectedSignal.await();
    this.clearUpZk(zk);
  }
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

  public ZkCtl(String hosts, String root, String user, String pass, Store store) {
    this.timer = new Timer();
    this.store = store;
   
    try {
      this.zk = new ZooKeeper(hosts + root, Constants.SESSION_TIMEOUT, this);
      checkTask = new CheckTask(this.store);
      this.timer.schedule(checkTask, Constants.CHECK_TM)
    } catch(Exception e) {
      e.printStackTrace();
      this.store.inform(Constants.ZK_ERROR);
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

    connectedSignal.await();
    this.clearUpZk(zk);
  }
 
  public ZooKeeper initZk() throws Exception{
    ZooKeeper zk = new ZooKeeper(TestConf.host + TestConf.root, Constants.SESSION_TIMEOUT, null);
    List<ACL> acls = new ArrayList<ACL>();
    acls.add(new ACL(Perms.ALL, Ids.ANYONE_ID_UNSAFE));
    zk.create("/iserviceTest", "node1".getBytes(), acls, CreateMode.PERSISTENT);
    zk.create("/iserviceTest/node1", "node1-node1".getBytes(), acls, CreateMode.PERSISTENT);
    zk.create("/iserviceTest/node1/node1", "node1-node1-node1".getBytes(), acls, CreateMode.PERSISTENT);
    return zk;
  }
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

    s.init();
    connectedSignal.await();
  }
 
  public void testDump() throws Exception{
    ZooKeeper zk = this.initZk();
   
    Store s = new Store(TestConf.host, TestConf.root, "", "", TestConf.tmpPath);
    s.init();
    s.dump("/iserviceTest/node1");
   
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

    this.clearUpZk(zk);
    this.clearUpFiles(TestConf.tmpPath);
  }
 
  public void testDump2() throws Exception{
    ZooKeeper zk = this.initZk();
    int pid = Extends.getPid();
   
    FS.dump(TestConf.tmpPath + "/" + pid + "/iserviceTest/node2/node.data", "version:0\r\ni'm node2/node.data for check");
    FS.dump(TestConf.tmpPath + "/" + pid + "/iserviceTest/node2.data", "version:0\r\ni'm node2.data for check");
    FS.dump(TestConf.tmpPath + "/" + pid + "/iserviceTest/node1/node1.data", "version:-1\r\ni'm node1/node1.data for check");
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

    File f = new File(path);
    f.delete();
  }
 
  public ZooKeeper initZk() throws Exception{
    ZooKeeper zk = new ZooKeeper(TestConf.host + TestConf.root, Constants.SESSION_TIMEOUT, null);
    List<ACL> acls = new ArrayList<ACL>();
    acls.add(new ACL(Perms.ALL, Ids.ANYONE_ID_UNSAFE));
    zk.create("/iserviceTest", "node1".getBytes(), acls, CreateMode.PERSISTENT);
    zk.create("/iserviceTest/node1", "node1-node1".getBytes(), acls, CreateMode.PERSISTENT);
    zk.create("/iserviceTest/node1/node1", "node1-node1-node1".getBytes(), acls, CreateMode.PERSISTENT);
    return zk;
  }
View Full Code Here

Examples of org.apache.zookeeper.ZooKeeper

  public void setUp(){
    this.clearUpFiles(TestConf.tmpPath);
  }
 
  public void testGetConfigOK() throws Exception{
    ZooKeeper zk = this.initZK();
   
    CountDownLatch connectedSignal = new CountDownLatch(1);
    TestHandler th = new TestHandler(connectedSignal);
    IService iservice = new IService(TestConf.host,null,null,null,"./src/test/tmp");   
    iservice.setEventHandle(Constants.CONNECT_EVENT, th);
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.