Search in sources :

Example 11 with LogFixture

use of com.thoughtworks.go.util.LogFixture in project gocd by gocd.

the class AgentServiceTest method shouldThrowExceptionWhenAgentWithNoCookieTriesToUpdateStatus.

@Test
public void shouldThrowExceptionWhenAgentWithNoCookieTriesToUpdateStatus() throws Exception {
    AgentRuntimeInfo runtimeInfo = new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, false);
    try (LogFixture logFixture = logFixtureFor(AgentService.class, Level.DEBUG)) {
        try {
            agentService.updateRuntimeInfo(runtimeInfo);
            fail("should throw exception when no cookie is set");
        } catch (Exception e) {
            assertThat(e, instanceOf(AgentNoCookieSetException.class));
            assertThat(e.getMessage(), is(format("Agent [%s] has no cookie set", runtimeInfo.agentInfoDebugString())));
            assertThat(Arrays.asList(logFixture.getMessages()), hasItem(format("Agent [%s] has no cookie set", runtimeInfo.agentInfoDebugString())));
        }
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) IOException(java.io.IOException) Test(org.junit.Test)

Example 12 with LogFixture

use of com.thoughtworks.go.util.LogFixture in project gocd by gocd.

the class AgentProcessParentImplTest method shouldLogFailureToStartSubprocess.

@Test
public void shouldLogFailureToStartSubprocess() throws InterruptedException {
    final List<String> cmd = new ArrayList<>();
    try (LogFixture logFixture = logFixtureFor(AgentProcessParentImpl.class, Level.DEBUG)) {
        AgentProcessParentImpl bootstrapper = new AgentProcessParentImpl() {

            @Override
            Process invoke(String[] command) throws IOException {
                cmd.addAll(Arrays.asList(command));
                throw new RuntimeException("something failed!");
            }
        };
        int returnCode = bootstrapper.run("bootstrapper_version", "bar", getURLGenerator(), new HashMap<>(), context());
        assertThat(returnCode, is(-373));
        assertThat(logFixture.contains(Level.ERROR, "Exception while executing command: " + StringUtils.join(cmd, " ") + " - java.lang.RuntimeException: something failed!"), is(true));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) Test(org.junit.Test)

Example 13 with LogFixture

use of com.thoughtworks.go.util.LogFixture in project gocd by gocd.

the class DownloadActionTest method shouldRetryThreeTimesWhenDownloadFails.

@Test
public void shouldRetryThreeTimesWhenDownloadFails() throws Exception {
    when(fetchHandler.handleResult(200, publisher)).thenReturn(true);
    try (LogFixture logging = logFixtureFor(DownloadAction.class, Level.DEBUG)) {
        FailSometimesHttpService httpService = new FailSometimesHttpService(3);
        DownloadAction downloadAction = new DownloadAction(httpService, publisher, clock);
        downloadAction.perform("foo", fetchHandler);
        assertThat(httpService.timesCalled, is(4));
        shouldHaveLogged(logging, Level.WARN, "Could not fetch artifact foo.");
        shouldHaveLogged(logging, Level.WARN, "Error was : Caught an exception 'Connection Reset'");
        assertBetween(clock.getSleeps().get(0), 10000L, 20000L);
        assertBetween(clock.getSleeps().get(1), 20000L, 30000L);
        assertBetween(clock.getSleeps().get(2), 30000L, 40000L);
        assertThat(clock.getSleeps().size(), is(3));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) Test(org.junit.Test)

Example 14 with LogFixture

use of com.thoughtworks.go.util.LogFixture in project gocd by gocd.

the class JobInstanceSqlMapDaoTest method shouldLogStatusUpdatesOfCompletedJobs.

@Test
public void shouldLogStatusUpdatesOfCompletedJobs() throws Exception {
    try (LogFixture logFixture = logFixtureFor(JobInstanceSqlMapDao.class, Level.DEBUG)) {
        JobInstance instance = runningJob("1");
        completeJobs(instance);
        instance.schedule();
        jobInstanceDao.updateStateAndResult(instance);
        assertThat(logFixture.getLog(), logFixture.contains(Level.WARN, "State change for a completed Job is not allowed."), is(true));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) Test(org.junit.Test)

Example 15 with LogFixture

use of com.thoughtworks.go.util.LogFixture in project gocd by gocd.

the class PipelineScheduleQueueIntegrationTest method shouldLogWithInfoIfPipelineISScheduled.

@Test
public void shouldLogWithInfoIfPipelineISScheduled() throws Exception {
    try (LogFixture logging = logFixtureFor(PipelineScheduleQueue.class, Level.DEBUG)) {
        JobConfigs jobConfigs = new JobConfigs();
        Resources resources = new Resources(new Resource("resource1"));
        ArtifactPlans artifactPlans = new ArtifactPlans();
        ArtifactPropertiesGenerators generators = new ArtifactPropertiesGenerators();
        generators.add(new ArtifactPropertiesGenerator("property-name", "artifact-path", "artifact-xpath"));
        JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("test-job"), resources, artifactPlans, generators);
        jobConfigs.add(jobConfig);
        StageConfig stage = new StageConfig(new CaseInsensitiveString("test-stage"), jobConfigs);
        MaterialConfigs materialConfigs = new MaterialConfigs(MaterialConfigsMother.dependencyMaterialConfig());
        PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("test-pipeline"), materialConfigs, stage);
        configFileEditor.addPipeline(CaseInsensitiveString.str(pipelineConfig.name()), CaseInsensitiveString.str(stage.name()));
        BuildCause cause = modifySomeFiles(pipelineConfig, ModificationsMother.nextRevision());
        saveRev(cause);
        queue.createPipeline(cause, pipelineConfig, new DefaultSchedulingContext(cause.getApprover(), new Agents()), "md5-test", new TimeProvider());
        assertThat(logging.getLog(), containsString("[Pipeline Schedule] Successfully scheduled pipeline test-pipeline, buildCause:[ModificationBuildCause: triggered by " + cause.getMaterialRevisions().latestRevision() + "]"));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) TimeProvider(com.thoughtworks.go.util.TimeProvider) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Aggregations

LogFixture (com.thoughtworks.go.util.LogFixture)20 Test (org.junit.Test)20 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)4 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)3 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)3 IOException (java.io.IOException)3 RunIf (com.googlecode.junit.ext.RunIf)1 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 ConfigUpdateCheckFailedException (com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 NullUser (com.thoughtworks.go.domain.NullUser)1 Modification (com.thoughtworks.go.domain.materials.Modification)1 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)1 OperationResult (com.thoughtworks.go.server.service.result.OperationResult)1 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)1 TimeProvider (com.thoughtworks.go.util.TimeProvider)1 ConsoleResult (com.thoughtworks.go.util.command.ConsoleResult)1