use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method findStageHistoryPage_shouldCacheStageHistoryPage.
@Test
public void findStageHistoryPage_shouldCacheStageHistoryPage() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
Stage stage = StageMother.passedStageInstance("dev", "java", "pipeline-name");
stage.setApprovedBy("admin");
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("getStageHistoryCount"), any())).thenReturn(20);
when(mockTemplate.queryForObject(eq("findOffsetForStage"), any())).thenReturn(10);
List<StageHistoryEntry> stageList = asList(new StageHistoryEntry(stage, 1, 10));
when(mockTemplate.queryForList(eq("findStageHistoryPage"), any())).thenReturn(stageList);
StageHistoryPage stageHistoryPage = stageDao.findStageHistoryPage(stage, 10);
StageHistoryPage stageHistoryPageInNextQuery = stageDao.findStageHistoryPage(stage, 10);
assertThat(stageHistoryPage.getStages(), is(stageList));
assertThat(stageHistoryPage.getPagination(), is(Pagination.pageFor(10, 20, 10)));
assertThat(stageHistoryPageInNextQuery.getStages(), is(stageList));
assertThat(stageHistoryPageInNextQuery.getPagination(), is(Pagination.pageFor(10, 20, 10)));
stageHistoryPage.getStages().get(0).setState(StageState.Failing);
assertThat(stageHistoryPageInNextQuery.getStages().get(0).getState(), is(StageState.Passed));
verify(mockTemplate, times(1)).queryForList(eq("findStageHistoryPage"), any());
}
use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldServeStageByIdLookupFromCache.
@Test
public void shouldServeStageByIdLookupFromCache() throws Exception {
Pipeline[] pipelines = pipelineWithOnePassedAndOneCurrentlyRunning(mingleConfig);
Stage stage = pipelines[1].getStages().get(0);
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject("getStageById", stage.getId())).thenReturn(stage);
assertThat(stageDao.stageById(stage.getId()), is(stage));
assertThat(stageDao.stageById(stage.getId()), is(not(sameInstance(stageDao.stageById(stage.getId())))));
stageDao.jobStatusChanged(stage.getFirstJob());
assertThat(stageDao.stageById(stage.getId()), is(stage));
verify(mockTemplate, times(2)).queryForObject("getStageById", stage.getId());
}
use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method getTotalStageCountForChart_shouldInvalidateTheCountCacheOnStageUpdate.
@Test
public void getTotalStageCountForChart_shouldInvalidateTheCountCacheOnStageUpdate() throws SQLException {
SqlMapClientTemplate mockClient = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockClient);
Map<String, Object> toGet = arguments("pipelineName", "maar").and("stageName", "khoon").asMap();
when(mockClient.queryForObject("getTotalStageCountForChart", toGet)).thenReturn(3).thenReturn(4);
// Should prime the cache
assertThat(stageDao.getTotalStageCountForChart("maar", "khoon"), is(3));
Stage stage = new Stage("khoon", new JobInstances(), "foo", "manual", new TimeProvider());
stage.setIdentifier(new StageIdentifier("maar/2/khoon/1"));
// Should Invalidate the cache
updateResultInTransaction(stage, StageResult.Cancelled);
// should refetch
assertThat(stageDao.getTotalStageCountForChart("maar", "khoon"), is(4));
verify(mockClient, times(2)).queryForObject("getTotalStageCountForChart", toGet);
}
use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldCacheAllStagesForAPipelineInstance.
@Test
public void shouldCacheAllStagesForAPipelineInstance() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockTemplate);
Stage stage1 = StageMother.passedStageInstance("first", "job", "pipeline");
Stage stage2 = StageMother.passedStageInstance("second", "job", "pipeline");
List<Stage> stages = asList(stage1, stage2);
when(mockTemplate.queryForList("getStagesByPipelineNameAndCounter", arguments("pipelineName", "pipeline").and("pipelineCounter", 1).asMap())).thenReturn(stages);
Stages actual = stageDao.findAllStagesFor("pipeline", 1);
assertThat(actual, is(new Stages(stages)));
// Should return from cache
actual = stageDao.findAllStagesFor("pipeline", 1);
assertThat(actual, is(new Stages(stages)));
verify(mockTemplate, times(1)).queryForList("getStagesByPipelineNameAndCounter", arguments("pipelineName", "pipeline").and("pipelineCounter", 1).asMap());
}
use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method mostRecentId_shouldCacheResults.
@Test
public void mostRecentId_shouldCacheResults() throws Exception {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("getMostRecentId"), any())).thenReturn(20L);
stageDao.mostRecentId(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.get(0).name()));
Long id = stageDao.mostRecentId(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.get(0).name()));
assertThat(id, is(20L));
verify(mockTemplate, times(1)).queryForObject(eq("getMostRecentId"), any());
}
Aggregations