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));
}
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);
}
}
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"));
}
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]));
}
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]));
}
Aggregations