Package org.apache.zookeeper

Examples of org.apache.zookeeper.ZooKeeper$WatchRegistration


      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


   
    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

  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

    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

    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

    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

    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

  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

    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

    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

TOP

Related Classes of org.apache.zookeeper.ZooKeeper$WatchRegistration

Copyright © 2018 www.massapicom. 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.