Search in sources :

Example 6 with HgMaterial

use of com.thoughtworks.go.config.materials.mercurial.HgMaterial 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)

Example 7 with HgMaterial

use of com.thoughtworks.go.config.materials.mercurial.HgMaterial in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntry.

@Test
public void shouldLoadTheStageHistoryEntryNextInTimeFromAGivenStageHistoryEntry() 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 < 11; i++) {
        scheduleUtil.runAndPass(p1, "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() + 1));
    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 8 with HgMaterial

use of com.thoughtworks.go.config.materials.mercurial.HgMaterial in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method shouldInvalidateStageHistoryCachesOnStageSave.

@Test
public void shouldInvalidateStageHistoryCachesOnStageSave() 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));
    scheduleUtil.runAndPass(p1, "h1");
    Stage stage = stageDao.mostRecentStage(new StageConfigIdentifier(pipelineName, stageName));
    // PRIME CACHE
    stageDao.findStageHistoryPage(stage, 10);
    Method cacheKeyForStageHistories = getMethodViaReflection("cacheKeyForStageHistories", String.class, String.class);
    Method cacheKeyForStageCount = getMethodViaReflection("cacheKeyForStageCount", String.class, String.class);
    Method cacheKeyForStageOffset = getMethodViaReflection("cacheKeyForStageOffset", Stage.class);
    Object primedStageHistoryPage = goCache.get((String) cacheKeyForStageHistories.invoke(stageDao, pipelineName, stageName));
    Object primedStageHistoryCount = goCache.get((String) cacheKeyForStageCount.invoke(stageDao, pipelineName, stageName));
    Object primedStageHistoryOffset = goCache.get((String) cacheKeyForStageOffset.invoke(stageDao, stage), String.valueOf(stage.getId()));
    // NEW RUN OF STAGE, CACHE SHOULD BE INVALIDATED
    scheduleUtil.runAndPass(p1, "h1");
    stage = stageDao.mostRecentStage(new StageConfigIdentifier(pipelineName, stageName));
    // SHOULD QUERY AGAIN
    stageDao.findStageHistoryPage(stage, 10);
    Object reprimedStageHistoryPage = goCache.get((String) cacheKeyForStageHistories.invoke(stageDao, pipelineName, stageName));
    Object reprimedStageHistoryCount = goCache.get((String) cacheKeyForStageCount.invoke(stageDao, pipelineName, stageName));
    Object reprimedStageHistoryOffset = goCache.get((String) cacheKeyForStageOffset.invoke(stageDao, stage), String.valueOf(stage.getId()));
    assertThat(reprimedStageHistoryPage, is(not(sameInstance(primedStageHistoryPage))));
    assertThat(reprimedStageHistoryCount, is(not(sameInstance(primedStageHistoryCount))));
    assertThat(reprimedStageHistoryOffset, is(not(sameInstance(primedStageHistoryOffset))));
}
Also used : 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 9 with HgMaterial

use of com.thoughtworks.go.config.materials.mercurial.HgMaterial 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 HgMaterial

use of com.thoughtworks.go.config.materials.mercurial.HgMaterial in project gocd by gocd.

the class GoCacheTest method get_shouldBombWhenValueIsAPersistentObjectWithoutId.

@Test
public void get_shouldBombWhenValueIsAPersistentObjectWithoutId() throws Exception {
    HgMaterial material = MaterialsMother.hgMaterial();
    MaterialInstance materialInstance = material.createMaterialInstance();
    materialInstance.setId(10);
    goCache.put("foo", materialInstance);
    materialInstance.setId(-1);
    try {
        goCache.get("foo");
        fail("should not allow getting a persistent object without id: " + materialInstance);
    } catch (Exception e) {
    // ok
    }
}
Also used : HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)121 Test (org.junit.Test)107 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)34 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)29 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)23 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)23 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)20 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)18 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)16 Material (com.thoughtworks.go.domain.materials.Material)15 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)10 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)10 Date (java.util.Date)10 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)9 ScheduleTestUtil (com.thoughtworks.go.server.service.ScheduleTestUtil)9 TimeProvider (com.thoughtworks.go.util.TimeProvider)8 Pagination (com.thoughtworks.go.server.util.Pagination)7 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)6 Modification (com.thoughtworks.go.domain.materials.Modification)6 File (java.io.File)6