Search in sources :

Example 16 with SqlMapClientTemplate

use of org.springframework.orm.ibatis.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(stages);
    Stages actual = stageDao.findAllStagesFor("pipeline", 1);
    assertThat(actual, is(new Stages(stages)));
    //Should return from cache
    actual = stageDao.findAllStagesFor("pipeline", 1);
    assertThat(actual, is(new Stages(stages)));
    verify(mockTemplate, times(1)).queryForList("getStagesByPipelineNameAndCounter", arguments("pipelineName", "pipeline").and("pipelineCounter", 1).asMap());
}
Also used : SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Test(org.junit.Test)

Example 17 with SqlMapClientTemplate

use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method findStageWithIdentifier_shouldRemoveFromTheCacheOnSave.

@Test
public void findStageWithIdentifier_shouldRemoveFromTheCacheOnSave() {
    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"));
    assertEquals(first, actual);
    Pipeline pipeline = new Pipeline("pipeline", "label", BuildCause.createManualForced(), first);
    pipeline.setCounter(1);
    //save stage 2.. This should invalidate the stage 1 because of the latest run state.
    stageDao.save(pipeline, second);
    stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
    verify(mockTemplate, times(2)).queryForObject(eq("findStageWithJobsByIdentifier"), any());
}
Also used : SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Test(org.junit.Test)

Example 18 with SqlMapClientTemplate

use of org.springframework.orm.ibatis.SqlMapClientTemplate in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method getTotalStageCountForChart_shouldInvalidateTheCountCacheOnStageUpdate.

@Test
public void getTotalStageCountForChart_shouldInvalidateTheCountCacheOnStageUpdate() 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).thenReturn(4);
    //Should prime the cache
    assertThat(stageDao.getTotalStageCountForChart("maar", "khoon"), is(3));
    Stage stage = new Stage("khoon", new JobInstances(), "foo", "manual", new TimeProvider());
    stage.setIdentifier(new StageIdentifier("maar/2/khoon/1"));
    //Should Invalidate the cache
    updateResultInTransaction(stage, StageResult.Cancelled);
    //should refetch
    assertThat(stageDao.getTotalStageCountForChart("maar", "khoon"), is(4));
    verify(mockClient, times(2)).queryForObject("getTotalStageCountForChart", toGet);
}
Also used : SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Test(org.junit.Test)

Example 19 with SqlMapClientTemplate

use of org.springframework.orm.ibatis.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"));
    assertEquals(stage, actual);
    stageDao.findStageWithIdentifier(new StageIdentifier("pipeline", 1, "stage", "1"));
    verify(mockTemplate, times(1)).queryForObject(eq("findStageWithJobsByIdentifier"), any());
}
Also used : SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Test(org.junit.Test)

Example 20 with SqlMapClientTemplate

use of org.springframework.orm.ibatis.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(expected, 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(), is(2));
    assertThat(actual, hasItem(newStage));
    assertThat(actual, hasItem(first));
    verify(mockTemplate, times(2)).queryForList(eq("getAllRunsOfStageForPipelineInstance"), any());
}
Also used : SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Test(org.junit.Test)

Aggregations

SqlMapClientTemplate (org.springframework.orm.ibatis.SqlMapClientTemplate)35 Test (org.junit.Test)34 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)8 Method (java.lang.reflect.Method)8 StageHistoryEntry (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryEntry)2 StageHistoryPage (com.thoughtworks.go.presentation.pipelinehistory.StageHistoryPage)2 TransactionManager (com.ibatis.sqlmap.engine.transaction.TransactionManager)1 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 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)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 Before (org.junit.Before)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1