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;
});
}
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));
}
}
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();
}
}
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);
}
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);
}
Aggregations