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 89d4e30ce2..ada4cd80e4 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 @@ private boolean compareTestOutput(ComparatorData compdata, Result cmdResult) { return compareOutput; } + + private boolean compareTextExitCode(ComparatorData compdata, + Result cmdResult) { + return compdata.getExitCode() == cmdResult.getExitCode(); + } /*********************************** ************* TESTS RUNNER @@ -330,10 +335,17 @@ public void testAll() { 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 void startElement(String uri, testComparators = new ArrayList(); } else if (qName.equals("comparator")) { comparatorData = new ComparatorData(); + comparatorData.setExitCode(-1); } charString = ""; } @@ -422,6 +435,8 @@ public void endElement(String uri, String localName,String qName) 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); 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 79df284045..5ef129cdc8 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 Result executeCommand(final String cmd) throws Exception { System.setErr(new PrintStream(bao)); try { - execute(cmd); + exitCode = execute(cmd); } catch (Exception e) { e.printStackTrace(); lastException = e; @@ -87,7 +87,7 @@ public Result executeCommand(final String cmd) throws Exception { 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; 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 98237ac726..e2693bb6ea 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 FSCmdExecutor(String namenode, FsShell shell) { } @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); } } 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 8bab5505ef..2c5fb0e1e8 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 int run(Configuration conf, List args) throws IOException { 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 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 4c7335ffb2..14abf6e074 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 int run(Configuration conf, List args) throws IOException { 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()); 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 922020faf8..75efb3edf4 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 CacheAdminCmdExecutor(String namenode, CacheAdmin admin) { } @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); } } 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 f781bf8d87..0ab5b0ea28 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 CryptoAdminCmdExecutor(String namenode, CryptoAdmin admin) { } @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); } } 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 59b2a73e2d..e39b4c9cbd 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 ErasureCodingCliCmdExecutor(String namenode, ECAdmin admin) { } @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); } } 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 7e372becaf..f9bb29eb9e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testCryptoConf.xml +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testCryptoConf.xml @@ -46,6 +46,37 @@ + + Test help usage + + -help + + + + + + SubstringComparator + [-createZone -keyName + + + + + + Test extra help argument + + -help arg1 arg2 + + + + + + SubstringComparator + You must give exactly one argument to -help. + 1 + + + + Test create ez, dir doesn't exist 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 8dda6c1af2..0a71109d78 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml @@ -71,6 +71,22 @@ + + help: help with extra argument + + -help arg1 arg2 + + + + + + SubstringComparator + You must give exactly one argument to -help. + 1 + + + + help: setPolicy command