Repository: asterixdb Updated Branches: refs/heads/master 85d4627e3 -> 7ed80afb7
[NO ISSUE][TEST] Use logger in place of System.err for TestExecutor Change-Id: Ia53aa832b29d03257a48cc5d198703bcf94dd4ca Reviewed-on: https://asterix-gerrit.ics.uci.edu/2338 Sonar-Qube: Jenkins <[email protected]> Reviewed-by: Murtadha Hubail <[email protected]> Integration-Tests: Murtadha Hubail <[email protected]> Tested-by: Murtadha Hubail <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/7ed80afb Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/7ed80afb Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/7ed80afb Branch: refs/heads/master Commit: 7ed80afb749c90e508a441547b47de5ab60d5066 Parents: 85d4627 Author: Michael Blow <[email protected]> Authored: Tue Jan 30 13:24:07 2018 -0500 Committer: Michael Blow <[email protected]> Committed: Tue Jan 30 11:13:08 2018 -0800 ---------------------------------------------------------------------- .../asterix/test/common/TestExecutor.java | 70 ++++++++------------ .../asterix/test/sqlpp/ParserTestExecutor.java | 3 +- .../src/test/resources/log4j2-test.xml | 12 +++- .../src/test/resources/log4j2-test.xml | 8 ++- 4 files changed, 45 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7ed80afb/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java index deb2c72..9cce657 100644 --- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java +++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java @@ -187,9 +187,9 @@ public class TestExecutor { return path.delete(); } - public void runScriptAndCompareWithResult(File scriptFile, PrintWriter print, File expectedFile, File actualFile, + public void runScriptAndCompareWithResult(File scriptFile, File expectedFile, File actualFile, ComparisonEnum compare) throws Exception { - System.err.println("Expected results file: " + expectedFile.toString()); + LOGGER.info("Expected results file: {} ", expectedFile); BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFile), "UTF-8")); BufferedReader readerActual = @@ -255,7 +255,7 @@ public class TestExecutor { throw createLineChangedException(scriptFile, "<EOF>", lineActual, num); } } catch (Exception e) { - System.err.println("Actual results file: " + actualFile.toString()); + LOGGER.info("Actual results file: {}", actualFile); throw e; } finally { readerExpected.close(); @@ -946,8 +946,7 @@ public class TestExecutor { + "_qar.adm"); writeOutputToFile(qarFile, resultStream); qbcFile = getTestCaseQueryBeforeCrashFile(actualPath, testCaseCtx, cUnit); - runScriptAndCompareWithResult(testFile, new PrintWriter(System.err), qbcFile, qarFile, - ComparisonEnum.TEXT); + runScriptAndCompareWithResult(testFile, qbcFile, qarFile, ComparisonEnum.TEXT); break; case "txneu": // eu represents erroneous update try { @@ -955,12 +954,11 @@ public class TestExecutor { } catch (Exception e) { // An exception is expected. failed = true; - System.err.println("testFile " + testFile.toString() + " raised an exception: " + e); + LOGGER.info("testFile {} raised an (expected) exception", testFile, e.toString()); } if (!failed) { - throw new Exception("Test \"" + testFile + "\" FAILED!\n An exception" + "is expected."); + throw new Exception("Test \"" + testFile + "\" FAILED; an exception was expected"); } - System.err.println("...but that was expected."); break; case "script": try { @@ -970,7 +968,7 @@ public class TestExecutor { throw new Exception(output); } } catch (Exception e) { - throw new Exception("Test \"" + testFile + "\" FAILED!\n", e); + throw new Exception("Test \"" + testFile + "\" FAILED!", e); } break; case "sleep": @@ -983,12 +981,11 @@ public class TestExecutor { } catch (Exception e) { // expected error happens failed = true; - System.err.println("testFile " + testFile.toString() + " raised an exception: " + e); + LOGGER.info("testFile {} raised an (expected) exception", testFile, e.toString()); } if (!failed) { - throw new Exception("Test \"" + testFile + "\" FAILED!\n An exception is expected."); + throw new Exception("Test \"" + testFile + "\" FAILED; an exception was expected"); } - System.err.println("...but that was expected."); break; case "get": case "post": @@ -1186,17 +1183,14 @@ public class TestExecutor { } else { if (expectedResultFile == null) { if (testFile.getName().startsWith(DIAGNOSE)) { - System.err.println("Diagnostic Output:"); - IOUtils.copy(resultStream, System.err); - System.err.println(); + LOGGER.info("Diagnostic output: {}", IOUtils.toString(resultStream, StandardCharsets.UTF_8)); } else { Assert.fail("no result file for " + testFile.toString() + "; queryCount: " + queryCount + ", filectxs.size: " + numResultFiles); } } else { writeOutputToFile(actualResultFile, resultStream); - runScriptAndCompareWithResult(testFile, new PrintWriter(System.err), expectedResultFile, - actualResultFile, compare); + runScriptAndCompareWithResult(testFile, expectedResultFile, actualResultFile, compare); } } queryCount.increment(); @@ -1240,9 +1234,7 @@ public class TestExecutor { } if (actualResultFile == null) { if (testFile.getName().startsWith(DIAGNOSE)) { - System.err.println("Diagnostic Output:"); - IOUtils.copy(resultStream, System.err); - System.err.println(); + LOGGER.info("Diagnostic output: {}", IOUtils.toString(resultStream, StandardCharsets.UTF_8)); } else { Assert.fail("no result file for " + testFile.toString() + "; queryCount: " + queryCount + ", filectxs.size: " + numResultFiles); @@ -1257,8 +1249,7 @@ public class TestExecutor { + ", filectxs.size: " + numResultFiles); } } - runScriptAndCompareWithResult(testFile, new PrintWriter(System.err), expectedResultFile, actualResultFile, - compare); + runScriptAndCompareWithResult(testFile, expectedResultFile, actualResultFile, compare); if (!reqType.equals("validate")) { queryCount.increment(); } @@ -1543,28 +1534,26 @@ public class TestExecutor { queryCount.setValue(savedQueryCounts[numOfFiles]); } } catch (Exception e) { - System.err.println("testFile " + testFile.toString() + " raised an exception: " + e); numOfErrors++; - if (isUnExpected(e, expectedErrors, numOfErrors, queryCount)) { - e.printStackTrace(); - System.err.println("...Unexpected!"); + boolean unexpected = isUnExpected(e, expectedErrors, numOfErrors, queryCount); + if (unexpected) { + LOGGER.error("testFile {} raised an unexpected exception", testFile, e); if (failedGroup != null) { failedGroup.getTestCase().add(testCaseCtx.getTestCase()); } fail(true, testCaseCtx, cUnit, testFileCtxs, pb, testFile, e); + } else { + LOGGER.info("testFile {} raised an (expected) exception", testFile, e.toString()); } - } finally { - if (numOfFiles == testFileCtxs.size()) { - if (numOfErrors < cUnit.getExpectedError().size()) { - System.err.println("...Unexpected!"); - Exception e = new Exception( - "Test \"" + cUnit.getName() + "\" FAILED!\nExpected error was not thrown..."); - System.err.println(e); - throw e; - } - LOGGER.info("[TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/" + cUnit.getName() - + " PASSED "); + } + if (numOfFiles == testFileCtxs.size()) { + if (numOfErrors < cUnit.getExpectedError().size()) { + LOGGER.error("Test {} failed to raise (an) expected exception(s)", cUnit.getName()); + throw new Exception( + "Test \"" + cUnit.getName() + "\" FAILED; expected exception was not thrown..."); } + LOGGER.info( + "[TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/" + cUnit.getName() + " PASSED "); } } } @@ -1576,8 +1565,7 @@ public class TestExecutor { try { // execute diagnostic files Map<String, Object> variableCtx = new HashMap<>(); - for (ListIterator<TestFileContext> iter = testFileCtxs.listIterator(); iter.hasNext();) { - TestFileContext ctx = iter.next(); + for (TestFileContext ctx : testFileCtxs) { if (ctx.getFile().getName().startsWith(TestExecutor.DIAGNOSE)) { // execute the file final File file = ctx.getFile(); @@ -1601,11 +1589,9 @@ public class TestExecutor { // Get the expected exception expectedError = expectedErrors.get(numOfErrors - 1); if (e.toString().contains(expectedError)) { - System.err.println("...but that was expected."); return false; } else { - System.err - .println("Expected to find the following in error text:\n+++++\n" + expectedError + "\n+++++"); + LOGGER.error("Expected to find the following in error text: +++++{}+++++", expectedError); return true; } } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7ed80afb/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestExecutor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestExecutor.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestExecutor.java index 85b8c8a..0d0c1d9 100644 --- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestExecutor.java +++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/sqlpp/ParserTestExecutor.java @@ -149,8 +149,7 @@ public class ParserTestExecutor extends TestExecutor { } writer.close(); // Compares the actual result and the expected result. - runScriptAndCompareWithResult(queryFile, new PrintWriter(System.err), expectedFile, actualResultFile, - ComparisonEnum.TEXT); + runScriptAndCompareWithResult(queryFile, expectedFile, actualResultFile, ComparisonEnum.TEXT); } catch (Exception e) { GlobalConfig.ASTERIX_LOGGER.warn("Failed while testing file " + queryFile); throw e; http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7ed80afb/asterixdb/asterix-app/src/test/resources/log4j2-test.xml ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/resources/log4j2-test.xml b/asterixdb/asterix-app/src/test/resources/log4j2-test.xml index 3edb700..387e900 100644 --- a/asterixdb/asterix-app/src/test/resources/log4j2-test.xml +++ b/asterixdb/asterix-app/src/test/resources/log4j2-test.xml @@ -24,6 +24,9 @@ <File name="InfoLog" fileName="target/info.log"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> </File> + <Console name="ConsoleTest" target="SYSTEM_OUT"> + <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %c{1} - %msg%n"/> + </Console> </Appenders> <Loggers> <Root level="WARN"> @@ -35,8 +38,13 @@ <Logger name="org.apache.asterix" level="INFO" additivity="false"> <AppenderRef ref="InfoLog"/> </Logger> - <Logger name="org.apache.asterix.test" level="WARN"> - <AppenderRef ref="Console"/> + <Logger name="org.apache.hyracks.test" level="INFO" additivity="false"> + <AppenderRef ref="ConsoleTest"/> + <AppenderRef ref="InfoLog"/> + </Logger> + <Logger name="org.apache.asterix.test" level="INFO" additivity="false"> + <AppenderRef ref="ConsoleTest"/> + <AppenderRef ref="InfoLog"/> </Logger> </Loggers> </Configuration> http://git-wip-us.apache.org/repos/asf/asterixdb/blob/7ed80afb/hyracks-fullstack/src/test/resources/log4j2-test.xml ---------------------------------------------------------------------- diff --git a/hyracks-fullstack/src/test/resources/log4j2-test.xml b/hyracks-fullstack/src/test/resources/log4j2-test.xml index 71c5612..d56f215 100644 --- a/hyracks-fullstack/src/test/resources/log4j2-test.xml +++ b/hyracks-fullstack/src/test/resources/log4j2-test.xml @@ -24,6 +24,9 @@ <File name="InfoLog" fileName="target/info.log"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> </File> + <Console name="ConsoleTest" target="SYSTEM_OUT"> + <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %c{1} - %msg%n"/> + </Console> </Appenders> <Loggers> <Root level="WARN"> @@ -32,8 +35,9 @@ <Logger name="org.apache.hyracks" level="INFO" additivity="false"> <AppenderRef ref="InfoLog"/> </Logger> - <Logger name="org.apache.hyracks.test" level="WARN"> - <AppenderRef ref="Console"/> + <Logger name="org.apache.hyracks.test" level="INFO" additivity="false"> + <AppenderRef ref="ConsoleTest"/> + <AppenderRef ref="InfoLog"/> </Logger> </Loggers> </Configuration>
