Search in sources :

Example 11 with TestTree

use of org.eclipse.n4js.tester.domain.TestTree in project n4js by eclipse.

the class TestTreeRegistryImpl method putTestResult.

@Override
public void putTestResult(final String sessionId, final String testId, final TestResult result) {
    final TestTree t = getTree(sessionId);
    if (null == t) {
        throw new IllegalStateException("Test tree does not exist for session. Session ID: '" + sessionId + "'.");
    }
    if (null == t.getTestCase(testId)) {
        throw new IllegalStateException("Test case cannot be found in test tree. Session ID: '" + sessionId + "'. Test ID: " + testId);
    }
    getExecutorService(sessionId).submit(() -> {
        synchronized (mutex.get(sessionId)) {
            final TestTree tree = getTree(sessionId);
            if (null == tree) {
                throw new IllegalStateException("Test tree does not exist for session. Session ID: '" + sessionId + "'.");
            }
            final TestTree updatedTree = updateWithResult(tree, testId, result);
            cache.put(sessionId, updatedTree);
        }
        // the Void
        return null;
    });
}
Also used : TestTree(org.eclipse.n4js.tester.domain.TestTree)

Example 12 with TestTree

use of org.eclipse.n4js.tester.domain.TestTree in project n4js by eclipse.

the class TestTreeRegistryImpl method validateTestTree.

@Override
public boolean validateTestTree(final String sessionId) {
    final TestTree copy = getTree(sessionId);
    if (null == copy) {
        throw new IllegalStateException("Test tree does not exist for session. Session ID: '" + sessionId + "'.");
    }
    synchronized (this) {
        final ExecutorService executorService = getExecutorService(sessionId);
        if (debugEnabled) {
            LOGGER.debug("Validating test tree for session: '" + sessionId + "'.");
        }
        if (!executorService.isShutdown()) {
            if (debugEnabled) {
                LOGGER.debug("Test tree is incomplete. Waiting for executors to finish the tree state update...");
            }
            try {
                executorService.shutdown();
                executorService.awaitTermination(timeout, MILLISECONDS);
            } catch (final InterruptedException e) {
                throw new RuntimeException(e);
            }
            if (debugEnabled) {
                LOGGER.debug("Test tree is in complete state.");
            }
        }
        return validate(getTree(sessionId));
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) TestTree(org.eclipse.n4js.tester.domain.TestTree)

Example 13 with TestTree

use of org.eclipse.n4js.tester.domain.TestTree in project n4js by eclipse.

the class HeadlessTester method runTests.

/**
 * Actually start the requested tester to test provided location. Workspace from headlesCompiler should be
 * configured before calling this method.
 *
 * @param tester
 *            the tester to be used
 * @param implementationId
 *            to be used for API-IMPL projects
 * @param locationToTest
 *            location of the test code
 * @throws ExitCodeException
 *             in cases of errors
 */
public void runTests(String tester, String implementationId, URI locationToTest, File testReportRoot) throws ExitCodeException {
    ITesterDescriptor testerDescriptor = checkTester(tester);
    logger.info("Using tester :" + testerDescriptor.getId());
    TestConfiguration testConfiguration = null;
    try {
        testConfiguration = testerFrontEnd.createConfiguration(testerDescriptor.getId(), implementationId, locationToTest);
    } catch (java.lang.IllegalStateException e2) {
        logger.error(Throwables.getStackTraceAsString(e2));
        throw new ExitCodeException(EXITCODE_TESTER_STOPPED_WITH_ERROR, "Cannot create test configuration.", e2);
    }
    try {
        TestTree testTree = testConfiguration.getTestTree();
        LoggingTestListener testListener = new LoggingTestListener(testerEventBus, logger, testTree);
        Process process = testerFrontEnd.test(testConfiguration);
        int exit = process.waitFor();
        if (!testListener.finished())
            throw new ExitCodeException(EXITCODE_TESTER_STOPPED_WITH_ERROR, "Test session has not finished.");
        if (testReportRoot != null)
            createTestReport(testReportRoot, testTree);
        if (!testListener.isOK())
            throw new ExitCodeException(EXITCODE_TESTER_STOPPED_WITH_ERROR, "There were test errors, see console logs and/or test report for details.");
        if (exit != 0)
            throw new ExitCodeException(EXITCODE_TESTER_STOPPED_WITH_ERROR, "The spawned tester '" + testerDescriptor.getId() + "' exited with code=" + exit);
    } catch (InterruptedException e1) {
        logger.error(Throwables.getStackTraceAsString(e1));
        throw new ExitCodeException(EXITCODE_TESTER_STOPPED_WITH_ERROR, "The spawned tester exited by throwing an exception", e1);
    } finally {
        testerFacade.shutdownFramework();
    }
}
Also used : ITesterDescriptor(org.eclipse.n4js.tester.extension.ITesterDescriptor) TestConfiguration(org.eclipse.n4js.tester.TestConfiguration) ExitCodeException(org.eclipse.n4js.hlc.base.ExitCodeException) TestTree(org.eclipse.n4js.tester.domain.TestTree)

Example 14 with TestTree

use of org.eclipse.n4js.tester.domain.TestTree in project n4js by eclipse.

the class MockTest method createNewTestTree.

private TestTree createNewTestTree(final String sessionId, final int testCaseCountFactor) {
    final List<TestSuite> testSuites = newArrayList();
    create(closed(1, testCaseCountFactor), integers()).forEach(i -> {
        final String suiteName = format("%05d", i) + "_TestSuite";
        final TestSuite suite = new TestSuite(suiteName);
        create(closed(1, testCaseCountFactor), integers()).forEach(j -> {
            final String testCaseId = getTestCaseId(i, j);
            suite.add(new TestCase(new ID(testCaseId), "origin." + suiteName + "." + testCaseId + ".0.0.1", suiteName + "." + testCaseId, testCaseId, testCaseId, URI.createURI("testURI_" + testCaseId)));
        });
        testSuites.add(suite);
    });
    return new TestTree(new ID(sessionId), testSuites);
}
Also used : TestSuite(org.eclipse.n4js.tester.domain.TestSuite) TestCase(org.eclipse.n4js.tester.domain.TestCase) ID(org.eclipse.n4js.tester.domain.ID) UUID.randomUUID(java.util.UUID.randomUUID) TestTree(org.eclipse.n4js.tester.domain.TestTree)

Example 15 with TestTree

use of org.eclipse.n4js.tester.domain.TestTree in project n4js by eclipse.

the class TestTreeRegistryTest method testRegisterTestTreeThenPurgeAssertNotFound.

/**
 */
@Test(expected = IllegalStateException.class)
public void testRegisterTestTreeThenPurgeAssertNotFound() {
    final String sessionId = valueOf(randomUUID());
    fsmRegistry.registerFsm(sessionId);
    final TestTree original = newTestTree(sessionId);
    treeRegistry.registerTestTree(original);
    assertNotNull(treeRegistry.getTestTree(sessionId));
    internalTreeRegistry.purgeTestTree(sessionId);
    treeRegistry.getTestTree(sessionId);
}
Also used : TestTree(org.eclipse.n4js.tester.domain.TestTree) Test(org.junit.Test)

Aggregations

TestTree (org.eclipse.n4js.tester.domain.TestTree)25 Test (org.junit.Test)14 UUID.randomUUID (java.util.UUID.randomUUID)7 ID (org.eclipse.n4js.tester.domain.ID)7 TestSuite (org.eclipse.n4js.tester.domain.TestSuite)7 TestCase (org.eclipse.n4js.tester.domain.TestCase)4 Function (com.google.common.base.Function)1 IOException (java.io.IOException)1 ExecutorService (java.util.concurrent.ExecutorService)1 URI (org.eclipse.emf.common.util.URI)1 ExitCodeException (org.eclipse.n4js.hlc.base.ExitCodeException)1 TestConfiguration (org.eclipse.n4js.tester.TestConfiguration)1 ITesterDescriptor (org.eclipse.n4js.tester.extension.ITesterDescriptor)1 TesterActivator (org.eclipse.n4js.tester.internal.TesterActivator)1 TModule (org.eclipse.n4js.ts.types.TModule)1