use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class InstanceFactoryTest method shouldClear_DatabaseIds_State_and_Result_ForJobObjectHierarchy.
@Test
public void shouldClear_DatabaseIds_State_and_Result_ForJobObjectHierarchy() {
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);
assertThat(stage.hasRerunJobs(), CoreMatchers.is(false));
Stage newStage = instanceFactory.createStageForRerunOfJobs(stage, a("rails"), new DefaultSchedulingContext("loser", new Agents()), StageConfigMother.custom("dev", "rails", "java"), new TimeProvider(), "md5");
assertThat(stage.hasRerunJobs(), CoreMatchers.is(false));
assertThat(newStage.getId(), CoreMatchers.is(-1l));
assertThat(newStage.getJobInstances().size(), CoreMatchers.is(2));
assertThat(newStage.isLatestRun(), CoreMatchers.is(true));
JobInstance newRails = newStage.getJobInstances().getByName("rails");
assertNewJob(old, newRails);
JobInstance newJava = newStage.getJobInstances().getByName("java");
assertCopiedJob(newJava, 12l);
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class InstanceFactoryTest method shouldCreatePipelineInstanceWithEnvironmentVariablesOverriddenAccordingToScope.
@Test
public void shouldCreatePipelineInstanceWithEnvironmentVariablesOverriddenAccordingToScope() {
StageConfig stageConfig = StageConfigMother.custom("stage", "foo", "bar");
JobConfig fooConfig = stageConfig.jobConfigByConfigName(new CaseInsensitiveString("foo"));
fooConfig.addVariable("foo", "foo");
JobConfig barConfig = stageConfig.jobConfigByConfigName(new CaseInsensitiveString("bar"));
barConfig.addVariable("foo", "bar");
MaterialConfigs materialConfigs = MaterialConfigsMother.defaultMaterialConfigs();
PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("pipeline"), materialConfigs, stageConfig);
DefaultSchedulingContext context = new DefaultSchedulingContext("anonymous");
Pipeline instance = instanceFactory.createPipelineInstance(pipelineConfig, ModificationsMother.forceBuild(pipelineConfig), context, "some-md5", new TimeProvider());
assertThat(instance.findStage("stage").findJob("foo").getPlan().getVariables(), is(new EnvironmentVariables(Arrays.asList(new EnvironmentVariable("foo", "foo")))));
assertThat(instance.findStage("stage").findJob("bar").getPlan().getVariables(), is(new EnvironmentVariables(Arrays.asList(new EnvironmentVariable("foo", "bar")))));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class InstanceFactoryTest method shouldCreateAJobForEachAgentIfRunOnAllAgentsIsTrue.
/*
RunOnAllAgents tests
*/
@Test
public void shouldCreateAJobForEachAgentIfRunOnAllAgentsIsTrue() throws Exception {
Agents agents = new Agents();
agents.add(new AgentConfig("uuid1"));
agents.add(new AgentConfig("uuid2"));
JobConfig jobConfig = new JobConfig("foo");
jobConfig.setRunOnAllAgents(true);
SchedulingContext context = mock(SchedulingContext.class);
when(context.getApprovedBy()).thenReturn("chris");
when(context.findAgentsMatching(new ResourceConfigs())).thenReturn(agents);
when(context.getEnvironmentVariablesConfig()).thenReturn(new EnvironmentVariablesConfig());
when(context.overrideEnvironmentVariables(any(EnvironmentVariablesConfig.class))).thenReturn(context);
RunOnAllAgents.CounterBasedJobNameGenerator jobNameGenerator = new RunOnAllAgents.CounterBasedJobNameGenerator(CaseInsensitiveString.str(jobConfig.name()));
JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("stageName"), jobConfig, context, new TimeProvider(), jobNameGenerator);
assertThat(jobs.toArray(), hasItemInArray(hasProperty("name", is("foo-runOnAll-1"))));
assertThat(jobs.toArray(), hasItemInArray(hasProperty("agentUuid", is("uuid1"))));
assertThat(jobs.toArray(), hasItemInArray(hasProperty("runOnAllAgents", is(true))));
assertThat(jobs.toArray(), hasItemInArray(hasProperty("name", is("foo-runOnAll-1"))));
assertThat(jobs.toArray(), hasItemInArray(hasProperty("agentUuid", is("uuid2"))));
assertThat(jobs.toArray(), hasItemInArray(hasProperty("runOnAllAgents", is(true))));
assertThat(jobs.size(), is(2));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class InstanceFactoryTest method shouldSetManualApprovalOnStageInstance.
@Test
public void shouldSetManualApprovalOnStageInstance() {
StageConfig stageConfig = StageConfigMother.custom("test", Approval.manualApproval());
Stage instance = instanceFactory.createStageInstance(stageConfig, new DefaultSchedulingContext("anyone"), "md5", new TimeProvider());
assertThat(instance.getApprovalType(), is(GoConstants.APPROVAL_MANUAL));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class InstanceFactoryTest method shouldNotRerun_WhenJobConfigIsChangedToRunMultipleInstance_ForSingleJobInstance.
@Test
public void shouldNotRerun_WhenJobConfigIsChangedToRunMultipleInstance_ForSingleJobInstance() {
Date old = new DateTime().minusDays(2).toDate();
StageConfig stageConfig = StageConfigMother.custom("dev", "rails", "java");
JobConfig railsConfig = stageConfig.getJobs().getJob(new CaseInsensitiveString("rails"));
DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext("loser", new Agents());
JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("dev"), railsConfig, schedulingContext, new TimeProvider(), null);
Stage stage = createStageInstance(old, jobs);
Stage newStage = null;
railsConfig.setRunInstanceCount(10);
CannotRerunJobException exception = null;
try {
newStage = instanceFactory.createStageForRerunOfJobs(stage, a("rails"), schedulingContext, stageConfig, new TimeProvider(), "md5");
fail("should not schedule since job config changed to run multiple instance");
} catch (CannotRerunJobException e) {
exception = e;
}
assertThat(exception.getJobName(), is("rails"));
assertThat(exception.getInformation(), is("Run configuration for job has been changed to 'run multiple instance'."));
assertThat(newStage, is(nullValue()));
}
Aggregations