Search in sources :

Example 61 with ServerHealthStateOperationResult

use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.

the class BuildCauseProducerServiceIntegrationSvnTest method shouldCreateBuildCauseWithModifications.

@Test
public void shouldCreateBuildCauseWithModifications() throws Exception {
    repositoryForMaterial(new SvnTestRepo(tempDir));
    prepareAPipelineWithHistory();
    checkInFiles("foo");
    ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
    materialDatabaseUpdater.updateMaterial(svnMaterial);
    buildCauseProducerService.autoSchedulePipeline(CaseInsensitiveString.str(mingleConfig.name()), result, 123);
    assertThat(result.canContinue(), is(true));
    BuildCause mingleBuildCause = pipelineScheduleQueue.toBeScheduled().get(mingleConfig.name());
    MaterialRevisions materialRevisions = mingleBuildCause.getMaterialRevisions();
    assertThat(materialRevisions.getRevisions().size(), is(1));
    Materials materials = materialRevisions.getMaterials();
    assertThat(materials.size(), is(1));
    assertThat(materials.get(0), is(svnMaterial));
}
Also used : MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) SvnTestRepo(com.thoughtworks.go.helper.SvnTestRepo) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.jupiter.api.Test)

Example 62 with ServerHealthStateOperationResult

use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.

the class BuildCauseProducerServiceIntegrationSvnTest method shouldCreateBuildCauseWithModificationsForSvnRepoWithExternal.

@Test
public void shouldCreateBuildCauseWithModificationsForSvnRepoWithExternal() throws Exception {
    SvnTestRepoWithExternal repo = new SvnTestRepoWithExternal(tempDir);
    repositoryForMaterial(repo);
    prepareAPipelineWithHistory();
    checkInFiles("foo");
    ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
    materialDatabaseUpdater.updateMaterial(svnMaterial);
    buildCauseProducerService.autoSchedulePipeline(CaseInsensitiveString.str(mingleConfig.name()), result, 123);
    assertThat(result.canContinue(), is(true));
    BuildCause mingleBuildCause = pipelineScheduleQueue.toBeScheduled().get(mingleConfig.name());
    MaterialRevisions materialRevisions = mingleBuildCause.getMaterialRevisions();
    assertThat(materialRevisions.getRevisions().size(), is(2));
    Materials materials = materialRevisions.getMaterials();
    assertThat(materials.size(), is(2));
    assertThat(materials.get(0), is(svnMaterial));
    SvnMaterial external = (SvnMaterial) materials.get(1);
    assertThat(external.getUrl(), is(repo.externalRepositoryUrl()));
}
Also used : MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) SvnTestRepoWithExternal(com.thoughtworks.go.helper.SvnTestRepoWithExternal) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.jupiter.api.Test)

Example 63 with ServerHealthStateOperationResult

use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.

the class BuildCauseProducerServiceIntegrationTimerTest method pipelineWithTimerShouldRerunWhenItHasAlreadyRunWithLatestMaterials_GivenTimerIsNOTSetToTriggerOnlyForNewMaterials.

@Test
public void pipelineWithTimerShouldRerunWhenItHasAlreadyRunWithLatestMaterials_GivenTimerIsNOTSetToTriggerOnlyForNewMaterials() throws Exception {
    int i = 1;
    String pipelineName = "p1";
    GitMaterial git1 = u.wf(new GitMaterial("git1"), "folder");
    ScheduleTestUtil.AddedPipeline up1 = u.saveConfigWith("up1", u.m(git1));
    ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWithTimer(pipelineName, u.timer("* * * * * ? 2000", false), u.m(git1), u.m(up1));
    u.checkinFile(git1, "g11", newFile(tempDir.resolve("blah_g11")), ModifiedAction.added);
    String up1_1 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(up1, u.d(i++), "g11");
    pipelineTimeline.update();
    // Run once with latest, when pipeline schedules due to timer.
    buildCauseProducerService.timerSchedulePipeline(p1.config, new ServerHealthStateOperationResult());
    assertThat(piplineScheduleQueue.toBeScheduled().size(), is(1));
    assertThat(piplineScheduleQueue.toBeScheduled().get(new CaseInsensitiveString(pipelineName)).getMaterialRevisions(), isSameMaterialRevisionsAs(u.mrs(u.mr(git1, true, "g11"), u.mr(up1, true, up1_1))));
    BuildCause buildCause = piplineScheduleQueue.toBeScheduled().get(new CaseInsensitiveString(pipelineName));
    String up1_2 = u.runAndPassWithGivenMDUTimestampAndRevisionStrings(up1, u.d(i++), "g11");
    piplineScheduleQueue.finishSchedule(new CaseInsensitiveString(pipelineName), buildCause, buildCause);
    try (LogFixture logFixture = logFixtureFor(TimedBuild.class, Level.INFO)) {
        // Timer time comes around again. Will rerun since the new flag (runOnlyOnNewMaterials) is not ON.
        buildCauseProducerService.timerSchedulePipeline(p1.config, new ServerHealthStateOperationResult());
        assertThat(piplineScheduleQueue.toBeScheduled().size(), is(1));
        assertThat(piplineScheduleQueue.toBeScheduled().get(new CaseInsensitiveString(pipelineName)).getMaterialRevisions(), is(u.mrs(u.mr(git1, false, "g11"), u.mr(up1, false, up1_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) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.jupiter.api.Test)

Example 64 with ServerHealthStateOperationResult

use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldReloadPipelineConfigurationAndUpdateNewMaterialWhenManuallyTriggered.

@Test
public void shouldReloadPipelineConfigurationAndUpdateNewMaterialWhenManuallyTriggered(@TempDir Path tempDir) throws Exception {
    GitTestRepo otherGitRepo = new GitTestRepo(tempDir);
    pipelineConfig = PipelineConfigMother.createPipelineConfigWithStages("pipe1", "build", "test");
    pipelineConfig.materialConfigs().clear();
    materialConfig = hgRepo.createMaterialConfig("dest1");
    materialConfig.setAutoUpdate(true);
    pipelineConfig.materialConfigs().add(materialConfig);
    // new material is added
    GitMaterial gitMaterial = otherGitRepo.createMaterial("dest2");
    gitMaterial.setAutoUpdate(true);
    MaterialConfig otherMaterialConfig = gitMaterial.config();
    otherMaterialConfig.setAutoUpdate(true);
    pipelineConfig.materialConfigs().add(otherMaterialConfig);
    List<Modification> mod = configTestRepo.addPipelineToRepositoryAndPush(fileName, pipelineConfig);
    final HashMap<String, String> revisions = new HashMap<>();
    final HashMap<String, String> environmentVariables = new HashMap<>();
    buildCauseProducer.manualProduceBuildCauseAndSave(PIPELINE_NAME, Username.ANONYMOUS, new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), new ServerHealthStateOperationResult());
    cachedGoConfig.throwExceptionIfExists();
    Map<CaseInsensitiveString, BuildCause> afterLoad = scheduleHelper.waitForAnyScheduled(20);
    assertThat(afterLoad.keySet(), hasItem(new CaseInsensitiveString(PIPELINE_NAME)));
    BuildCause cause = afterLoad.get(new CaseInsensitiveString(PIPELINE_NAME));
    assertThat(cause.getBuildCauseMessage(), containsString("Forced by anonymous"));
    PipelineConfig pipelineConfigAfterSchedule = goConfigService.pipelineConfigNamed(pipelineConfig.name());
    RepoConfigOrigin configOriginAfterSchedule = (RepoConfigOrigin) pipelineConfigAfterSchedule.getOrigin();
    String lastPushedRevision = mod.get(0).getRevision();
    assertThat("revisionOfPipelineConfigOriginShouldMatchLastPushedCommit", configOriginAfterSchedule.getRevision(), is(lastPushedRevision));
    assertThat(pipelineConfig.materialConfigs(), hasItem(otherMaterialConfig));
    assertThat("buildCauseRevisionShouldMatchLastPushedCommit", cause.getMaterialRevisions().latestRevision(), is(lastPushedRevision));
    // update of commited material happened during manual trigger
    MaterialRevisions modificationsInDb = materialRepository.findLatestModification(gitMaterial);
    assertThat(modificationsInDb.latestRevision(), is(otherGitRepo.latestModification().get(0).getRevision()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) HashMap(java.util.HashMap) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.jupiter.api.Test)

Example 65 with ServerHealthStateOperationResult

use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult in project gocd by gocd.

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldSchedulePipeline.

@Test
public void shouldSchedulePipeline() throws Exception {
    configTestRepo.addCodeToRepositoryAndPush("a.java", "added code file", "some java code");
    materialUpdateService.updateMaterial(material);
    waitForMaterialNotInProgress();
    buildCauseProducerService.autoSchedulePipeline(PIPELINE_NAME, new ServerHealthStateOperationResult(), 123);
    assertThat(scheduleHelper.waitForAnyScheduled(5).keySet(), hasItem(new CaseInsensitiveString(PIPELINE_NAME)));
}
Also used : ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) Test(org.junit.jupiter.api.Test)

Aggregations

ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)89 Test (org.junit.jupiter.api.Test)78 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)28 ScheduleOptions (com.thoughtworks.go.server.scheduling.ScheduleOptions)17 HashMap (java.util.HashMap)17 Pipeline (com.thoughtworks.go.domain.Pipeline)16 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)15 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)12 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)12 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)11 Modification (com.thoughtworks.go.domain.materials.Modification)10 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)8 Username (com.thoughtworks.go.server.domain.Username)8 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)6 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)6 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)6 SendEmailMessage (com.thoughtworks.go.server.messaging.SendEmailMessage)6 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)5 Materials (com.thoughtworks.go.config.materials.Materials)5 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)5