Search in sources :

Example 1 with ConfigChangedListener

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));
}
Also used : EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) Test(org.junit.jupiter.api.Test)

Example 2 with ConfigChangedListener

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);
}
Also used : ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) ConfigRepoReparseListener(com.thoughtworks.go.config.ConfigReposMaterialParseResultManager.ConfigRepoReparseListener) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ConfigChangedListener

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));
}
Also used : HealthStateScope(com.thoughtworks.go.serverhealth.HealthStateScope) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.jupiter.api.Test)

Example 4 with ConfigChangedListener

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));
}
Also used : ConfigReposConfig(com.thoughtworks.go.config.remote.ConfigReposConfig) ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigChangedListener

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);
}
Also used : EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigChangedListener (com.thoughtworks.go.listener.ConfigChangedListener)14 EntityConfigChangedListener (com.thoughtworks.go.listener.EntityConfigChangedListener)12 Test (org.junit.jupiter.api.Test)11 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)5 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)2 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)1 ConfigRepoReparseListener (com.thoughtworks.go.config.ConfigReposMaterialParseResultManager.ConfigRepoReparseListener)1 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)1 TimerConfig (com.thoughtworks.go.config.TimerConfig)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1 ConfigReposConfig (com.thoughtworks.go.config.remote.ConfigReposConfig)1 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 SecurityConfigChangeListener (com.thoughtworks.go.listener.SecurityConfigChangeListener)1 HealthStateScope (com.thoughtworks.go.serverhealth.HealthStateScope)1 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)1 Date (java.util.Date)1 Test (org.junit.Test)1