use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method findStageWithIdentifier_shouldNotCacheWhenTheStageIsNull.
@Test
public void findStageWithIdentifier_shouldNotCacheWhenTheStageIsNull() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("findStageWithJobsByIdentifier"), any())).thenReturn(null);
Stage actual = stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
assertThat(actual).isEqualTo(new NullStage("stage"));
stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
verify(mockTemplate, times(2)).queryForObject(eq("findStageWithJobsByIdentifier"), any());
}
use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldNotInvalidateCachedAllStagesForAPipelineInstanceWhenTheStatusOfAStageOfDifferentPipelineInstance.
@Test
public void shouldNotInvalidateCachedAllStagesForAPipelineInstanceWhenTheStatusOfAStageOfDifferentPipelineInstance() {
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((List) stages);
Stages actual = stageDao.findAllStagesFor("pipeline", 1);
assertThat(actual).isEqualTo(new Stages(stages));
// Should not invalidate the cached stages as it is from a different Pipeline instance
stageDao.stageStatusChanged(StageMother.scheduledStage("pipeline", 2, "first", 2, "job"));
actual = stageDao.findAllStagesFor("pipeline", 1);
assertThat(actual).isEqualTo(new Stages(stages));
verify(mockTemplate, times(1)).queryForList("getStagesByPipelineNameAndCounter", arguments("pipelineName", "pipeline").and("pipelineCounter", 1).asMap());
}
use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method getTotalStageCountForChart_shouldInvalidateTheCountCacheOnStageSchedule.
@Test
public void getTotalStageCountForChart_shouldInvalidateTheCountCacheOnStageSchedule() 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")).isEqualTo(3);
Stage stage = new Stage("khoon", new JobInstances(), "foo", null, "manual", new TimeProvider());
Pipeline pipeline = new Pipeline("maar", "${COUNT}", BuildCause.createWithEmptyModifications(), new EnvironmentVariables(), stage);
pipeline.setId(1);
// Should Invalidate the cache
stageDao.save(pipeline, stage);
// should refetch
assertThat(stageDao.getTotalStageCountForChart("maar", "khoon")).isEqualTo(4);
verify(mockClient, times(2)).queryForObject("getTotalStageCountForChart", toGet);
}
use of com.thoughtworks.go.server.transaction.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"));
assertThat(actual).isEqualTo(first);
Pipeline pipeline = new Pipeline("pipeline", "label", BuildCause.createManualForced(), new EnvironmentVariables(), 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 com.thoughtworks.go.server.transaction.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")).isEqualTo(3);
Stage stage = new Stage("khoon", new JobInstances(), "foo", null, "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")).isEqualTo(4);
verify(mockClient, times(2)).queryForObject("getTotalStageCountForChart", toGet);
}
Aggregations