Search in sources :

Example 11 with ServerHealthStateOperationResult

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

the class BuildCauseProducerServiceIntegrationTimerTest method pipelineWithTimerShouldRunWithLatestMaterialsWhenItHasBeenForceRunWithOlderMaterials_GivenTimerIsSetToTriggerOnlyForNewMaterials.

@Test
public void pipelineWithTimerShouldRunWithLatestMaterialsWhenItHasBeenForceRunWithOlderMaterials_GivenTimerIsSetToTriggerOnlyForNewMaterials() throws Exception {
    int i = 1;
    String pipelineName = "p1";
    GitMaterial git1 = u.wf(new GitMaterial("git1"), "folder");
    ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWithTimer(pipelineName, u.timer("* * * * * ? 2000", true), u.m(git1));
    u.checkinFile(git1, "g11", newFile(tempDir.resolve("blah_g11")), ModifiedAction.added);
    u.checkinFile(git1, "g12", newFile(tempDir.resolve("blah_g12")), ModifiedAction.added);
    Date mduTimeForG11 = u.d(i++);
    u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, mduTimeForG11, "g11");
    u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, u.d(i++), "g12");
    u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p1, mduTimeForG11, "g11");
    pipelineTimeline.update();
    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, false, "g12"))));
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.jupiter.api.Test)

Example 12 with ServerHealthStateOperationResult

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

the class BuildCauseProducerServiceIntegrationTimerTest method pipelineWithTimerShouldNotRerunWhenItHasAlreadyRunWithLatestMaterials_GivenTimerIsSetToTriggerOnlyForNewMaterials.

@Test
public void pipelineWithTimerShouldNotRerunWhenItHasAlreadyRunWithLatestMaterials_GivenTimerIsSetToTriggerOnlyForNewMaterials() throws Exception {
    String pipelineName = "p1";
    GitMaterial git1 = u.wf(new GitMaterial("git1"), "folder1");
    GitMaterial git2 = u.wf(new GitMaterial("git2"), "folder2");
    ScheduleTestUtil.AddedPipeline p1 = u.saveConfigWithTimer(pipelineName, u.timer("* * * * * ? 2000", true), u.m(git1), u.m(git2));
    u.checkinFile(git1, "g11", newFile(tempDir.resolve("blah_g11")), ModifiedAction.added);
    u.checkinFile(git2, "g21", newFile(tempDir.resolve("blah_g21")), ModifiedAction.added);
    // 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(git2, true, "g21"))));
    BuildCause buildCause = piplineScheduleQueue.toBeScheduled().get(new CaseInsensitiveString(pipelineName));
    piplineScheduleQueue.finishSchedule(new CaseInsensitiveString(pipelineName), buildCause, buildCause);
    try (LogFixture logFixture = logFixtureFor(TimedBuild.class, Level.INFO)) {
        // Timer time comes around again. Will NOT rerun since the new flag (runOnlyOnNewMaterials) is ON.
        buildCauseProducerService.timerSchedulePipeline(p1.config, new ServerHealthStateOperationResult());
        assertThat(piplineScheduleQueue.toBeScheduled().size(), is(0));
        assertThat(logFixture.contains(Level.INFO, "Skipping scheduling of timer-triggered pipeline 'p1' as it has previously run with the latest material(s)."), is(true));
    }
}
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 13 with ServerHealthStateOperationResult

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

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldNotScheduleWhenPipelineRemovedFromConfigRepoWhenManuallyTriggered.

@Test
public void shouldNotScheduleWhenPipelineRemovedFromConfigRepoWhenManuallyTriggered() throws Exception {
    configTestRepo.addCodeToRepositoryAndPush(fileName, "removed pipeline from configuration", "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<cruise xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"cruise-config.xsd\" schemaVersion=\"38\">\n" + "</cruise>");
    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());
    waitForMaterialNotInProgress();
    // config is correct
    cachedGoConfig.throwExceptionIfExists();
    assertThat(pipelineScheduleQueue.toBeScheduled().keySet(), not(hasItem(new CaseInsensitiveString(PIPELINE_NAME))));
    assertThat(goConfigService.hasPipelineNamed(pipelineConfig.name()), is(false));
}
Also used : ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) HashMap(java.util.HashMap) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) Test(org.junit.jupiter.api.Test)

Example 14 with ServerHealthStateOperationResult

use of com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult 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", newFile(tempDir.resolve("blah_g11")), ModifiedAction.added);
    u.checkinFile(git2, "g21", newFile(tempDir.resolve("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(new CaseInsensitiveString(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(new CaseInsensitiveString(pipelineName));
    u.runAndPassWithGivenMDUTimestampAndRevisionStrings(p2, u.d(i++), "g11", "g21", p1_1);
    piplineScheduleQueue.finishSchedule(new CaseInsensitiveString(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", newFile(tempDir.resolve("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(new CaseInsensitiveString(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) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.jupiter.api.Test)

Example 15 with ServerHealthStateOperationResult

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

the class DiskSpaceFullCheckerTest method shouldSendEmailsAgainIfDiskSpaceIsFixedAndFallsBelowAgain.

@Test
public void shouldSendEmailsAgainIfDiskSpaceIsFixedAndFallsBelowAgain() {
    CruiseConfig cruiseConfig = simulateFullDisk();
    ArtifactsDiskSpaceFullChecker fullChecker = createChecker(cruiseConfig);
    ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
    fullChecker.check(result);
    assertThat(result.canContinue(), is(false));
    simulateEmptyDisk();
    result = new ServerHealthStateOperationResult();
    fullChecker.check(result);
    assertThat(result.canContinue(), is(true));
    simulateFullDisk();
    result = new ServerHealthStateOperationResult();
    fullChecker.check(result);
    assertThat(result.canContinue(), is(false));
    verify(sender, times(2)).sendEmail(any(SendEmailMessage.class));
}
Also used : SendEmailMessage(com.thoughtworks.go.server.messaging.SendEmailMessage) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) 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