Search in sources :

Example 21 with ServerHealthStateOperationResult

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

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldNotSchedulePipelineWhenConfigAndMaterialRevisionsMismatch.

@Test
public void shouldNotSchedulePipelineWhenConfigAndMaterialRevisionsMismatch() throws Exception {
    // we will use this worker to force material update without updating config
    MaterialUpdateListener byPassWorker = new MaterialUpdateListener(topic, materialDatabaseUpdater, logger, goDiskSpaceMonitor, maintenanceModeService);
    List<Modification> mod = configTestRepo.addCodeToRepositoryAndPush("a.java", "added code file", "some java code");
    byPassWorker.onMessage(new MaterialUpdateMessage(material, 123));
    // now db should have been updated, but config is still old
    RepoConfigOrigin configOrigin = (RepoConfigOrigin) goConfigService.pipelineConfigNamed(new CaseInsensitiveString(PIPELINE_NAME)).getOrigin();
    assertThat(configOrigin.getRevision(), is(firstRevisions.latestRevision()));
    buildCauseProducerService.autoSchedulePipeline(PIPELINE_NAME, new ServerHealthStateOperationResult(), 123);
    scheduleHelper.waitForNotScheduled(5, PIPELINE_NAME);
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) Test(org.junit.jupiter.api.Test)

Example 22 with ServerHealthStateOperationResult

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

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldSchedulePipelineWithSameMaterialIn2DestinationsWhenManuallyTriggered_WithSpecifiedRevisions.

@Test
public void shouldSchedulePipelineWithSameMaterialIn2DestinationsWhenManuallyTriggered_WithSpecifiedRevisions() throws Exception {
    pipelineConfig = PipelineConfigMother.createPipelineConfigWithStages("pipe1", "build", "test");
    pipelineConfig.materialConfigs().clear();
    materialConfig = hgRepo.createMaterialConfig("dest1");
    materialConfig.setAutoUpdate(true);
    // new material is added
    MaterialConfig otherMaterialConfig = hgRepo.createMaterialConfig("dest2");
    otherMaterialConfig.setAutoUpdate(true);
    pipelineConfig.materialConfigs().add(materialConfig);
    pipelineConfig.materialConfigs().add(otherMaterialConfig);
    List<Modification> firstBuildModifications = configTestRepo.addPipelineToRepositoryAndPush(fileName, pipelineConfig);
    materialUpdateService.updateMaterial(material);
    waitForMaterialNotInProgress();
    cachedGoConfig.throwExceptionIfExists();
    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(5);
    assertThat(afterLoad.keySet(), hasItem(new CaseInsensitiveString(PIPELINE_NAME)));
    BuildCause cause = afterLoad.get(new CaseInsensitiveString(PIPELINE_NAME));
    assertThat(cause.getBuildCauseMessage(), containsString("Forced by anonymous"));
    List<Modification> secondBuildModifications = configTestRepo.addCodeToRepositoryAndPush("a.java", "added code file", "some java code");
    materialUpdateService.updateMaterial(material);
    waitForMaterialNotInProgress();
    pipelineScheduleQueue.clear();
    // revision in dest 1 will be older by 1 commit - this is kind of scm-config-consistency violation
    String explicitRevision = firstBuildModifications.get(0).getRevision();
    revisions.put(materialConfig.getPipelineUniqueFingerprint(), explicitRevision);
    buildCauseProducer.manualProduceBuildCauseAndSave(PIPELINE_NAME, new Username(new CaseInsensitiveString("Admin")), new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), new ServerHealthStateOperationResult());
    cachedGoConfig.throwExceptionIfExists();
    afterLoad = scheduleHelper.waitForAnyScheduled(5);
    assertThat(afterLoad.keySet(), hasItem(new CaseInsensitiveString(PIPELINE_NAME)));
    cause = afterLoad.get(new CaseInsensitiveString(PIPELINE_NAME));
    assertThat(cause.getBuildCauseMessage(), containsString("Forced by Admin"));
    PipelineConfig pipelineConfigAfterSchedule = goConfigService.pipelineConfigNamed(pipelineConfig.name());
    RepoConfigOrigin configOriginAfterSchedule = (RepoConfigOrigin) pipelineConfigAfterSchedule.getOrigin();
    String lastPushedRevision = secondBuildModifications.get(0).getRevision();
    assertThat("revisionOfPipelineConfigOriginShouldMatchLastPushedCommit", configOriginAfterSchedule.getRevision(), is(lastPushedRevision));
    assertThat(pipelineConfigAfterSchedule.materialConfigs(), hasItem(otherMaterialConfig));
    assertThat("buildCauseRevisionShouldMatchSpecifiedRevision", cause.getMaterialRevisions().latestRevision(), is(explicitRevision));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) HashMap(java.util.HashMap) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) Username(com.thoughtworks.go.server.domain.Username) 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 23 with ServerHealthStateOperationResult

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

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldSchedulePipelineWhenConfigAndMaterialRevisionsMismatch_AndManuallyTriggered.

@Test
public // We already let all manual triggers to bypass revision match check
void shouldSchedulePipelineWhenConfigAndMaterialRevisionsMismatch_AndManuallyTriggered() throws Exception {
    // we will use this worker to force material update without updating config
    MaterialUpdateListener byPassWorker = new MaterialUpdateListener(topic, materialDatabaseUpdater, logger, goDiskSpaceMonitor, maintenanceModeService);
    List<Modification> lastPush = configTestRepo.addCodeToRepositoryAndPush("a.java", "added code file", "some java code");
    byPassWorker.onMessage(new MaterialUpdateMessage(material, 123));
    // now db should have been updated, but config is still old
    RepoConfigOrigin configOrigin = (RepoConfigOrigin) goConfigService.pipelineConfigNamed(new CaseInsensitiveString(PIPELINE_NAME)).getOrigin();
    assertThat(configOrigin.getRevision(), is(firstRevisions.latestRevision()));
    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());
    Map<CaseInsensitiveString, BuildCause> afterLoad = scheduleHelper.waitForAnyScheduled(5);
    assertThat(afterLoad.keySet(), hasItem(new CaseInsensitiveString(PIPELINE_NAME)));
    BuildCause cause = afterLoad.get(new CaseInsensitiveString(PIPELINE_NAME));
    assertThat(cause.getBuildCauseMessage(), containsString("Forced by anonymous"));
    assertThat("buildCauseRevisionShouldMatchLastPushedCommit", cause.getMaterialRevisions().latestRevision(), is(lastPush.get(0).getRevision()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) HashMap(java.util.HashMap) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.jupiter.api.Test)

Example 24 with ServerHealthStateOperationResult

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

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldSchedulePipelineRerunWithSpecifiedRevisions.

@Test
public void shouldSchedulePipelineRerunWithSpecifiedRevisions() throws Exception {
    List<Modification> firstBuildModifications = configTestRepo.addCodeToRepositoryAndPush("a.java", "added first code file", "some java code");
    materialUpdateService.updateMaterial(material);
    waitForMaterialNotInProgress();
    cachedGoConfig.throwExceptionIfExists();
    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(5);
    assertThat(afterLoad.keySet(), hasItem(new CaseInsensitiveString(PIPELINE_NAME)));
    BuildCause cause = afterLoad.get(new CaseInsensitiveString(PIPELINE_NAME));
    assertThat(cause.getBuildCauseMessage(), containsString("Forced by anonymous"));
    List<Modification> secondBuildModifications = configTestRepo.addCodeToRepositoryAndPush("a.java", "added second code file", "some java code");
    materialUpdateService.updateMaterial(material);
    waitForMaterialNotInProgress();
    pipelineScheduleQueue.clear();
    // revision will be older by 1 commit -
    // formally this is scm-config-consistency violation but we let this schedule because of manual trigger
    String explicitRevision = firstBuildModifications.get(0).getRevision();
    revisions.put(materialConfig.getPipelineUniqueFingerprint(), explicitRevision);
    buildCauseProducer.manualProduceBuildCauseAndSave(PIPELINE_NAME, new Username(new CaseInsensitiveString("Admin")), new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), new ServerHealthStateOperationResult());
    cachedGoConfig.throwExceptionIfExists();
    afterLoad = scheduleHelper.waitForAnyScheduled(5);
    assertThat(afterLoad.keySet(), hasItem(new CaseInsensitiveString(PIPELINE_NAME)));
    cause = afterLoad.get(new CaseInsensitiveString(PIPELINE_NAME));
    assertThat(cause.getBuildCauseMessage(), containsString("Forced by Admin"));
    PipelineConfig pipelineConfigAfterSchedule = goConfigService.pipelineConfigNamed(pipelineConfig.name());
    RepoConfigOrigin configOriginAfterSchedule = (RepoConfigOrigin) pipelineConfigAfterSchedule.getOrigin();
    String lastPushedRevision = secondBuildModifications.get(0).getRevision();
    assertThat("revisionOfPipelineConfigOriginShouldMatchLastPushedCommit", configOriginAfterSchedule.getRevision(), is(lastPushedRevision));
    assertThat("buildCauseRevisionShouldMatchSpecifiedRevision", cause.getMaterialRevisions().latestRevision(), is(explicitRevision));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) HashMap(java.util.HashMap) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) Username(com.thoughtworks.go.server.domain.Username) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.jupiter.api.Test)

Example 25 with ServerHealthStateOperationResult

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

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldReloadPipelineConfigurationWhenManuallyTriggered.

@Test
public void shouldReloadPipelineConfigurationWhenManuallyTriggered() throws Exception {
    // we change configuration of the pipeline by pushing new stage to config repo
    pipelineConfig = PipelineConfigMother.createPipelineConfigWithStages("pipe1", "build", "test", "newStage");
    pipelineConfig.materialConfigs().clear();
    pipelineConfig.materialConfigs().add(materialConfig);
    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());
    Map<CaseInsensitiveString, BuildCause> afterLoad = scheduleHelper.waitForAnyScheduled(5);
    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("buildCauseRevisionShouldMatchLastPushedCommit", cause.getMaterialRevisions().latestRevision(), is(lastPushedRevision));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) HashMap(java.util.HashMap) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) 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