Codota Logo
ZooKeeperMain$MyCommandOptions.parseCommand
Code IndexAdd Codota to your IDE (free)

How to use
parseCommand
method
in
org.apache.zookeeper.ZooKeeperMain$MyCommandOptions

Best Java code snippets using org.apache.zookeeper.ZooKeeperMain$MyCommandOptions.parseCommand (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
StringBuilder s =
  • Codota Iconnew StringBuilder()
  • Codota Iconnew StringBuilder(32)
  • Codota IconString str;new StringBuilder(str)
  • Smart code suggestions by Codota
}
origin: apache/zookeeper

public void executeLine(String line) throws CliException, InterruptedException, IOException {
 if (!line.equals("")) {
  cl.parseCommand(line);
  addToHistory(commandCount,line);
  processCmd(cl);
  commandCount++;
 }
}
origin: apache/zookeeper

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

/**
 * 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
public void testParseWithEmptyQuotes() throws Exception {
  final ZooKeeper zk = createClient();
  ZooKeeperMain zkMain = new ZooKeeperMain(zk);
  String cmdstring = "create /node ''";
  zkMain.cl.parseCommand(cmdstring);
  Assert.assertEquals("empty quotes should produce arguments", zkMain.cl.getNumArguments(), 3);
  Assert.assertEquals("create is not taken as first argument", zkMain.cl.getCmdArgument(0), "create");
  Assert.assertEquals("/node is not taken as second argument", zkMain.cl.getCmdArgument(1), "/node");
  Assert.assertEquals("empty string is not taken as third argument", zkMain.cl.getCmdArgument(2), "");
}
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

@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

@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

@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

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 testParseWithMixedQuotes() throws Exception {
  final ZooKeeper zk = createClient();
  ZooKeeperMain zkMain = new ZooKeeperMain(zk);
  for (String[] quoteChars : new String[][] {{"'", "\""}, {"\"", "'"}}) {
    String outerQuotes = quoteChars[0];
    String innerQuotes = quoteChars[1];
    String cmdstring = String.format("create /node %1$s%2$squoted data%2$s%1$s", outerQuotes, innerQuotes);
    zkMain.cl.parseCommand(cmdstring);
    Assert.assertEquals("quotes combine arguments", zkMain.cl.getNumArguments(), 3);
    Assert.assertEquals("create is not taken as first argument", zkMain.cl.getCmdArgument(0), "create");
    Assert.assertEquals("/node is not taken as second argument", zkMain.cl.getCmdArgument(1), "/node");
    Assert.assertEquals("quoted data is not taken as third argument", zkMain.cl.getCmdArgument(2), innerQuotes + "quoted data" + innerQuotes);
  }
}
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 testParseWithQuotes() throws Exception {
  final ZooKeeper zk = createClient();
  ZooKeeperMain zkMain = new ZooKeeperMain(zk);
  for (String quoteChar : new String[] {"'", "\""}) {
    String cmdstring = String.format("create /node %1$squoted data%1$s", quoteChar);
    zkMain.cl.parseCommand(cmdstring);
    Assert.assertEquals("quotes combine arguments", zkMain.cl.getNumArguments(), 3);
    Assert.assertEquals("create is not taken as first argument", zkMain.cl.getCmdArgument(0), "create");
    Assert.assertEquals("/node is not taken as second argument", zkMain.cl.getCmdArgument(1), "/node");
    Assert.assertEquals("quoted data is not taken as third argument", zkMain.cl.getCmdArgument(2), "quoted data");
  }
}
origin: org.apache.zookeeper/zookeeper

public void executeLine(String line)
throws InterruptedException, IOException, KeeperException {
 if (!line.equals("")) {
  cl.parseCommand(line);
  addToHistory(commandCount,line);
  processCmd(cl);
  commandCount++;
 }
}
origin: apache/zookeeper

@Test
public void testParseWithExtraSpaces() throws Exception {
  final ZooKeeper zk = createClient();
  ZooKeeperMain zkMain = new ZooKeeperMain(zk);
  String cmdstring = "      ls       /  ";
  zkMain.cl.parseCommand(cmdstring);
  Assert.assertEquals("Spaces also considered as characters", zkMain.cl.getNumArguments(), 2);
  Assert.assertEquals("ls is not taken as first argument", zkMain.cl.getCmdArgument(0), "ls");
  Assert.assertEquals("/ is not taken as second argument", zkMain.cl.getCmdArgument(1), "/");
}
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

@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

zkMain.cl.parseCommand(cmdstring);
Assert.assertTrue("Removewatches cmd fails to remove child watches",
    zkMain.processZKCmd(zkMain.cl));
origin: apache/zookeeper

@Test
public void testParseWithMultipleQuotes() throws Exception {
  final ZooKeeper zk = createClient();
  ZooKeeperMain zkMain = new ZooKeeperMain(zk);
  String cmdstring = "create /node '' ''";
  zkMain.cl.parseCommand(cmdstring);
  Assert.assertEquals("expected 5 arguments", zkMain.cl.getNumArguments(), 4);
  Assert.assertEquals("create is not taken as first argument", zkMain.cl.getCmdArgument(0), "create");
  Assert.assertEquals("/node is not taken as second argument", zkMain.cl.getCmdArgument(1), "/node");
  Assert.assertEquals("empty string is not taken as third argument", zkMain.cl.getCmdArgument(2), "");
  Assert.assertEquals("empty string is not taken as fourth argument", zkMain.cl.getCmdArgument(3), "");
}
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());
  }
}
org.apache.zookeeperZooKeeperMain$MyCommandOptionsparseCommand

Javadoc

Breaks a string into command + arguments.

Popular methods of ZooKeeperMain$MyCommandOptions

  • getArgArray
  • getCommand
  • getOption
  • parseOptions
    Parses a command line that may contain one or more flags before an optional command string
  • getCmdArgument
  • getNumArguments

Popular in Java

  • Reactive rest calls using spring rest template
  • onCreateOptionsMenu (Activity)
  • getApplicationContext (Context)
  • addToBackStack (FragmentTransaction)
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • PrintWriter (java.io)
    Prints formatted representations of objects to a text-output stream. This class implements all of th
  • Path (java.nio.file)
  • Dictionary (java.util)
    The Dictionary class is the abstract parent of any class, such as Hashtable, which maps keys to valu
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now