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())));
}
}
}
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));
}
}
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));
}
}
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));
}
}
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() + "]"));
}
}
Aggregations