use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method findCompletedStagesFor_shouldInvalidateCacheOnCompletionOfAStageForTheGivenPipeline.
@Test
public void findCompletedStagesFor_shouldInvalidateCacheOnCompletionOfAStageForTheGivenPipeline() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockTemplate);
List<StageFeedEntry> entries = asList(new StageFeedEntry(1L, 1L, null, 1L, null, null));
when(mockTemplate.queryForList(eq("allCompletedStagesForPipeline"), any())).thenReturn((List) entries);
stageDao.findCompletedStagesFor("cruise", FeedModifier.Latest, 10, 100);
updateResultInTransaction(StageMother.completedFailedStageInstance("cruise", "stage", "job"), StageResult.Failed);
List<FeedEntry> actual = new ArrayList<>(stageDao.findCompletedStagesFor("cruise", FeedModifier.Latest, 10, 100));
assertThat(actual).isEqualTo(entries);
verify(mockTemplate, times(2)).queryForList(eq("allCompletedStagesForPipeline"), any());
}
use of com.thoughtworks.go.server.transaction.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((List) expected, (List) 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()).isEqualTo(2);
assertThat(actual).contains(newStage);
assertThat(actual).contains(first);
verify(mockTemplate, times(2)).queryForList(eq("getAllRunsOfStageForPipelineInstance"), any());
}
use of com.thoughtworks.go.server.transaction.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"));
assertThat(actual).isEqualTo(stage);
stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
verify(mockTemplate, times(1)).queryForObject(eq("findStageWithJobsByIdentifier"), any());
}
use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method findStageWithIdentifier_shouldRemoveFromTheCacheAllStagesWithTheNameOfTheSameCounterOnStageStatusChange.
@Test
public void findStageWithIdentifier_shouldRemoveFromTheCacheAllStagesWithTheNameOfTheSameCounterOnStageStatusChange() {
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);
// status of stage 2 changed. This should invalidate the stage 1 because of the latest run state.
updateResultInTransaction(second, StageResult.Unknown);
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_shouldCacheTheCount.
@Test
public void getTotalStageCountForChart_shouldCacheTheCount() 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);
// Should prime the cache
assertThat(stageDao.getTotalStageCountForChart("maar", "khoon")).isEqualTo(3);
// should use the cache
assertThat(stageDao.getTotalStageCountForChart("maar", "khoon")).isEqualTo(3);
verify(mockClient).queryForObject("getTotalStageCountForChart", toGet);
verifyNoMoreInteractions(mockClient);
}
Aggregations