コード例 #1
0
  @Before
  public void setup() throws Exception {

    zk = newZooKeeper();

    // be sure that the lock-place is created
    ZkUtils.recursiveSafeDelete(zk, baseLockPath, -1);
    zk.create(baseLockPath, new byte[] {}, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

    zkSessionManager = new BaseZkSessionManager(zk);
  }
コード例 #2
0
  @After
  public void tearDown() throws Exception {
    try {
      List<String> children = zk.getChildren(baseLockPath, false);
      for (String child : children) {
        ZkUtils.safeDelete(zk, baseLockPath + "/" + child, -1);
      }
      ZkUtils.safeDelete(zk, baseLockPath, -1);

    } catch (KeeperException ke) {
      // suppress because who cares what went wrong after our tests did their thing?
    } finally {
      closeZooKeeper(zk);
    }
  }
コード例 #3
0
 private static void closeZooKeeper(ZooKeeper zk) throws InterruptedException {
   System.out.printf("%s: Closing ZooKeeper%n", Thread.currentThread().getName());
   zk.close();
 }