Repository: hadoop
Updated Branches:
  refs/heads/trunk 86035c164 -> 92ea6d74e


HDFS-11516. Admin command line should print message to stderr in failure case. 
Contributed by Kai Sasaki.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/92ea6d74
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/92ea6d74
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/92ea6d74

Branch: refs/heads/trunk
Commit: 92ea6d74ecd84b86771e285902dd2a80bccbe3ea
Parents: 86035c1
Author: Andrew Wang <w...@apache.org>
Authored: Fri Mar 17 11:26:02 2017 -0700
Committer: Andrew Wang <w...@apache.org>
Committed: Fri Mar 17 11:26:02 2017 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/cli/CLITestHelper.java    | 17 ++++++++++-
 .../apache/hadoop/cli/util/CommandExecutor.java |  4 +--
 .../apache/hadoop/cli/util/FSCmdExecutor.java   |  4 +--
 .../apache/hadoop/hdfs/tools/AdminHelper.java   |  6 ++--
 .../apache/hadoop/hdfs/tools/CryptoAdmin.java   |  2 +-
 .../hadoop/cli/util/CacheAdminCmdExecutor.java  |  4 +--
 .../hadoop/cli/util/CryptoAdminCmdExecutor.java |  4 +--
 .../cli/util/ErasureCodingCliCmdExecutor.java   |  4 +--
 .../src/test/resources/testCryptoConf.xml       | 31 ++++++++++++++++++++
 .../test/resources/testErasureCodingConf.xml    | 16 ++++++++++
 10 files changed, 77 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/92ea6d74/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/CLITestHelper.java
----------------------------------------------------------------------
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/CLITestHelper.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/CLITestHelper.java
index 89d4e30..ada4cd8 100644
--- 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/CLITestHelper.java
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/CLITestHelper.java
@@ -298,6 +298,11 @@ public class CLITestHelper {
     
     return compareOutput;
   }
+
+  private boolean compareTextExitCode(ComparatorData compdata,
+      Result cmdResult) {
+    return compdata.getExitCode() == cmdResult.getExitCode();
+  }
   
   /***********************************
    ************* TESTS RUNNER
@@ -330,10 +335,17 @@ public class CLITestHelper {
         final String comptype = cd.getComparatorType();
         
         boolean compareOutput = false;
+        boolean compareExitCode = false;
         
         if (! comptype.equalsIgnoreCase("none")) {
           compareOutput = compareTestOutput(cd, cmdResult);
-          overallTCResult &= compareOutput;
+          if (cd.getExitCode() == -1) {
+            // No need to check exit code if not specified
+            compareExitCode = true;
+          } else {
+            compareExitCode = compareTextExitCode(cd, cmdResult);
+          }
+          overallTCResult &= (compareOutput & compareExitCode);
         }
         
         cd.setExitCode(cmdResult.getExitCode());
@@ -391,6 +403,7 @@ public class CLITestHelper {
         testComparators = new ArrayList<ComparatorData>();
       } else if (qName.equals("comparator")) {
         comparatorData = new ComparatorData();
+        comparatorData.setExitCode(-1);
       }
       charString = "";
     }
@@ -422,6 +435,8 @@ public class CLITestHelper {
         comparatorData.setComparatorType(charString);
       } else if (qName.equals("expected-output")) {
         comparatorData.setExpectedOutput(charString);
+      } else if (qName.equals("expected-exit-code")) {
+        comparatorData.setExitCode(Integer.valueOf(charString));
       } else if (qName.equals("test")) {
         if (!Shell.WINDOWS || runOnWindows) {
           testsFromConfigFile.add(td);

http://git-wip-us.apache.org/repos/asf/hadoop/blob/92ea6d74/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/util/CommandExecutor.java
----------------------------------------------------------------------
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/util/CommandExecutor.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/util/CommandExecutor.java
index 79df284..5ef129c 100644
--- 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/util/CommandExecutor.java
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/util/CommandExecutor.java
@@ -75,7 +75,7 @@ public abstract class CommandExecutor {
     System.setErr(new PrintStream(bao));
     
     try {
-      execute(cmd);
+      exitCode = execute(cmd);
     } catch (Exception e) {
       e.printStackTrace();
       lastException = e;
@@ -87,7 +87,7 @@ public abstract class CommandExecutor {
     return new Result(bao.toString(), exitCode, lastException, cmd);
   }
   
-  protected abstract void execute(final String cmd) throws Exception;
+  protected abstract int execute(String cmd) throws Exception;
   
   public static class Result {
     final String commandOutput;

http://git-wip-us.apache.org/repos/asf/hadoop/blob/92ea6d74/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/util/FSCmdExecutor.java
----------------------------------------------------------------------
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/util/FSCmdExecutor.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/util/FSCmdExecutor.java
index 98237ac..e2693bb 100644
--- 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/util/FSCmdExecutor.java
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/cli/util/FSCmdExecutor.java
@@ -30,8 +30,8 @@ public class FSCmdExecutor extends CommandExecutor {
   }
 
   @Override
-  protected void execute(final String cmd) throws Exception{
+  protected int execute(final String cmd) throws Exception{
     String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode);
-    ToolRunner.run(shell, args);
+    return ToolRunner.run(shell, args);
   }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/92ea6d74/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/AdminHelper.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/AdminHelper.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/AdminHelper.java
index 8bab550..2c5fb0e 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/AdminHelper.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/AdminHelper.java
@@ -176,11 +176,11 @@ public class AdminHelper {
         for (AdminHelper.Command command : commands) {
           System.err.println(command.getLongUsage());
         }
-        return 0;
+        return 1;
       }
       if (args.size() != 1) {
-        System.out.println("You must give exactly one argument to -help.");
-        return 0;
+        System.err.println("You must give exactly one argument to -help.");
+        return 1;
       }
       final String commandName = args.get(0);
       // prepend a dash to match against the command names

http://git-wip-us.apache.org/repos/asf/hadoop/blob/92ea6d74/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/CryptoAdmin.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/CryptoAdmin.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/CryptoAdmin.java
index 4c7335f..14abf6e 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/CryptoAdmin.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/CryptoAdmin.java
@@ -233,7 +233,7 @@ public class CryptoAdmin extends Configured implements Tool 
{
         final FileEncryptionInfo fei =
             admin.getFileEncryptionInfo(p);
         if (fei == null) {
-          System.out.println("No FileEncryptionInfo found for path " + path);
+          System.err.println("No FileEncryptionInfo found for path " + path);
           return 2;
         }
         System.out.println(fei.toStringStable());

http://git-wip-us.apache.org/repos/asf/hadoop/blob/92ea6d74/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/CacheAdminCmdExecutor.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/CacheAdminCmdExecutor.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/CacheAdminCmdExecutor.java
index 922020f..75efb3e 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/CacheAdminCmdExecutor.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/CacheAdminCmdExecutor.java
@@ -30,8 +30,8 @@ public class CacheAdminCmdExecutor extends CommandExecutor {
   }
 
   @Override
-  protected void execute(final String cmd) throws Exception {
+  protected int execute(final String cmd) throws Exception {
     String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode);
-    ToolRunner.run(admin, args);
+    return ToolRunner.run(admin, args);
   }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/92ea6d74/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/CryptoAdminCmdExecutor.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/CryptoAdminCmdExecutor.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/CryptoAdminCmdExecutor.java
index f781bf8..0ab5b0e 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/CryptoAdminCmdExecutor.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/CryptoAdminCmdExecutor.java
@@ -30,8 +30,8 @@ public class CryptoAdminCmdExecutor extends CommandExecutor {
   }
 
   @Override
-  protected void execute(final String cmd) throws Exception {
+  protected int execute(final String cmd) throws Exception {
     String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode);
-    ToolRunner.run(admin, args);
+    return ToolRunner.run(admin, args);
   }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/92ea6d74/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/ErasureCodingCliCmdExecutor.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/ErasureCodingCliCmdExecutor.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/ErasureCodingCliCmdExecutor.java
index 59b2a73..e39b4c9 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/ErasureCodingCliCmdExecutor.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/ErasureCodingCliCmdExecutor.java
@@ -30,8 +30,8 @@ public class ErasureCodingCliCmdExecutor extends 
CommandExecutor {
   }
 
   @Override
-  protected void execute(final String cmd) throws Exception {
+  protected int execute(final String cmd) throws Exception {
     String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode);
-    ToolRunner.run(admin, args);
+    return ToolRunner.run(admin, args);
   }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/92ea6d74/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testCryptoConf.xml
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testCryptoConf.xml 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testCryptoConf.xml
index 7e372be..f9bb29e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testCryptoConf.xml
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testCryptoConf.xml
@@ -47,6 +47,37 @@
     </test>
 
     <test>
+      <description>Test help usage</description>
+      <test-commands>
+        <crypto-admin-command>-help</crypto-admin-command>
+      </test-commands>
+      <cleanup-commands>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>[-createZone -keyName</expected-output>
+        </comparator>
+      </comparators>
+    </test>
+
+    <test>
+      <description>Test extra help argument</description>
+      <test-commands>
+        <crypto-admin-command>-help arg1 arg2</crypto-admin-command>
+      </test-commands>
+      <cleanup-commands>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>You must give exactly one argument to 
-help.</expected-output>
+          <expected-exit-code>1</expected-exit-code>
+        </comparator>
+      </comparators>
+    </test>
+
+    <test>
       <description>Test create ez, dir doesn't exist</description>
       <test-commands>
         <command>-fs NAMENODE -ls /test</command>-

http://git-wip-us.apache.org/repos/asf/hadoop/blob/92ea6d74/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml
index 8dda6c1..0a71109 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml
@@ -72,6 +72,22 @@
     </test>
 
     <test>
+      <description>help: help with extra argument</description>
+      <test-commands>
+        <ec-admin-command>-help arg1 arg2</ec-admin-command>
+      </test-commands>
+      <cleanup-commands>
+      </cleanup-commands>
+      <comparators>
+        <comparator>
+          <type>SubstringComparator</type>
+          <expected-output>You must give exactly one argument to 
-help.</expected-output>
+          <expected-exit-code>1</expected-exit-code>
+        </comparator>
+      </comparators>
+    </test>
+
+    <test>
       <description>help: setPolicy command</description>
       <test-commands>
         <ec-admin-command>-fs NAMENODE -help setPolicy</ec-admin-command>


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to