Search in sources :

Example 16 with ServerHealthService

use of com.thoughtworks.go.serverhealth.ServerHealthService in project gocd by gocd.

the class GoFileConfigDataSourceTest method shouldNotRetryConfigSaveWhenConfigRepoIsNotSetup.

@Test
public void shouldNotRetryConfigSaveWhenConfigRepoIsNotSetup() throws Exception {
    MagicalGoConfigXmlLoader loader = mock(MagicalGoConfigXmlLoader.class);
    MagicalGoConfigXmlWriter writer = mock(MagicalGoConfigXmlWriter.class);
    GoConfigMigration migration = mock(GoConfigMigration.class);
    ServerHealthService serverHealthService = mock(ServerHealthService.class);
    CachedGoPartials cachedGoPartials = mock(CachedGoPartials.class);
    ConfigRepository configRepository = mock(ConfigRepository.class);
    dataSource = new GoFileConfigDataSource(migration, configRepository, systemEnvironment, timeProvider, mock(ServerVersion.class), loader, writer, serverHealthService, cachedGoPartials, null, null, null, null);
    final String pipelineName = UUID.randomUUID().toString();
    BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines(pipelineName);
    ConfigErrors configErrors = new ConfigErrors();
    configErrors.add("key", "some error");
    when(loader.loadConfigHolder(Matchers.any(String.class))).thenThrow(new GoConfigInvalidException(cruiseConfig, configErrors.firstError()));
    try {
        dataSource.writeWithLock(new UpdateConfigCommand() {

            @Override
            public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
                cruiseConfig.getPipelineConfigByName(new CaseInsensitiveString(pipelineName)).clear();
                return cruiseConfig;
            }
        }, new GoConfigHolder(cruiseConfig, cruiseConfig));
        fail("expected the test to fail");
    } catch (Exception e) {
        verifyZeroInteractions(configRepository);
        verifyZeroInteractions(serverHealthService);
        verify(loader, times(1)).loadConfigHolder(Matchers.any(String.class), Matchers.any(MagicalGoConfigXmlLoader.Callback.class));
    }
}
Also used : ConfigRepository(com.thoughtworks.go.service.ConfigRepository) StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ExpectedException(org.junit.rules.ExpectedException) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) IOException(java.io.IOException) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) ConfigErrors(com.thoughtworks.go.domain.ConfigErrors) Test(org.junit.Test)

Example 17 with ServerHealthService

use of com.thoughtworks.go.serverhealth.ServerHealthService in project gocd by gocd.

the class PipelineServiceTriangleDependencyTest method stubPipelineSaveForStatusListener.

private Pipeline stubPipelineSaveForStatusListener(StageStatusListener stageStatusListener, JobStatusListener jobStatusListener) {
    StageDao stageDao = mock(StageDao.class);
    ServerHealthService serverHealthService = mock(ServerHealthService.class);
    when(serverHealthService.logs()).thenReturn(new ServerHealthStates());
    JobInstanceService jobInstanceService = new JobInstanceService(mock(JobInstanceDao.class), mock(PropertiesService.class), mock(JobResultTopic.class), mock(JobStatusCache.class), actualTransactionTemplate, transactionSynchronizationManager, null, null, goConfigService, null, pluginManager, serverHealthService, jobStatusListener);
    StageService stageService = new StageService(stageDao, jobInstanceService, mock(StageStatusTopic.class), mock(StageStatusCache.class), mock(SecurityService.class), mock(PipelineDao.class), mock(ChangesetService.class), mock(GoConfigService.class), actualTransactionTemplate, transactionSynchronizationManager, goCache);
    Stage savedStage = StageMother.passedStageInstance("stage", "job", "pipeline-name");
    when(stageDao.save(any(Pipeline.class), any(Stage.class))).thenReturn(savedStage);
    stageService.addStageStatusListener(stageStatusListener);
    service = new PipelineService(pipelineDao, stageService, mock(PipelineLockService.class), pipelineTimeline, materialRepository, actualTransactionTemplate, systemEnvironment, null, materialConfigConverter);
    Pipeline pipeline = PipelineMother.pipeline("cruise", savedStage);
    when(pipelineDao.save(pipeline)).thenReturn(pipeline);
    when(pipelineTimeline.pipelineBefore(anyLong())).thenReturn(9L);
    when(pipelineTimeline.pipelineAfter(pipeline.getId())).thenReturn(-1L);
    when(materialRepository.findMaterialRevisionsForPipeline(9L)).thenReturn(MaterialRevisions.EMPTY);
    return pipeline;
}
Also used : StageDao(com.thoughtworks.go.server.dao.StageDao) JobResultTopic(com.thoughtworks.go.server.messaging.JobResultTopic) StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) ServerHealthStates(com.thoughtworks.go.serverhealth.ServerHealthStates) JobInstanceDao(com.thoughtworks.go.server.dao.JobInstanceDao) Pipeline(com.thoughtworks.go.domain.Pipeline) StageStatusCache(com.thoughtworks.go.domain.activity.StageStatusCache) JobStatusCache(com.thoughtworks.go.domain.activity.JobStatusCache) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) PipelineDao(com.thoughtworks.go.server.dao.PipelineDao) Stage(com.thoughtworks.go.domain.Stage)

Example 18 with ServerHealthService

use of com.thoughtworks.go.serverhealth.ServerHealthService in project gocd by gocd.

the class JobInstanceServiceTest method shouldRemoveJobRelatedServerHealthMessagesOnPipelineConfigChange.

@Test
public void shouldRemoveJobRelatedServerHealthMessagesOnPipelineConfigChange() {
    ServerHealthService serverHealthService = new ServerHealthService();
    serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(HealthStateScope.forJob("p1", "s1", "j1"))));
    serverHealthService.update(ServerHealthState.error("message", "description", HealthStateType.general(HealthStateScope.forJob("p2", "s2", "j2"))));
    assertThat(serverHealthService.getAllLogs().errorCount(), is(2));
    JobInstanceService jobService = new JobInstanceService(jobInstanceDao, null, null, jobStatusCache, transactionTemplate, transactionSynchronizationManager, null, null, goConfigService, null, pluginManager, serverHealthService);
    JobInstanceService.PipelineConfigChangedListener pipelineConfigChangedListener = jobService.new PipelineConfigChangedListener();
    pipelineConfigChangedListener.onEntityConfigChange(PipelineConfigMother.pipelineConfig("p1", "s_new", new MaterialConfigs(), "j1"));
    assertThat(serverHealthService.getAllLogs().errorCount(), is(1));
    assertThat(serverHealthService.getAllLogs().get(0).getType().getScope().getScope(), is("p2/s2/j2"));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) Test(org.junit.Test)

Example 19 with ServerHealthService

use of com.thoughtworks.go.serverhealth.ServerHealthService in project gocd by gocd.

the class AutoBuildCauseTest method setUp.

@Before
public void setUp() throws Exception {
    initMocks(this);
    cruiseConfig = new BasicCruiseConfig();
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    when(materialChecker.hasPipelineEverRunWith(any(String.class), any(MaterialRevisions.class))).thenReturn(false);
    serverHealthService = new ServerHealthService();
}
Also used : MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) Before(org.junit.Before)

Example 20 with ServerHealthService

use of com.thoughtworks.go.serverhealth.ServerHealthService in project gocd by gocd.

the class CachedGoPartialsTest method setUp.

@Before
public void setUp() throws Exception {
    serverHealthService = new ServerHealthService();
    partials = new CachedGoPartials(serverHealthService);
    configRepo1 = new ConfigRepoConfig(new GitMaterialConfig("url1"), "plugin");
    part1 = PartialConfigMother.withPipeline("p1", new RepoConfigOrigin(configRepo1, "1"));
    configRepo2 = new ConfigRepoConfig(new GitMaterialConfig("url2"), "plugin");
    part2 = PartialConfigMother.withPipeline("p2", new RepoConfigOrigin(configRepo2, "1"));
    partials.addOrUpdate(configRepo1.getMaterialConfig().getFingerprint(), part1);
    partials.addOrUpdate(configRepo2.getMaterialConfig().getFingerprint(), part2);
    fingerprintForRepo1 = ((RepoConfigOrigin) part1.getOrigin()).getMaterial().getFingerprint();
    fingerprintForRepo2 = ((RepoConfigOrigin) part2.getOrigin()).getMaterial().getFingerprint();
}
Also used : ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Before(org.junit.Before)

Aggregations

ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)26 Before (org.junit.Before)13 Test (org.junit.Test)7 SchedulingPerformanceLogger (com.thoughtworks.go.server.perf.SchedulingPerformanceLogger)4 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)4 ConfigRepository (com.thoughtworks.go.service.ConfigRepository)4 IOException (java.io.IOException)4 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)3 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)3 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)3 TestTransactionTemplate (com.thoughtworks.go.server.transaction.TestTransactionTemplate)3 ServerVersion (com.thoughtworks.go.server.util.ServerVersion)3 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)3 TimeProvider (com.thoughtworks.go.util.TimeProvider)3 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)2 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)2 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)2 ConfigElementImplementationRegistry (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry)2 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)2 Pipeline (com.thoughtworks.go.domain.Pipeline)2