Search in sources :

Example 1 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 2 with ServerHealthService

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

the class GoConfigFileHelper method createTestingDao.

/**
     * Creates config dao that accesses single file
     */
public static GoConfigDao createTestingDao() {
    SystemEnvironment systemEnvironment = new SystemEnvironment();
    try {
        ServerHealthService serverHealthService = new ServerHealthService();
        ConfigRepository configRepository = new ConfigRepository(systemEnvironment);
        configRepository.initialize();
        ConfigCache configCache = new ConfigCache();
        ConfigElementImplementationRegistry configElementImplementationRegistry = ConfigElementImplementationRegistryMother.withNoPlugins();
        CachedGoPartials cachedGoPartials = new CachedGoPartials(serverHealthService);
        FullConfigSaveNormalFlow normalFlow = new FullConfigSaveNormalFlow(configCache, configElementImplementationRegistry, systemEnvironment, new ServerVersion(), new TimeProvider(), configRepository, cachedGoPartials);
        GoFileConfigDataSource dataSource = new GoFileConfigDataSource(new DoNotUpgrade(), configRepository, systemEnvironment, new TimeProvider(), configCache, new ServerVersion(), configElementImplementationRegistry, serverHealthService, cachedGoPartials, null, normalFlow);
        dataSource.upgradeIfNecessary();
        CachedGoConfig cachedConfigService = new CachedGoConfig(serverHealthService, dataSource, cachedGoPartials, null, null);
        cachedConfigService.loadConfigIfNull();
        return new GoConfigDao(cachedConfigService);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ServerVersion(com.thoughtworks.go.server.util.ServerVersion) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) IOException(java.io.IOException) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService)

Example 3 with ServerHealthService

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

the class GoConfigFileHelper method createTestingDao.

/**
     * Creates config dao that has custom remote configuration parts provided by partialConfig argument
     */
public static GoConfigDao createTestingDao(GoPartialConfig partialConfig) {
    SystemEnvironment systemEnvironment = new SystemEnvironment();
    try {
        ServerHealthService serverHealthService = new ServerHealthService();
        ConfigRepository configRepository = new ConfigRepository(systemEnvironment);
        configRepository.initialize();
        FullConfigSaveNormalFlow normalFlow = new FullConfigSaveNormalFlow(new ConfigCache(), com.thoughtworks.go.util.ConfigElementImplementationRegistryMother.withNoPlugins(), systemEnvironment, new ServerVersion(), new TimeProvider(), configRepository, new CachedGoPartials(serverHealthService));
        GoFileConfigDataSource dataSource = new GoFileConfigDataSource(new DoNotUpgrade(), configRepository, systemEnvironment, new TimeProvider(), new ConfigCache(), new ServerVersion(), com.thoughtworks.go.util.ConfigElementImplementationRegistryMother.withNoPlugins(), serverHealthService, new CachedGoPartials(serverHealthService), null, normalFlow);
        dataSource.upgradeIfNecessary();
        CachedGoPartials cachedGoPartials = new CachedGoPartials(serverHealthService);
        CachedGoConfig cachedConfigService = new CachedGoConfig(serverHealthService, dataSource, cachedGoPartials, null, null);
        cachedConfigService.loadConfigIfNull();
        return new GoConfigDao(cachedConfigService);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ServerVersion(com.thoughtworks.go.server.util.ServerVersion) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) IOException(java.io.IOException) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService)

Example 4 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.getAllLogs()).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 5 with ServerHealthService

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

the class ScheduleServiceTest method setup.

@Before
public void setup() {
    jobInstanceService = mock(JobInstanceService.class);
    goConfigService = mock(GoConfigService.class);
    environmentConfigService = mock(EnvironmentConfigService.class);
    serverHealthService = mock(ServerHealthService.class);
    final TestTransactionSynchronizationManager synchronizationManager = new TestTransactionSynchronizationManager();
    schedulingChecker = mock(SchedulingCheckerService.class);
    pipelineScheduleQueue = mock(PipelineScheduleQueue.class);
    consoleActivityMonitor = mock(ConsoleActivityMonitor.class);
    pipelinePauseService = mock(PipelinePauseService.class);
    stageService = mock(StageService.class);
    securityService = mock(SecurityService.class);
    pipelineService = mock(PipelineService.class);
    localizer = mock(Localizer.class);
    timeProvider = new TimeProvider();
    schedulingPerformanceLogger = mock(SchedulingPerformanceLogger.class);
    elasticProfileService = mock(ElasticProfileService.class);
    service = new ScheduleService(goConfigService, pipelineService, stageService, schedulingChecker, mock(PipelineScheduledTopic.class), mock(PipelineDao.class), mock(StageDao.class), mock(StageOrderService.class), securityService, pipelineScheduleQueue, jobInstanceService, mock(JobInstanceDao.class), mock(AgentAssignment.class), environmentConfigService, mock(PipelineLockService.class), serverHealthService, new TestTransactionTemplate(synchronizationManager), mock(AgentService.class), synchronizationManager, timeProvider, consoleActivityMonitor, pipelinePauseService, instanceFactory, schedulingPerformanceLogger, elasticProfileService);
}
Also used : TestTransactionTemplate(com.thoughtworks.go.server.transaction.TestTransactionTemplate) TimeProvider(com.thoughtworks.go.util.TimeProvider) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) Localizer(com.thoughtworks.go.i18n.Localizer) SchedulingPerformanceLogger(com.thoughtworks.go.server.perf.SchedulingPerformanceLogger) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) Before(org.junit.Before)

Aggregations

ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)25 Before (org.junit.Before)12 Test (org.junit.Test)8 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 SchedulingPerformanceLogger (com.thoughtworks.go.server.perf.SchedulingPerformanceLogger)3 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)3 ServerVersion (com.thoughtworks.go.server.util.ServerVersion)3 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)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 Stage (com.thoughtworks.go.domain.Stage)2 JobStatusCache (com.thoughtworks.go.domain.activity.JobStatusCache)2 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)2