use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class InstanceFactoryTest method should_MaintainRerunOfReferences_InCaseOfMultipleCopyForRerunOperations.
@Test
public void should_MaintainRerunOfReferences_InCaseOfMultipleCopyForRerunOperations() {
Date old = new DateTime().minusDays(2).toDate();
JobInstance rails = jobInstance(old, "rails", 7, 10);
JobInstance java = jobInstance(old, "java", 12, 22);
Stage stage = stage(9, rails, java);
stage.setCounter(2);
Stage newStage = instanceFactory.createStageForRerunOfJobs(stage, a("rails"), new DefaultSchedulingContext("loser", new Agents()), StageConfigMother.custom("dev", "rails", "java"), new TimeProvider(), "md5");
newStage.setCounter(3);
assertThat(newStage.getId(), CoreMatchers.is(-1l));
assertThat(newStage.getJobInstances().size(), CoreMatchers.is(2));
assertThat(newStage.isLatestRun(), CoreMatchers.is(true));
assertThat(newStage.getRerunOfCounter(), CoreMatchers.is(2));
JobInstance newJava = newStage.getJobInstances().getByName("java");
assertCopiedJob(newJava, 12l);
// set id, to assert if original ends up pointing to copied job's id
newJava.setId(18l);
newStage = instanceFactory.createStageForRerunOfJobs(newStage, a("rails"), new DefaultSchedulingContext("loser", new Agents()), StageConfigMother.custom("dev", "rails", "java"), new TimeProvider(), "md5");
newStage.setCounter(4);
assertThat(newStage.getId(), CoreMatchers.is(-1l));
assertThat(newStage.getJobInstances().size(), CoreMatchers.is(2));
assertThat(newStage.isLatestRun(), CoreMatchers.is(true));
assertThat(newStage.getRerunOfCounter(), CoreMatchers.is(2));
newJava = newStage.getJobInstances().getByName("java");
assertCopiedJob(newJava, 12l);
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class InstanceFactoryTest method shouldBomb_ForRerun_OfASingleInstanceJobType_WhichWasEarlierRunOnAll_WithTwoRunOnAllInstancesSelectedForRerun.
@Test
public void shouldBomb_ForRerun_OfASingleInstanceJobType_WhichWasEarlierRunOnAll_WithTwoRunOnAllInstancesSelectedForRerun() {
Date old = new DateTime().minusDays(2).toDate();
StageConfig stageConfig = StageConfigMother.custom("dev", "rails", "java");
JobConfig railsConfig = stageConfig.getJobs().getJob(new CaseInsensitiveString("rails"));
railsConfig.setRunOnAllAgents(true);
railsConfig.addResourceConfig("foobar");
DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext("loser", new Agents(new AgentConfig("abcd1234", "host", "127.0.0.2", new ResourceConfigs(new ResourceConfig("foobar"))), new AgentConfig("1234abcd", "ghost", "192.168.1.2", new ResourceConfigs(new ResourceConfig("baz"), new ResourceConfig("foobar"))), new AgentConfig("7890abdc", "lost", "10.4.3.55", new ResourceConfigs(new ResourceConfig("crapyagent")))));
RunOnAllAgents.CounterBasedJobNameGenerator jobNameGenerator = new RunOnAllAgents.CounterBasedJobNameGenerator(CaseInsensitiveString.str(railsConfig.name()));
JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("dev"), railsConfig, schedulingContext, new TimeProvider(), jobNameGenerator);
Stage stage = createStageInstance(old, jobs);
railsConfig.setRunOnAllAgents(false);
try {
instanceFactory.createStageForRerunOfJobs(stage, a("rails-runOnAll-1", "rails-runOnAll-2"), schedulingContext, stageConfig, new TimeProvider(), "md5");
fail("should have failed when multiple run on all agents jobs are selected when job-config does not have run on all flag anymore");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), CoreMatchers.is("Cannot schedule multiple instances of job named 'rails'."));
}
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class InstanceFactoryTest method should_NOT_ClearAgentAssignment_ForRerun_OfASingleInstanceJobType_WhichWasEarlierRunOnAll.
@Test
public void should_NOT_ClearAgentAssignment_ForRerun_OfASingleInstanceJobType_WhichWasEarlierRunOnAll() {
Date old = new DateTime().minusDays(2).toDate();
StageConfig stageConfig = StageConfigMother.custom("dev", "rails", "java");
JobConfig railsConfig = stageConfig.getJobs().getJob(new CaseInsensitiveString("rails"));
railsConfig.setRunOnAllAgents(true);
railsConfig.addResourceConfig("foobar");
DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext("loser", new Agents(new AgentConfig("abcd1234", "host", "127.0.0.2", new ResourceConfigs(new ResourceConfig("foobar"))), new AgentConfig("1234abcd", "ghost", "192.168.1.2", new ResourceConfigs(new ResourceConfig("baz"), new ResourceConfig("foobar"))), new AgentConfig("7890abdc", "lost", "10.4.3.55", new ResourceConfigs(new ResourceConfig("crapyagent")))));
RunOnAllAgents.CounterBasedJobNameGenerator jobNameGenerator = new RunOnAllAgents.CounterBasedJobNameGenerator(CaseInsensitiveString.str(railsConfig.name()));
JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("dev"), railsConfig, schedulingContext, new TimeProvider(), jobNameGenerator);
Stage stage = createStageInstance(old, jobs);
railsConfig.setRunOnAllAgents(false);
Stage newStage = instanceFactory.createStageForRerunOfJobs(stage, a("rails-runOnAll-1"), schedulingContext, stageConfig, new TimeProvider(), "md5");
assertThat(newStage.getJobInstances().size(), CoreMatchers.is(3));
JobInstance newRailsJob = newStage.getJobInstances().getByName("rails");
assertNewJob(old, newRailsJob);
assertThat(newRailsJob.getAgentUuid(), CoreMatchers.is("abcd1234"));
JobInstance copiedRailsJob = newStage.getJobInstances().getByName("rails-runOnAll-2");
assertCopiedJob(copiedRailsJob, 102l);
assertThat(copiedRailsJob.getAgentUuid(), CoreMatchers.is("1234abcd"));
JobInstance copiedJavaJob = newStage.getJobInstances().getByName("java");
assertCopiedJob(copiedJavaJob, 12l);
assertThat(copiedJavaJob.getAgentUuid(), CoreMatchers.is(not(nullValue())));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class GoConfigRevisionTest method shouldUnderstandEquality.
@Test
public void shouldUnderstandEquality() {
GoConfigRevision rev1 = new GoConfigRevision("blah", "md5", "loser", "2.2.2", new TimeProvider());
GoConfigRevision rev2 = new GoConfigRevision("blah blah", "md5", "loser 2", "2.2.3", new TimeProvider());
assertThat(rev1, is(rev2));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class GoConfigAdministrationControllerTest method shouldLoadSpecificConfigVersionWhenHistoricalVersionIsRequested.
@Test
public void shouldLoadSpecificConfigVersionWhenHistoricalVersionIsRequested() throws Exception {
MockHttpServletResponse response = new MockHttpServletResponse();
String configXml = "config-content";
when(goConfigService.getConfigAtVersion("some-md5")).thenReturn(new GoConfigRevision(configXml, "some-md5", "loser", "100.9.3.1", new TimeProvider()));
controller.getConfigRevision("some-md5", response);
assertThat(response.getContentAsString(), is(configXml));
assertThat(response.getHeader(XmlAction.X_CRUISE_CONFIG_MD5).toString(), is("some-md5"));
}
Aggregations