Search in sources :

Example 6 with LogFixture

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

the class GoCacheTest method shouldAllowAddingUnpersistedNullObjects.

@Test
public void shouldAllowAddingUnpersistedNullObjects() {
    NullUser user = new NullUser();
    goCache.put("loser_user", user);
    assertThat(goCache.get("loser_user"), is(user));
    try (LogFixture logFixture = logFixtureFor(GoCache.class, Level.DEBUG)) {
        String allLogs = logFixture.allLogs();
        assertThat(allLogs, not(containsString("added to cache without an id.")));
        assertThat(allLogs, not(containsString("without an id served out of cache.")));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) NullUser(com.thoughtworks.go.domain.NullUser) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 7 with LogFixture

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

the class BuildCauseProducerServiceIntegrationTimerTest method pipelineWithTimerShouldNotRerunWhenItHasAlreadyRunWithLatestMaterials_GivenTimerIsSetToTriggerOnlyForNewMaterials.

@Test
public void pipelineWithTimerShouldNotRerunWhenItHasAlreadyRunWithLatestMaterials_GivenTimerIsSetToTriggerOnlyForNewMaterials() throws Exception {
    String pipelineName = "p1";
    GitMaterial git1 = u.wf(new GitMaterial("git1"), "folder1");
    GitMaterial git2 = u.wf(new GitMaterial("git2"), "folder2");
    ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWithTimer(pipelineName, u.timer("* * * * * ? 2000", true), u.m(git1), u.m(git2));
    u.checkinFile(git1, "g11", TestFileUtil.createTempFile("blah_g11"), ModifiedAction.added);
    u.checkinFile(git2, "g21", TestFileUtil.createTempFile("blah_g21"), ModifiedAction.added);
    // 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(git2, true, "g21"))));
    BuildCause buildCause = piplineScheduleQueue.toBeScheduled().get(pipelineName);
    piplineScheduleQueue.finishSchedule(pipelineName, buildCause, buildCause);
    try (LogFixture logFixture = logFixtureFor(TimedBuild.class, Level.INFO)) {
        // Timer time comes around again. Will NOT rerun since the new flag (runOnlyOnNewMaterials) is ON.
        buildCauseProducerService.timerSchedulePipeline(p1.config, new ServerHealthStateOperationResult());
        assertThat(piplineScheduleQueue.toBeScheduled().size(), is(0));
        assertThat(logFixture.contains(Level.INFO, "Skipping scheduling of timer-triggered pipeline 'p1' as it has previously run with the latest material(s)."), is(true));
    }
}
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 8 with LogFixture

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

the class BuildCauseProducerServiceIntegrationTimerTest method pipelineWithTimerShouldRunOnlyWithMaterialsWhichChanged_GivenTimerIsSetToTriggerOnlyForNewMaterials.

@Test
public void pipelineWithTimerShouldRunOnlyWithMaterialsWhichChanged_GivenTimerIsSetToTriggerOnlyForNewMaterials() throws Exception {
    int i = 1;
    String pipelineName = "p1";
    GitMaterial git1 = u.wf(new GitMaterial("git1"), "folder1");
    GitMaterial git2 = u.wf(new GitMaterial("git2"), "folder2");
    ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("up1", u.m(git1));
    ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWithTimer(pipelineName, u.timer("* * * * * ? 2000", true), u.m(git1), u.m(git2), u.m(p1));
    u.checkinFile(git1, "g11", TestFileUtil.createTempFile("blah_g11"), ModifiedAction.added);
    u.checkinFile(git2, "g21", TestFileUtil.createTempFile("blah_g21"), ModifiedAction.added);
    Date mduTimeOfG11 = u.d(i++);
    String p1_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, mduTimeOfG11, "g11");
    pipelineTimeline.update();
    // Run once with latest, when pipeline schedules due to timer.
    buildCauseProducerService.timerSchedulePipeline(p2.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(git2, true, "g21"), u.mr(p1, true, p1_1))));
    BuildCause buildCause = piplineScheduleQueue.toBeScheduled().get(pipelineName);
    u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p2, u.d(i++), "g11", "g21", p1_1);
    piplineScheduleQueue.finishSchedule(pipelineName, buildCause, buildCause);
    // Check in to git2 and run pipeline P1 once before the timer time. Then, timer happens. Shows those two materials in "yellow" (changed), on the UI.
    u.checkinFile(git2, "g22", TestFileUtil.createTempFile("blah_g22"), ModifiedAction.added);
    String p1_2 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, mduTimeOfG11, "g11");
    pipelineTimeline.update();
    try (LogFixture logFixture = logFixtureFor(TimedBuild.class, Level.INFO)) {
        buildCauseProducerService.timerSchedulePipeline(p2.config, new ServerHealthStateOperationResult());
        assertThat(piplineScheduleQueue.toBeScheduled().size(), is(1));
        assertThat(piplineScheduleQueue.toBeScheduled().get(pipelineName).getMaterialRevisions(), isSameMaterialRevisionsAs(u.mrs(u.mr(git1, false, "g11"), u.mr(git2, true, "g22"), u.mr(p1, true, p1_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) Date(java.util.Date) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 9 with LogFixture

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

the class AgentServiceTest method shouldThrowExceptionWhenADuplicateAgentTriesToUpdateStatus.

@Test
public void shouldThrowExceptionWhenADuplicateAgentTriesToUpdateStatus() throws Exception {
    AgentRuntimeInfo runtimeInfo = new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, false);
    runtimeInfo.setCookie("invalid_cookie");
    AgentInstance original = AgentInstance.createFromLiveAgent(new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, false), new SystemEnvironment());
    try (LogFixture logFixture = logFixtureFor(AgentService.class, Level.DEBUG)) {
        try {
            when(agentService.findAgentAndRefreshStatus(runtimeInfo.getUUId())).thenReturn(original);
            agentService.updateRuntimeInfo(runtimeInfo);
            fail("should throw exception when cookie mismatched");
        } catch (Exception e) {
            assertThat(e.getMessage(), is(format("Agent [%s] has invalid cookie", runtimeInfo.agentInfoDebugString())));
            assertThat(Arrays.asList(logFixture.getMessages()), hasItem(format("Found agent [%s] with duplicate uuid. Please check the agent installation.", runtimeInfo.agentInfoDebugString())));
            verify(serverHealthService).update(ServerHealthState.warning(format("[%s] has duplicate unique identifier which conflicts with [%s]", runtimeInfo.agentInfoForDisplay(), original.agentInfoForDisplay()), "Please check the agent installation. Click <a href='https://docs.gocd.io/current/faq/agent_guid_issue.html' target='_blank'>here</a> for more info.", HealthStateType.duplicateAgent(HealthStateScope.forAgent(runtimeInfo.getCookie())), Timeout.THIRTY_SECONDS));
        }
    }
    verify(agentInstances).findAgentAndRefreshStatus(runtimeInfo.getUUId());
    verifyNoMoreInteractions(agentInstances);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) LogFixture(com.thoughtworks.go.util.LogFixture) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with LogFixture

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

the class RandomPortTest method shouldLogPortsAllocated.

@Test
public void shouldLogPortsAllocated() {
    try (LogFixture logFixture = logFixtureFor(RandomPort.class, Level.DEBUG)) {
        int port = RandomPort.find("foo");
        assertThat(logFixture.getLog(), containsString("RandomPort: Allocating port " + port + " for 'foo'"));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) 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