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