This is an automated email from the ASF dual-hosted git repository. mblow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit b2099a5253018451c12e35853172ba7f671eff1c Author: Hussain Towaileb <[email protected]> AuthorDate: Tue Feb 23 16:26:54 2021 +0300 [ASTERIXDB-2836][TEST]: Extend test framework to support random order of string lines result - user model changes: no - storage format changes: no - interface changes: no Details: - Extend the test framework to test multiple string lines results (non-JSON) where the result lines can appear in any order. Change-Id: I4d7bb26deba13880c7f82b54d647a04bda21cfaf Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/10123 Reviewed-by: Michael Blow <[email protected]> Integration-Tests: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> --- .../apache/asterix/test/common/TestExecutor.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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 44038cc..b8524c0 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 @@ -294,7 +294,11 @@ public class TestExecutor { boolean compareUnorderedArray = statement != null && getCompareUnorderedArray(statement); runScriptAndCompareWithResultRegexJson(scriptFile, readerExpected, readerActual, compareUnorderedArray); return; + } else if (actualFile.toString().endsWith(".unorderedtxt")) { + runScriptAndCompareWithResultUnorderedLinesText(scriptFile, readerExpected, readerActual); + return; } + String lineExpected, lineActual; int num = 1; while ((lineExpected = readerExpected.readLine()) != null) { @@ -358,6 +362,16 @@ public class TestExecutor { + ":\nexpected < " + truncateIfLong(lineExpected) + "\nactual > " + truncateIfLong(lineActual)); } + private ComparisonException createLineNotFoundException(File scriptFile, String lineExpected) { + return new ComparisonException( + "Result for " + canonicalize(scriptFile) + " expected line not found: " + truncateIfLong(lineExpected)); + } + + private ComparisonException createExpectedLinesNotReturnedException(File scriptFile, List<String> expectedLines) { + return new ComparisonException("Result for " + canonicalize(scriptFile) + " expected lines not returned:\n" + + String.join("\n", expectedLines)); + } + private String truncateIfLong(String string) { if (string.length() < TRUNCATE_THRESHOLD) { return string; @@ -555,6 +569,24 @@ public class TestExecutor { } } + public void runScriptAndCompareWithResultUnorderedLinesText(File scriptFile, BufferedReader readerExpected, + BufferedReader readerActual) throws Exception { + // Using Lists to allow duplicate lines in the result + List<String> expectedLines = readerExpected.lines().collect(Collectors.toList()); + List<String> actualLines = readerActual.lines().collect(Collectors.toList()); + + for (String line : actualLines) { + if (!expectedLines.remove(line)) { + throw createLineNotFoundException(scriptFile, line); + } + } + + // number of expect > actual + if (expectedLines.size() > 0) { + throw createExpectedLinesNotReturnedException(scriptFile, expectedLines); + } + } + // For tests where you simply want the byte-for-byte output. private static void writeOutputToFile(File actualFile, InputStream resultStream) throws Exception { final File parentDir = actualFile.getParentFile();
