当前位置: 首页>>代码示例>>Java>>正文


Java ZooKeeper.delete方法代码示例

本文整理汇总了Java中org.apache.zookeeper.ZooKeeper.delete方法的典型用法代码示例。如果您正苦于以下问题:Java ZooKeeper.delete方法的具体用法?Java ZooKeeper.delete怎么用?Java ZooKeeper.delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.zookeeper.ZooKeeper的用法示例。


在下文中一共展示了ZooKeeper.delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSuperIsSuper

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
@Test
public void testSuperIsSuper() throws Exception {
    ZooKeeper zk = createClient();
    try {
        zk.create("/digest_read", null, Arrays.asList(new ACL(Perms.READ, otherDigestUser)), CreateMode.PERSISTENT);
        zk.create("/digest_read/sub", null, Arrays.asList(new ACL(Perms.READ, otherDigestUser)), CreateMode.PERSISTENT);
        zk.create("/sasl_read", null, Arrays.asList(new ACL(Perms.READ, otherSaslUser)), CreateMode.PERSISTENT);
        zk.create("/sasl_read/sub", null, Arrays.asList(new ACL(Perms.READ, otherSaslUser)), CreateMode.PERSISTENT);
        zk.delete("/digest_read/sub", -1);
        zk.delete("/digest_read", -1);
        zk.delete("/sasl_read/sub", -1);
        zk.delete("/sasl_read", -1);
        //If the test failes it will most likely fail with a NoAuth exception before it ever gets to this assertion
        Assert.assertEquals(authFailed.get(), 0);
    } finally {
        zk.close();
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:19,代码来源:SaslSuperUserTest.java

示例2: deleteZKDir

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
private void deleteZKDir(ZooKeeper zk, String nodeName)
        throws IOException, InterruptedException, KeeperException {

  Stat stat = zk.exists(nodeName, false);
  if (stat == null) {
    return;
  }

  List<String> children1 = zk.getChildren(nodeName, false);
  List<String> c2 = zk.getChildren(nodeName, false, stat);

  if (!children1.equals(c2)) {
      Assert.fail("children lists from getChildren()/getChildren2() do not match");
  }

  if (!stat.equals(stat)) {
      Assert.fail("stats from exists()/getChildren2() do not match");
  }

  if (children1.size() == 0) {
    zk.delete(nodeName, -1);
    return;
  }
  for (String n : children1) {
    deleteZKDir(zk, n);
  }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:28,代码来源:ZooKeeperTestClient.java

示例3: testDeleteWithChildren

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
@Test
public void testDeleteWithChildren() throws Exception {
    ZooKeeper zk = createClient();
    zk.create("/parent", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/parent/child", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    try {
        zk.delete("/parent", -1);
        Assert.fail("Should have received a not equals message");
    } catch (KeeperException e) {
        Assert.assertEquals(KeeperException.Code.NOTEMPTY, e.code());
    }
    zk.delete("/parent/child", -1);
    zk.delete("/parent", -1);
    zk.close();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:16,代码来源:ClientTest.java

示例4: testNodeDeleted

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
@Test
public void testNodeDeleted() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

    EventsWatcher watcher = new EventsWatcher();
    ZooKeeper zk1 = createClient(qu, 1, watcher);
    ZooKeeper zk2 = createClient(qu, 2);

    String path = "/test-deleted";

    zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    zk1.getData(path, watcher, null);
    qu.shutdown(1);
    zk2.delete(path, -1);
    qu.start(1);
    watcher.waitForConnected(TIMEOUT * 1000L);
    watcher.assertEvent(TIMEOUT, EventType.NodeDeleted);

    zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    zk1.exists(path, watcher);
    qu.shutdown(1);
    zk2.delete(path, -1);
    qu.start(1);
    watcher.waitForConnected(TIMEOUT * 1000L);
    watcher.assertEvent(TIMEOUT, EventType.NodeDeleted);

    zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    zk1.getChildren(path, watcher);
    qu.shutdown(1);
    zk2.delete(path, -1);
    qu.start(1);
    watcher.waitForConnected(TIMEOUT * 1000L);
    watcher.assertEvent(TIMEOUT, EventType.NodeDeleted);

    qu.shutdownAll();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:41,代码来源:WatchEventWhenAutoResetTest.java

示例5: testNodeDataChanged

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
@Test
public void testNodeDataChanged() throws Exception {
    QuorumUtil qu = new QuorumUtil(1);
    qu.startAll();

    EventsWatcher watcher = new EventsWatcher();
    ZooKeeper zk1 = createClient(qu, 1, watcher);
    ZooKeeper zk2 = createClient(qu, 2);

    String path = "/test-changed";

    zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    zk1.getData(path, watcher, null);
    qu.shutdown(1);
    zk2.delete(path, -1);
    zk2.create(path, new byte[2], ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    qu.start(1);
    watcher.waitForConnected(TIMEOUT);
    watcher.assertEvent(TIMEOUT, EventType.NodeDataChanged);

    zk1.exists(path, watcher);
    qu.shutdown(1);
    zk2.delete(path, -1);
    zk2.create(path, new byte[2], ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    qu.start(1);
    watcher.waitForConnected(TIMEOUT * 1000L);
    watcher.assertEvent(TIMEOUT, EventType.NodeDataChanged);

    qu.shutdownAll();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:34,代码来源:WatchEventWhenAutoReset.java

示例6: testSync

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
@Test
public void testSync() throws Exception {
    try {
        LOG.info("Starting ZK:" + (new Date()).toString());
        opsCount = new CountDownLatch(limit);
        ZooKeeper zk = createClient();
        
        LOG.info("Beginning test:" + (new Date()).toString());
        for(int i = 0; i < 100; i++)
            zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT, this, results);
        zk.sync("/test", this, results);
        for(int i = 0; i < 100; i++)
            zk.delete("/test" + i, 0, this, results);
        for(int i = 0; i < 100; i++)
            zk.getChildren("/", new NullWatcher(), (ChildrenCallback)this,
                    results);
        for(int i = 0; i < 100; i++)
            zk.getChildren("/", new NullWatcher(), (Children2Callback)this,
                    results);
        LOG.info("Submitted all operations:" + (new Date()).toString());
        
        if(!opsCount.await(10000, TimeUnit.MILLISECONDS))
            Assert.fail("Haven't received all confirmations" + opsCount.getCount());

        for(int i = 0; i < limit ; i++){
            Assert.assertEquals(0, (int) results.get(i));
        }
        
    } catch (IOException e) {
        System.out.println(e.toString());
    } 
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:34,代码来源:SyncCallTest.java

示例7: delQuota

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
/**
 * this method deletes quota for a node.
 *
 * @param zk the zookeeper client
 * @param path the path to delete quota for
 * @param bytes true if number of bytes needs to be unset
 * @param numNodes true if number of nodes needs to be unset
 * @return true if quota deletion is successful
 * @throws KeeperException
 * @throws IOException
 * @throws InterruptedException
 */
public static boolean delQuota(ZooKeeper zk, String path,
        boolean bytes, boolean numNodes)
        throws KeeperException, IOException, InterruptedException, MalformedPathException {
    String parentPath = Quotas.quotaZookeeper + path;
    String quotaPath = Quotas.quotaZookeeper + path + "/" + 
            Quotas.limitNode;
    if (zk.exists(quotaPath, false) == null) {
        System.out.println("Quota does not exist for " + path);
        return true;
    }
    byte[] data = null;
    try {
        data = zk.getData(quotaPath, false, new Stat());
    } catch (IllegalArgumentException ex) {
        throw new MalformedPathException(ex.getMessage());
    } catch (KeeperException.NoNodeException ne) {
        System.err.println("quota does not exist for " + path);
        return true;
    }
    StatsTrack strack = new StatsTrack(new String(data));
    if (bytes && !numNodes) {
        strack.setBytes(-1L);
        zk.setData(quotaPath, strack.toString().getBytes(), -1);
    } else if (!bytes && numNodes) {
        strack.setCount(-1);
        zk.setData(quotaPath, strack.toString().getBytes(), -1);
    } else if (bytes && numNodes) {
        // delete till you can find a node with more than
        // one child
        List<String> children = zk.getChildren(parentPath, false);
        /// delete the direct children first
        for (String child : children) {
            zk.delete(parentPath + "/" + child, -1);
        }
        // cut the tree till their is more than one child
        trimProcQuotas(zk, parentPath);
    }
    return true;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:52,代码来源:DelQuotaCommand.java

示例8: releaseTicket

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
static void releaseTicket(ZooKeeper zookeeper, String lockNode,
                          String ticket) throws KeeperException, InterruptedException {

    logger.debug("Releasing ticket {}.", ticket);
    try {
        zookeeper.delete(lockNode + "/" + ticket, -1);
    } catch (KeeperException e) {
        if (e.code() != KeeperException.Code.NONODE) {
            // If it the node is already gone, than that is fine, otherwise:
            throw e;
        }
    }
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:14,代码来源:ResourceClaim.java

示例9: testSecureQuorumServer

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
/**
 * This test checks that SSL works in cluster setup of ZK servers, which includes:
 * 1. setting "secureClientPort" in "zoo.cfg" file.
 * 2. setting jvm flags for serverCnxn, keystore, truststore.
 * Finally, a zookeeper client should be able to connect to the secure port and
 * communicate with server via secure connection.
 * <p/>
 * Note that in this test a ZK server has two ports -- clientPort and secureClientPort.
 */
@Test
public void testSecureQuorumServer() throws Exception {
    final int SERVER_COUNT = 3;
    final int clientPorts[] = new int[SERVER_COUNT];
    final Integer secureClientPorts[] = new Integer[SERVER_COUNT];
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < SERVER_COUNT; i++) {
        clientPorts[i] = PortAssignment.unique();
        secureClientPorts[i] = PortAssignment.unique();
        String server = String.format("server.%d=localhost:%d:%d:participant;localhost:%d",
                i, PortAssignment.unique(), PortAssignment.unique(), clientPorts[i]);
        sb.append(server + "\n");
    }
    String quorumCfg = sb.toString();


    MainThread[] mt = new MainThread[SERVER_COUNT];
    for (int i = 0; i < SERVER_COUNT; i++) {
        mt[i] = new MainThread(i, quorumCfg, secureClientPorts[i], true);
        mt[i].start();
    }

    // Servers have been set up. Now go test if secure connection is successful.
    for (int i = 0; i < SERVER_COUNT; i++) {
        Assert.assertTrue("waiting for server " + i + " being up",
                ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], TIMEOUT));

        ZooKeeper zk = ClientBase.createZKClient("127.0.0.1:" + secureClientPorts[i], TIMEOUT);
        // Do a simple operation to make sure the connection is fine.
        zk.create("/test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        zk.delete("/test", -1);
        zk.close();
    }

    for (int i = 0; i < mt.length; i++) {
        mt[i].shutdown();
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:48,代码来源:SSLTest.java

示例10: testSecureStandaloneServer

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
/**
 * Developers might use standalone mode (which is the default for one server).
 * This test checks SSL works in standalone mode of ZK server.
 * <p/>
 * Note that in this test the Zk server has only secureClientPort
 */
@Test
public void testSecureStandaloneServer() throws Exception {
    Integer secureClientPort = PortAssignment.unique();
    MainThread mt = new MainThread(MainThread.UNSET_MYID, "", secureClientPort, false);
    mt.start();

    ZooKeeper zk = ClientBase.createZKClient("127.0.0.1:" + secureClientPort, TIMEOUT);
    zk.create("/test", "".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.delete("/test", -1);
    zk.close();
    mt.shutdown();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:19,代码来源:SSLTest.java

示例11: deleteNodeIfExists

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
private void deleteNodeIfExists(ZooKeeper zk, String nodeName)
    throws InterruptedException {
  try {
    zk.delete(nodeName, -1);
  } catch (KeeperException ke) {
    Code code = ke.code();
    boolean valid = code == KeeperException.Code.NONODE ||
                    code == KeeperException.Code.NOTEMPTY;
    if (!valid) {
      Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
    }
  }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:14,代码来源:ZooKeeperTestClient.java

示例12: testSync

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
@Test
public void testSync() throws Exception {
    try {
        LOG.info("Starting ZK:" + (new Date()).toString());
        opsCount = new CountDownLatch(limit);
        ZooKeeper zk = createClient();

        LOG.info("Beginning test:" + (new Date()).toString());
        for(int i = 0; i < 50; i++)
            zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                      CreateMode.PERSISTENT, (StringCallback)this, results);

        for(int i = 50; i < 100; i++) {
          zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT, (Create2Callback)this, results);
        }
        zk.sync("/test", this, results);
        for(int i = 0; i < 100; i++)
            zk.delete("/test" + i, 0, this, results);
        for(int i = 0; i < 100; i++)
            zk.getChildren("/", new NullWatcher(), (ChildrenCallback)this,
                    results);
        for(int i = 0; i < 100; i++)
            zk.getChildren("/", new NullWatcher(), (Children2Callback)this,
                    results);
        LOG.info("Submitted all operations:" + (new Date()).toString());
        
        if(!opsCount.await(10000, TimeUnit.MILLISECONDS))
            Assert.fail("Haven't received all confirmations" + opsCount.getCount());

        for(int i = 0; i < limit ; i++){
            Assert.assertEquals(0, (int) results.get(i));
        }
        
    } catch (IOException e) {
        System.out.println(e.toString());
    } 
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:39,代码来源:SyncCallTest.java

示例13: deleteTree

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
public static void deleteTree(ZooKeeper zk,String path) throws Exception{
 String[] list = getTree(zk,path);
 for(int i= list.length -1;i>=0; i--){
  zk.delete(list[i],-1);
 }
}
 
开发者ID:hungki,项目名称:tbschedule-wed,代码行数:7,代码来源:ZKTools.java

示例14: testChrootSynchronous

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
@Test
public void testChrootSynchronous()
    throws IOException, InterruptedException, KeeperException
{
    ZooKeeper zk1 = createClient();
    try {
        zk1.create("/ch1", null, Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);
    } finally {
        if(zk1 != null)
            zk1.close();
    }
    ZooKeeper zk2 = createClient(hostPort + "/ch1");
    try {
        Assert.assertEquals("/ch2",
                zk2.create("/ch2", null, Ids.OPEN_ACL_UNSAFE,
                        CreateMode.PERSISTENT));
    } finally {
        if(zk2 != null)
            zk2.close();
    }

    zk1 = createClient();
    zk2 = createClient(hostPort + "/ch1");
    try {
        // check get
        MyWatcher w1 = new MyWatcher("/ch1");
        Assert.assertNotNull(zk1.exists("/ch1", w1));
        MyWatcher w2 = new MyWatcher("/ch1/ch2");
        Assert.assertNotNull(zk1.exists("/ch1/ch2", w2));

        MyWatcher w3 = new MyWatcher("/ch2");
        Assert.assertNotNull(zk2.exists("/ch2", w3));

        // set watches on child
        MyWatcher w4 = new MyWatcher("/ch1");
        zk1.getChildren("/ch1",w4);
        MyWatcher w5 = new MyWatcher("/");
        zk2.getChildren("/",w5);

        // check set
        zk1.setData("/ch1", "1".getBytes(), -1);
        zk2.setData("/ch2", "2".getBytes(), -1);

        // check watches
        Assert.assertTrue(w1.matches());
        Assert.assertTrue(w2.matches());
        Assert.assertTrue(w3.matches());

        // check exceptions
        try {
            zk2.setData("/ch3", "3".getBytes(), -1);
        } catch (KeeperException.NoNodeException e) {
            Assert.assertEquals("/ch3", e.getPath());
        }

        Assert.assertTrue(Arrays.equals("1".getBytes(),
                zk1.getData("/ch1", false, null)));
        Assert.assertTrue(Arrays.equals("2".getBytes(),
                zk1.getData("/ch1/ch2", false, null)));
        Assert.assertTrue(Arrays.equals("2".getBytes(),
                zk2.getData("/ch2", false, null)));

        // check delete
        zk2.delete("/ch2", -1);
        Assert.assertTrue(w4.matches());
        Assert.assertTrue(w5.matches());

        zk1.delete("/ch1", -1);
        Assert.assertNull(zk1.exists("/ch1", false));
        Assert.assertNull(zk1.exists("/ch1/ch2", false));
        Assert.assertNull(zk2.exists("/ch2", false));
    } finally {
        if(zk1 != null)
            zk1.close();
        if(zk2 != null)
            zk2.close();
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:80,代码来源:ChrootTest.java

示例15: testAsync

import org.apache.zookeeper.ZooKeeper; //导入方法依赖的package包/类
@Test
public void testAsync() throws Exception
{
    ZooKeeper zk = null;
    zk = createClient();
    try {
        zk.addAuthInfo("digest", "ben:passwd".getBytes());
        zk.create("/ben", new byte[0], Ids.READ_ACL_UNSAFE, CreateMode.PERSISTENT, this, results);
        zk.create("/ben/2", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT, this, results);
        zk.delete("/ben", -1, this, results);
        zk.create("/ben2", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT, this, results);
        zk.getData("/ben2", false, this, results);
        synchronized (results) {
            while (results.size() < 5) {
                results.wait();
            }
        }
        Assert.assertEquals(0, (int) results.get(0));
        Assert.assertEquals(Code.NOAUTH, Code.get(results.get(1)));
        Assert.assertEquals(0, (int) results.get(2));
        Assert.assertEquals(0, (int) results.get(3));
        Assert.assertEquals(0, (int) results.get(4));
    } finally {
        zk.close();
    }

    zk = createClient();
    try {
        zk.addAuthInfo("digest", "ben:passwd2".getBytes());
        try {
            zk.getData("/ben2", false, new Stat());
            Assert.fail("Should have received a permission error");
        } catch (KeeperException e) {
            Assert.assertEquals(Code.NOAUTH, e.code());
        }
    } finally {
        zk.close();
    }

    zk = createClient();
    try {
        zk.addAuthInfo("digest", "ben:passwd".getBytes());
        zk.getData("/ben2", false, new Stat());
    } finally {
        zk.close();
    }
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:48,代码来源:AsyncTest.java


注:本文中的org.apache.zookeeper.ZooKeeper.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。