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 findStageWithIdentifier_shouldRemoveFromTheCacheOnSave.
@Test
public void findStageWithIdentifier_shouldRemoveFromTheCacheOnSave() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
Stage first = StageMother.passedStageInstance("pipeline", "stage", "job", new Date());
first.setCounter(1);
Stage second = StageMother.passedStageInstance("pipeline", "stage", "job", new Date());
second.setCounter(2);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("findStageWithJobsByIdentifier"), any())).thenReturn(first);
Stage actual = stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
assertEquals(first, actual);
Pipeline pipeline = new Pipeline("pipeline", "label", BuildCause.createManualForced(), first);
pipeline.setCounter(1);
//save stage 2.. This should invalidate the stage 1 because of the latest run state.
stageDao.save(pipeline, second);
stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
verify(mockTemplate, times(2)).queryForObject(eq("findStageWithJobsByIdentifier"), any());
}
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 findStageWithIdentifier_shouldCacheTheStage.
@Test
public void findStageWithIdentifier_shouldCacheTheStage() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
Stage stage = StageMother.passedStageInstance("pipeline", "stage", "job", new Date());
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("findStageWithJobsByIdentifier"), any())).thenReturn(stage);
Stage actual = stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
assertEquals(stage, actual);
stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
verify(mockTemplate, times(1)).queryForObject(eq("findStageWithJobsByIdentifier"), any());
}
use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method getAllRunsOfStageForPipelineInstance_shouldRemoveFromCacheOnStageSave.
@Test
public void getAllRunsOfStageForPipelineInstance_shouldRemoveFromCacheOnStageSave() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
Stage newStage = StageMother.passedStageInstance("pipeline", "stage", 2, "job", new Date());
Stage first = StageMother.passedStageInstance("pipeline", "stage", 1, "job", new Date());
List<Stage> expected = asList(first);
List<Stage> expectedSecondTime = asList(first, newStage);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForList(eq("getAllRunsOfStageForPipelineInstance"), any())).thenReturn(expected, expectedSecondTime);
stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage");
Pipeline pipeline = PipelineMother.pipeline("pipeline");
pipeline.setCounter(1);
//should remove first from cache
stageDao.save(pipeline, newStage);
Stages actual = stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage");
assertThat(actual.size(), is(2));
assertThat(actual, hasItem(newStage));
assertThat(actual, hasItem(first));
verify(mockTemplate, times(2)).queryForList(eq("getAllRunsOfStageForPipelineInstance"), any());
}
Aggregations