Преглед на файлове

ZOOKEEPER-1379. 'printwatches, redo, history and connect '. client commands always print usage. This is not necessary (edward via fpj)


git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1519515 13f79535-47bb-0310-9956-ffa450edef68
Flavio Paiva Junqueira преди 12 години
родител
ревизия
15c32d1979
променени са 3 файла, в които са добавени 32 реда и са изтрити 6 реда
  1. 2 0
      CHANGES.txt
  2. 7 6
      src/java/main/org/apache/zookeeper/ZooKeeperMain.java
  3. 23 0
      src/java/test/org/apache/zookeeper/ZooKeeperTest.java

+ 2 - 0
CHANGES.txt

@@ -367,6 +367,8 @@ BUGFIXES:
   ZOOKEEPER-1629. testTransactionLogCorruption occasionally fails. (shralex via camille)
 
   ZOOKEEPER-1713. wrong time calculation in zkfuse.cc (german via fpj)
+ 
+  ZOOKEEPER-1379. 'printwatches, redo, history and connect '. client commands always print usage. This is not necessary (edward via fpj)
   
 IMPROVEMENTS:
 

+ 7 - 6
src/java/main/org/apache/zookeeper/ZooKeeperMain.java

@@ -663,14 +663,15 @@ public class ZooKeeperMain {
         if(cliCmd != null) {
             cliCmd.setZk(zk);
             watch = cliCmd.parse(args).exec();
-            } else {
-                usage();
-            }
+        } else if (!commandMap.containsKey(cmd)) {
+             usage();
+        }
+
         } catch (ParseException ex) {
             System.err.println(ex.getMessage());
-                usage();
+            usage();
             return false;
-            }
+        }
         return watch;
     }
-        }
+}

+ 23 - 0
src/java/test/org/apache/zookeeper/ZooKeeperTest.java

@@ -19,7 +19,9 @@ package org.apache.zookeeper;
 
 import static org.junit.Assert.*;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.PrintStream;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -344,4 +346,25 @@ public class ZooKeeperTest extends ClientBase {
             }
     }
 
+    @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!");
+        }
+    }
+
 }