Search in sources :

Example 1 with CompilationUnit

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();
}
Also used : CompilationUnit(org.apache.asterix.testframework.xml.TestCase.CompilationUnit)

Example 2 with CompilationUnit

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.");
                }
            }
        }
    }
}
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)

Example 3 with CompilationUnit

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 ");
                }
            }
        }
    }
}
Also used : CompilationUnit(org.apache.asterix.testframework.xml.TestCase.CompilationUnit) HashMap(java.util.HashMap) TestFileContext(org.apache.asterix.testframework.context.TestFileContext) URISyntaxException(java.net.URISyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) MutableInt(org.apache.commons.lang3.mutable.MutableInt) File(java.io.File)

Aggregations

CompilationUnit (org.apache.asterix.testframework.xml.TestCase.CompilationUnit)3 File (java.io.File)2 TestFileContext (org.apache.asterix.testframework.context.TestFileContext)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 AsterixException (org.apache.asterix.common.exceptions.AsterixException)1 ComparisonException (org.apache.asterix.test.common.ComparisonException)1 MutableInt (org.apache.commons.lang3.mutable.MutableInt)1