Search in sources :

Example 21 with SqlMapClientTemplate

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

Example 22 with SqlMapClientTemplate

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

Example 23 with SqlMapClientTemplate

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

Example 24 with SqlMapClientTemplate

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

Example 25 with SqlMapClientTemplate

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());
}
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