Search in sources :

Example 16 with SqlMapClientTemplate

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());
}
Also used : StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) FeedEntry(com.thoughtworks.go.domain.feed.FeedEntry) SqlMapClientTemplate(com.thoughtworks.go.server.transaction.SqlMapClientTemplate) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) Test(org.junit.jupiter.api.Test)

Example 17 with SqlMapClientTemplate

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());
}
Also used : SqlMapClientTemplate(com.thoughtworks.go.server.transaction.SqlMapClientTemplate) Test(org.junit.jupiter.api.Test)

Example 18 with SqlMapClientTemplate

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());
}
Also used : SqlMapClientTemplate(com.thoughtworks.go.server.transaction.SqlMapClientTemplate) Test(org.junit.jupiter.api.Test)

Example 19 with SqlMapClientTemplate

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());
}
Also used : SqlMapClientTemplate(com.thoughtworks.go.server.transaction.SqlMapClientTemplate) Test(org.junit.jupiter.api.Test)

Example 20 with SqlMapClientTemplate

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);
}
Also used : SqlMapClientTemplate(com.thoughtworks.go.server.transaction.SqlMapClientTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

SqlMapClientTemplate (com.thoughtworks.go.server.transaction.SqlMapClientTemplate)26 Test (org.junit.jupiter.api.Test)25 StageHistoryEntry (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)2 StageHistoryPage (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage)2 TimeProvider (com.thoughtworks.go.util.TimeProvider)2 Cache (com.opensymphony.oscache.base.Cache)1 Cloner (com.rits.cloning.Cloner)1 FeedEntry (com.thoughtworks.go.domain.feed.FeedEntry)1 StageFeedEntry (com.thoughtworks.go.domain.feed.stage.StageFeedEntry)1 GoCache (com.thoughtworks.go.server.cache.GoCache)1 StubGoCache (com.thoughtworks.go.server.service.StubGoCache)1 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1