Search in sources :

Example 1 with GoConfigDao

use of com.thoughtworks.go.config.GoConfigDao in project gocd by gocd.

the class PipelineSqlMapDaoCachingTest method loadActivePipelines_shouldCacheResult.

@Test
public void loadActivePipelines_shouldCacheResult() {
    final String pipelineName = "pipeline";
    CruiseConfig mockCruiseConfig = mock(BasicCruiseConfig.class);
    GoConfigDao mockconfigFileDao = mock(GoConfigDao.class);
    when(mockconfigFileDao.load()).thenReturn(mockCruiseConfig);
    when(mockCruiseConfig.getAllPipelineNames()).thenReturn(Arrays.asList(new CaseInsensitiveString(pipelineName)));
    //need to mock configfileDao for this test
    pipelineDao = new PipelineSqlMapDao(null, repository, goCache, environmentVariableDao, transactionTemplate, null, transactionSynchronizationManager, systemEnvironment, mockconfigFileDao, databaseStrategy);
    pipelineDao.setSqlMapClientTemplate(mockTemplate);
    PipelineInstanceModel pipeline = new PipelineInstanceModel(pipelineName, -2, "label", BuildCause.createManualForced(), new StageInstanceModels());
    PipelineInstanceModels pims = PipelineInstanceModels.createPipelineInstanceModels(pipeline);
    when(mockTemplate.queryForList("allActivePipelines")).thenReturn(pims);
    when(mockTemplate.queryForObject(eq("getPipelineHistoryById"), any())).thenReturn(pipeline);
    PipelineInstanceModels loaded;
    loaded = pipelineDao.loadActivePipelines();
    loaded = pipelineDao.loadActivePipelines();
    assertNotSame(pipeline, loaded);
    assertTrue(ToStringBuilder.reflectionToString(loaded) + " not equal to\n" + ToStringBuilder.reflectionToString(pipeline), EqualsBuilder.reflectionEquals(loaded, pims));
    verify(mockTemplate, times(1)).queryForList("allActivePipelines");
    verify(mockTemplate, times(1)).queryForObject(eq("getPipelineHistoryById"), any());
    verify(mockconfigFileDao, times(2)).load();
    verify(mockCruiseConfig, times(2)).getAllPipelineNames();
}
Also used : CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) GoConfigDao(com.thoughtworks.go.config.GoConfigDao) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 2 with GoConfigDao

use of com.thoughtworks.go.config.GoConfigDao in project gocd by gocd.

the class PipelineSqlMapDaoCachingTest method shouldRemovePipelineIdFromCacheWhenStageFinishesForNonLatestPipeline.

@Test
public void shouldRemovePipelineIdFromCacheWhenStageFinishesForNonLatestPipeline() {
    final String pipelineName = "pipeline";
    CruiseConfig mockCruiseConfig = mock(BasicCruiseConfig.class);
    GoConfigDao mockconfigFileDao = mock(GoConfigDao.class);
    when(mockconfigFileDao.load()).thenReturn(mockCruiseConfig);
    when(mockCruiseConfig.getAllPipelineNames()).thenReturn(Arrays.asList(new CaseInsensitiveString(pipelineName)));
    //need to mock configfileDao for this test
    pipelineDao = new PipelineSqlMapDao(null, repository, goCache, environmentVariableDao, transactionTemplate, null, transactionSynchronizationManager, systemEnvironment, mockconfigFileDao, databaseStrategy);
    pipelineDao.setSqlMapClientTemplate(mockTemplate);
    PipelineInstanceModel first = model(1, JobState.Building, JobResult.Unknown);
    PipelineInstanceModel second = model(2, JobState.Building, JobResult.Unknown);
    PipelineInstanceModels pims = PipelineInstanceModels.createPipelineInstanceModels(first, second);
    when(mockTemplate.queryForList("allActivePipelines")).thenReturn(pims);
    when(mockTemplate.queryForObject("getPipelineHistoryById", arguments("id", 1L).asMap())).thenReturn(first);
    when(mockTemplate.queryForObject("getPipelineHistoryById", arguments("id", 2L).asMap())).thenReturn(second);
    // ensure cache is initialized
    pipelineDao.loadActivePipelines();
    Stage stage = new Stage("first", new JobInstances(JobInstanceMother.assigned("job")), "me", "whatever", new TimeProvider());
    stage.fail();
    stage.calculateResult();
    changeStageStatus(stage, 1);
    //notifying latest id should not remove it from the cache
    stage.setPipelineId(2l);
    pipelineDao.stageStatusChanged(stage);
    PipelineInstanceModels models = pipelineDao.loadActivePipelines();
    assertThat(models.size(), is(1));
    assertThat(models.get(0).getId(), is(2L));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) GoConfigDao(com.thoughtworks.go.config.GoConfigDao) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 3 with GoConfigDao

use of com.thoughtworks.go.config.GoConfigDao in project gocd by gocd.

the class PipelineSqlMapDaoCachingTest method shouldRemovePipelineIdFromCacheWhenPipelineCeasesToBeTheLatestAndIsNotActive.

@Test
public void shouldRemovePipelineIdFromCacheWhenPipelineCeasesToBeTheLatestAndIsNotActive() {
    final String pipelineName = "pipeline";
    CruiseConfig mockCruiseConfig = mock(BasicCruiseConfig.class);
    GoConfigDao mockconfigFileDao = mock(GoConfigDao.class);
    when(mockconfigFileDao.load()).thenReturn(mockCruiseConfig);
    when(mockCruiseConfig.getAllPipelineNames()).thenReturn(Arrays.asList(new CaseInsensitiveString(pipelineName)));
    //need to mock configfileDao for this test
    pipelineDao = new PipelineSqlMapDao(null, repository, goCache, environmentVariableDao, transactionTemplate, null, transactionSynchronizationManager, systemEnvironment, mockconfigFileDao, databaseStrategy);
    pipelineDao.setSqlMapClientTemplate(mockTemplate);
    PipelineInstanceModel first = model(1, JobState.Completed, JobResult.Passed);
    PipelineInstanceModel second = model(2, JobState.Building, JobResult.Unknown);
    PipelineInstanceModels pims = PipelineInstanceModels.createPipelineInstanceModels(first);
    when(mockTemplate.queryForList("allActivePipelines")).thenReturn(pims);
    when(mockTemplate.queryForObject("getPipelineHistoryById", arguments("id", 1L).asMap())).thenReturn(first);
    when(mockTemplate.queryForObject("getPipelineHistoryById", arguments("id", 2L).asMap())).thenReturn(second);
    // ensure cache is initialized
    pipelineDao.loadActivePipelines();
    changeStageStatus(2);
    PipelineInstanceModels models = pipelineDao.loadActivePipelines();
    assertThat(models.size(), is(1));
    assertThat(models.get(0).getId(), is(2L));
}
Also used : CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) GoConfigDao(com.thoughtworks.go.config.GoConfigDao) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)3 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)3 Test (org.junit.Test)3 TimeProvider (com.thoughtworks.go.util.TimeProvider)1