@Test public void shouldCancelAScheduledJobInCaseThePipelineIsRemovedFromTheConfig_SpecificallyAPipelineRenameToADifferentCaseAndStageNameToADifferentName() throws Exception { Material hgMaterial = new HgMaterial("url", "folder"); String[] hgRevs = new String[] {"h1"}; u.checkinInOrder(hgMaterial, hgRevs); ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("PIPELINE_WHICH_WILL_EVENTUALLY_CHANGE_CASE", u.m(hgMaterial)); u.scheduleWith(p1, hgRevs); ScheduleTestUtil.AddedPipeline renamedPipeline = u.renamePipelineAndFirstStage( p1, "pipeline_which_will_eventually_change_case", "NEW_RANDOM_STAGE_NAME" + UUID.randomUUID()); Pipeline p1_2 = u.scheduleWith(renamedPipeline, hgRevs); CruiseConfig cruiseConfig = configHelper.load(); buildAssignmentService.onTimer(); // To Reload Job Plans buildAssignmentService.onConfigChange(cruiseConfig); Stages allStages = stageDao.findAllStagesFor(p1_2.getName(), p1_2.getCounter()); assertThat( allStages.byName(CaseInsensitiveString.str(p1.config.first().name())).getState(), is(StageState.Cancelled)); }
@Test public void shouldRemoveAllJobPlansThatAreNotInConfig() { CruiseConfig oldConfig = goConfigService.getCurrentConfig(); ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("p1", "s1", u.m(new HgMaterial("hg", null))); Pipeline p1_1 = instanceFactory.createPipelineInstance( p1.config, modifyNoFiles(p1.config), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider()); ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWith("p2", "s1", u.m(new HgMaterial("hg", null))); Pipeline p2_1 = instanceFactory.createPipelineInstance( p2.config, modifyNoFiles(p2.config), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider()); dbHelper.savePipelineWithStagesAndMaterials(p1_1); dbHelper.savePipelineWithStagesAndMaterials(p2_1); CruiseConfig cruiseConfig = goConfigService.getCurrentConfig(); buildAssignmentService.onConfigChange(cruiseConfig); buildAssignmentService.onTimer(); List<JobPlan> plans = (List<JobPlan>) ReflectionUtil.getField(buildAssignmentService, "jobPlans"); assertThat(plans.isEmpty(), is(false)); assertThat(plans.size(), is(2)); configHelper.writeConfigFile(oldConfig); plans = (List<JobPlan>) ReflectionUtil.getField(buildAssignmentService, "jobPlans"); assertThat("Actual size is " + plans.size(), plans.isEmpty(), is(true)); }
@Test public void shouldNotAutoSchedulePausedPipeline() throws Exception { ScheduleTestUtil u = new ScheduleTestUtil(transactionTemplate, materialRepository, dbHelper, configHelper); HgMaterial hg = new HgMaterial("url", null); String[] hg_revs = {"h1", "h2"}; u.checkinInOrder(hg, hg_revs); ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("p1", u.m(hg)); ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWith("p2", u.m(hg)); pipelinePauseService.pause(p1.config.name().toString(), "pausing p1", Username.ANONYMOUS); ServerHealthStateOperationResult p1Result = new ServerHealthStateOperationResult(); service.autoSchedulePipeline(p1.config.name().toString(), p1Result, 1234); assertThat(p1Result.canContinue(), is(false)); ServerHealthStateOperationResult p2Result = new ServerHealthStateOperationResult(); service.autoSchedulePipeline(p2.config.name().toString(), p2Result, 1234); assertThat(p2Result.canContinue(), is(true)); }