Search in sources :

Example 1 with LogFile

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));
}
Also used : Expectations(org.jmock.Expectations) LogFile(com.thoughtworks.go.server.domain.LogFile) JobInstance(com.thoughtworks.go.domain.JobInstance) HashMap(java.util.HashMap) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) LogFile(com.thoughtworks.go.server.domain.LogFile) File(java.io.File) Test(org.junit.Test)

Example 2 with LogFile

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));
    }
}
Also used : LogFile(com.thoughtworks.go.server.domain.LogFile) Map(java.util.Map) JobInstanceLog(com.thoughtworks.go.domain.JobInstanceLog)

Example 3 with LogFile

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));
}
Also used : LogFile(com.thoughtworks.go.server.domain.LogFile) BuildTestSuite(com.thoughtworks.go.server.domain.BuildTestSuite) BuildTestCase(com.thoughtworks.go.server.domain.BuildTestCase) List(java.util.List) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Map(java.util.Map) Test(org.junit.Test)

Example 4 with LogFile

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()));
    }
}
Also used : LogFile(com.thoughtworks.go.server.domain.LogFile) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) LogFile(com.thoughtworks.go.server.domain.LogFile) File(java.io.File) Test(org.junit.Test)

Example 5 with LogFile

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);
    }
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) LogFile(com.thoughtworks.go.server.domain.LogFile) File(java.io.File) IOException(java.io.IOException) IllegalArtifactLocationException(com.thoughtworks.go.domain.exception.IllegalArtifactLocationException)

Aggregations

LogFile (com.thoughtworks.go.server.domain.LogFile)6 Map (java.util.Map)4 Test (org.junit.Test)4 File (java.io.File)3 BuildTestCase (com.thoughtworks.go.server.domain.BuildTestCase)2 BuildTestSuite (com.thoughtworks.go.server.domain.BuildTestSuite)2 HashMap (java.util.HashMap)2 List (java.util.List)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 JobInstanceLog (com.thoughtworks.go.domain.JobInstanceLog)1 IllegalArtifactLocationException (com.thoughtworks.go.domain.exception.IllegalArtifactLocationException)1 IOException (java.io.IOException)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Expectations (org.jmock.Expectations)1