Search in sources :

Example 1 with StageIdentity

use of com.thoughtworks.go.server.domain.StageIdentity in project gocd by gocd.

the class CcTrayStageStatusLoaderTest method setupStagesInDB.

private List<Stage> setupStagesInDB(StageIdentity... stageIdentities) {
    when(stageDao.findLatestStageInstances()).thenReturn(asList(stageIdentities));
    List<Stage> stages = new ArrayList<>();
    for (StageIdentity identity : stageIdentities) {
        Stage stage = StageMother.custom(identity.getPipelineName() + " - " + identity.getStageName());
        lenient().when(stageDao.stageById(identity.getStageId())).thenReturn(stage);
        stages.add(stage);
    }
    return stages;
}
Also used : ArrayList(java.util.ArrayList) Stage(com.thoughtworks.go.domain.Stage) StageIdentity(com.thoughtworks.go.server.domain.StageIdentity)

Example 2 with StageIdentity

use of com.thoughtworks.go.server.domain.StageIdentity in project gocd by gocd.

the class CcTrayStageStatusLoaderTest method shouldConvertToStatusesIfAStageIsFoundInDB.

@Test
public void shouldConvertToStatusesIfAStageIsFoundInDB() throws Exception {
    List<ProjectStatus> expectedStatuses = asList(new ProjectStatus("pipeline1 :: stage1", "Sleeping", "some-status", "some-label", new Date(), "some-url"));
    List<Stage> stages = setupStagesInDB(new StageIdentity("pipeline1", "stage1", 12L), new StageIdentity("pipeline2", "stage2", 14L));
    when(stageChangeHandler.statusesOfStageAndItsJobsFor(stages.get(0))).thenReturn(expectedStatuses);
    List<ProjectStatus> actualStatuses = loader.getStatusesForStageAndJobsOf(pipelineConfigFor("pipeline1"), stageConfigFor("stage1"));
    assertThat(actualStatuses, is(expectedStatuses));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) Stage(com.thoughtworks.go.domain.Stage) StageIdentity(com.thoughtworks.go.server.domain.StageIdentity) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with StageIdentity

use of com.thoughtworks.go.server.domain.StageIdentity in project gocd by gocd.

the class CcTrayStageStatusLoaderTest method shouldNotHaveAnyStatusesIfAStageCannotBeFoundInDB.

@Test
public void shouldNotHaveAnyStatusesIfAStageCannotBeFoundInDB() throws Exception {
    setupStagesInDB(new StageIdentity("pipeline1", "stage1", 12L), new StageIdentity("pipeline2", "stage2", 14L));
    List<ProjectStatus> actualStatuses = loader.getStatusesForStageAndJobsOf(pipelineConfigFor("pipeline1"), stageConfigFor("non-existent-stage"));
    assertThat(actualStatuses, is(Collections.<ProjectStatus>emptyList()));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) StageIdentity(com.thoughtworks.go.server.domain.StageIdentity) Test(org.junit.jupiter.api.Test)

Example 4 with StageIdentity

use of com.thoughtworks.go.server.domain.StageIdentity in project gocd by gocd.

the class CcTrayStageStatusLoaderTest method shouldCacheResultOfLatestStageInstancesOnce.

@Test
public void shouldCacheResultOfLatestStageInstancesOnce() throws Exception {
    setupStagesInDB(new StageIdentity("pipeline1", "stage1", 12L), new StageIdentity("pipeline2", "stage2", 14L));
    loader.getStatusesForStageAndJobsOf(pipelineConfigFor("pipeline1"), stageConfigFor("stage1"));
    loader.getStatusesForStageAndJobsOf(pipelineConfigFor("pipeline1"), stageConfigFor("stage2"));
    loader.getStatusesForStageAndJobsOf(pipelineConfigFor("pipeline1"), stageConfigFor("stage-some-nonexistent-one"));
    verify(stageDao, times(1)).findLatestStageInstances();
}
Also used : StageIdentity(com.thoughtworks.go.server.domain.StageIdentity) Test(org.junit.jupiter.api.Test)

Example 5 with StageIdentity

use of com.thoughtworks.go.server.domain.StageIdentity in project gocd by gocd.

the class StageSqlMapDao method findLatestStageInstances.

@Override
public List<StageIdentity> findLatestStageInstances() {
    String key = cacheKeyForLatestStageInstances();
    List<StageIdentity> stageIdentities = (List<StageIdentity>) goCache.get(key);
    if (stageIdentities == null) {
        synchronized (key) {
            stageIdentities = (List<StageIdentity>) goCache.get(key);
            if (stageIdentities == null) {
                stageIdentities = (List<StageIdentity>) getSqlMapClientTemplate().queryForList("latestStageInstances");
                goCache.put(key, stageIdentities);
            }
        }
    }
    return stageIdentities;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageIdentity(com.thoughtworks.go.server.domain.StageIdentity)

Aggregations

StageIdentity (com.thoughtworks.go.server.domain.StageIdentity)6 Test (org.junit.jupiter.api.Test)4 Stage (com.thoughtworks.go.domain.Stage)2 ProjectStatus (com.thoughtworks.go.domain.activity.ProjectStatus)2 ArrayList (java.util.ArrayList)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 Date (java.util.Date)1 List (java.util.List)1