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.")));
}
}
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));
}
}
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));
}
}
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);
}
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'"));
}
}
Aggregations