use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry in project gocd by gocd.
the class StageServiceIntegrationTest method shouldReturnLatestPipelineHistory.
@Test
public void shouldReturnLatestPipelineHistory() {
StageHistoryEntry[] stages = createFiveStages();
StageInstanceModels history = stageService.findStageHistoryViaCursor(new Username(new CaseInsensitiveString("admin1")), savedPipeline.getName(), savedPipeline.getFirstStage().getName(), 0, 0, 10);
assertThat(history.size(), is(5));
assertThat(history.get(0).getId(), is(stages[4].getId()));
assertThat(history.get(4).getId(), is(stages[0].getId()));
}
use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry in project gocd by gocd.
the class StageServiceIntegrationTest method shouldGetStageHistoryForLastPage.
@Test
public void shouldGetStageHistoryForLastPage() {
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.StageHistoryEntry 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.StageHistoryEntry in project gocd by gocd.
the class StageSqlMapDaoTest method shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntry.
@Test
void shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntry() {
StageIdentifier stageIdentifier = mock(StageIdentifier.class);
String pipelineName = "some_pipeline_name";
String stageName = "stage_name";
long pipelineId = 41l;
when(stageIdentifier.getPipelineName()).thenReturn(pipelineName);
when(stageIdentifier.getStageName()).thenReturn(stageName);
StageHistoryEntry topOfThisPage = mock(StageHistoryEntry.class);
StageHistoryEntry bottomOfPreviousPage = mock(StageHistoryEntry.class);
when(topOfThisPage.getId()).thenReturn(pipelineId);
when(topOfThisPage.getIdentifier()).thenReturn(stageIdentifier);
HashMap args = new HashMap();
args.put("pipelineName", pipelineName);
args.put("stageName", stageName);
args.put("id", pipelineId);
args.put("limit", 1);
when(sqlMapClientTemplate.queryForObject("findStageHistoryEntryBefore", args)).thenReturn(bottomOfPreviousPage);
StageHistoryEntry actual = stageSqlMapDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfThisPage);
assertThat(actual, is(bottomOfPreviousPage));
verify(stageIdentifier).getPipelineName();
verify(stageIdentifier).getStageName();
verify(topOfThisPage).getId();
verify(topOfThisPage).getIdentifier();
verify(sqlMapClientTemplate).queryForObject("findStageHistoryEntryBefore", args);
}
use of com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry in project gocd by gocd.
the class StageSqlMapDao method findStageHistoryPage.
public StageHistoryPage findStageHistoryPage(String pipelineName, String stageName, Supplier<com.thoughtworks.go.server.util.Pagination> 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.get();
String subKey = 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);
}
}
Aggregations