Method readLine = consoleC.getMethod("readLine", String.class); while ((line = (String)readLine.invoke(console, getPrompt())) != null) { executeLine(line); executeLine(line);
Method readLine = consoleC.getMethod("readLine", String.class); while ((line = (String)readLine.invoke(console, getPrompt())) != null) { executeLine(line); executeLine(line);
@Test public void testDeleteWithInvalidVersionNo() throws Exception { final ZooKeeper zk = createClient(); ZooKeeperMain zkMain = new ZooKeeperMain(zk); String cmdstring = "create -s -e /node1 data "; String cmdstring1 = "delete /node1 2";//invalid dataversion no zkMain.executeLine(cmdstring); // For Invalid dataversion number should not throw exception zkMain.executeLine(cmdstring1); }
@Test public void testSortedLs() throws Exception { final ZooKeeper zk = createClient(); ZooKeeperMain zkMain = new ZooKeeperMain(zk); zkMain.executeLine("create /aa1"); zkMain.executeLine("create /aa2"); zkMain.executeLine("create /aa3"); zkMain.executeLine("create /test1"); zkMain.executeLine("create /zk1"); LsCommand cmd = new LsCommand(); cmd.setZk(zk); cmd.parse("ls /".split(" ")); List<String> expected = new ArrayList<String>(); expected.add("[aa1, aa2, aa3, test1, zk1, zookeeper]"); runCommandExpect(cmd, expected); }
@Test public void testCliCommandsNotEchoingUsage() throws Exception { // setup redirect out/err streams to get System.in/err, use this judiciously! final PrintStream systemErr = System.err; // get current err final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); final ZooKeeper zk = createClient(); ZooKeeperMain zkMain = new ZooKeeperMain(zk); String cmd1 = "printwatches"; zkMain.executeLine(cmd1); String cmd2 = "history"; zkMain.executeLine(cmd2); String cmd3 = "redo"; zkMain.executeLine(cmd3); // revert redirect of out/err streams - important step! System.setErr(systemErr); if (errContent.toString().contains("ZooKeeper -server host:port cmd args")) { fail("CLI commands (history, redo, connect, printwatches) display usage info!"); } }
@Test public void testLsrCommand() throws Exception { final ZooKeeper zk = createClient(); ZooKeeperMain zkMain = new ZooKeeperMain(zk); zkMain.executeLine("create /a"); zkMain.executeLine("create /a/b"); zkMain.executeLine("create /a/c"); zkMain.executeLine("create /a/b/d"); zkMain.executeLine("create /a/c/e"); zkMain.executeLine("create /a/f"); LsCommand cmd = new LsCommand(); cmd.setZk(zk); cmd.parse("ls -R /a".split(" ")); List<String> expected = new ArrayList<String>(); expected.add("/a"); expected.add("/a/b"); expected.add("/a/c"); expected.add("/a/f"); expected.add("/a/b/d"); expected.add("/a/c/e"); runCommandExpect(cmd, expected); }
@Test public void testRedoWithNegativeCmdNumber() throws Exception { final ZooKeeper zk = createClient(); ZooKeeperMain zkMain = new ZooKeeperMain(zk); String cmd1 = "redo -1"; // setup redirect out/err streams to get System.in/err, use this // judiciously! final PrintStream systemErr = System.err; // get current err final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); System.setErr(new PrintStream(errContent)); try { zkMain.executeLine(cmd1); Assert.assertEquals("Command index out of range", errContent .toString().trim()); } finally { // revert redirect of out/err streams - important step! System.setErr(systemErr); } }
@Test public void testLsrLeafCommand() throws Exception { final ZooKeeper zk = createClient(); ZooKeeperMain zkMain = new ZooKeeperMain(zk); zkMain.executeLine("create /b"); zkMain.executeLine("create /b/c"); LsCommand cmd = new LsCommand(); cmd.setZk(zk); cmd.parse("ls -R /b/c".split(" ")); List<String> expected = new ArrayList<String>(); expected.add("/b/c"); runCommandExpect(cmd, expected); }
@Test public void testCheckInvalidAcls() throws Exception { final ZooKeeper zk = createClient(); ZooKeeperMain zkMain = new ZooKeeperMain(zk); String cmdstring = "create -s -e /node data ip:scheme:gggsd"; //invalid acl's // For Invalid ACls should not throw exception zkMain.executeLine(cmdstring); }
@Test public void testLsrNonexistantZnodeCommand() throws Exception { final ZooKeeper zk = createClient(); ZooKeeperMain zkMain = new ZooKeeperMain(zk); zkMain.executeLine("create /b"); zkMain.executeLine("create /b/c"); LsCommand cmd = new LsCommand(); cmd.setZk(zk); cmd.parse("ls -R /b/c/d".split(" ")); try { runCommandExpect(cmd, new ArrayList<String>()); Assert.fail("Path doesn't exists so, command should fail."); } catch (CliWrapperException e) { Assert.assertEquals(KeeperException.Code.NONODE, ((KeeperException)e.getCause()).code()); } }
Method readLine = consoleC.getMethod("readLine", String.class); while ((line = (String)readLine.invoke(console, getPrompt())) != null) { executeLine(line); executeLine(line);