Search in sources :

Example 6 with TimeProvider

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();
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) TimeProvider(com.thoughtworks.go.util.TimeProvider) TestingMaterial(com.thoughtworks.go.domain.materials.TestingMaterial) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 7 with TimeProvider

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)))));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) TimeProvider(com.thoughtworks.go.util.TimeProvider) TestingMaterial(com.thoughtworks.go.domain.materials.TestingMaterial) Material(com.thoughtworks.go.domain.materials.Material) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) TestingMaterial(com.thoughtworks.go.domain.materials.TestingMaterial) Test(org.junit.Test)

Example 8 with TimeProvider

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);
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) JobInstance(com.thoughtworks.go.domain.JobInstance)

Example 9 with TimeProvider

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);
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 10 with TimeProvider

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");
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

TimeProvider (com.thoughtworks.go.util.TimeProvider)137 Test (org.junit.Test)91 Date (java.util.Date)23 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)22 DateTime (org.joda.time.DateTime)17 GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)13 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)11 DefaultSchedulingContext (com.thoughtworks.go.domain.DefaultSchedulingContext)11 Before (org.junit.Before)11 Username (com.thoughtworks.go.server.domain.Username)10 Pipeline (com.thoughtworks.go.domain.Pipeline)9 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)9 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)8 Stage (com.thoughtworks.go.domain.Stage)7 TransactionStatus (org.springframework.transaction.TransactionStatus)7 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)6 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)6 Material (com.thoughtworks.go.domain.materials.Material)5 TestingMaterial (com.thoughtworks.go.domain.materials.TestingMaterial)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5