use of org.apache.maven.plugins.surefire.report.ReportTestSuite in project elastest-torm by elastest.
the class TJobExecOrchestratorService method executeTJob.
@Async
public Future<Void> executeTJob(TJobExecution tJobExec, String tJobServices) {
dbmanager.bindSession();
tJobExec = tJobExecRepositoryImpl.findOne(tJobExec.getId());
elasticsearchService.createMonitoringIndex(tJobExec.getMonitoringIndicesList());
String resultMsg = "Initializing";
tJobExec.setResultMsg(resultMsg);
tJobExecRepositoryImpl.save(tJobExec);
initTSS(tJobExec, tJobServices);
setTJobExecEnvVars(tJobExec, false, false);
tJobExecRepositoryImpl.save(tJobExec);
DockerExecution dockerExec = new DockerExecution(tJobExec);
try {
// Create queues and load basic services
dockerService.loadBasicServices(dockerExec);
resultMsg = "Starting Dockbeat to get metrics...";
updateTJobExecResultStatus(tJobExec, TJobExecution.ResultEnum.IN_PROGRESS, resultMsg);
// Start Dockbeat
dockerService.startDockbeat(dockerExec);
// Start SuT if it's necessary
if (dockerExec.isWithSut()) {
initSut(dockerExec);
}
List<ReportTestSuite> testSuites;
// Start Test
resultMsg = "Executing Test";
updateTJobExecResultStatus(tJobExec, TJobExecution.ResultEnum.EXECUTING_TEST, resultMsg);
dockerService.createTestContainer(dockerExec);
testSuites = dockerService.startTestContainer(dockerExec);
resultMsg = "Waiting for Test Results";
updateTJobExecResultStatus(tJobExec, TJobExecution.ResultEnum.WAITING, resultMsg);
saveTestResults(testSuites, tJobExec);
tJobExec.setEndDate(new Date());
logger.info("Ending Execution...");
// End and purge services
endAllExecs(dockerExec);
saveFinishStatus(tJobExec, dockerExec);
} catch (TJobStoppedException e) {
logger.debug("TJob Stopped");
// Stop exception
} catch (Exception e) {
logger.error("Error during Test execution", e);
if (!"end error".equals(e.getMessage())) {
resultMsg = "Error";
updateTJobExecResultStatus(tJobExec, TJobExecution.ResultEnum.ERROR, resultMsg);
tJobExec.setEndDate(new Date());
try {
endAllExecs(dockerExec);
} catch (Exception e1) {
e1.printStackTrace();
}
} else {
saveFinishStatus(tJobExec, dockerExec);
}
} finally {
if (tJobServices != null && tJobServices != "") {
try {
deprovideServices(tJobExec);
} catch (Exception e) {
logger.error("Exception deprovision TSS: {}", e.getMessage());
// TODO Customize Exception
}
}
}
// Setting execution data
tJobExec.setSutExecution(dockerExec.getSutExec());
// Saving execution data
tJobExecRepositoryImpl.save(tJobExec);
dbmanager.unbindSession();
return new AsyncResult<Void>(null);
}
use of org.apache.maven.plugins.surefire.report.ReportTestSuite in project elastest-torm by elastest.
the class DockerService2 method getTestSuitesByString.
private List<ReportTestSuite> getTestSuitesByString(String result) {
List<ReportTestSuite> results = new ArrayList<>();
String head = "<testsuite ";
String foot = "</testsuite>";
List<String> splitedHeadResult = new ArrayList<String>(Arrays.asList(result.split(head)));
if (splitedHeadResult != null) {
if (!result.startsWith(head)) {
// delete non-deseable string
// (surefire-reports/)
splitedHeadResult.remove(0);
}
for (String piece : splitedHeadResult) {
List<String> splitedFootResult = new ArrayList<String>(Arrays.asList(piece.split(foot)));
String newResult = head + splitedFootResult.get(0) + foot;
ReportTestSuite testSuite = null;
try {
testSuite = this.testSuiteStringToReportTestSuite(newResult);
} catch (ParserConfigurationException | SAXException | IOException e) {
logger.error("Error on parse testSuite {}", e);
}
if (testSuite != null) {
results.add(testSuite);
}
}
}
return results;
}
use of org.apache.maven.plugins.surefire.report.ReportTestSuite in project repairnator by Spirals-Team.
the class GatherTestInformation method businessExecute.
@Override
protected void businessExecute() {
this.getLogger().debug("Gathering test information...");
File rootRepo = new File(this.inspector.getJobStatus().getPomDirPath());
final List<File> surefireDirs = new ArrayList<File>();
try {
Files.walkFileTree(rootRepo.toPath(), new SimpleFileVisitor<Path>() {
public FileVisitResult preVisitDirectory(Path file, BasicFileAttributes attrs) throws IOException {
if (file.toString().endsWith(SUREFIREREPORT_PATH)) {
surefireDirs.add(file.toFile());
return FileVisitResult.SKIP_SUBTREE;
} else {
return FileVisitResult.CONTINUE;
}
}
});
} catch (IOException e) {
this.getLogger().warn("Error while traversing files to get surefire reports: " + e);
this.addStepError(e.getMessage());
}
for (File surefireDir : surefireDirs) {
SurefireReportParser parser = new SurefireReportParser(Arrays.asList(new File[] { surefireDir }), Locale.ENGLISH, null);
try {
List<ReportTestSuite> testSuites = parser.parseXMLReportFiles();
for (ReportTestSuite testSuite : testSuites) {
if (!skipSettingStatusInformation) {
this.nbTotalTests += testSuite.getNumberOfTests();
this.nbSkippingTests += testSuite.getNumberOfSkipped();
if (testSuite.getNumberOfFailures() > 0 || testSuite.getNumberOfErrors() > 0) {
File failingModule = surefireDir.getParentFile().getParentFile();
this.failingModulePath = failingModule.getCanonicalPath();
this.getInspector().getJobStatus().setFailingModulePath(this.failingModulePath);
this.writeProperty("failingModule", this.failingModulePath);
getLogger().info("Get the following failing module path: " + failingModulePath);
for (ReportTestCase testCase : testSuite.getTestCases()) {
if (testCase.hasFailure() || testCase.hasError()) {
// sometimes surefire reports a failureType on the form:
// "java.lang.NullPointerException:" we should avoid this case
String failureType = testCase.getFailureType();
if (failureType.endsWith(":")) {
failureType = failureType.substring(0, failureType.length() - 1);
}
this.failureNames.add(failureType);
FailureType typeTof = new FailureType(testCase.getFailureType(), testCase.getFailureMessage(), testCase.hasError());
FailureLocation failureLocation = null;
for (FailureLocation location : this.failureLocations) {
if (location.getClassName().equals(testCase.getFullClassName())) {
failureLocation = location;
break;
}
}
if (failureLocation == null) {
failureLocation = new FailureLocation(testCase.getFullClassName());
this.failureLocations.add(failureLocation);
}
failureLocation.addFailure(typeTof);
if (testCase.hasError()) {
failureLocation.addErroringMethod(testCase.getFullClassName() + "#" + testCase.getName());
} else {
failureLocation.addFailingMethod(testCase.getFullClassName() + "#" + testCase.getName());
}
}
}
}
}
this.nbErroringTests += testSuite.getNumberOfErrors();
this.nbFailingTests += testSuite.getNumberOfFailures();
}
if (this.nbFailingTests > 0) {
this.setPipelineState(PipelineState.HASTESTFAILURE);
} else if (this.nbErroringTests > 0) {
this.setPipelineState(PipelineState.HASTESTERRORS);
} else {
this.setPipelineState(PipelineState.NOTFAILING);
}
} catch (MavenReportException e) {
this.addStepError("Error while parsing files to get test information:", e);
} catch (IOException e) {
this.addStepError("Error while getting the failing module path: ", e);
}
}
if (!this.skipSettingStatusInformation) {
this.writeProperty("error-types", this.failureNames);
this.writeProperty("failing-test-cases", this.failureLocations);
this.writeProperty("totalNumberFailingTests", this.nbFailingTests);
this.writeProperty("totalNumberErroringTests", this.nbErroringTests);
this.writeProperty("totalNumberSkippingTests", this.nbSkippingTests);
this.writeProperty("totalNumberRunningTests", this.nbTotalTests);
this.inspector.getJobStatus().setFailureLocations(this.failureLocations);
Metrics metrics = this.inspector.getJobStatus().getMetrics();
metrics.setFailureNames(this.failureNames);
metrics.setNbFailingTests(this.nbErroringTests + this.nbFailingTests);
metrics.setNbRunningTests(this.nbTotalTests);
}
this.shouldStop = contract.shouldBeStopped(this);
}
use of org.apache.maven.plugins.surefire.report.ReportTestSuite in project elastest-torm by elastest.
the class DockerService2 method getTestResults.
private List<ReportTestSuite> getTestResults(DockerExecution dockerExec) {
List<ReportTestSuite> testSuites = null;
String resultsPath = dockerExec.gettJobexec().getTjob().getResultsPath();
if (resultsPath != null && !resultsPath.isEmpty()) {
try {
InputStream inputStream = getFileFromContainer(dockerExec.getTestContainerId(), resultsPath, dockerExec);
String result = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
testSuites = getTestSuitesByString(result);
} catch (IOException e) {
}
}
return testSuites;
}
use of org.apache.maven.plugins.surefire.report.ReportTestSuite in project elastest-torm by elastest.
the class TJobExecOrchestratorService method saveTestResults.
public void saveTestResults(List<ReportTestSuite> testSuites, TJobExecution tJobExec) {
logger.info("Saving test results {} ", tJobExec.getId());
TestSuite tSuite;
TestCase tCase;
if (testSuites != null && testSuites.size() > 0) {
for (ReportTestSuite reportTestSuite : testSuites) {
tSuite = new TestSuite();
tSuite.setTimeElapsed(reportTestSuite.getTimeElapsed());
tSuite.setErrors(reportTestSuite.getNumberOfErrors());
tSuite.setFailures(reportTestSuite.getNumberOfFailures());
tSuite.setFlakes(reportTestSuite.getNumberOfFlakes());
tSuite.setSkipped(reportTestSuite.getNumberOfSkipped());
tSuite.setName(reportTestSuite.getName());
tSuite.setnumTests(reportTestSuite.getNumberOfTests());
tSuite = testSuiteRepo.save(tSuite);
for (ReportTestCase reportTestCase : reportTestSuite.getTestCases()) {
tCase = new TestCase();
// Remove parentheses
tCase.cleanNameAndSet(reportTestCase.getName());
tCase.setTime(reportTestCase.getTime());
tCase.setFailureDetail(reportTestCase.getFailureDetail());
tCase.setFailureErrorLine(reportTestCase.getFailureErrorLine());
tCase.setFailureMessage(reportTestCase.getFailureMessage());
tCase.setFailureType(reportTestCase.getFailureType());
tCase.setTestSuite(tSuite);
try {
Date startDate = this.elasticsearchService.findFirstMsgAndGetTimestamp(tJobExec.getMonitoringIndex(), this.tcStartMsgPrefix + tCase.getName() + " ", "test");
tCase.setStartDate(startDate);
Date endDate = this.elasticsearchService.findFirstMsgAndGetTimestamp(tJobExec.getMonitoringIndex(), this.tcFinishMsgPrefix + tCase.getName() + " ", "test");
tCase.setEndDate(endDate);
} catch (Exception e) {
logger.debug("Cannot save start/end date for Test Case {}", tCase.getName(), e);
}
testCaseRepo.save(tCase);
}
tSuite.settJobExec(tJobExec);
testSuiteRepo.save(tSuite);
tJobExec.getTestSuites().add(tSuite);
}
}
}
Aggregations