gpt4 book ai didi

org.apache.zookeeper.ZooKeeperMain.processZKCmd()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 09:34:49 28 4
gpt4 key购买 nike

本文整理了Java中org.apache.zookeeper.ZooKeeperMain.processZKCmd()方法的一些代码示例,展示了ZooKeeperMain.processZKCmd()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperMain.processZKCmd()方法的具体详情如下:
包路径:org.apache.zookeeper.ZooKeeperMain
类名称:ZooKeeperMain
方法名:processZKCmd

ZooKeeperMain.processZKCmd介绍

暂无

代码示例

代码示例来源:origin: apache/zookeeper

protected boolean processCmd(MyCommandOptions co) throws CliException, IOException, InterruptedException {
  boolean watch = false;
  try {
    watch = processZKCmd(co);
    exitCode = ExitCode.EXECUTION_FINISHED.getValue();
  } catch (CliException ex) {
    exitCode = ex.getExitCode();
    System.err.println(ex.getMessage());
  }
  return watch;
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

protected boolean processCmd(MyCommandOptions co)
  throws KeeperException, IOException, InterruptedException
{
  try {
    return processZKCmd(co);
  } catch (IllegalArgumentException e) {
    System.err.println("Command failed: " + e);
  } catch (KeeperException.NoNodeException e) {
    System.err.println("Node does not exist: " + e.getPath());
  } catch (KeeperException.NoChildrenForEphemeralsException e) {
    System.err.println("Ephemerals cannot have children: "
        + e.getPath());
  } catch (KeeperException.NodeExistsException e) {
    System.err.println("Node already exists: " + e.getPath());
  } catch (KeeperException.NotEmptyException e) {
    System.err.println("Node not empty: " + e.getPath());
  } catch (KeeperException.NotReadOnlyException e) {
    System.err.println("Not a read-only call: " + e.getPath());
  }catch (KeeperException.InvalidACLException  e) {
    System.err.println("Acl is not valid : "+e.getPath());
  }catch (KeeperException.NoAuthException  e) {
    System.err.println("Authentication is not valid : "+e.getPath());
  }catch (KeeperException.BadArgumentsException   e) {
    System.err.println("Arguments are not valid : "+e.getPath());
  }catch (KeeperException.BadVersionException e) {
    System.err.println("version No is not valid : "+e.getPath());
  }
  return false;
}

代码示例来源:origin: apache/zookeeper

@Test
public void testStatCommand() throws Exception {
  final ZooKeeper zk = createClient();
  ZooKeeperMain zkMain = new ZooKeeperMain(zk);
  String cmdstring1 = "create -e /node3 data";
  String cmdstring2 = "stat /node3";
  String cmdstring3 = "delete /node3";
  zkMain.cl.parseCommand(cmdstring1);
  Assert.assertTrue(zkMain.processZKCmd(zkMain.cl));
  zkMain.cl.parseCommand(cmdstring2);
  Assert.assertFalse(zkMain.processZKCmd(zkMain.cl));
  zkMain.cl.parseCommand(cmdstring3);
  Assert.assertFalse(zkMain.processZKCmd(zkMain.cl));
}

代码示例来源:origin: apache/zookeeper

zkMain.cl.parseCommand(cmdstring);
Assert.assertTrue("Removewatches cmd fails to remove child watches",
    zkMain.processZKCmd(zkMain.cl));
LOG.info("Waiting for the DataWatchRemoved event");
myWatcher.matches();

代码示例来源:origin: apache/zookeeper

/**
 * Test verifies deletion of NodeChildrenChanged watches
 */
@Test(timeout = 30000)
public void testRemoveNodeChildrenChangedWatches() throws Exception {
  List<EventType> expectedEvents = new ArrayList<Watcher.Event.EventType>();
  expectedEvents.add(EventType.ChildWatchRemoved);
  MyWatcher myWatcher = new MyWatcher("/testnode1", expectedEvents, 1);
  zk.create("/testnode1", "data".getBytes(), Ids.OPEN_ACL_UNSAFE,
      CreateMode.PERSISTENT);
  LOG.info("Adding child changed watcher");
  zk.getChildren("/testnode1", myWatcher);
  String cmdstring = "removewatches /testnode1 -c";
  LOG.info("Remove watchers using shell command : {}", cmdstring);
  zkMain.cl.parseCommand(cmdstring);
  Assert.assertTrue("Removewatches cmd fails to remove child watches",
      zkMain.processZKCmd(zkMain.cl));
  myWatcher.matches();
  Assert.assertEquals(
      "Failed to remove child watches : " + zk.getChildWatches(), 0,
      zk.getChildWatches().size());
}

代码示例来源:origin: apache/zookeeper

/**
 * Test verifies deletion of NodeDataChanged watches
 */
@Test(timeout = 30000)
public void testRemoveNodeDataChangedWatches() throws Exception {
  LOG.info("Adding data watcher using getData()");
  List<EventType> expectedEvents = new ArrayList<Watcher.Event.EventType>();
  expectedEvents.add(EventType.DataWatchRemoved);
  MyWatcher myWatcher = new MyWatcher("/testnode1", expectedEvents, 1);
  zk.create("/testnode1", "data".getBytes(), Ids.OPEN_ACL_UNSAFE,
      CreateMode.PERSISTENT);
  zk.getData("/testnode1", myWatcher, null);
  String cmdstring = "removewatches /testnode1 -d";
  LOG.info("Remove watchers using shell command : {}", cmdstring);
  zkMain.cl.parseCommand(cmdstring);
  Assert.assertTrue("Removewatches cmd fails to remove data watches",
      zkMain.processZKCmd(zkMain.cl));
  LOG.info("Waiting for the DataWatchRemoved event");
  myWatcher.matches();
  // verifying that other path data watches are removed
  Assert.assertEquals(
      "Data watches are not removed : " + zk.getDataWatches(), 0, zk
          .getDataWatches().size());
}

代码示例来源:origin: apache/zookeeper

String cmdstring1 = "deleteall /a";
zkMain.cl.parseCommand(cmdstring0);
Assert.assertFalse(zkMain.processZKCmd(zkMain.cl));
Assert.assertEquals(null, zk.exists("/a/b/v", null));
zkMain.cl.parseCommand(cmdstring1);
Assert.assertFalse(zkMain.processZKCmd(zkMain.cl));
Assert.assertNull(zk.exists("/a", null));

代码示例来源:origin: apache/zookeeper

Assert.assertTrue(
    "Removewatches cmd fails to remove child/data watches",
    zkMain.processZKCmd(zkMain.cl));
LOG.info("Waiting for the WatchRemoved events");
watcherLatch.await(10, TimeUnit.SECONDS);

代码示例来源:origin: apache/zookeeper

zkMain.cl.parseCommand(cmdstring);
Assert.assertTrue("Removewatches cmd fails to remove child watches",
    zkMain.processZKCmd(zkMain.cl));
LOG.info("Waiting for the ChildWatchRemoved event");
myWatcher.matches();

代码示例来源:origin: apache/zookeeper

@Test
public void testSetData() throws Exception {
  final ZooKeeper zk = createClient();
  ZooKeeperMain zkMain = new ZooKeeperMain(zk);
  String cmdstring1 = "create -e /node4 data";
  String cmdstring2 = "set /node4 " + "data";
  String cmdstring3 = "delete /node4";
  Stat stat = new Stat();
  int version = 0;
  zkMain.cl.parseCommand(cmdstring1);
  Assert.assertTrue(zkMain.processZKCmd(zkMain.cl));
  stat = zk.exists("/node4", true);
  version = stat.getVersion();
  zkMain.cl.parseCommand(cmdstring2);
  Assert.assertFalse(zkMain.processZKCmd(zkMain.cl));
  stat = zk.exists("/node4", true);
  Assert.assertEquals(version + 1, stat.getVersion());
  zkMain.cl.parseCommand(cmdstring3);
  Assert.assertFalse(zkMain.processZKCmd(zkMain.cl));
}

代码示例来源:origin: apache/zookeeper

@Test
  public void testSetAclRecursive() throws Exception {
    final ZooKeeper zk = createClient();
    final byte[] EMPTY = new byte[0];

    zk.setData("/", EMPTY, -1);
    zk.create("/a", EMPTY, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/a/b", EMPTY, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/a/b/c", EMPTY, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/a/d", EMPTY, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/e", EMPTY, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

    ZooKeeperMain zkMain = new ZooKeeperMain(zk);
    String setAclCommand = "setAcl -R /a world:anyone:r";
    zkMain.cl.parseCommand(setAclCommand);
    Assert.assertFalse(zkMain.processZKCmd(zkMain.cl));

    Assert.assertEquals(Ids.READ_ACL_UNSAFE, zk.getACL("/a", new Stat()));
    Assert.assertEquals(Ids.READ_ACL_UNSAFE, zk.getACL("/a/b", new Stat()));
    Assert.assertEquals(Ids.READ_ACL_UNSAFE, zk.getACL("/a/b/c", new Stat()));
    Assert.assertEquals(Ids.READ_ACL_UNSAFE, zk.getACL("/a/d", new Stat()));
    // /e is unset, its acl should remain the same.
    Assert.assertEquals(Ids.OPEN_ACL_UNSAFE, zk.getACL("/e", new Stat()));
  }
}

代码示例来源:origin: apache/zookeeper

@Test
public void testACLWithExtraAgruments() throws Exception {
  final ZooKeeper zk = createClient();
  ZooKeeperMain zkMain = new ZooKeeperMain(zk);
  // create persistent sequential node
  String cmdstring = "create -s /l data ip:10.18.52.144:cdrwa f g h";
  zkMain.cl.parseCommand(cmdstring);
  Assert.assertTrue(
      "Not considering the extra arguments after the acls.", zkMain
          .processZKCmd(zkMain.cl));
}

代码示例来源:origin: apache/zookeeper

@Test
public void testCreatePersistentNode() throws Exception {
  final ZooKeeper zk = createClient();
  ZooKeeperMain zkMain = new ZooKeeperMain(zk);
  String cmdstring = "create /node2";
  zkMain.cl.parseCommand(cmdstring);
  Assert.assertTrue("Not creating Persistent node.", zkMain
      .processZKCmd(zkMain.cl));
}

代码示例来源:origin: apache/zookeeper

@Test
public void testDelete() throws Exception {
  final ZooKeeper zk = createClient();
  ZooKeeperMain zkMain = new ZooKeeperMain(zk);
  String cmdstring1 = "create -e /node2 data";
  String cmdstring2 = "delete /node2";
  String cmdstring3 = "ls /node2";
  zkMain.cl.parseCommand(cmdstring1);
  Assert.assertTrue(zkMain.processZKCmd(zkMain.cl));
  zkMain.cl.parseCommand(cmdstring2);
  Assert.assertFalse(zkMain.processZKCmd(zkMain.cl));
  zkMain.cl.parseCommand(cmdstring3);
  Assert.assertFalse("", zkMain.processCmd(zkMain.cl));
}

代码示例来源:origin: apache/zookeeper

Assert.assertTrue(
    "Removewatches cmd fails to remove pre-create watches",
    zkMain.processZKCmd(zkMain.cl));
myWatcher1.matches();
Assert.assertEquals(
zkMain.cl.parseCommand(cmdstring2);
Assert.assertTrue("Removewatches cmd fails to remove data watches",
    zkMain.processZKCmd(zkMain.cl));

代码示例来源:origin: apache/zookeeper

zkMain.cl.parseCommand(cmdstring);
Assert.assertTrue("Doesn't create node without data", zkMain
    .processZKCmd(zkMain.cl));
    .processZKCmd(zkMain.cl));
    .processZKCmd(zkMain.cl));
try {
  Assert.assertTrue("Created node with wrong option", zkMain
      .processZKCmd(zkMain.cl));
  Assert.fail("Created the node with wrong option should "
      + "throw Exception.");

代码示例来源:origin: apache/zookeeper

@Test
public void testStatWhenPathDoesNotExist() throws IOException,
    InterruptedException, MalformedCommandException {
  final ZooKeeper zk = createClient();
  ZooKeeperMain main = new ZooKeeperMain(zk);
  String cmdstring = "stat /invalidPath";
  main.cl.parseCommand(cmdstring);
  try {
    main.processZKCmd(main.cl);
    Assert.fail("As Node does not exist, command should fail by throwing No Node Exception.");
  } catch (CliException e) {
    Assert.assertEquals("Node does not exist: /invalidPath", e.getMessage());
  }
}

代码示例来源:origin: apache/zookeeper

private void testInvalidCommand(String cmdString, int exitCode) throws Exception {
  final ZooKeeper zk = createClient();
  ZooKeeperMain zkMain = new ZooKeeperMain(zk);
  zkMain.cl.parseCommand(cmdString);
  // Verify that the exit code is set properly
  zkMain.processCmd(zkMain.cl);
  Assert.assertEquals(exitCode, zkMain.exitCode);
  // Verify that the correct exception is thrown
  try {
   zkMain.processZKCmd(zkMain.cl);
   Assert.fail();
  } catch (CliException e) {
   return;
  }
  Assert.fail("invalid command should throw CliException");
}

代码示例来源:origin: apache/zookeeper

@Test
public void testInvalidStatCommand() throws Exception {
  final ZooKeeper zk = createClient();
  ZooKeeperMain zkMain = new ZooKeeperMain(zk);
  // node doesn't exists
  String cmdstring1 = "stat /node123";
  zkMain.cl.parseCommand(cmdstring1);
  try {
    Assert.assertFalse(zkMain.processZKCmd(zkMain.cl));
    Assert.fail("Path doesn't exists so, command should fail.");
  } catch (CliWrapperException e) {
    Assert.assertEquals(KeeperException.Code.NONODE, ((KeeperException)e.getCause()).code());
  }
}

代码示例来源:origin: org.apache.hadoop/zookeeper

protected boolean processCmd(MyCommandOptions co)
  throws KeeperException, IOException, InterruptedException
{
  try {
    return processZKCmd(co);
  } catch (IllegalArgumentException e) {
    System.err.println("Command failed: " + e);
  } catch (KeeperException.NoNodeException e) {
    System.err.println("Node does not exist: " + e.getPath());
  } catch (KeeperException.NoChildrenForEphemeralsException e) {
    System.err.println("Ephemerals cannot have children: "
        + e.getPath());
  } catch (KeeperException.NodeExistsException e) {
    System.err.println("Node already exists: " + e.getPath());
  } catch (KeeperException.NotEmptyException e) {
    System.err.println("Node not empty: " + e.getPath());
  }
  return false;
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com