use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class PipelineScheduleServiceTest method shouldForceStagePlanWithModificationsSinceLast.
@Test
public void shouldForceStagePlanWithModificationsSinceLast() throws Exception {
Pipeline completedMingle = scheduleAndCompleteInitialPipelines();
pipelineDao.loadPipeline(completedMingle.getId());
TestingMaterial testingMaterial = new TestingMaterial();
mingleConfig.setMaterialConfigs(new MaterialConfigs(testingMaterial.config()));
MaterialRevisions revisions = new MaterialRevisions();
revisions.addRevision(testingMaterial, testingMaterial.modificationsSince(null, null, subprocessExecutionContext));
BuildCause buildCause = BuildCause.createManualForced(revisions, Username.ANONYMOUS);
dbHelper.saveMaterials(buildCause.getMaterialRevisions());
Pipeline forcedPipeline = instanceFactory.createPipelineInstance(mingleConfig, buildCause, new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider());
pipelineService.save(forcedPipeline);
verifyMingleScheduledWithModifications();
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class PipelineScheduleServiceTest method shouldScheduleMultipleJobsWhenToBeRunMultipleInstance.
@Test
public void shouldScheduleMultipleJobsWhenToBeRunMultipleInstance() throws Exception {
configHelper.setRunMultipleInstance(CaseInsensitiveString.str(evolveConfig.name()), STAGE_NAME, "unit", 2);
Material stubMaterial = new TestingMaterial();
evolveConfig.setMaterialConfigs(new MaterialConfigs(stubMaterial.config()));
MaterialRevisions revisions = new MaterialRevisions();
revisions.addRevision(stubMaterial, ((TestingMaterial) stubMaterial).modificationsSince(null, null, subprocessExecutionContext));
BuildCause buildCause = BuildCause.createWithModifications(revisions, "");
dbHelper.saveMaterials(buildCause.getMaterialRevisions());
Pipeline pipeline = instanceFactory.createPipelineInstance(evolveConfig, buildCause, new DefaultSchedulingContext(DEFAULT_APPROVED_BY, environmentConfigService.agentsForPipeline(evolveConfig.name())), md5, new TimeProvider());
pipelineService.save(pipeline);
Stage instance = scheduleService.scheduleStage(pipeline, STAGE_NAME, "anyone", new ScheduleService.NewStageInstanceCreator(goConfigService), new ScheduleService.ExceptioningErrorHandler());
JobInstances scheduledJobs = instance.getJobInstances();
assertThat(scheduledJobs.size(), is(2));
assertThat(scheduledJobs.toArray(), hasItemInArray(hasProperty("name", is(RunMultipleInstance.CounterBasedJobNameGenerator.appendMarker("unit", 1)))));
assertThat(scheduledJobs.toArray(), hasItemInArray(hasProperty("name", is(RunMultipleInstance.CounterBasedJobNameGenerator.appendMarker("unit", 2)))));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class PipelineBuilder method addJob.
public void addJob(String jobName) {
JobInstance instance = new JobInstance(jobName, null, new TimeProvider());
currentStage().getJobInstances().add(instance);
}
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 shouldCreateJobInstancesCorrectly_RunMultipleInstance_Rerun.
@Test
public void shouldCreateJobInstancesCorrectly_RunMultipleInstance_Rerun() {
Date old = new DateTime().minusDays(2).toDate();
StageConfig stageConfig = StageConfigMother.custom("dev", "rails", "java");
JobConfig railsConfig = stageConfig.getJobs().getJob(new CaseInsensitiveString("rails"));
railsConfig.setRunInstanceCount(3);
DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext("loser", new Agents());
RunMultipleInstance.CounterBasedJobNameGenerator jobNameGenerator = new RunMultipleInstance.CounterBasedJobNameGenerator(CaseInsensitiveString.str(railsConfig.name()));
JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("dev"), railsConfig, schedulingContext, new TimeProvider(), jobNameGenerator);
assertThat(jobs.get(0).getName(), is("rails-runInstance-1"));
assertEnvironmentVariable(jobs.get(0), 0, "GO_JOB_RUN_INDEX", "1");
assertEnvironmentVariable(jobs.get(0), 1, "GO_JOB_RUN_COUNT", "3");
assertThat(jobs.get(1).getName(), is("rails-runInstance-2"));
assertEnvironmentVariable(jobs.get(1), 0, "GO_JOB_RUN_INDEX", "2");
assertEnvironmentVariable(jobs.get(1), 1, "GO_JOB_RUN_COUNT", "3");
assertThat(jobs.get(2).getName(), is("rails-runInstance-3"));
assertEnvironmentVariable(jobs.get(2), 0, "GO_JOB_RUN_INDEX", "3");
assertEnvironmentVariable(jobs.get(2), 1, "GO_JOB_RUN_COUNT", "3");
Stage stage = createStageInstance(old, jobs);
Stage stageForRerun = instanceFactory.createStageForRerunOfJobs(stage, a("rails-runInstance-1", "rails-runInstance-2"), schedulingContext, stageConfig, clock, "md5");
JobInstances jobsForRerun = stageForRerun.getJobInstances();
assertThat(jobsForRerun.get(0).getName(), is("rails-runInstance-3"));
assertEnvironmentVariable(jobsForRerun.get(0), 0, "GO_JOB_RUN_INDEX", "3");
assertEnvironmentVariable(jobsForRerun.get(0), 1, "GO_JOB_RUN_COUNT", "3");
assertThat(jobsForRerun.get(2).getName(), is("rails-runInstance-1"));
assertEnvironmentVariable(jobsForRerun.get(2), 0, "GO_JOB_RUN_INDEX", "1");
assertEnvironmentVariable(jobsForRerun.get(2), 1, "GO_JOB_RUN_COUNT", "3");
assertThat(jobsForRerun.get(3).getName(), is("rails-runInstance-2"));
assertEnvironmentVariable(jobsForRerun.get(3), 0, "GO_JOB_RUN_INDEX", "2");
assertEnvironmentVariable(jobsForRerun.get(3), 1, "GO_JOB_RUN_COUNT", "3");
assertThat(jobsForRerun.size(), is(4));
assertRunMultipleJobInstance(jobsForRerun.get(0), "rails-runInstance-3");
assertThat(jobsForRerun.get(1).getName(), is("java"));
assertReRunMultipleJobInstance(jobsForRerun.get(2), "rails-runInstance-1");
assertReRunMultipleJobInstance(jobsForRerun.get(3), "rails-runInstance-2");
}
Aggregations