Search in sources :

Example 51 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class BuildCauseProducerServiceIntegrationTimerTest method pipelineWithTimerShouldRunOnlyWithMaterialsWhichChanged_GivenTimerIsSetToTriggerOnlyForNewMaterials.

@Test
public void pipelineWithTimerShouldRunOnlyWithMaterialsWhichChanged_GivenTimerIsSetToTriggerOnlyForNewMaterials() throws Exception {
    int i = 1;
    String pipelineName = "p1";
    GitMaterial git1 = u.wf(new GitMaterial("git1"), "folder1");
    GitMaterial git2 = u.wf(new GitMaterial("git2"), "folder2");
    ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWith("up1", u.m(git1));
    ScheduleTestUtil.AddedPipeline p2 = u.saveConfigWithTimer(pipelineName, u.timer("* * * * * ? 2000", true), u.m(git1), u.m(git2), u.m(p1));
    u.checkinFile(git1, "g11", temporaryFolder.newFile("blah_g11"), ModifiedAction.added);
    u.checkinFile(git2, "g21", temporaryFolder.newFile("blah_g21"), ModifiedAction.added);
    Date mduTimeOfG11 = u.d(i++);
    String p1_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, mduTimeOfG11, "g11");
    pipelineTimeline.update();
    // Run once with latest, when pipeline schedules due to timer.
    buildCauseProducerService.timerSchedulePipeline(p2.config, new ServerHealthStateOperationResult());
    assertThat(piplineScheduleQueue.toBeScheduled().size(), is(1));
    assertThat(piplineScheduleQueue.toBeScheduled().get(pipelineName).getMaterialRevisions(), isSameMaterialRevisionsAs(u.mrs(u.mr(git1, true, "g11"), u.mr(git2, true, "g21"), u.mr(p1, true, p1_1))));
    BuildCause buildCause = piplineScheduleQueue.toBeScheduled().get(pipelineName);
    u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p2, u.d(i++), "g11", "g21", p1_1);
    piplineScheduleQueue.finishSchedule(pipelineName, buildCause, buildCause);
    // Check in to git2 and run pipeline P1 once before the timer time. Then, timer happens. Shows those two materials in "yellow" (changed), on the UI.
    u.checkinFile(git2, "g22", temporaryFolder.newFile("blah_g22"), ModifiedAction.added);
    String p1_2 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, mduTimeOfG11, "g11");
    pipelineTimeline.update();
    try (LogFixture logFixture = logFixtureFor(TimedBuild.class, Level.INFO)) {
        buildCauseProducerService.timerSchedulePipeline(p2.config, new ServerHealthStateOperationResult());
        assertThat(piplineScheduleQueue.toBeScheduled().size(), is(1));
        assertThat(piplineScheduleQueue.toBeScheduled().get(pipelineName).getMaterialRevisions(), isSameMaterialRevisionsAs(u.mrs(u.mr(git1, false, "g11"), u.mr(git2, true, "g22"), u.mr(p1, true, p1_2))));
        assertThat(logFixture.contains(Level.INFO, "Skipping scheduling of timer-triggered pipeline 'p1' as it has previously run with the latest material(s)."), is(false));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) Date(java.util.Date) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 52 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class BuildCauseProducerServiceWithFlipModificationTest method buildCauseForPipeline.

private BuildCause buildCauseForPipeline() {
    BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(PIPELINE_NAME);
    assertThat("Should be scheduled", buildCause, is(not(nullValue())));
    return buildCause;
}
Also used : BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 53 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class ScheduleServiceIntegrationTest method runAndPass.

private Pipeline runAndPass(PipelineConfig pipelineConfig, int counter) {
    BuildCause buildCause = ModificationsMother.modifySomeFiles(pipelineConfig);
    dbHelper.saveMaterials(buildCause.getMaterialRevisions());
    String pipelineName = pipelineConfig.name().toString();
    pipelineScheduleQueue.schedule(pipelineName, buildCause);
    scheduleService.autoSchedulePipelinesFromRequestBuffer();
    Pipeline pipeline = pipelineDao.findPipelineByNameAndCounter(pipelineName, counter);
    pipeline = pipelineDao.loadAssociations(pipeline, pipelineName);
    return pipeline;
}
Also used : BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 54 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class PipelineScheduleQueueIntegrationTest method shouldCreateJobsMatchingRealAgentsIfRunOnAllAgentsIsSet.

@Test
public void shouldCreateJobsMatchingRealAgentsIfRunOnAllAgentsIsSet() {
    JobConfigs jobConfigs = new JobConfigs();
    ArtifactConfigs artifactConfigs = new ArtifactConfigs();
    ArtifactPropertiesConfig generators = new ArtifactPropertiesConfig();
    generators.add(new ArtifactPropertyConfig("property-name", "artifact-path", "artifact-xpath"));
    JobConfig jobConfig = new JobConfig(new CaseInsensitiveString("test-job"), new ResourceConfigs(), artifactConfigs, generators);
    jobConfig.setRunOnAllAgents(true);
    jobConfigs.add(jobConfig);
    StageConfig stage = new StageConfig(new CaseInsensitiveString("test-stage"), jobConfigs);
    MaterialConfigs materialConfigs = new MaterialConfigs(MaterialConfigsMother.dependencyMaterialConfig());
    PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("test-pipeline"), materialConfigs, stage);
    BuildCause cause = modifySomeFiles(pipelineConfig, ModificationsMother.nextRevision());
    saveRev(cause);
    configFileEditor.addAgent("localhost", "uuid1");
    configFileEditor.addAgent("localhost", "uuid2");
    configFileEditor.addAgent("localhost", "uuid3");
    configFileEditor.addAgentToEnvironment("env", "uuid1");
    configFileEditor.addPipeline(CaseInsensitiveString.str(pipelineConfig.name()), CaseInsensitiveString.str(stage.name()));
    queue.createPipeline(cause, pipelineConfig, new DefaultSchedulingContext(cause.getApprover(), configFileEditor.currentConfig().agents()), "md5-test", new TimeProvider());
    List<JobPlan> plans = jobService.orderedScheduledBuilds();
    assertThat(plans.toArray(), hasItemInArray(hasProperty("name", is(RunOnAllAgents.CounterBasedJobNameGenerator.appendMarker("test-job", 1)))));
    assertThat(plans.toArray(), hasItemInArray(hasProperty("name", is(RunOnAllAgents.CounterBasedJobNameGenerator.appendMarker("test-job", 2)))));
    assertThat(plans.toArray(), hasItemInArray(hasProperty("name", is(RunOnAllAgents.CounterBasedJobNameGenerator.appendMarker("test-job", 3)))));
    assertThat(plans.size(), is(3));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) TimeProvider(com.thoughtworks.go.util.TimeProvider) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 55 with BuildCause

use of com.thoughtworks.go.domain.buildcause.BuildCause in project gocd by gocd.

the class PipelineScheduleQueueIntegrationTest method shouldClearMostRecentScheduledIfPipelineIsDeleted.

@Test
public void shouldClearMostRecentScheduledIfPipelineIsDeleted() {
    BuildCause buildCause = BuildCause.createWithEmptyModifications();
    queue.schedule("cruise", buildCause);
    queue.finishSchedule("cruise", buildCause, newCause);
    queue.clearPipeline("cruise");
    assertThat(queue.mostRecentScheduled("cruise").hasNeverRun(), is(true));
}
Also used : BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Aggregations

BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)158 Test (org.junit.Test)115 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)33 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)32 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)31 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)31 TimeProvider (com.thoughtworks.go.util.TimeProvider)28 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)21 Modification (com.thoughtworks.go.domain.materials.Modification)21 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)16 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)16 ValueStreamMapPresentationModel (com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel)16 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)14 Date (java.util.Date)14 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)13 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)12 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)11 Username (com.thoughtworks.go.server.domain.Username)10 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)10 Builder (com.thoughtworks.go.domain.builder.Builder)9