Search in sources :

Example 1 with ComparisonException

use of org.apache.asterix.test.common.ComparisonException 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.");
                }
            }
        }
    }
}
Also used : CompilationUnit(org.apache.asterix.testframework.xml.TestCase.CompilationUnit) TestFileContext(org.apache.asterix.testframework.context.TestFileContext) File(java.io.File) ComparisonException(org.apache.asterix.test.common.ComparisonException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) ComparisonException(org.apache.asterix.test.common.ComparisonException)

Aggregations

File (java.io.File)1 AsterixException (org.apache.asterix.common.exceptions.AsterixException)1 ComparisonException (org.apache.asterix.test.common.ComparisonException)1 TestFileContext (org.apache.asterix.testframework.context.TestFileContext)1 CompilationUnit (org.apache.asterix.testframework.xml.TestCase.CompilationUnit)1