use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class DependencyMaterialUpdater method insertRevisionsForParentStagesAfter.
private void insertRevisionsForParentStagesAfter(DependencyMaterial dependencyMaterial, Modifications list) {
Pagination pagination = Pagination.pageStartingAt(0, null, MaterialDatabaseUpdater.STAGES_PER_PAGE);
List<Modification> modifications = null;
do {
modifications = dependencyMaterialSourceDao.getPassedStagesAfter(list.last().getRevision(), dependencyMaterial, pagination);
for (Modification modification : modifications) {
MaterialRevision revision = new MaterialRevision(dependencyMaterial, modification);
materialRepository.saveMaterialRevision(revision);
}
pagination = Pagination.pageStartingAt(pagination.getOffset() + pagination.getPageSize(), null, pagination.getPageSize());
} while (!modifications.isEmpty());
}
use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldReturnNullStageHistoryEntryWhenGettingHistoryForPage1.
@Test
public void shouldReturnNullStageHistoryEntryWhenGettingHistoryForPage1() throws Exception {
HgMaterial hg = new HgMaterial("url", null);
String[] hg_revs = { "h1" };
scheduleUtil.checkinInOrder(hg, hg_revs);
String pipelineName = "p1";
String stageName = "stage_name";
ScheduleTestUtil.AddedPipeline p1 = scheduleUtil.saveConfigWith(pipelineName, stageName, scheduleUtil.m(hg));
for (int i = 0; i < 10; i++) {
scheduleUtil.runAndPass(p1, "h1");
}
StageHistoryPage historyPage = stageDao.findStageHistoryPage(pipelineName, stageName, new FuncVarArg<Pagination, Object>() {
@Override
public Pagination call(Object... args) {
return Pagination.pageByNumber(1, 1, 10);
}
});
StageHistoryEntry topOfSecondPage = historyPage.getStages().get(0);
StageHistoryEntry bottomOfFirstPage = stageDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfSecondPage);
assertThat(bottomOfFirstPage, is(Matchers.nullValue()));
}
use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntryEvenThoughOtherStageInstanceAreInBetween.
@Test
public void shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntryEvenThoughOtherStageInstanceAreInBetween() throws Exception {
HgMaterial hg = new HgMaterial("url", null);
String[] hg_revs = { "h1" };
scheduleUtil.checkinInOrder(hg, hg_revs);
String pipelineName = "p1";
String anotherPipeline = "p2";
String stageName = "stage_name";
String anotherStage = "another_stage_name";
ScheduleTestUtil.AddedPipeline p1 = scheduleUtil.saveConfigWith(pipelineName, stageName, scheduleUtil.m(hg));
ScheduleTestUtil.AddedPipeline p2 = scheduleUtil.saveConfigWith(anotherPipeline, anotherStage, scheduleUtil.m(hg));
for (int i = 0; i < 11; i++) {
scheduleUtil.runAndPass(p1, "h1");
scheduleUtil.runAndPass(p2, "h1");
}
StageHistoryPage historyPage = stageDao.findStageHistoryPage(pipelineName, stageName, new FuncVarArg<Pagination, Object>() {
@Override
public Pagination call(Object... args) {
return Pagination.pageByNumber(2, 2, 10);
}
});
StageHistoryEntry topOfSecondPage = historyPage.getStages().get(0);
StageHistoryEntry bottomOfFirstPage = stageDao.findImmediateChronologicallyForwardStageHistoryEntry(topOfSecondPage);
assertThat(bottomOfFirstPage.getId(), is(topOfSecondPage.getId() + 2));
assertThat(bottomOfFirstPage.getIdentifier().getPipelineName(), is(pipelineName));
assertThat(bottomOfFirstPage.getIdentifier().getStageName(), is(stageName));
assertThat(bottomOfFirstPage.getIdentifier().getPipelineCounter(), is(2));
}
use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldInvalidateDetailedStageHistoryCachesOnStageSave.
@Test
public void shouldInvalidateDetailedStageHistoryCachesOnStageSave() throws Exception {
HgMaterial hg = new HgMaterial("url", null);
String[] hg_revs = { "h1" };
scheduleUtil.checkinInOrder(hg, hg_revs);
String pipelineName = "p1";
String stageName = "stage_name";
Pagination pagination = Pagination.pageStartingAt(0, 10, 10);
ScheduleTestUtil.AddedPipeline p1 = scheduleUtil.saveConfigWith(pipelineName, stageName, scheduleUtil.m(hg));
scheduleUtil.runAndPass(p1, "h1");
Stage stage = stageDao.mostRecentStage(new StageConfigIdentifier(pipelineName, stageName));
// PRIME CACHE
stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
Method cacheKeyForDetailedStageHistories = getMethodViaReflection("cacheKeyForDetailedStageHistories", String.class, String.class);
Object primedDetailedStageHistoryPage = goCache.get((String) cacheKeyForDetailedStageHistories.invoke(stageDao, pipelineName, stageName));
// NEW RUN OF STAGE, CACHE SHOULD BE INVALIDATED
scheduleUtil.runAndPass(p1, "h1");
stage = stageDao.mostRecentStage(new StageConfigIdentifier(pipelineName, stageName));
// SHOULD QUERY AGAIN
stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
Object reprimedDetailedStageHistoryPage = goCache.get((String) cacheKeyForDetailedStageHistories.invoke(stageDao, pipelineName, stageName));
assertThat(reprimedDetailedStageHistoryPage, is(not(sameInstance(primedDetailedStageHistoryPage))));
}
use of com.thoughtworks.go.server.util.Pagination in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldCacheDetailedStageHistoryPageAndCountAndOffset.
@Test
public void shouldCacheDetailedStageHistoryPageAndCountAndOffset() throws Exception {
HgMaterial hg = new HgMaterial("url", null);
String[] hg_revs = { "h1" };
scheduleUtil.checkinInOrder(hg, hg_revs);
String pipelineName = "p1";
String stageName = "stage_name";
Pagination pagination = Pagination.pageStartingAt(0, 10, 10);
ScheduleTestUtil.AddedPipeline p1 = scheduleUtil.saveConfigWith(pipelineName, stageName, scheduleUtil.m(hg));
scheduleUtil.runAndPass(p1, "h1");
Stage stage = stageDao.mostRecentStage(new StageConfigIdentifier(pipelineName, stageName));
// PRIME CACHE
stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
Method cacheKeyForDetailedStageHistories = getMethodViaReflection("cacheKeyForDetailedStageHistories", String.class, String.class);
Object primedDetailedStageHistoryPage = goCache.get((String) cacheKeyForDetailedStageHistories.invoke(stageDao, pipelineName, stageName));
// SHOULD RETURN FROM CACHE
stageDao.findDetailedStageHistoryByOffset(pipelineName, stageName, pagination);
Object cachedDetailedStageHistoryPage = goCache.get((String) cacheKeyForDetailedStageHistories.invoke(stageDao, pipelineName, stageName));
assertThat(cachedDetailedStageHistoryPage, is(sameInstance(primedDetailedStageHistoryPage)));
}
Aggregations