From 02da23b62b4124c59565435f58ceaeaecc20c842 Mon Sep 17 00:00:00 2001 From: Hyunsik Choi Date: Mon, 14 Mar 2016 17:42:22 -0700 Subject: [PATCH 1/2] TAJO-2091: Error or progress update should use stderr instead of stdout. --- .../org/apache/tajo/cli/tsql/TajoCli.java | 27 +++++++---- .../tsql/commands/ConnectDatabaseCommand.java | 2 +- .../cli/tsql/commands/DescTableCommand.java | 4 +- .../commands/ExecExternalShellCommand.java | 3 +- .../tajo/cli/tsql/commands/ExitCommand.java | 4 +- .../tajo/cli/tsql/commands/HdfsCommand.java | 2 +- .../tajo/cli/tsql/commands/HelpCommand.java | 2 +- .../tajo/cli/tsql/commands/SetCommand.java | 2 +- .../cli/tsql/commands/TajoAdminCommand.java | 2 +- .../cli/tsql/commands/TajoGetConfCommand.java | 2 +- .../cli/tsql/commands/TajoHAAdminCommand.java | 2 +- .../tsql/TestDefaultCliOutputFormatter.java | 2 +- .../org/apache/tajo/cli/tsql/TestTajoCli.java | 48 ++++++++++++++----- .../tajo/cli/tsql/TestTajoCliNegatives.java | 16 ++++--- .../TestExecExternalShellCommand.java | 3 +- .../cli/tsql/commands/TestHdfsCommand.java | 7 +-- ...estAddPartitionNotimplementedException.err | 1 + ...AddPartitionNotimplementedException.result | 3 +- ...testSelectResultWithNullTrueDeprecated.err | 1 + ...tSelectResultWithNullTrueDeprecated.result | 1 - .../results/TestTajoCli/testStopWhenError.err | 1 + .../TestTajoCli/testStopWhenError.result | 3 +- .../testStopWhenErrorDeprecated.err | 2 + .../testStopWhenErrorDeprecated.result | 4 +- 24 files changed, 90 insertions(+), 54 deletions(-) create mode 100644 tajo-core-tests/src/test/resources/results/TestTajoCli/testAddPartitionNotimplementedException.err create mode 100644 tajo-core-tests/src/test/resources/results/TestTajoCli/testSelectResultWithNullTrueDeprecated.err create mode 100644 tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenError.err create mode 100644 tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenErrorDeprecated.err diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java index 1fa78628db..b9686aa0c0 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java @@ -64,6 +64,7 @@ public class TajoCli implements Closeable { private final ConsoleReader reader; private final InputStream sin; private final PrintWriter sout; + private final PrintWriter serr; private TajoFileHistory history; private final boolean reconnect; // reconnect on invalid session @@ -132,6 +133,10 @@ public PrintWriter getOutput() { return sout; } + public PrintWriter getError() { + return serr; + } + public TajoConf getConf() { return conf; } @@ -177,7 +182,7 @@ public Map getCommands() { } } - public TajoCli(TajoConf c, String [] args, @Nullable Properties clientParams, InputStream in, OutputStream out) + public TajoCli(TajoConf c, String [] args, @Nullable Properties clientParams, InputStream in, OutputStream out, OutputStream err) throws Exception { CommandLineParser parser = new PosixParser(); @@ -194,6 +199,7 @@ public TajoCli(TajoConf c, String [] args, @Nullable Properties clientParams, In this.reader.setExpandEvents(false); this.sout = new PrintWriter(reader.getOutput()); + this.serr = new PrintWriter(new OutputStreamWriter(err, "UTF-8")); initFormatter(); if (cmd.hasOption("help")) { @@ -264,6 +270,7 @@ public TajoCli(TajoConf c, String [] args, @Nullable Properties clientParams, In displayFormatter.setScriptMode(); int exitCode = executeScript(cmd.getOptionValue("c")); sout.flush(); + serr.flush(); System.exit(exitCode); } if (cmd.hasOption("f")) { @@ -275,6 +282,7 @@ public TajoCli(TajoConf c, String [] args, @Nullable Properties clientParams, In script = replaceParam(script, cmd.getOptionValues("param")); int exitCode = executeScript(script); sout.flush(); + serr.flush(); System.exit(exitCode); } else { System.err.println(ERROR_PREFIX + "No such a file \"" + cmd.getOptionValue("f") + "\""); @@ -493,6 +501,7 @@ public int executeMetaCommand(String line) { onError(t); return -1; } finally { + context.getError().flush(); context.getOutput().flush(); } @@ -614,11 +623,11 @@ private void waitForQueryCompleted(QueryId queryId) { } if (TajoClientUtil.isQueryRunning(status.getState())) { - displayFormatter.printProgress(sout, status); + displayFormatter.printProgress(serr, status); } if (TajoClientUtil.isQueryComplete(status.getState()) && status.getState() != QueryState.QUERY_KILL_WAIT) { - displayFormatter.printProgress(sout, status); + displayFormatter.printProgress(serr, status); break; } else { Thread.sleep(Math.min(200 * progressRetries, 1000)); @@ -627,10 +636,10 @@ private void waitForQueryCompleted(QueryId queryId) { } if (status.getState() == QueryState.QUERY_ERROR || status.getState() == QueryState.QUERY_FAILED) { - displayFormatter.printErrorMessage(sout, status); + displayFormatter.printErrorMessage(serr, status); wasError = true; } else if (status.getState() == QueryState.QUERY_KILLED) { - displayFormatter.printKilledMessage(sout, queryId); + displayFormatter.printKilledMessage(serr, queryId); wasError = true; } else { if (status.getState() == QueryState.QUERY_SUCCEEDED) { @@ -671,18 +680,18 @@ public int executeScript(String script) throws Exception { private void printUsage() { HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp("tsql [options] [database]", options); + formatter.printUsage(this.serr, 80, "tsql [options] [database]", options); } private void printInvalidCommand(String command) { - sout.println("Invalid command " + command + ". Try \\? for help."); + serr.println("Invalid command " + command + ". Try \\? for help."); } private void onError(Throwable t) { Preconditions.checkNotNull(t); wasError = true; - displayFormatter.printErrorMessage(sout, t.getMessage()); + displayFormatter.printErrorMessage(serr, t.getMessage()); if (reconnect && (t instanceof InvalidClientSessionException)) { try { @@ -707,7 +716,7 @@ public void close() { public static void main(String [] args) throws Exception { TajoConf conf = new TajoConf(); - TajoCli shell = new TajoCli(conf, args, new Properties(), System.in, System.out); + TajoCli shell = new TajoCli(conf, args, new Properties(), System.in, System.out, System.err); System.out.println(); System.exit(shell.runShell()); } diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java index d524d8093b..717a0fe98f 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ConnectDatabaseCommand.java @@ -65,7 +65,7 @@ public void invoke(String[] cmd) throws Exception { ); } catch (TajoException se) { - context.getOutput().write(String.format("ERROR: %s%n", se.getMessage())); + context.getError().write(String.format("ERROR: %s%n", se.getMessage())); } } } diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescTableCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescTableCommand.java index 12d23cf3a0..abfcfe41f6 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescTableCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescTableCommand.java @@ -58,7 +58,7 @@ public void invoke(String[] cmd) throws TajoException { String tableName = tableNameMaker.toString().replace("\"", ""); TableDesc desc = client.getTableDesc(tableName); if (desc == null) { - context.getOutput().println("Did not find any relation named \"" + tableName + "\""); + context.getError().println("Did not find any relation named \"" + tableName + "\""); } else { context.getOutput().println(toFormattedString(desc)); // If there exists any indexes for the table, print index information @@ -81,7 +81,7 @@ public void invoke(String[] cmd) throws TajoException { } else if (cmd.length == 1) { List tableList = client.getTableList(null); if (tableList.size() == 0) { - context.getOutput().println("No Relation Found"); + context.getError().println("No Relation Found"); } for (String table : tableList) { context.getOutput().println(table); diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ExecExternalShellCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ExecExternalShellCommand.java index ac97959a46..90fad7014c 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ExecExternalShellCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ExecExternalShellCommand.java @@ -53,12 +53,13 @@ public void invoke(String[] command) throws Exception { execCommand[2] = builtCommand; PrintWriter sout = context.getOutput(); + PrintWriter serr = context.getError(); CountDownLatch latch = new CountDownLatch(2); Process process = Runtime.getRuntime().exec(execCommand); try { InputStreamConsoleWriter inWriter = new InputStreamConsoleWriter(process.getInputStream(), sout, "", latch); - InputStreamConsoleWriter errWriter = new InputStreamConsoleWriter(process.getErrorStream(), sout, "ERROR: ", latch); + InputStreamConsoleWriter errWriter = new InputStreamConsoleWriter(process.getErrorStream(), serr, "ERROR: ", latch); inWriter.start(); errWriter.start(); diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ExitCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ExitCommand.java index a9f0846144..15b664d1ea 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ExitCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/ExitCommand.java @@ -36,8 +36,8 @@ public String getCommand() { @Override public void invoke(String[] cmd) throws Exception { - context.getOutput().println("bye!"); - context.getOutput().close(); + context.getError().println("bye!"); + context.getError().flush(); System.exit(0); } diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/HdfsCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/HdfsCommand.java index 8f57b74402..ad3539805f 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/HdfsCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/HdfsCommand.java @@ -42,7 +42,7 @@ public void invoke(String[] command) throws Exception { fsShell.run(dfsCommands); } catch (Exception e) { - context.getOutput().println("ERROR: " + e.getMessage()); + context.getError().println("ERROR: " + e.getMessage()); } } diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/HelpCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/HelpCommand.java index f051e6a252..aeb60de2f4 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/HelpCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/HelpCommand.java @@ -96,7 +96,7 @@ public void invoke(String[] cmd) throws Exception { if (context.getCommands().containsKey(slashCommand)) { context.getCommands().get(slashCommand).printHelp(); } else { - context.getOutput().println("Command not found: " + cmd[1]); + context.getError().println("Command not found: " + cmd[1]); } } } diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java index 5cff2c7be8..526b9d0c05 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/SetCommand.java @@ -71,7 +71,7 @@ public void set(String key, String val) throws NoSuchSessionVariableException { } if (SessionVars.isDeprecated(key)) { - context.getOutput().println("Warning: deprecated to directly use config key in TajoConf.ConfVars. " + + context.getError().println("Warning: deprecated to directly use config key in TajoConf.ConfVars. " + "Please execute '\\help set'."); } } else { diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoAdminCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoAdminCommand.java index 53f66b0e0b..9c31758971 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoAdminCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoAdminCommand.java @@ -42,7 +42,7 @@ public void invoke(String[] command) throws Exception { admin.runCommand(dfsCommands); } catch (Exception e) { - context.getOutput().println("ERROR: " + e.getMessage()); + context.getError().println("ERROR: " + e.getMessage()); } } diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoGetConfCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoGetConfCommand.java index 5c7dd0ec4b..a860503641 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoGetConfCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoGetConfCommand.java @@ -42,7 +42,7 @@ public void invoke(String[] command) throws Exception { getconf.runCommand(getConfCommands); } catch (Exception e) { - context.getOutput().println("ERROR: " + e.getMessage()); + context.getError().println("ERROR: " + e.getMessage()); } } diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoHAAdminCommand.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoHAAdminCommand.java index 49dee28d44..2ea9b858d0 100644 --- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoHAAdminCommand.java +++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/TajoHAAdminCommand.java @@ -42,7 +42,7 @@ public void invoke(String[] command) throws Exception { haAdmin.runCommand(haAdminCommands); } catch (Exception e) { - context.getOutput().println("ERROR: " + e.getMessage()); + context.getError().println("ERROR: " + e.getMessage()); } } diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestDefaultCliOutputFormatter.java b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestDefaultCliOutputFormatter.java index c497d74b9a..fefdbb1f60 100644 --- a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestDefaultCliOutputFormatter.java +++ b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestDefaultCliOutputFormatter.java @@ -66,7 +66,7 @@ public class TestDefaultCliOutputFormatter { public void setUp() throws Exception { conf = cluster.getConfiguration(); ByteArrayOutputStream out = new ByteArrayOutputStream(); - tajoCli = new TajoCli(conf, new String[]{}, null, System.in, out); + tajoCli = new TajoCli(conf, new String[]{}, null, System.in, out, out); cliContext = tajoCli.getContext(); } diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java index 6bd694fad3..39c760c8a1 100644 --- a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java +++ b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java @@ -69,6 +69,7 @@ public class TestTajoCli { private TajoCli tajoCli; private Path currentResultPath; private ByteArrayOutputStream out; + private ByteArrayOutputStream err; @Rule public TestName name = new TestName(); @@ -81,14 +82,16 @@ public TestTajoCli() { @Before public void setUp() throws Exception { out = new ByteArrayOutputStream(); + err = new ByteArrayOutputStream(); Properties connParams = new Properties(); connParams.setProperty(RpcConstants.CLIENT_RETRY_NUM, "3"); - tajoCli = new TajoCli(cluster.getConfiguration(), new String[]{}, connParams, System.in, out); + tajoCli = new TajoCli(cluster.getConfiguration(), new String[]{}, connParams, System.in, out, err); } @After public void tearDown() throws IOException { out.close(); + err.close(); if (tajoCli != null) { tajoCli.close(); } @@ -106,17 +109,33 @@ private void assertOutputResult(String actual) throws Exception { assertOutputResult(name.getMethodName() + ".result", actual); } + private void assertErrorResult(String actual, boolean required) throws Exception { + String fileName = name.getMethodName() + ".err"; + if (required) { + assertOutputResult(fileName, actual); + } + } + private void assertOutputResult(String expectedResultFile, String actual) throws Exception { assertOutputResult(expectedResultFile, actual, null, null); } + private boolean existsFile(String fileName) throws IOException { + FileSystem fs = currentResultPath.getFileSystem(testBase.getTestingCluster().getConfiguration()); + Path filePath = StorageUtil.concatPath(currentResultPath, fileName); + return fs.exists(filePath); + } + + private Path getAbsolutePath(String fileName) { + return StorageUtil.concatPath(currentResultPath, fileName); + } + private void assertOutputResult(String expectedResultFile, String actual, String[] paramKeys, String[] paramValues) throws Exception { - FileSystem fs = currentResultPath.getFileSystem(testBase.getTestingCluster().getConfiguration()); - Path resultFile = StorageUtil.concatPath(currentResultPath, expectedResultFile); - assertTrue(resultFile.toString() + " existence check", fs.exists(resultFile)); + Path path = getAbsolutePath(expectedResultFile); + assertTrue(path.toString() + " existence check", existsFile(expectedResultFile)); - String expectedResult = FileUtil.readTextFile(new File(resultFile.toUri())); + String expectedResult = FileUtil.readTextFile(new File(path.toUri())); if (paramKeys != null) { for (int i = 0; i < paramKeys.length; i++) { @@ -164,7 +183,7 @@ public void testParseConf() throws Exception { assertEquals("tajo.executor.join.inner.in-memory-table-num=256", confValues[1]); TajoConf tajoConf = TpchTestBase.getInstance().getTestingCluster().getConfiguration(); - try (TajoCli testCli = new TajoCli(tajoConf, args, null, System.in, System.out)) { + try (TajoCli testCli = new TajoCli(tajoConf, args, null, System.in, System.out, err)) { assertEquals("false", testCli.getContext().get(SessionVars.CLI_PAGING_ENABLED)); assertEquals("256", testCli.getContext().getConf().get("tajo.executor.join.inner.in-memory-table-num")); } @@ -310,8 +329,10 @@ private void verifySelectResultWithNullTrue() throws Exception { tajoCli.executeScript(sql); - String consoleResult = new String(out.toByteArray()); - assertOutputResult(consoleResult); + String stdoutResult = new String(out.toByteArray()); + assertOutputResult(stdoutResult); + String stdErrResult = new String(err.toByteArray()); + assertErrorResult(stdErrResult, true); } @Test @@ -345,7 +366,8 @@ public void testGetConf() throws Exception { setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName()); try (ByteArrayOutputStream out = new ByteArrayOutputStream(); - TajoCli tajoCli = new TajoCli(tajoConf, new String[]{}, null, System.in, out)) { + ByteArrayOutputStream err = new ByteArrayOutputStream(); + TajoCli tajoCli = new TajoCli(tajoConf, new String[]{}, null, System.in, out, err)) { tajoCli.executeMetaCommand("\\getconf tajo.rootdir"); String consoleResult = new String(out.toByteArray()); @@ -359,7 +381,7 @@ public void testShowMasters() throws Exception { setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName()); ByteArrayOutputStream out = new ByteArrayOutputStream(); - TajoCli tajoCli = new TajoCli(tajoConf, new String[]{}, null, System.in, out); + TajoCli tajoCli = new TajoCli(tajoConf, new String[]{}, null, System.in, out, err); tajoCli.executeMetaCommand("\\admin -showmasters"); String consoleResult = new String(out.toByteArray()); @@ -395,7 +417,7 @@ public void run() { setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName()); Properties connParams = new Properties(); connParams.setProperty(ClientParameters.RETRY, "3"); - TajoCli tc = new TajoCli(tajoConf, new String[]{}, connParams, is, out); + TajoCli tc = new TajoCli(tajoConf, new String[]{}, connParams, is, out, err); tc.executeMetaCommand("\\set ON_ERROR_STOP false"); assertSessionVar(tc, SessionVars.ON_ERROR_STOP.keyname(), "false"); @@ -489,7 +511,7 @@ public void testNonForwardQueryPause() throws Exception { assertEquals(0L, tableDesc.getStats().getNumRows().longValue()); try (InputStream testInput = new ByteArrayInputStream(new byte[]{(byte) DefaultTajoCliOutputFormatter.QUIT_COMMAND}); - TajoCli cli = new TajoCli(cluster.getConfiguration(), new String[]{}, null, testInput, out)) { + TajoCli cli = new TajoCli(cluster.getConfiguration(), new String[]{}, null, testInput, out, err)) { setVar(cli, SessionVars.CLI_PAGE_ROWS, "2"); setVar(cli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName()); @@ -504,7 +526,7 @@ public void testNonForwardQueryPause() throws Exception { @Test public void testResultRowNumWhenSelectingOnPartitionedTable() throws Exception { try (TajoCli cli2 = new TajoCli(cluster.getConfiguration(), new String[]{}, null, System.in, - new NullOutputStream())) { + new NullOutputStream(), new NullOutputStream())) { cli2.executeScript("create table region_part (r_regionkey int8, r_name text) " + "partition by column (r_comment text) as select * from region"); diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCliNegatives.java b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCliNegatives.java index fcf4546c7f..aea82ab2a1 100644 --- a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCliNegatives.java +++ b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCliNegatives.java @@ -36,16 +36,19 @@ public class TestTajoCliNegatives extends QueryTestCaseBase { private static TajoCli tajoCli; private static ByteArrayOutputStream out; + private static ByteArrayOutputStream err; @BeforeClass public static void setUp() throws Exception { out = new ByteArrayOutputStream(); - tajoCli = new TajoCli(testingCluster.getConfiguration(), new String[]{}, null, System.in, out); + err = new ByteArrayOutputStream(); + tajoCli = new TajoCli(testingCluster.getConfiguration(), new String[]{}, null, System.in, out, err); } @AfterClass public static void tearDown() throws IOException { out.close(); + err.close(); if (tajoCli != null) { tajoCli.close(); } @@ -54,11 +57,12 @@ public static void tearDown() throws IOException { @Before public void resetConsole() throws IOException { out.reset(); + err.reset(); } public void assertMetaCommandFailure(String cmd, String expectedMsg) throws Exception { tajoCli.executeMetaCommand(cmd); - String consoleResult = new String(out.toByteArray()); + String consoleResult = new String(err.toByteArray()); assertEquals(expectedMsg, consoleResult); } @@ -67,13 +71,13 @@ public void assertScriptFailure(String cmd) throws Exception { String expected = FileUtil.readTextFile(new File(resultFile.toUri())); tajoCli.executeScript(cmd); - String consoleResult = new String(out.toByteArray()); + String consoleResult = new String(err.toByteArray()); assertEquals(expected, consoleResult); } public void assertScriptFailure(String cmd, String expectedMsg) throws Exception { tajoCli.executeScript(cmd); - String consoleResult = new String(out.toByteArray()); + String consoleResult = new String(err.toByteArray()); assertEquals(expectedMsg, consoleResult); } @@ -132,9 +136,7 @@ public void testQueryNotImplementedFeature() throws Exception { public void testQueryFailureOfSimpleQuery() throws Exception { setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName()); assertScriptFailure("select fail(3, l_orderkey, 'testQueryFailureOfSimpleQuery') from default.lineitem" , - "?fail\n" + - "-------------------------------\n" + - "ERROR: internal error: internal error: internal error: testQueryFailureOfSimpleQuery\n"); + "ERROR: internal error: internal error: internal error: testQueryFailureOfSimpleQuery\n"); } @Test diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/commands/TestExecExternalShellCommand.java b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/commands/TestExecExternalShellCommand.java index 95c3a8bdf8..cd2d1b780a 100644 --- a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/commands/TestExecExternalShellCommand.java +++ b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/commands/TestExecExternalShellCommand.java @@ -33,8 +33,9 @@ public void testCommand() throws Exception { TajoConf tajoConf = TpchTestBase.getInstance().getTestingCluster().getConfiguration(); ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayOutputStream err = new ByteArrayOutputStream(); - TajoCli cli = new TajoCli(tajoConf, new String[]{}, null, null, out); + TajoCli cli = new TajoCli(tajoConf, new String[]{}, null, null, out, err); cli.executeMetaCommand("\\! echo \"this is test\""); String consoleResult = new String(out.toByteArray()); diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/commands/TestHdfsCommand.java b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/commands/TestHdfsCommand.java index d239c0ac00..c4c76cd8ee 100644 --- a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/commands/TestHdfsCommand.java +++ b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/commands/TestHdfsCommand.java @@ -34,13 +34,14 @@ public void testHdfCommand() throws Exception { TajoConf tajoConf = TpchTestBase.getInstance().getTestingCluster().getConfiguration(); ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayOutputStream err = new ByteArrayOutputStream(); System.setOut(new PrintStream(out)); - System.setErr(new PrintStream(out)); - TajoCli cli = new TajoCli(tajoConf, new String[]{}, null, null, out); + System.setErr(new PrintStream(err)); + TajoCli cli = new TajoCli(tajoConf, new String[]{}, null, null, out, err); cli.executeMetaCommand("\\dfs -test"); - String consoleResult = new String(out.toByteArray()); + String consoleResult = new String(err.toByteArray()); assertEquals("-test: Not enough arguments: expected 1 but got 0\n" + "Usage: hadoop fs [generic options] -test -[defsz] \n", consoleResult); } diff --git a/tajo-core-tests/src/test/resources/results/TestTajoCli/testAddPartitionNotimplementedException.err b/tajo-core-tests/src/test/resources/results/TestTajoCli/testAddPartitionNotimplementedException.err new file mode 100644 index 0000000000..0f931467af --- /dev/null +++ b/tajo-core-tests/src/test/resources/results/TestTajoCli/testAddPartitionNotimplementedException.err @@ -0,0 +1 @@ +ERROR: not implemented feature: ADD PARTITION \ No newline at end of file diff --git a/tajo-core-tests/src/test/resources/results/TestTajoCli/testAddPartitionNotimplementedException.result b/tajo-core-tests/src/test/resources/results/TestTajoCli/testAddPartitionNotimplementedException.result index 4aab8c8045..a0aba9318a 100644 --- a/tajo-core-tests/src/test/resources/results/TestTajoCli/testAddPartitionNotimplementedException.result +++ b/tajo-core-tests/src/test/resources/results/TestTajoCli/testAddPartitionNotimplementedException.result @@ -1,2 +1 @@ -OK -ERROR: not implemented feature: ADD PARTITION \ No newline at end of file +OK \ No newline at end of file diff --git a/tajo-core-tests/src/test/resources/results/TestTajoCli/testSelectResultWithNullTrueDeprecated.err b/tajo-core-tests/src/test/resources/results/TestTajoCli/testSelectResultWithNullTrueDeprecated.err new file mode 100644 index 0000000000..634795ac66 --- /dev/null +++ b/tajo-core-tests/src/test/resources/results/TestTajoCli/testSelectResultWithNullTrueDeprecated.err @@ -0,0 +1 @@ +Warning: deprecated to directly use config key in TajoConf.ConfVars. Please execute '\help set'. \ No newline at end of file diff --git a/tajo-core-tests/src/test/resources/results/TestTajoCli/testSelectResultWithNullTrueDeprecated.result b/tajo-core-tests/src/test/resources/results/TestTajoCli/testSelectResultWithNullTrueDeprecated.result index 1212ade8e0..302d80c499 100644 --- a/tajo-core-tests/src/test/resources/results/TestTajoCli/testSelectResultWithNullTrueDeprecated.result +++ b/tajo-core-tests/src/test/resources/results/TestTajoCli/testSelectResultWithNullTrueDeprecated.result @@ -1,4 +1,3 @@ -Warning: deprecated to directly use config key in TajoConf.ConfVars. Please execute '\help set'. c_custkey, o_orderkey, o_orderstatus ------------------------------- 1, 1, O diff --git a/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenError.err b/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenError.err new file mode 100644 index 0000000000..bff3cfedc4 --- /dev/null +++ b/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenError.err @@ -0,0 +1 @@ +ERROR: relation 'default.lineitem2' does not exist \ No newline at end of file diff --git a/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenError.result b/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenError.result index a0044c2df4..d480b2b097 100644 --- a/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenError.result +++ b/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenError.result @@ -1,5 +1,4 @@ ?count ------------------------------- 5 -(1 rows, , 16 B selected) -ERROR: relation 'default.lineitem2' does not exist \ No newline at end of file +(1 rows, , 16 B selected) \ No newline at end of file diff --git a/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenErrorDeprecated.err b/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenErrorDeprecated.err new file mode 100644 index 0000000000..6affb7fd55 --- /dev/null +++ b/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenErrorDeprecated.err @@ -0,0 +1,2 @@ +Warning: deprecated to directly use config key in TajoConf.ConfVars. Please execute '\help set'. +ERROR: relation 'default.lineitem2' does not exist \ No newline at end of file diff --git a/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenErrorDeprecated.result b/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenErrorDeprecated.result index e3f1e6ba8d..d480b2b097 100644 --- a/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenErrorDeprecated.result +++ b/tajo-core-tests/src/test/resources/results/TestTajoCli/testStopWhenErrorDeprecated.result @@ -1,6 +1,4 @@ -Warning: deprecated to directly use config key in TajoConf.ConfVars. Please execute '\help set'. ?count ------------------------------- 5 -(1 rows, , 16 B selected) -ERROR: relation 'default.lineitem2' does not exist \ No newline at end of file +(1 rows, , 16 B selected) \ No newline at end of file From 34cac2580185be303cae2c7bec07ce6d010539aa Mon Sep 17 00:00:00 2001 From: Hyunsik Choi Date: Mon, 14 Mar 2016 18:11:12 -0700 Subject: [PATCH 2/2] Fix one test error. --- .../src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java index 39c760c8a1..c210a24949 100644 --- a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java +++ b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java @@ -332,7 +332,7 @@ private void verifySelectResultWithNullTrue() throws Exception { String stdoutResult = new String(out.toByteArray()); assertOutputResult(stdoutResult); String stdErrResult = new String(err.toByteArray()); - assertErrorResult(stdErrResult, true); + assertErrorResult(stdErrResult, false); } @Test