Search in sources :

Example 6 with Command

use of org.apache.hadoop.fs.shell.Command in project hadoop by apache.

the class TestFsShell method testExceptionNullMessage.

@Test
public void testExceptionNullMessage() throws Exception {
    final String cmdName = "-cmdExNullMsg";
    final Command cmd = Mockito.mock(Command.class);
    Mockito.when(cmd.run(Mockito.anyVararg())).thenThrow(new IllegalArgumentException());
    Mockito.when(cmd.getUsage()).thenReturn(cmdName);
    final CommandFactory cmdFactory = Mockito.mock(CommandFactory.class);
    final String[] names = { cmdName };
    Mockito.when(cmdFactory.getNames()).thenReturn(names);
    Mockito.when(cmdFactory.getInstance(cmdName)).thenReturn(cmd);
    FsShell shell = new FsShell(new Configuration());
    shell.commandFactory = cmdFactory;
    try (GenericTestUtils.SystemErrCapturer capture = new GenericTestUtils.SystemErrCapturer()) {
        ToolRunner.run(shell, new String[] { cmdName });
        Assert.assertThat(capture.getOutput(), StringContains.containsString(cmdName + ": Null exception message"));
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Command(org.apache.hadoop.fs.shell.Command) GenericTestUtils(org.apache.hadoop.test.GenericTestUtils) CommandFactory(org.apache.hadoop.fs.shell.CommandFactory) Test(org.junit.Test)

Example 7 with Command

use of org.apache.hadoop.fs.shell.Command in project hadoop by apache.

the class FsShell method displayError.

private void displayError(String cmd, String message) {
    for (String line : message.split("\n")) {
        System.err.println(cmd + ": " + line);
        if (cmd.charAt(0) != '-') {
            Command instance = null;
            instance = commandFactory.getInstance("-" + cmd);
            if (instance != null) {
                System.err.println("Did you mean -" + cmd + "?  This command " + "begins with a dash.");
            }
        }
    }
}
Also used : Command(org.apache.hadoop.fs.shell.Command) FsCommand(org.apache.hadoop.fs.shell.FsCommand)

Aggregations

Command (org.apache.hadoop.fs.shell.Command)7 FsCommand (org.apache.hadoop.fs.shell.FsCommand)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Configuration (org.apache.hadoop.conf.Configuration)1 CommandFactory (org.apache.hadoop.fs.shell.CommandFactory)1 GenericTestUtils (org.apache.hadoop.test.GenericTestUtils)1 TraceScope (org.apache.htrace.core.TraceScope)1 Tracer (org.apache.htrace.core.Tracer)1 Test (org.junit.Test)1