From dde3eaed629ea1849a67c14648c50a131f9d4f09 Mon Sep 17 00:00:00 2001 From: Akira Ajisaka Date: Tue, 23 Aug 2016 19:56:27 +0900 Subject: [PATCH] HDFS-10783. The option '-maxSize' and '-step' fail in OfflineImageViewer. Contributed by Yiqun Lin. (cherry picked from commit e90f3359de299ef5e3a54ca71070e3dfe1dbb98c) (cherry picked from commit 94a844b4f61d4a47b2a5885e3db065a07ed29d97) --- .../OfflineImageViewer.java | 2 ++ .../TestOfflineImageViewer.java | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewer.java index f1dd9597632..630e4f0f91e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageViewer.java @@ -186,6 +186,8 @@ public class OfflineImageViewer { options.addOption("p", "processor", true, ""); options.addOption("h", "help", false, ""); + options.addOption("maxSize", true, ""); + options.addOption("step", true, ""); options.addOption("skipBlocks", false, ""); options.addOption("printToScreen", false, ""); options.addOption("delimiter", true, ""); 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 b9aa7f39e93..a7c30ecf353 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 @@ -601,4 +601,23 @@ public class TestOfflineImageViewer { "FileDistribution", "-maxSize", "23", "-step", "4"}); assertEquals(0, status); } + + @Test + public void testOfflineImageViewerMaxSizeAndStepOptions() throws Exception { + final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + final PrintStream out = new PrintStream(bytes); + final PrintStream oldOut = System.out; + try { + System.setOut(out); + // Add the -h option to make the test only for option parsing, + // and don't need to do the following operations. + OfflineImageViewer.main(new String[] {"-i", "-", "-o", "-", "-p", + "FileDistribution", "-maxSize", "512", "-step", "8", "-h"}); + Assert.assertFalse(bytes.toString().contains( + "Error parsing command-line options: ")); + } finally { + System.setOut(oldOut); + IOUtils.closeStream(out); + } + } }