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 RescheduleJobTest method shouldRescheduleBuildAlongWithAssociatedEntitiesCorrectly.
@Test
public void shouldRescheduleBuildAlongWithAssociatedEntitiesCorrectly() {
dbHelper.cancelStage(stage);
ResourceConfigs resourceConfigs = new ResourceConfigs(new ResourceConfig("r1"), new ResourceConfig("r2"));
ArtifactConfigs artifactConfigs = new ArtifactConfigs(Arrays.asList(new ArtifactConfig("s1", "d1"), new ArtifactConfig("s2", "d2")));
ArtifactPropertiesConfig artifactPropertiesConfig = new ArtifactPropertiesConfig(new ArtifactPropertyConfig("n1", "s1", "x1"), new ArtifactPropertyConfig("n2", "s2", "x2"));
configHelper.addAssociatedEntitiesForAJob(PIPELINE_NAME, STAGE_NAME, JOB_NAME, resourceConfigs, artifactConfigs, artifactPropertiesConfig);
dbHelper.schedulePipeline(configHelper.currentConfig().getPipelineConfigByName(new CaseInsensitiveString(PIPELINE_NAME)), new TimeProvider());
JobPlan oldJobPlan = dbHelper.getBuildInstanceDao().orderedScheduledBuilds().get(0);
assertThat(oldJobPlan.getResources().size(), is(2));
assertThat(oldJobPlan.getArtifactPlans().size(), is(2));
assertThat(oldJobPlan.getPropertyGenerators().size(), is(2));
JobInstance oldJobInstance = dbHelper.getBuildInstanceDao().buildById(oldJobPlan.getJobId());
scheduleService.rescheduleJob(oldJobInstance);
JobInstance reloadedOldJobInstance = dbHelper.getBuildInstanceDao().buildById(oldJobInstance.getId());
assertThat(reloadedOldJobInstance.isIgnored(), is(true));
assertThat(reloadedOldJobInstance.getState(), is(JobState.Rescheduled));
JobPlan newJobPlan = dbHelper.getBuildInstanceDao().orderedScheduledBuilds().get(1);
assertThat(newJobPlan.getJobId(), is(not(oldJobInstance.getId())));
assertThat(newJobPlan.getResources().size(), is(2));
for (int i = 0; i < newJobPlan.getResources().size(); i++) {
Resource newResource = newJobPlan.getResources().get(i);
Resource oldResource = oldJobPlan.getResources().get(i);
assertThat(newResource.getId(), is(not(oldResource.getId())));
assertThat(newResource.getName(), is(oldResource.getName()));
assertThat(ReflectionUtil.getField(newResource, "buildId"), is(newJobPlan.getJobId()));
}
assertThat(newJobPlan.getArtifactPlans().size(), is(2));
for (int i = 0; i < newJobPlan.getArtifactPlans().size(); i++) {
ArtifactPlan newArtifactPlan = newJobPlan.getArtifactPlans().get(i);
ArtifactPlan oldArtifactPlan = oldJobPlan.getArtifactPlans().get(i);
assertThat(newArtifactPlan.getId(), is(not(oldArtifactPlan.getId())));
assertThat(newArtifactPlan.getArtifactType(), is(oldArtifactPlan.getArtifactType()));
assertThat(newArtifactPlan.getSrc(), is(oldArtifactPlan.getSrc()));
assertThat(newArtifactPlan.getDest(), is(oldArtifactPlan.getDest()));
assertThat(newArtifactPlan.getArtifactType(), is(oldArtifactPlan.getArtifactType()));
assertThat(ReflectionUtil.getField(newArtifactPlan, "buildId"), is(newJobPlan.getJobId()));
}
assertThat(newJobPlan.getPropertyGenerators().size(), is(2));
for (int i = 0; i < newJobPlan.getPropertyGenerators().size(); i++) {
ArtifactPropertiesGenerator newArtifactPropertiesGenerator = newJobPlan.getPropertyGenerators().get(i);
ArtifactPropertiesGenerator oldArtifactPropertiesGenerator = oldJobPlan.getPropertyGenerators().get(i);
assertThat(newArtifactPropertiesGenerator.getId(), is(not(oldArtifactPropertiesGenerator.getId())));
assertThat(newArtifactPropertiesGenerator.getName(), is(oldArtifactPropertiesGenerator.getName()));
assertThat(newArtifactPropertiesGenerator.getSrc(), is(oldArtifactPropertiesGenerator.getSrc()));
assertThat(newArtifactPropertiesGenerator.getXpath(), is(oldArtifactPropertiesGenerator.getXpath()));
assertThat(ReflectionUtil.getField(newArtifactPropertiesGenerator, "jobId"), is(newJobPlan.getJobId()));
}
JobInstance newJobInstance = dbHelper.getBuildInstanceDao().buildById(newJobPlan.getJobId());
assertThat(newJobInstance.getState(), is(JobState.Scheduled));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class JobInstanceServiceIntegrationTest method shouldFindAllCopiesOfJobsRunOnAllAgents.
@Test
public void shouldFindAllCopiesOfJobsRunOnAllAgents() throws Exception {
StageConfig stageConfig = StageConfigMother.custom("dev", "build");
JobConfig jobConfig = stageConfig.jobConfigByInstanceName("build", true);
jobConfig.setRunOnAllAgents(true);
String uuid1 = UUID.randomUUID().toString();
String uuid2 = UUID.randomUUID().toString();
DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext("anyone", new Agents(new AgentConfig(uuid1), new AgentConfig(uuid2)));
Stage stage = instanceFactory.createStageInstance(stageConfig, schedulingContext, "md5-test", new TimeProvider());
for (JobInstance instance : stage.getJobInstances()) {
instance.setIdentifier(new JobIdentifier("cruise", "1", "dev", "1", instance.getName()));
}
jobStatusCache.jobStatusChanged(stage.getJobInstances().first());
jobStatusCache.jobStatusChanged(stage.getJobInstances().last());
JobInstances jobs = jobInstanceService.currentJobsOfStage("cruise", stageConfig);
assertThat(jobs.toArray(), hasItemInArray(hasProperty("name", is(RunOnAllAgents.CounterBasedJobNameGenerator.appendMarker("build", 1)))));
assertThat(jobs.toArray(), hasItemInArray(hasProperty("name", is(RunOnAllAgents.CounterBasedJobNameGenerator.appendMarker("build", 2)))));
assertThat(jobs.size(), is(2));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class JobInstanceServiceIntegrationTest method shouldThrowExceptionIfThereAreNoJobsToBeScheduled.
@Test
public void shouldThrowExceptionIfThereAreNoJobsToBeScheduled() throws Exception {
StageConfig stageConfig = StageConfigMother.custom("dev", "build");
JobConfig jobConfig = stageConfig.jobConfigByInstanceName("build", true);
jobConfig.setRunOnAllAgents(true);
jobConfig.addResourceConfig("non-existent");
String uuid1 = UUID.randomUUID().toString();
String uuid2 = UUID.randomUUID().toString();
DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext("anyone", new Agents(new AgentConfig(uuid1), new AgentConfig(uuid2)));
try {
instanceFactory.createStageInstance(stageConfig, schedulingContext, "md5-test", new TimeProvider());
fail("Expected a CannotScheduleException to be thrown");
} catch (CannotScheduleException e) {
// expected
}
}
Aggregations