[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 <mblow@apache.org>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
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 @@
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 @@
+ ":\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 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();