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