use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.
the class CachedGoConfigTest method shouldNotifyConfigListenersWhenConfigChanges.
@Test
public void shouldNotifyConfigListenersWhenConfigChanges() throws Exception {
when(dataSource.writeWithLock(any(UpdateConfigCommand.class), any(GoConfigHolder.class))).thenReturn(new GoFileConfigDataSource.GoConfigSaveResult(configHolder, ConfigSaveState.UPDATED));
final ConfigChangedListener listener = mock(ConfigChangedListener.class);
cachedGoConfig.registerListener(listener);
cachedGoConfig.forceReload();
cachedGoConfig.writeWithLock(new UpdateConfigCommand() {
@Override
public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
return cruiseConfig;
}
});
verify(listener, times(2)).onConfigChange(any(BasicCruiseConfig.class));
}
use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.
the class ConfigReposMaterialParseResultManagerTest method shouldAddEntityConfigChangedListeners.
@Test
void shouldAddEntityConfigChangedListeners() {
final GoConfigService goConfigService = mock(GoConfigService.class);
manager.attachConfigUpdateListeners(goConfigService);
final ArgumentCaptor<ConfigChangedListener> listenerArgumentCaptor = ArgumentCaptor.forClass(ConfigChangedListener.class);
verify(goConfigService).register(listenerArgumentCaptor.capture());
assertTrue(listenerArgumentCaptor.getValue() instanceof ConfigRepoReparseListener);
}
use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.
the class InvalidConfigMessageRemoverTest method shouldRemoveServerHealthServiceMessageAboutStartedWithInvalidConfigurationOnPipelineConfigSave.
@Test
public void shouldRemoveServerHealthServiceMessageAboutStartedWithInvalidConfigurationOnPipelineConfigSave() {
GoConfigService goConfigService = mock(GoConfigService.class);
ServerHealthService serverHealthService = mock(ServerHealthService.class);
ArgumentCaptor<ConfigChangedListener> configChangedListenerArgumentCaptor = ArgumentCaptor.forClass(ConfigChangedListener.class);
doNothing().when(goConfigService).register(configChangedListenerArgumentCaptor.capture());
InvalidConfigMessageRemover invalidConfigMessageRemover = new InvalidConfigMessageRemover(goConfigService, serverHealthService);
invalidConfigMessageRemover.initialize();
invalidConfigMessageRemover.onConfigChange(null);
List<ConfigChangedListener> listeners = configChangedListenerArgumentCaptor.getAllValues();
assertThat(listeners.get(1) instanceof EntityConfigChangedListener, is(true));
EntityConfigChangedListener listener = (EntityConfigChangedListener) listeners.get(1);
assertThat(listener.shouldCareAbout(mock(PipelineConfig.class)), is(true));
invalidConfigMessageRemover.pipelineConfigChangedListener().onEntityConfigChange(mock(PipelineConfig.class));
ArgumentCaptor<HealthStateScope> captor = ArgumentCaptor.forClass(HealthStateScope.class);
verify(serverHealthService).removeByScope(captor.capture());
assertThat(captor.getValue().compareTo(HealthStateScope.forInvalidConfig()), is(0));
}
use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.
the class PipelineSchedulerTest method shouldRemovePipelinesOnConfigRepoDeletion.
@Test
public void shouldRemovePipelinesOnConfigRepoDeletion() {
// setup 2 config repos
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
ConfigRepoConfig repoConfig1 = ConfigRepoConfig.createConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url1"), "plugin", "id1");
ConfigRepoConfig repoConfig2 = ConfigRepoConfig.createConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url2"), "plugin", "id2");
cruiseConfig.setConfigRepos(new ConfigReposConfig(repoConfig1, repoConfig2));
PartialConfig partialConfigInRepo1 = PartialConfigMother.withPipeline("pipeline_in_repo1", new RepoConfigOrigin(repoConfig1, "repo1_r1"));
PartialConfig partialConfigInRepo2 = PartialConfigMother.withPipeline("pipeline_in_repo2", new RepoConfigOrigin(repoConfig2, "repo2_r1"));
cruiseConfig.merge(asList(partialConfigInRepo1, partialConfigInRepo2), false);
when(configService.cruiseConfig()).thenReturn(cruiseConfig);
ArgumentCaptor<ConfigChangedListener> captor = ArgumentCaptor.forClass(ConfigChangedListener.class);
doNothing().when(configService).register(captor.capture());
scheduler.initialize();
List<ConfigChangedListener> listeners = captor.getAllValues();
listeners.get(0).onConfigChange(cruiseConfig);
assertThat(listeners.contains(scheduler), is(true));
assertThat(listeners.get(2) instanceof EntityConfigChangedListener, is(true));
EntityConfigChangedListener<ConfigRepoConfig> entityConfigChangedListener = (EntityConfigChangedListener<ConfigRepoConfig>) listeners.get(2);
// both should get scheduled
scheduler.checkPipelines();
verify(queue, times(2)).post(any(ScheduleCheckMessage.class));
// reset
scheduler.onMessage(new ScheduleCheckCompletedMessage("pipeline_in_repo1", 0));
scheduler.onMessage(new ScheduleCheckCompletedMessage("pipeline_in_repo2", 0));
reset(queue);
// remove one config repo
BasicCruiseConfig updatedConfig = new BasicCruiseConfig();
updatedConfig.setConfigRepos(new ConfigReposConfig(repoConfig1, repoConfig2));
updatedConfig.merge(Collections.singletonList(partialConfigInRepo1), false);
when(configService.cruiseConfig()).thenReturn(updatedConfig);
entityConfigChangedListener.onEntityConfigChange(null);
// removed pipeline should not get scheduled
scheduler.checkPipelines();
verify(queue, times(1)).post(any(ScheduleCheckMessage.class));
}
use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.
the class CcTrayActivityListenerTest method postIntializationAndStartOfDaemon_WhenPipelineConfigChanges_ShouldInvokeConfigChangeHandler.
@Test
public void postIntializationAndStartOfDaemon_WhenPipelineConfigChanges_ShouldInvokeConfigChangeHandler() throws InterruptedException {
PipelineConfig pipelineConfig = mock(PipelineConfig.class);
CaseInsensitiveString p1 = new CaseInsensitiveString("p1");
when(pipelineConfig.name()).thenReturn(p1);
CcTrayConfigChangeHandler ccTrayConfigChangeHandler = mock(CcTrayConfigChangeHandler.class);
ArgumentCaptor<ConfigChangedListener> captor = ArgumentCaptor.forClass(ConfigChangedListener.class);
doNothing().when(goConfigService).register(captor.capture());
CcTrayActivityListener listener = new CcTrayActivityListener(goConfigService, mock(CcTrayJobStatusChangeHandler.class), mock(CcTrayStageStatusChangeHandler.class), ccTrayConfigChangeHandler);
listener.initialize();
listener.startDaemon();
List<ConfigChangedListener> listeners = captor.getAllValues();
assertThat(listeners.get(1) instanceof EntityConfigChangedListener, is(true));
EntityConfigChangedListener<PipelineConfig> pipelineConfigChangeListener = (EntityConfigChangedListener<PipelineConfig>) listeners.get(1);
pipelineConfigChangeListener.onEntityConfigChange(pipelineConfig);
waitForProcessingToHappen();
verify(ccTrayConfigChangeHandler).call(pipelineConfig);
}
Aggregations