You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by vi...@apache.org on 2015/10/15 14:08:57 UTC
[1/2] hadoop git commit: HDFS-9157. [OEV and OIV] : Unnecessary
parsing for mandatory arguements if '-h' option is specified as the only
option (Contributed by nijel)
Repository: hadoop
Updated Branches:
refs/heads/branch-2 342870b70 -> 0956aed25
refs/heads/trunk a49298d58 -> 08f5de1ef
HDFS-9157. [OEV and OIV] : Unnecessary parsing for mandatory arguements if '-h' option is specified as the only option (Contributed by nijel)
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/08f5de1e
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/08f5de1e
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/08f5de1e
Branch: refs/heads/trunk
Commit: 08f5de1ef55f637b3bbde0ace28b42f155e285a1
Parents: a49298d
Author: Vinayakumar B <vi...@apache.org>
Authored: Thu Oct 15 17:37:06 2015 +0530
Committer: Vinayakumar B <vi...@apache.org>
Committed: Thu Oct 15 17:37:06 2015 +0530
----------------------------------------------------------------------
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++
.../offlineEditsViewer/OfflineEditsViewer.java | 19 ++++++++++++---
.../OfflineImageViewerPB.java | 19 ++++++++++++---
.../TestOfflineEditsViewer.java | 23 ++++++++++++++++++
.../TestOfflineImageViewer.java | 25 ++++++++++++++++++++
5 files changed, 83 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/08f5de1e/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
index cb6a6a1..674b090 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
@@ -2066,6 +2066,9 @@ Release 2.8.0 - UNRELEASED
HDFS-9187. Fix null pointer error in Globber when FS was not constructed
via FileSystem#createFileSystem (cmccabe)
+ HDFS-9157. [OEV and OIV] : Unnecessary parsing for mandatory arguements if
+ '-h' option is specified as the only option (nijel via vinayakumarb)
+
Release 2.7.2 - UNRELEASED
INCOMPATIBLE CHANGES
http://git-wip-us.apache.org/repos/asf/hadoop/blob/08f5de1e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsViewer.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsViewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsViewer.java
index 54b8511..107881f 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsViewer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsViewer.java
@@ -39,7 +39,8 @@ import org.apache.commons.cli.PosixParser;
@InterfaceAudience.Private
@InterfaceStability.Unstable
public class OfflineEditsViewer extends Configured implements Tool {
-
+ private static final String HELP_OPT = "-h";
+ private static final String HELP_LONGOPT = "--help";
private final static String defaultProcessor = "xml";
/**
@@ -192,7 +193,12 @@ public class OfflineEditsViewer extends Configured implements Tool {
Options options = buildOptions();
if(argv.length == 0) {
printHelp();
- return -1;
+ return 0;
+ }
+ // print help and exit with zero exit code
+ if (argv.length == 1 && isHelpOption(argv[0])) {
+ printHelp();
+ return 0;
}
CommandLineParser parser = new PosixParser();
CommandLine cmd;
@@ -205,7 +211,9 @@ public class OfflineEditsViewer extends Configured implements Tool {
return -1;
}
- if(cmd.hasOption("h")) { // print help and exit
+ if (cmd.hasOption("h")) {
+ // print help and exit with non zero exit code since
+ // it is not expected to give help and other options together.
printHelp();
return -1;
}
@@ -237,4 +245,9 @@ public class OfflineEditsViewer extends Configured implements Tool {
int res = ToolRunner.run(new OfflineEditsViewer(), argv);
System.exit(res);
}
+
+ private static boolean isHelpOption(String arg) {
+ return arg.equalsIgnoreCase(HELP_OPT) ||
+ arg.equalsIgnoreCase(HELP_LONGOPT);
+ }
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/08f5de1e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java
index 777acdf..4afbdb8 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java
@@ -41,6 +41,8 @@ import org.apache.hadoop.net.NetUtils;
*/
@InterfaceAudience.Private
public class OfflineImageViewerPB {
+ private static final String HELP_OPT = "-h";
+ private static final String HELP_LONGOPT = "--help";
public static final Log LOG = LogFactory.getLog(OfflineImageViewerPB.class);
private final static String usage = "Usage: bin/hdfs oiv [OPTIONS] -i INPUTFILE -o OUTPUTFILE\n"
@@ -131,7 +133,11 @@ public class OfflineImageViewerPB {
printUsage();
return 0;
}
-
+ // print help and exit with zero exit code
+ if (args.length == 1 && isHelpOption(args[0])) {
+ printUsage();
+ return 0;
+ }
CommandLineParser parser = new PosixParser();
CommandLine cmd;
@@ -143,9 +149,11 @@ public class OfflineImageViewerPB {
return -1;
}
- if (cmd.hasOption("h")) { // print help and exit
+ if (cmd.hasOption("h")) {
+ // print help and exit with non zero exit code since
+ // it is not expected to give help and other options together.
printUsage();
- return 0;
+ return -1;
}
String inputFile = cmd.getOptionValue("i");
@@ -202,4 +210,9 @@ public class OfflineImageViewerPB {
private static void printUsage() {
System.out.println(usage);
}
+
+ private static boolean isHelpOption(String arg) {
+ return arg.equalsIgnoreCase(HELP_OPT) ||
+ arg.equalsIgnoreCase(HELP_LONGOPT);
+ }
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/08f5de1e/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
index fbbbc29..c5bc721 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
@@ -21,9 +21,11 @@ package org.apache.hadoop.hdfs.tools.offlineEditsViewer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.PrintStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
@@ -35,8 +37,10 @@ import org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes;
import org.apache.hadoop.hdfs.server.namenode.NameNodeLayoutVersion;
import org.apache.hadoop.hdfs.server.namenode.OfflineEditsViewerHelper;
import org.apache.hadoop.hdfs.tools.offlineEditsViewer.OfflineEditsViewer.Flags;
+import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.test.PathUtils;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -285,4 +289,23 @@ public class TestOfflineEditsViewer {
return true;
}
+
+ @Test
+ public void testOfflineEditsViewerHelpMessage() throws Throwable {
+ final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ final PrintStream out = new PrintStream(bytes);
+ final PrintStream oldOut = System.out;
+ try {
+ System.setOut(out);
+ int status = new OfflineEditsViewer().run(new String[] { "-h" });
+ assertTrue("" + "Exit code returned for help option is incorrect",
+ status == 0);
+ Assert.assertFalse(
+ "Invalid Command error displayed when help option is passed.", bytes
+ .toString().contains("Error parsing command-line options"));
+ } finally {
+ System.setOut(oldOut);
+ IOUtils.closeStream(out);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/08f5de1e/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java
index e1beca5..467534a 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java
@@ -67,6 +67,7 @@ import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.token.Token;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
@@ -350,6 +351,30 @@ public class TestOfflineImageViewer {
status != 0);
}
+ @Test
+ public void testOfflineImageViewerHelpMessage() throws Throwable {
+ final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ final PrintStream out = new PrintStream(bytes);
+ final PrintStream oldOut = System.out;
+ try {
+ System.setOut(out);
+ int status = OfflineImageViewerPB.run(new String[] { "-h" });
+ assertTrue("Exit code returned for help option is incorrect", status == 0);
+ Assert.assertFalse(
+ "Invalid Command error displayed when help option is passed.", bytes
+ .toString().contains("Error parsing command-line options"));
+ status =
+ OfflineImageViewerPB.run(new String[] { "-h", "-i",
+ originalFsimage.getAbsolutePath(), "-o", "-", "-p",
+ "FileDistribution", "-maxSize", "512", "-step", "8" });
+ Assert.assertTrue(
+ "Exit code returned for help with other option is incorrect",
+ status == -1);
+ } finally {
+ System.setOut(oldOut);
+ IOUtils.closeStream(out);
+ }
+ }
private void testPBDelimitedWriter(String db)
throws IOException, InterruptedException {
final String DELIMITER = "\t";
[2/2] hadoop git commit: HDFS-9157. [OEV and OIV] : Unnecessary
parsing for mandatory arguements if '-h' option is specified as the only
option (Contributed by nijel)
Posted by vi...@apache.org.
HDFS-9157. [OEV and OIV] : Unnecessary parsing for mandatory arguements if '-h' option is specified as the only option (Contributed by nijel)
(cherry picked from commit 08f5de1ef55f637b3bbde0ace28b42f155e285a1)
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/0956aed2
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/0956aed2
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/0956aed2
Branch: refs/heads/branch-2
Commit: 0956aed25a633b99fc75abcf1ce1a5f86e0d8fa0
Parents: 342870b
Author: Vinayakumar B <vi...@apache.org>
Authored: Thu Oct 15 17:37:06 2015 +0530
Committer: Vinayakumar B <vi...@apache.org>
Committed: Thu Oct 15 17:37:45 2015 +0530
----------------------------------------------------------------------
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++
.../offlineEditsViewer/OfflineEditsViewer.java | 19 ++++++++++++---
.../OfflineImageViewerPB.java | 19 ++++++++++++---
.../TestOfflineEditsViewer.java | 23 ++++++++++++++++++
.../TestOfflineImageViewer.java | 25 ++++++++++++++++++++
5 files changed, 83 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/0956aed2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
index 18aee53..97ad369 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
@@ -1238,6 +1238,9 @@ Release 2.8.0 - UNRELEASED
HDFS-9187. Fix null pointer error in Globber when FS was not constructed
via FileSystem#createFileSystem (cmccabe)
+ HDFS-9157. [OEV and OIV] : Unnecessary parsing for mandatory arguements if
+ '-h' option is specified as the only option (nijel via vinayakumarb)
+
Release 2.7.2 - UNRELEASED
INCOMPATIBLE CHANGES
http://git-wip-us.apache.org/repos/asf/hadoop/blob/0956aed2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsViewer.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsViewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsViewer.java
index 54b8511..107881f 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsViewer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsViewer.java
@@ -39,7 +39,8 @@ import org.apache.commons.cli.PosixParser;
@InterfaceAudience.Private
@InterfaceStability.Unstable
public class OfflineEditsViewer extends Configured implements Tool {
-
+ private static final String HELP_OPT = "-h";
+ private static final String HELP_LONGOPT = "--help";
private final static String defaultProcessor = "xml";
/**
@@ -192,7 +193,12 @@ public class OfflineEditsViewer extends Configured implements Tool {
Options options = buildOptions();
if(argv.length == 0) {
printHelp();
- return -1;
+ return 0;
+ }
+ // print help and exit with zero exit code
+ if (argv.length == 1 && isHelpOption(argv[0])) {
+ printHelp();
+ return 0;
}
CommandLineParser parser = new PosixParser();
CommandLine cmd;
@@ -205,7 +211,9 @@ public class OfflineEditsViewer extends Configured implements Tool {
return -1;
}
- if(cmd.hasOption("h")) { // print help and exit
+ if (cmd.hasOption("h")) {
+ // print help and exit with non zero exit code since
+ // it is not expected to give help and other options together.
printHelp();
return -1;
}
@@ -237,4 +245,9 @@ public class OfflineEditsViewer extends Configured implements Tool {
int res = ToolRunner.run(new OfflineEditsViewer(), argv);
System.exit(res);
}
+
+ private static boolean isHelpOption(String arg) {
+ return arg.equalsIgnoreCase(HELP_OPT) ||
+ arg.equalsIgnoreCase(HELP_LONGOPT);
+ }
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/0956aed2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java
index f15c81f..f27abb7 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewerPB.java
@@ -41,6 +41,8 @@ import org.apache.hadoop.net.NetUtils;
*/
@InterfaceAudience.Private
public class OfflineImageViewerPB {
+ private static final String HELP_OPT = "-h";
+ private static final String HELP_LONGOPT = "--help";
public static final Log LOG = LogFactory.getLog(OfflineImageViewerPB.class);
private final static String usage = "Usage: bin/hdfs oiv [OPTIONS] -i INPUTFILE -o OUTPUTFILE\n"
@@ -131,7 +133,11 @@ public class OfflineImageViewerPB {
printUsage();
return 0;
}
-
+ // print help and exit with zero exit code
+ if (args.length == 1 && isHelpOption(args[0])) {
+ printUsage();
+ return 0;
+ }
CommandLineParser parser = new PosixParser();
CommandLine cmd;
@@ -143,9 +149,11 @@ public class OfflineImageViewerPB {
return -1;
}
- if (cmd.hasOption("h")) { // print help and exit
+ if (cmd.hasOption("h")) {
+ // print help and exit with non zero exit code since
+ // it is not expected to give help and other options together.
printUsage();
- return 0;
+ return -1;
}
String inputFile = cmd.getOptionValue("i");
@@ -202,4 +210,9 @@ public class OfflineImageViewerPB {
private static void printUsage() {
System.out.println(usage);
}
+
+ private static boolean isHelpOption(String arg) {
+ return arg.equalsIgnoreCase(HELP_OPT) ||
+ arg.equalsIgnoreCase(HELP_LONGOPT);
+ }
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/0956aed2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
index fbbbc29..c5bc721 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
@@ -21,9 +21,11 @@ package org.apache.hadoop.hdfs.tools.offlineEditsViewer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.PrintStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
@@ -35,8 +37,10 @@ import org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes;
import org.apache.hadoop.hdfs.server.namenode.NameNodeLayoutVersion;
import org.apache.hadoop.hdfs.server.namenode.OfflineEditsViewerHelper;
import org.apache.hadoop.hdfs.tools.offlineEditsViewer.OfflineEditsViewer.Flags;
+import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.test.PathUtils;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -285,4 +289,23 @@ public class TestOfflineEditsViewer {
return true;
}
+
+ @Test
+ public void testOfflineEditsViewerHelpMessage() throws Throwable {
+ final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ final PrintStream out = new PrintStream(bytes);
+ final PrintStream oldOut = System.out;
+ try {
+ System.setOut(out);
+ int status = new OfflineEditsViewer().run(new String[] { "-h" });
+ assertTrue("" + "Exit code returned for help option is incorrect",
+ status == 0);
+ Assert.assertFalse(
+ "Invalid Command error displayed when help option is passed.", bytes
+ .toString().contains("Error parsing command-line options"));
+ } finally {
+ System.setOut(oldOut);
+ IOUtils.closeStream(out);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/0956aed2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java
index e1beca5..467534a 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java
@@ -67,6 +67,7 @@ import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.token.Token;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
@@ -350,6 +351,30 @@ public class TestOfflineImageViewer {
status != 0);
}
+ @Test
+ public void testOfflineImageViewerHelpMessage() throws Throwable {
+ final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ final PrintStream out = new PrintStream(bytes);
+ final PrintStream oldOut = System.out;
+ try {
+ System.setOut(out);
+ int status = OfflineImageViewerPB.run(new String[] { "-h" });
+ assertTrue("Exit code returned for help option is incorrect", status == 0);
+ Assert.assertFalse(
+ "Invalid Command error displayed when help option is passed.", bytes
+ .toString().contains("Error parsing command-line options"));
+ status =
+ OfflineImageViewerPB.run(new String[] { "-h", "-i",
+ originalFsimage.getAbsolutePath(), "-o", "-", "-p",
+ "FileDistribution", "-maxSize", "512", "-step", "8" });
+ Assert.assertTrue(
+ "Exit code returned for help with other option is incorrect",
+ status == -1);
+ } finally {
+ System.setOut(oldOut);
+ IOUtils.closeStream(out);
+ }
+ }
private void testPBDelimitedWriter(String db)
throws IOException, InterruptedException {
final String DELIMITER = "\t";