@Test public void shouldScheduleJobForAllAgentsWhenToBeRunOnAllAgents() throws Exception { configHelper.addAgent("localhost", "uuid1"); configHelper.addAgent("localhost", "uuid2"); configHelper.addAgent("localhost", "uuid3"); configHelper.addAgentToEnvironment("dev", "uuid1"); configHelper.setRunOnAllAgents( CaseInsensitiveString.str(evolveConfig.name()), STAGE_NAME, "unit", true); 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.toArray(), hasItemInArray( hasProperty( "name", is(RunOnAllAgents.CounterBasedJobNameGenerator.appendMarker("unit", 1))))); assertThat(scheduledJobs.toArray(), hasItemInArray(hasProperty("agentUuid", is("uuid2")))); assertThat( scheduledJobs.toArray(), hasItemInArray( hasProperty( "name", is(RunOnAllAgents.CounterBasedJobNameGenerator.appendMarker("unit", 2))))); assertThat(scheduledJobs.toArray(), hasItemInArray(hasProperty("agentUuid", is("uuid3")))); assertThat(scheduledJobs.size(), is(2)); }
@Test public void shouldLockPipelineWhenSchedulingStage() throws Exception { scheduleAndCompleteInitialPipelines(); Pipeline pipeline = pipelineDao.mostRecentPipeline("mingle"); configHelper.lockPipeline("mingle"); assertThat(pipelineLockService.isLocked("mingle"), is(false)); scheduleService.scheduleStage( pipeline, STAGE_NAME, "anonymous", new ScheduleService.NewStageInstanceCreator(goConfigService), new ScheduleService.ExceptioningErrorHandler()); assertThat(pipelineLockService.isLocked("mingle"), is(true)); }
@Test public void shouldPassEnvironmentLevelEnvironmentVariablesToJobsForNewlyScheduledStage() throws Exception { scheduleAndCompleteInitialPipelines(); Pipeline pipeline = pipelineDao.mostRecentPipeline("go"); Stage stage = scheduleService.scheduleStage( pipeline, "ft", "anonymous", new ScheduleService.NewStageInstanceCreator(goConfigService), new ScheduleService.ExceptioningErrorHandler()); EnvironmentVariablesConfig jobVariables = stage.getJobInstances().first().getPlan().getVariables(); assertThat( jobVariables.size(), is(3)); // pipeline, stage, job, env is applied while creating work assertThat( jobVariables, hasItem(new EnvironmentVariableConfig("PIPELINE_LVL", "pipeline value"))); assertThat(jobVariables, hasItem(new EnvironmentVariableConfig("STAGE_LVL", "stage value"))); assertThat(jobVariables, hasItem(new EnvironmentVariableConfig("JOB_LVL", "job value"))); }
@Test public void shouldUpdateServerHealthWhenScheduleStageFails() throws Exception { try { scheduleService.scheduleStage( manualSchedule("blahPipeline"), "blahStage", "blahUser", new ScheduleService.NewStageInstanceCreator(goConfigService), new ScheduleService.ExceptioningErrorHandler()); fail("should throw CannotScheduleException"); } catch (CannotScheduleException e) { } List<ServerHealthState> stateList = serverHealthService.filterByScope(HealthStateScope.forStage("blahPipeline", "blahStage")); assertThat(stateList.size(), is(1)); assertThat( stateList.get(0).getMessage(), is("Failed to trigger stage [blahStage] pipeline [blahPipeline]")); assertThat( stateList.get(0).getDescription(), is("Could not find matching agents to run job [job2] of stage [blahStage].")); }