|
@@ -17,8 +17,12 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.fs;
|
|
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.PrintStream;
|
|
|
+
|
|
|
import junit.framework.AssertionFailedError;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.io.IOUtils;
|
|
|
import org.apache.hadoop.tracing.SetSpanReceiver;
|
|
|
import org.apache.hadoop.tracing.SpanReceiverHost;
|
|
|
import org.apache.hadoop.util.ToolRunner;
|
|
@@ -67,4 +71,33 @@ public class TestFsShell {
|
|
|
SetSpanReceiver.getMap()
|
|
|
.get("help").get(0).getKVAnnotations().get("args"));
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDFSWithInvalidCommmand() throws Throwable {
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ FsShell shell = new FsShell(conf);
|
|
|
+ String[] args = new String[1];
|
|
|
+ args[0] = "dfs -mkdirs";
|
|
|
+ final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
+ final PrintStream out = new PrintStream(bytes);
|
|
|
+ final PrintStream oldErr = System.err;
|
|
|
+ try {
|
|
|
+ System.setErr(out);
|
|
|
+ ToolRunner.run(shell, args);
|
|
|
+ String errorValue=new String(bytes.toString());
|
|
|
+ Assert
|
|
|
+ .assertTrue(
|
|
|
+ "FSShell dfs command did not print the error " +
|
|
|
+ "message when invalid command is passed",
|
|
|
+ errorValue.contains("-mkdirs: Unknown command"));
|
|
|
+ Assert
|
|
|
+ .assertTrue(
|
|
|
+ "FSShell dfs command did not print help " +
|
|
|
+ "message when invalid command is passed",
|
|
|
+ errorValue.contains("Usage: hadoop fs [generic options]"));
|
|
|
+ } finally {
|
|
|
+ IOUtils.closeStream(out);
|
|
|
+ System.setErr(oldErr);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|