Пример #1
0
  @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)))));
  }