Search in sources :

Example 6 with Pagination

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());
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) Modification(com.thoughtworks.go.domain.materials.Modification) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision)

Example 7 with Pagination

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()));
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) ScheduleTestUtil(com.thoughtworks.go.server.service.ScheduleTestUtil) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.Test)

Example 8 with Pagination

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));
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) ScheduleTestUtil(com.thoughtworks.go.server.service.ScheduleTestUtil) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.Test)

Example 9 with Pagination

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))));
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Method(java.lang.reflect.Method) ScheduleTestUtil(com.thoughtworks.go.server.service.ScheduleTestUtil) Test(org.junit.Test)

Example 10 with Pagination

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)));
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Method(java.lang.reflect.Method) ScheduleTestUtil(com.thoughtworks.go.server.service.ScheduleTestUtil) Test(org.junit.Test)

Aggregations

Pagination (com.thoughtworks.go.server.util.Pagination)24 Test (org.junit.Test)16 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)7 ScheduleTestUtil (com.thoughtworks.go.server.service.ScheduleTestUtil)7 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)6 StageHistoryEntry (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)5 StageHistoryPage (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage)5 StageInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels)4 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)3 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 Method (java.lang.reflect.Method)2 Date (java.util.Date)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 PipelineNotFoundException (com.thoughtworks.go.config.PipelineNotFoundException)1 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 PipelinePauseInfo (com.thoughtworks.go.domain.PipelinePauseInfo)1