Search in sources :

Example 1 with SqlMapClientTemplate

use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method findStageHistoryPage_shouldCacheStageHistoryPage.

@Test
public void findStageHistoryPage_shouldCacheStageHistoryPage() {
    SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
    Stage stage = StageMother.passedStageInstance("dev", "java", "pipeline-name");
    stage.setApprovedBy("admin");
    stageDao.setSqlMapClientTemplate(mockTemplate);
    when(mockTemplate.queryForObject(eq("getStageHistoryCount"), any())).thenReturn(20);
    when(mockTemplate.queryForObject(eq("findOffsetForStage"), any())).thenReturn(10);
    List<StageHistoryEntry> stageList = asList(new StageHistoryEntry(stage, 1, 10));
    when(mockTemplate.queryForList(eq("findStageHistoryPage"), any())).thenReturn((List) stageList);
    StageHistoryPage stageHistoryPage = stageDao.findStageHistoryPage(stage, 10);
    StageHistoryPage stageHistoryPageInNextQuery = stageDao.findStageHistoryPage(stage, 10);
    assertThat(stageHistoryPage.getStages()).isEqualTo(stageList);
    assertThat(stageHistoryPage.getPagination()).isEqualTo(Pagination.pageFor(10, 20, 10));
    assertThat(stageHistoryPageInNextQuery.getStages()).isEqualTo(stageList);
    assertThat(stageHistoryPageInNextQuery.getPagination()).isEqualTo(Pagination.pageFor(10, 20, 10));
    stageHistoryPage.getStages().get(0).setState(StageState.Failing);
    assertThat(stageHistoryPageInNextQuery.getStages().get(0).getState()).isEqualTo(StageState.Passed);
    verify(mockTemplate, times(1)).queryForList(eq("findStageHistoryPage"), any());
}
Also used : StageHistoryPage(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage) SqlMapClientTemplate(com.thoughtworks.go.server.transaction.SqlMapClientTemplate) StageHistoryEntry(com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry) Test(org.junit.jupiter.api.Test)

Example 2 with SqlMapClientTemplate

use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method shouldServeStageByIdLookupFromCache.

@Test
public void shouldServeStageByIdLookupFromCache() throws Exception {
    Pipeline[] pipelines = pipelineWithOnePassedAndOneCurrentlyRunning(mingleConfig);
    Stage stage = pipelines[1].getStages().get(0);
    SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
    stageDao.setSqlMapClientTemplate(mockTemplate);
    when(mockTemplate.queryForObject("getStageById", stage.getId())).thenReturn(stage);
    assertThat(stageDao.stageById(stage.getId())).isEqualTo(stage);
    assertThat(stageDao.stageById(stage.getId())).isNotSameAs(stageDao.stageById(stage.getId()));
    stageDao.jobStatusChanged(stage.getFirstJob());
    assertThat(stageDao.stageById(stage.getId())).isEqualTo(stage);
    verify(mockTemplate, times(2)).queryForObject("getStageById", stage.getId());
}
Also used : SqlMapClientTemplate(com.thoughtworks.go.server.transaction.SqlMapClientTemplate) Test(org.junit.jupiter.api.Test)

Example 3 with SqlMapClientTemplate

use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method getAllRunsOfStageForPipelineInstance_shouldRemoveFromCacheOnStageStatusChange.

@Test
public void getAllRunsOfStageForPipelineInstance_shouldRemoveFromCacheOnStageStatusChange() {
    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);
    updateResultInTransaction(newStage, StageResult.Passed);
    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 4 with SqlMapClientTemplate

use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method shouldCacheAllStagesForAPipelineInstance.

@Test
public void shouldCacheAllStagesForAPipelineInstance() {
    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 return from cache
    actual = stageDao.findAllStagesFor("pipeline", 1);
    assertThat(actual).isEqualTo(new Stages(stages));
    verify(mockTemplate, times(1)).queryForList("getStagesByPipelineNameAndCounter", arguments("pipelineName", "pipeline").and("pipelineCounter", 1).asMap());
}
Also used : SqlMapClientTemplate(com.thoughtworks.go.server.transaction.SqlMapClientTemplate) Test(org.junit.jupiter.api.Test)

Example 5 with SqlMapClientTemplate

use of com.thoughtworks.go.server.transaction.SqlMapClientTemplate in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method mostRecentId_shouldCacheResults.

@Test
public void mostRecentId_shouldCacheResults() throws Exception {
    SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
    stageDao.setSqlMapClientTemplate(mockTemplate);
    when(mockTemplate.queryForObject(eq("getMostRecentId"), any())).thenReturn(20L);
    stageDao.mostRecentId(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.get(0).name()));
    Long id = stageDao.mostRecentId(CaseInsensitiveString.str(mingleConfig.name()), CaseInsensitiveString.str(mingleConfig.get(0).name()));
    assertThat(id).isEqualTo(20L);
    verify(mockTemplate, times(1)).queryForObject(eq("getMostRecentId"), any());
}
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