use of com.thoughtworks.go.server.domain.LogFile in project gocd by gocd.
the class JobDetailServiceTest method shouldCreateBuildInstanceDetailFromLogFileForCompletedBuild.
@Test
public void shouldCreateBuildInstanceDetailFromLogFileForCompletedBuild() throws Exception {
final String jobConfigName = "jobConfig1";
final int id = 1;
final JobInstance completed = JobInstanceMother.completed(jobConfigName, JobResult.Failed);
completed.setId(id);
completed.setIdentifier(new JobIdentifier("pipeline", "1", "stage", "1", jobConfigName));
final HashMap properties = new HashMap();
final File artifactsRoot = new File("artifacts");
context.checking(new Expectations() {
{
one(artifactsService).getInstanceLogFile(completed.getIdentifier());
LogFile buildLogFile = new LogFile(DataUtils.getFailedBuildLbuildAsFile().getFile());
will(returnValue(buildLogFile));
one(artifactsService).parseLogFile(buildLogFile, completed.isPassed());
will(returnValue(properties));
one(artifactsService).findArtifact(completed.getIdentifier(), "");
will(returnValue(artifactsRoot));
}
});
jobDetailService.loadBuildInstanceLog(completed);
assertThat(completed.getName(), is(jobConfigName));
assertThat(properties.get("artifactfolder"), is(artifactsRoot));
}
use of com.thoughtworks.go.server.domain.LogFile in project gocd by gocd.
the class JobDetailService method loadBuildInstanceLog.
public void loadBuildInstanceLog(JobInstance instance) throws Exception {
if (instance.isCompleted()) {
LogFile logFile = artifactsService.getInstanceLogFile(instance.getIdentifier());
Map properties = artifactsService.parseLogFile(logFile, instance.isPassed());
properties.put("artifactfolder", artifactsService.findArtifact(instance.getIdentifier(), ""));
instance.setInstanceLog(new JobInstanceLog(logFile, properties));
}
}
use of com.thoughtworks.go.server.domain.LogFile in project gocd by gocd.
the class LogParserTest method testCanReadFailure.
@Test
public void testCanReadFailure() throws Exception {
LogFile logFile = new LogFile(DataUtils.getFailedBuildLbuildAsFile().getFile());
boolean isPassed = false;
Map map = logParser.parseLogFile(logFile, isPassed);
List suites = getTestSuites(map);
BuildTestSuite firstSuite = (BuildTestSuite) suites.get(0);
List failingCases = firstSuite.getFailingTestCases();
assertThat(firstSuite.getNumberOfFailures(), is(3));
assertThat(failingCases.size(), is(3));
BuildTestCase failingTest = (BuildTestCase) failingCases.get(0);
String expectedNoClassDefFoundError = "junit.framework.AssertionFailedError: Error during schema validation";
String exptectedClassPath = "at junit.framework.Assert.fail(Assert.java:47)";
String className = "net.sourceforge.cruisecontrol.sampleproject.connectfour.PlayingStandTest";
assertThat(failingTest.getClassname(), is(className));
assertThat(failingTest.getDuration(), is("3.807"));
assertThat(failingTest.getName(), is("testSomething"));
assertThat(failingTest.getResult(), is(BuildTestCaseResult.FAILED));
assertThat(failingTest.getMessage(), is("Not the expected result"));
assertThat(failingTest.getMessageBody(), containsString(expectedNoClassDefFoundError));
assertThat(failingTest.getMessageBody(), containsString(exptectedClassPath));
}
use of com.thoughtworks.go.server.domain.LogFile in project gocd by gocd.
the class ArtifactsServiceTest method shouldThrowArtifactsParseExceptionWhenCannotParse.
@Test
public void shouldThrowArtifactsParseExceptionWhenCannotParse() throws IOException {
final File tempFolder = TestFileUtil.createTempFolder("tempFolder");
resourcesToBeCleanedOnTeardown.add(tempFolder);
final LogFile logFile = new LogFile(tempFolder, "logFile");
String invalidXml = "<xml></wrongClosingTag>";
FileUtils.writeStringToFile(logFile.getFile(), invalidXml);
assumeArtifactsRoot(new File("logs"));
ArtifactsService artifactsService = new ArtifactsService(resolverService, stageService, artifactsDirHolder, zipUtil, systemService);
try {
artifactsService.parseLogFile(logFile, true);
fail();
} catch (ArtifactsParseException e) {
assertThat(e.getMessage(), containsString("Error parsing log file:"));
assertThat(e.getMessage(), containsString(logFile.getPath()));
}
}
use of com.thoughtworks.go.server.domain.LogFile in project gocd by gocd.
the class ArtifactsService method parseLogFile.
public Map parseLogFile(LogFile logFile, boolean buildPassed) throws ArtifactsParseException {
try {
Map properties;
File cacheFile = serializedPropertiesFile(logFile.getFile());
if (cacheFile.exists()) {
properties = (Map) ObjectUtil.readObject(cacheFile);
} else if (logFile.getFile().exists()) {
properties = logParser.parseLogFile(logFile, buildPassed);
ObjectUtil.writeObject(properties, cacheFile);
} else {
properties = new HashMap();
}
return properties;
} catch (Exception e) {
LOGGER.error("Error parsing log file: ", e);
String filePath = logFile == null ? "null log file" : logFile.getFile().getPath();
throw new ArtifactsParseException("Error parsing log file: " + filePath, e);
}
}
Aggregations