use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method getAllRunsOfStageForPipelineInstance_shouldCacheAllTheStages.
@Test
public void getAllRunsOfStageForPipelineInstance_shouldCacheAllTheStages() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
Stage first = StageMother.passedStageInstance("pipeline", "stage", 1, "job", new Date());
Stage second = StageMother.passedStageInstance("pipeline", "stage", 2, "job", new Date());
Stage third = StageMother.passedStageInstance("pipeline", "stage", 3, "job", new Date());
List<Stage> expected = asList(third, second, first);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForList(eq("getAllRunsOfStageForPipelineInstance"), any())).thenReturn((List) expected);
Stages actual = stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage");
assertThat(actual).isEqualTo(expected);
assertThat(expected == actual).isFalse();
assertThat(expected.get(0) == actual.get(0)).isFalse();
stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage");
verify(mockTemplate, times(1)).queryForList(eq("getAllRunsOfStageForPipelineInstance"), any());
}
use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method findStageWithIdentifier_shouldClearCacheWhenJobStateChanges.
@Test
public void findStageWithIdentifier_shouldClearCacheWhenJobStateChanges() {
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);
assertThat(stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"))).isEqualTo(stage);
stageDao.jobStatusChanged(stage.getFirstJob());
assertThat(stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"))).isEqualTo(stage);
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 getAllRunsOfStageForPipelineInstance_shouldClearCacheOnJobStateChange.
@Test
public void getAllRunsOfStageForPipelineInstance_shouldClearCacheOnJobStateChange() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
Stage first = StageMother.passedStageInstance("pipeline", "stage", 1, "job", new Date());
Stage second = StageMother.passedStageInstance("pipeline", "stage", 2, "job", new Date());
Stage third = StageMother.passedStageInstance("pipeline", "stage", 3, "job", new Date());
List<Stage> expected = asList(third, second, first);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForList(eq("getAllRunsOfStageForPipelineInstance"), any())).thenReturn((List) expected);
assertThat(stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage")).isEqualTo(expected);
stageDao.jobStatusChanged(first.getFirstJob());
assertThat(stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage")).isEqualTo(expected);
stageDao.jobStatusChanged(second.getFirstJob());
assertThat(stageDao.getAllRunsOfStageForPipelineInstance("pipeline", 1, "stage")).isEqualTo(expected);
verify(mockTemplate, times(3)).queryForList(eq("getAllRunsOfStageForPipelineInstance"), any());
}
use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method findStageWithIdentifier_shouldRemoveFromTheCacheOnStageStatusChange.
@Test
public void findStageWithIdentifier_shouldRemoveFromTheCacheOnStageStatusChange() {
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);
assertThat(stage == actual).as("Make sure the cached object is cloned").isFalse();
updateResultInTransaction(actual, StageResult.Passed);
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 shouldInvalidateCachedAllStagesForAPipelineInstanceWhenTheStatusOfAStageOfThisPipelineInstanceIsChanged.
@Test
public void shouldInvalidateCachedAllStagesForAPipelineInstanceWhenTheStatusOfAStageOfThisPipelineInstanceIsChanged() {
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 invalidate the cached stages
stageDao.stageStatusChanged(StageMother.scheduledStage("pipeline", 1, "first", 2, "job"));
actual = stageDao.findAllStagesFor("pipeline", 1);
assertThat(actual).isEqualTo(new Stages(stages));
verify(mockTemplate, times(2)).queryForList("getStagesByPipelineNameAndCounter", arguments("pipelineName", "pipeline").and("pipelineCounter", 1).asMap());
}
Aggregations