use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method shouldRemoveCachedMostRecentIdOnStageStatusChange.
@Test
public void shouldRemoveCachedMostRecentIdOnStageStatusChange() throws Exception {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("getMostRecentId"), any())).thenReturn(20L);
String pipelineName = CaseInsensitiveString.str(mingleConfig.name());
String stageName = CaseInsensitiveString.str(mingleConfig.get(0).name());
String key = stageDao.cacheKeyForMostRecentId(pipelineName, stageName);
// should query and cache value
stageDao.mostRecentId(pipelineName, stageName);
Long id = stageDao.mostRecentId(pipelineName, stageName);
assertThat(id).isEqualTo(20L);
// should clear the cache
Stage stage = StageMother.custom(pipelineName, stageName, new JobInstances());
stageDao.stageStatusChanged(stage);
assertThat(goCache.get(key)).isNull();
// should requery and cache
stageDao.mostRecentId(pipelineName, stageName);
id = stageDao.mostRecentId(pipelineName, stageName);
assertThat(id).isEqualTo(20L);
assertThat(goCache.get(key)).isEqualTo(20L);
verify(mockTemplate, times(2)).queryForObject(eq("getMostRecentId"), any());
}
use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method isStageActive_shouldCacheTheResultAfterFirstExecution.
@Test
public void isStageActive_shouldCacheTheResultAfterFirstExecution() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("isStageActive"), any())).thenReturn(1);
boolean stageActive = stageDao.isStageActive(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.getFirstStageConfig().name()));
assertThat(stageActive).isTrue();
stageActive = stageDao.isStageActive(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.getFirstStageConfig().name()));
assertThat(stageActive).isTrue();
verify(mockTemplate, times(1)).queryForObject(eq("isStageActive"), any());
}
use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoIntegrationTest method isStageActive_shouldMakeIsActiveFalseWhenTheStageCompletes.
@Test
public void isStageActive_shouldMakeIsActiveFalseWhenTheStageCompletes() {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
stageDao.setSqlMapClientTemplate(mockTemplate);
when(mockTemplate.queryForObject(eq("isStageActive"), any())).thenReturn(1).thenReturn(0);
boolean stageActive = stageDao.isStageActive(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.getFirstStageConfig().name()));
assertThat(stageActive).isTrue();
Stage stage = StageMother.completedFailedStageInstance(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.getFirstStageConfig().name()), "job");
// The cached 'true' should now be removed
stageDao.stageStatusChanged(stage);
assertThat(stageDao.isStageActive(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.getFirstStageConfig().name()))).isFalse();
verify(mockTemplate, times(2)).queryForObject(eq("isStageActive"), any());
}
use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class PipelineSqlMapDaoTest method loadHistoryByIds_shouldLoadHistoryByIdWhenOnlyASingleIdIsNeedeSoThatItUsesTheExistingCacheForEnvironmentsPage.
@Test
void loadHistoryByIds_shouldLoadHistoryByIdWhenOnlyASingleIdIsNeedeSoThatItUsesTheExistingCacheForEnvironmentsPage() throws Exception {
SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
when(mockTemplate.queryForList(eq("getPipelineRange"), any())).thenReturn(Arrays.asList(2L));
pipelineSqlMapDao.setSqlMapClientTemplate(mockTemplate);
pipelineSqlMapDao.loadHistory("pipelineName", 1, 0);
verify(mockTemplate, never()).queryForList(eq("getPipelineHistoryByName"), any());
verify(mockTemplate, times(1)).queryForList(eq("getPipelineRange"), any());
}
use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.
the class StageSqlMapDaoTest method setUp.
@BeforeEach
void setUp() {
goCache = new StubGoCache(new TestTransactionSynchronizationManager());
sqlMapClientTemplate = mock(SqlMapClientTemplate.class);
stageSqlMapDao = new StageSqlMapDao(mock(JobInstanceSqlMapDao.class), new Cache(true, false, false), mock(TransactionTemplate.class), mock(SqlSessionFactory.class), goCache, mock(TransactionSynchronizationManager.class), mock(SystemEnvironment.class), null);
stageSqlMapDao.setSqlMapClientTemplate(sqlMapClientTemplate);
cloner = mock(Cloner.class);
ReflectionUtil.setField(stageSqlMapDao, "cloner", cloner);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) {
return invocationOnMock.getArguments()[0];
}
}).when(cloner).deepClone(any());
}
Aggregations