use of org.apache.asterix.testframework.xml.TestCase.CompilationUnit in project asterixdb by apache.
the class TestCaseContext method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder(testCase.getFilePath());
sb.append(':');
for (CompilationUnit cu : testCase.getCompilationUnit()) {
sb.append(' ');
sb.append(cu.getName());
}
return sb.toString();
}
use of org.apache.asterix.testframework.xml.TestCase.CompilationUnit in project asterixdb by apache.
the class ParserTestExecutor method executeTest.
@Override
public void executeTest(String actualPath, TestCaseContext testCaseCtx, ProcessBuilder pb, boolean isDmlRecoveryTest, TestGroup failedGroup) throws Exception {
int queryCount = 0;
List<CompilationUnit> cUnits = testCaseCtx.getTestCase().getCompilationUnit();
for (CompilationUnit cUnit : cUnits) {
LOGGER.info("Starting [TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/" + cUnit.getName() + " ... ");
List<TestFileContext> testFileCtxs = testCaseCtx.getTestFiles(cUnit);
List<TestFileContext> expectedResultFileCtxs = testCaseCtx.getExpectedResultFiles(cUnit);
for (TestFileContext ctx : testFileCtxs) {
File testFile = ctx.getFile();
try {
if (queryCount >= expectedResultFileCtxs.size() && !cUnit.getOutputDir().getValue().equals("none")) {
throw new ComparisonException("no result file for " + testFile.toString() + "; queryCount: " + queryCount + ", filectxs.size: " + expectedResultFileCtxs.size());
}
// Runs the test query.
File expectedResultFile = expectedResultFileCtxs.get(queryCount).getFile();
File actualResultFile = testCaseCtx.getActualResultFile(cUnit, expectedResultFile, new File(actualPath));
testSQLPPParser(testFile, actualResultFile, expectedResultFile);
LOGGER.info("[TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/" + cUnit.getName() + " PASSED ");
queryCount++;
} catch (Exception e) {
System.err.println("testFile " + testFile.toString() + " raised an exception: " + e);
if (cUnit.getExpectedError().isEmpty()) {
e.printStackTrace();
System.err.println("...Unexpected!");
if (failedGroup != null) {
failedGroup.getTestCase().add(testCaseCtx.getTestCase());
}
throw new Exception("Test \"" + testFile + "\" FAILED!", e);
} else {
// must compare with the expected failure message
if (e instanceof ComparisonException) {
throw e;
}
LOGGER.info("[TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/" + cUnit.getName() + " failed as expected: " + e.getMessage());
System.err.println("...but that was expected.");
}
}
}
}
}
use of org.apache.asterix.testframework.xml.TestCase.CompilationUnit in project asterixdb by apache.
the class TestExecutor method executeTest.
public void executeTest(String actualPath, TestCaseContext testCaseCtx, ProcessBuilder pb, boolean isDmlRecoveryTest, TestGroup failedGroup) throws Exception {
MutableInt queryCount = new MutableInt(0);
int numOfErrors = 0;
int numOfFiles = 0;
List<CompilationUnit> cUnits = testCaseCtx.getTestCase().getCompilationUnit();
for (CompilationUnit cUnit : cUnits) {
List<String> expectedErrors = cUnit.getExpectedError();
LOGGER.info("Starting [TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/" + cUnit.getName() + " ... ");
Map<String, Object> variableCtx = new HashMap<>();
List<TestFileContext> testFileCtxs = testCaseCtx.getTestFiles(cUnit);
List<TestFileContext> expectedResultFileCtxs = testCaseCtx.getExpectedResultFiles(cUnit);
for (TestFileContext ctx : testFileCtxs) {
numOfFiles++;
final File testFile = ctx.getFile();
final String statement = readTestFile(testFile);
try {
executeTestFile(testCaseCtx, ctx, variableCtx, statement, isDmlRecoveryTest, pb, cUnit, queryCount, expectedResultFileCtxs, testFile, actualPath);
} 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!");
if (failedGroup != null) {
failedGroup.getTestCase().add(testCaseCtx.getTestCase());
}
throw new Exception("Test \"" + testFile + "\" FAILED!", e);
}
} 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 ");
}
}
}
}
}
Aggregations