Search in sources :

Example 6 with StageHistoryPage

use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage in project gocd by gocd.

the class StageServiceIntegrationTest method shouldGetStageHistoryForLastPage.

@Test
public void shouldGetStageHistoryForLastPage() throws Exception {
    StageHistoryEntry[] stages = createFiveStages();
    StageHistoryPage history = stageService.findStageHistoryPage(stageService.stageById(stages[0].getId()), 3);
    assertThat("Found " + history, history.getStages().get(0), is(stages[1]));
    assertThat("Found " + history, history.getStages().get(1), is(stages[0]));
    assertThat("Found " + history, history.getPagination(), is(Pagination.pageStartingAt(3, 5, 3)));
    assertThat("Found " + history, history.getPagination().getCurrentPage(), is(2));
}
Also used : StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.Test)

Example 7 with StageHistoryPage

use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage in project gocd by gocd.

the class StageSqlMapDao method findStageHistoryPage.

public StageHistoryPage findStageHistoryPage(String pipelineName, String stageName, FuncVarArg<Pagination, Object> function) {
    //IMPORTANT: wire cache clearing on job-state-change for me, the day StageHistoryEntry gets jobs - Sachin & JJ
    String mutex = mutexForStageHistory(pipelineName, stageName);
    readWriteLock.acquireReadLock(mutex);
    try {
        Pagination pagination = function.call();
        String subKey = String.format("%s-%s", pagination.getCurrentPage(), pagination.getPageSize());
        String key = cacheKeyForStageHistories(pipelineName, stageName);
        StageHistoryPage stageHistoryPage = (StageHistoryPage) goCache.get(key, subKey);
        if (stageHistoryPage == null) {
            List<StageHistoryEntry> stageHistoryEntries = findStages(pagination, pipelineName, stageName);
            stageHistoryPage = new StageHistoryPage(stageHistoryEntries, pagination, findImmediateChronologicallyForwardStageHistoryEntry(stageHistoryEntries.get(0)));
            goCache.put(key, subKey, stageHistoryPage);
        }
        return cloner.deepClone(stageHistoryPage);
    } finally {
        readWriteLock.releaseReadLock(mutex);
    }
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)

Example 8 with StageHistoryPage

use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method findStageHistoryPage_shouldReturnStageHistoryEntryWithConfigVersion.

@Test
public void findStageHistoryPage_shouldReturnStageHistoryEntryWithConfigVersion() {
    SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
    Stage stage = StageMother.passedStageInstance("dev", "java", "pipeline-name");
    stage.setApprovedBy("admin");
    stage.setConfigVersion("md5-test");
    stageDao.setSqlMapClientTemplate(mockTemplate);
    when(mockTemplate.queryForObject(eq("getStageHistoryCount"), any())).thenReturn(20);
    when(mockTemplate.queryForObject(eq("findOffsetForStage"), any())).thenReturn(10);
    List<StageHistoryEntry> stageList = asList(new StageHistoryEntry(stage, 1, 10));
    when(mockTemplate.queryForList(eq("findStageHistoryPage"), any())).thenReturn(stageList);
    StageHistoryPage stageHistoryPage = stageDao.findStageHistoryPage(stage, 10);
    assertThat(stageHistoryPage.getStages().get(0).getConfigVersion(), is("md5-test"));
}
Also used : StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.Test)

Example 9 with StageHistoryPage

use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage in project gocd by gocd.

the class StageServiceIntegrationTest method shouldGetStageHistoryForCurrentPage.

@Test
public void shouldGetStageHistoryForCurrentPage() throws Exception {
    StageHistoryEntry[] stages = createFiveStages();
    StageHistoryPage history = stageService.findStageHistoryPage(stageService.stageById(stages[2].getId()), 3);
    assertThat("Found " + history, history.getPagination(), is(Pagination.pageStartingAt(0, 5, 3)));
    assertThat("Found " + history, history.getStages().size(), is(3));
    assertThat("Found " + history, history.getStages().get(0), is(stages[4]));
    assertThat("Found " + history, history.getStages().get(1), is(stages[3]));
    assertThat("Found " + history, history.getStages().get(2), is(stages[2]));
}
Also used : StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.Test)

Example 10 with StageHistoryPage

use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage in project gocd by gocd.

the class StageServiceIntegrationTest method shouldGetStageHistoryByPageNumber.

@Test
public void shouldGetStageHistoryByPageNumber() throws Exception {
    StageHistoryEntry[] stages = createFiveStages();
    StageHistoryPage history = stageService.findStageHistoryPageByNumber(PIPELINE_NAME, STAGE_NAME, 2, 3);
    assertThat("Found " + history, history.getPagination(), is(Pagination.pageStartingAt(3, 5, 3)));
    assertThat("Found " + history, history.getStages().size(), is(2));
    assertThat("Found " + history, history.getStages().get(0), is(stages[1]));
    assertThat("Found " + history, history.getStages().get(1), is(stages[0]));
}
Also used : StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.Test)

Aggregations

StageHistoryEntry (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)10 StageHistoryPage (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage)10 Test (org.junit.Test)9 Pagination (com.thoughtworks.go.server.util.Pagination)5 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)3 ScheduleTestUtil (com.thoughtworks.go.server.service.ScheduleTestUtil)3 SqlMapClientTemplate (org.springframework.orm.ibatis.SqlMapClientTemplate)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 FuncVarArg (com.thoughtworks.go.util.FuncVarArg)1