Search in sources :

Example 16 with LogFixture

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

the class CcTrayActivityListenerTest method shouldLogAndIgnoreAnyChangesWhichCannotBeHandled.

@Test
public void shouldLogAndIgnoreAnyChangesWhichCannotBeHandled() throws Exception {
    CcTrayStageStatusChangeHandler normalStageStatusChangeHandler = mock(CcTrayStageStatusChangeHandler.class);
    CcTrayJobStatusChangeHandler failingJobStatusChangeHandler = mock(CcTrayJobStatusChangeHandler.class);
    doThrow(new RuntimeException("Ouch. Failed.")).when(failingJobStatusChangeHandler).call(any(JobInstance.class));
    try (LogFixture logFixture = logFixtureFor(CcTrayActivityListener.class, Level.DEBUG)) {
        CcTrayActivityListener listener = new CcTrayActivityListener(goConfigService, failingJobStatusChangeHandler, normalStageStatusChangeHandler, configChangeHandler);
        listener.initialize();
        listener.jobStatusChanged(JobInstanceMother.passed("some-job-this-should-fail"));
        listener.stageStatusChanged(StageMother.unrunStage("some-stage"));
        waitForProcessingToHappen();
        assertThat(logFixture.contains(Level.WARN, "Failed to handle action in CCTray queue"), is(true));
    }
    verify(normalStageStatusChangeHandler).call(StageMother.unrunStage("some-stage"));
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) JobInstance(com.thoughtworks.go.domain.JobInstance) Test(org.junit.Test)

Example 17 with LogFixture

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

the class P4OutputParserTest method shouldIgnoreBadLinesAndLogThem.

@Test
public void shouldIgnoreBadLinesAndLogThem() throws ParseException {
    try (LogFixture logging = logFixtureFor(P4OutputParser.class, Level.DEBUG)) {
        final String output = "Change 539921 on 2008/09/24 " + "by abc@SomeRefinery_abc_sa1-sgr-xyz-001 'more work in progress on MDC un'\n";
        final String description = "Change that I cannot parse :-(\n";
        context.checking(new Expectations() {

            {
                allowing(p4Client).describe(with(any(Long.class)));
                will(returnValue(description));
            }
        });
        List<Modification> modifications = parser.modifications(new ConsoleResult(0, Arrays.asList(output.split("\n")), new ArrayList<>(), new ArrayList<>(), new ArrayList<>()));
        assertThat(modifications.size(), is(0));
        assertThat(logging.getLog(), containsString(description));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) Expectations(org.jmock.Expectations) Modification(com.thoughtworks.go.domain.materials.Modification) ConsoleResult(com.thoughtworks.go.util.command.ConsoleResult) ArrayList(java.util.ArrayList) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 18 with LogFixture

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

the class GoConfigDaoTestBase method shouldLogAnyErrorMessageIncludingTheValidationError.

@Test
public void shouldLogAnyErrorMessageIncludingTheValidationError() throws Exception {
    try (LogFixture logger = logFixtureFor(GoFileConfigDataSource.class, Level.DEBUG)) {
        try {
            cachedGoConfig.save(INVALID_CONFIG_WITH_TYPE_FOR_ARTIFACT, false);
            fail();
        } catch (Exception e) {
            assertThat(logger.getLog(), containsString("'type' is not allowed to appear in element 'test'."));
        }
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) ConfigUpdateCheckFailedException(com.thoughtworks.go.config.update.ConfigUpdateCheckFailedException) Test(org.junit.Test)

Example 19 with LogFixture

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

the class BuildCauseProducerServiceIntegrationTimerTest method pipelineWithTimerShouldRerunWhenItHasAlreadyRunWithLatestMaterials_GivenTimerIsNOTSetToTriggerOnlyForNewMaterials.

@Test
public void pipelineWithTimerShouldRerunWhenItHasAlreadyRunWithLatestMaterials_GivenTimerIsNOTSetToTriggerOnlyForNewMaterials() throws Exception {
    int i = 1;
    String pipelineName = "p1";
    GitMaterial git1 = u.wf(new GitMaterial("git1"), "folder");
    ScheduleTestUtil.AddedPipeline up1 = u.saveConfigWith("up1", u.m(git1));
    ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWithTimer(pipelineName, u.timer("* * * * * ? 2000", false), u.m(git1), u.m(up1));
    u.checkinFile(git1, "g11", TestFileUtil.createTempFile("blah_g11"), ModifiedAction.added);
    String up1_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(up1, u.d(i++), "g11");
    pipelineTimeline.update();
    // Run once with latest, when pipeline schedules due to timer.
    buildCauseProducerService.timerSchedulePipeline(p1.config, new ServerHealthStateOperationResult());
    assertThat(piplineScheduleQueue.toBeScheduled().size(), is(1));
    assertThat(piplineScheduleQueue.toBeScheduled().get(pipelineName).getMaterialRevisions(), isSameMaterialRevisionsAs(u.mrs(u.mr(git1, true, "g11"), u.mr(up1, true, up1_1))));
    BuildCause buildCause = piplineScheduleQueue.toBeScheduled().get(pipelineName);
    String up1_2 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(up1, u.d(i++), "g11");
    piplineScheduleQueue.finishSchedule(pipelineName, buildCause, buildCause);
    try (LogFixture logFixture = logFixtureFor(TimedBuild.class, Level.INFO)) {
        // Timer time comes around again. Will rerun since the new flag (runOnlyOnNewMaterials) is not ON.
        buildCauseProducerService.timerSchedulePipeline(p1.config, new ServerHealthStateOperationResult());
        assertThat(piplineScheduleQueue.toBeScheduled().size(), is(1));
        assertThat(piplineScheduleQueue.toBeScheduled().get(pipelineName).getMaterialRevisions(), is(u.mrs(u.mr(git1, false, "g11"), u.mr(up1, false, up1_2))));
        assertThat(logFixture.contains(Level.INFO, "Skipping scheduling of timer-triggered pipeline 'p1' as it has previously run with the latest material(s)."), is(false));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 20 with LogFixture

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

the class UpdateAgentStatusTest method shouldLogWarningWhenIPAddressChanges.

@Test
public void shouldLogWarningWhenIPAddressChanges() throws Exception {
    AgentIdentifier agentIdentifier1 = new AgentIdentifier("localhost", "10.18.3.95", "uuid");
    AgentRuntimeInfo agentRuntimeInfo1 = new AgentRuntimeInfo(agentIdentifier1, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false);
    agentRuntimeInfo1.busy(new AgentBuildingInfo("building", "buildLocator"));
    agentRuntimeInfo1.setLocation("/myDirectory");
    try (LogFixture logging = logFixtureFor(AgentService.class, Level.DEBUG)) {
        agentService.updateRuntimeInfo(agentRuntimeInfo1);
        assertThat(logging.getLog(), containsString("Agent with UUID [uuid] changed IP Address from [10.81.2.1] to [10.18.3.95]"));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) 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