some test cleanup
- avoid NPE when reading the "summary field" of the result
- avoid IndexOutOfBoundsException for missing result files
- get rid of exception tunneling through JsonMappingException
- refactor common code into TestCaseContext.getFilesInDir
move execution.tests to global.test.includes
diff --git a/asterix-common/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java b/asterix-common/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
index 9643e1d..b280ec9 100644
--- a/asterix-common/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
+++ b/asterix-common/src/test/java/edu/uci/ics/asterix/test/aql/TestsUtils.java
@@ -160,7 +160,7 @@
return fname.substring(0, dot + 1) + EXTENSION_AQL_RESULT;
}
- public static void writeResultsToFile(File actualFile, InputStream resultStream) throws IOException, JSONException {
+ public static void writeResultsToFile(File actualFile, InputStream resultStream) throws Exception {
BufferedWriter writer = new BufferedWriter(new FileWriter(actualFile));
try {
JsonFactory jsonFactory = new JsonFactory();
@@ -176,10 +176,10 @@
writer.write(record);
}
} else {
- String summary = resultParser.getValueAsString();
if (key.equals("summary")) {
+ String summary = resultParser.nextTextValue();
writer.write(summary);
- throw new JsonMappingException("Could not find results key in the JSON Object");
+ throw new Exception("Could not find results key in the JSON Object, result file is at " + actualFile);
}
}
}
@@ -377,86 +377,75 @@
for (TestFileContext ctx : testFileCtxs) {
testFile = ctx.getFile();
statement = TestsUtils.readTestFile(testFile);
+ InputStream resultStream;
try {
switch (ctx.getType()) {
case "ddl":
TestsUtils.executeDDL(statement);
break;
case "update":
-
//isDmlRecoveryTest: set IP address
if (isDmlRecoveryTest && statement.contains("nc1://")) {
statement = statement
.replaceAll("nc1://", "127.0.0.1://../../../../../../asterix-app/");
-
}
TestsUtils.executeUpdate(statement);
break;
case "query":
- try {
- // isDmlRecoveryTest: insert Crash and Recovery
- if (isDmlRecoveryTest) {
- executeScript(pb, pb.environment().get("SCRIPT_HOME") + File.separator
- + "dml_recovery" + File.separator + "kill_cc_and_nc.sh");
- executeScript(pb, pb.environment().get("SCRIPT_HOME") + File.separator
- + "dml_recovery" + File.separator + "stop_and_start.sh");
- }
-
- InputStream resultStream = executeQuery(statement);
- expectedResultFile = expectedResultFileCtxs.get(queryCount).getFile();
-
- File actualFile = new File(actualPath + File.separator
- + testCaseCtx.getTestCase().getFilePath().replace(File.separator, "_") + "_"
- + cUnit.getName() + ".adm");
- TestsUtils.writeResultsToFile(actualFile, resultStream);
-
- File actualResultFile = testCaseCtx.getActualResultFile(cUnit, new File(actualPath));
- actualResultFile.getParentFile().mkdirs();
-
- TestsUtils.runScriptAndCompareWithResult(testFile, new PrintWriter(System.err),
- expectedResultFile, actualFile);
- LOGGER.info("[TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/"
- + cUnit.getName() + " PASSED ");
- } catch (JsonMappingException e) {
- throw new Exception("Test \"" + testFile + "\" FAILED!\n");
+ // isDmlRecoveryTest: insert Crash and Recovery
+ if (isDmlRecoveryTest) {
+ executeScript(pb, pb.environment().get("SCRIPT_HOME") + File.separator + "dml_recovery"
+ + File.separator + "kill_cc_and_nc.sh");
+ executeScript(pb, pb.environment().get("SCRIPT_HOME") + File.separator + "dml_recovery"
+ + File.separator + "stop_and_start.sh");
}
+
+ resultStream = executeQuery(statement);
+ if (queryCount >= expectedResultFileCtxs.size()) {
+ throw new IllegalStateException("no result file for " + testFile.toString());
+ }
+ expectedResultFile = expectedResultFileCtxs.get(queryCount).getFile();
+
+ File actualFile = new File(actualPath + File.separator
+ + testCaseCtx.getTestCase().getFilePath().replace(File.separator, "_") + "_"
+ + cUnit.getName() + ".adm");
+ TestsUtils.writeResultsToFile(actualFile, resultStream);
+
+ File actualResultFile = testCaseCtx.getActualResultFile(cUnit, new File(actualPath));
+ actualResultFile.getParentFile().mkdirs();
+
+ TestsUtils.runScriptAndCompareWithResult(testFile, new PrintWriter(System.err),
+ expectedResultFile, actualFile);
+ LOGGER.info("[TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/" + cUnit.getName()
+ + " PASSED ");
+
queryCount++;
break;
case "mgx":
executeManagixCommand(statement);
break;
case "txnqbc": //qbc represents query before crash
- try {
- InputStream resultStream = executeQuery(statement);
- qbcFile = new File(actualPath + File.separator
- + testCaseCtx.getTestCase().getFilePath().replace(File.separator, "_") + "_"
- + cUnit.getName() + "_qbc.adm");
- qbcFile.getParentFile().mkdirs();
- TestsUtils.writeResultsToFile(qbcFile, resultStream);
- } catch (JsonMappingException e) {
- throw new Exception("Test \"" + testFile + "\" FAILED!\n");
- }
+ resultStream = executeQuery(statement);
+ qbcFile = new File(actualPath + File.separator
+ + testCaseCtx.getTestCase().getFilePath().replace(File.separator, "_") + "_"
+ + cUnit.getName() + "_qbc.adm");
+ qbcFile.getParentFile().mkdirs();
+ TestsUtils.writeResultsToFile(qbcFile, resultStream);
break;
case "txnqar": //qar represents query after recovery
- try {
+ resultStream = executeQuery(statement);
+ qarFile = new File(actualPath + File.separator
+ + testCaseCtx.getTestCase().getFilePath().replace(File.separator, "_") + "_"
+ + cUnit.getName() + "_qar.adm");
+ qarFile.getParentFile().mkdirs();
+ TestsUtils.writeResultsToFile(qarFile, resultStream);
- InputStream resultStream = executeQuery(statement);
+ TestsUtils.runScriptAndCompareWithResult(testFile, new PrintWriter(System.err),
+ qbcFile, qarFile);
- qarFile = new File(actualPath + File.separator
- + testCaseCtx.getTestCase().getFilePath().replace(File.separator, "_") + "_"
- + cUnit.getName() + "_qar.adm");
- qarFile.getParentFile().mkdirs();
- TestsUtils.writeResultsToFile(qarFile, resultStream);
-
- TestsUtils.runScriptAndCompareWithResult(testFile, new PrintWriter(System.err),
- qbcFile, qarFile);
-
- LOGGER.info("[TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/"
- + cUnit.getName() + " PASSED ");
- } catch (JsonMappingException e) {
- throw new Exception("Test \"" + testFile + "\" FAILED!\n");
- }
+ LOGGER.info("[TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/"
+ + cUnit.getName() + " PASSED ");
break;
case "txneu": //eu represents erroneous update
try {
@@ -502,5 +491,4 @@
}
}
}
-
}
diff --git a/asterix-test-framework/src/main/java/edu/uci/ics/asterix/testframework/context/TestCaseContext.java b/asterix-test-framework/src/main/java/edu/uci/ics/asterix/testframework/context/TestCaseContext.java
index eb096bd..04c10a5 100644
--- a/asterix-test-framework/src/main/java/edu/uci/ics/asterix/testframework/context/TestCaseContext.java
+++ b/asterix-test-framework/src/main/java/edu/uci/ics/asterix/testframework/context/TestCaseContext.java
@@ -60,66 +60,47 @@
return testCase;
}
- public List<TestFileContext> getTestFiles(CompilationUnit cUnit) {
+ public List<TestFileContext> getFilesInDir(String basePath, String dirName, boolean withType) {
List<TestFileContext> testFileCtxs = new ArrayList<TestFileContext>();
File path = tsRoot;
- path = new File(path, testSuite.getQueryOffsetPath());
+ path = new File(path, basePath);
path = new File(path, testCase.getFilePath());
- path = new File(path, cUnit.getName());
+ path = new File(path, dirName);
- String fileNames[] = path.list();
- for (String fName : fileNames) {
- if (fName.startsWith(".")) {
- continue;
+ if (path.isDirectory()) {
+ String fileNames[] = path.list();
+ for (String fName : fileNames) {
+ if (fName.startsWith(".")) {
+ continue;
+ }
+
+ File testFile = new File(path, fName);
+ TestFileContext tfsc = new TestFileContext(testFile);
+ String[] nameSplits = fName.split("\\.");
+ if (nameSplits.length < 3) {
+ throw new IllegalArgumentException("Test file '" + dirName + File.separatorChar + fName
+ + "' does not have the proper test file name format.");
+ }
+ if (withType) {
+ tfsc.setSeqNum(nameSplits[nameSplits.length - 3]);
+ tfsc.setType(nameSplits[nameSplits.length - 2]);
+ } else {
+ tfsc.setSeqNum(nameSplits[nameSplits.length - 2]);
+ }
+ testFileCtxs.add(tfsc);
}
-
- File testFile = new File(path, fName);
- TestFileContext tfsc = new TestFileContext(testFile);
- String[] nameSplits = fName.split("\\.");
- if (nameSplits.length < 3) {
- throw new IllegalArgumentException("Test file '" + cUnit.getName() + File.separatorChar
- + fName + "' does not have the proper test file name format.");
- }
- tfsc.setSeqNum(nameSplits[nameSplits.length - 3]);
- tfsc.setType(nameSplits[nameSplits.length - 2]);
- testFileCtxs.add(tfsc);
}
Collections.sort(testFileCtxs);
return testFileCtxs;
}
+ public List<TestFileContext> getTestFiles(CompilationUnit cUnit) {
+ return getFilesInDir(testSuite.getQueryOffsetPath(), cUnit.getName(), true);
+ }
+
public List<TestFileContext> getExpectedResultFiles(CompilationUnit cUnit) {
- List<TestFileContext> resultFileCtxs = new ArrayList<TestFileContext>();
-
- File path = tsRoot;
- path = new File(path, testSuite.getResultOffsetPath());
- path = new File(path, testCase.getFilePath());
- path = new File(path, cUnit.getOutputDir().getValue());
-
- String fileNames[] = path.list();
-
- if (fileNames != null) {
- for (String fName : fileNames) {
- if (fName.startsWith(".")) {
- continue;
- }
-
- File testFile = new File(path, fName);
- TestFileContext tfsc = new TestFileContext(testFile);
- String[] nameSplits = fName.split("\\.");
-
- if (nameSplits.length < 3) {
- throw new IllegalArgumentException("Test file '" + cUnit.getName() + File.separatorChar
- + fName + "' does not have the proper test file name format.");
- }
-
- tfsc.setSeqNum(nameSplits[nameSplits.length - 2]);
- resultFileCtxs.add(tfsc);
- }
- Collections.sort(resultFileCtxs);
- }
- return resultFileCtxs;
+ return getFilesInDir(testSuite.getResultOffsetPath(), cUnit.getOutputDir().getValue(), false);
}
public File getActualResultFile(CompilationUnit cUnit, File actualResultsBase) {
diff --git a/pom.xml b/pom.xml
index 2b059b8..74592ed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,8 +31,8 @@
<metadata.tests>**/metadata/*Test.java</metadata.tests>
<execution.tests>**/ExecutionTest.java</execution.tests>
<invalid.tests>**/DmlTest.java</invalid.tests>
- <global.test.includes>**/*TestSuite.java,**/*Test.java</global.test.includes>
- <global.test.excludes>${optimizer.tests},${metadata.tests},${execution.tests},${invalid.tests}</global.test.excludes>
+ <global.test.includes>**/*TestSuite.java,**/*Test.java,${execution.tests}</global.test.includes>
+ <global.test.excludes>${optimizer.tests},${metadata.tests},${invalid.tests}</global.test.excludes>
</properties>
<build>