Search in sources :

Example 6 with ConfigChangedListener

use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.

the class CcTrayActivityListenerTest method shouldInvokeConfigChangeHandlerWhenPipelineConfigChanges.

@Test
public void shouldInvokeConfigChangeHandlerWhenPipelineConfigChanges() 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());
    when(goConfigService.findGroupNameByPipeline(p1)).thenReturn("group1");
    CcTrayActivityListener listener = new CcTrayActivityListener(goConfigService, mock(CcTrayJobStatusChangeHandler.class), mock(CcTrayStageStatusChangeHandler.class), ccTrayConfigChangeHandler);
    listener.initialize();
    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, "group1");
}
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.Test)

Example 7 with ConfigChangedListener

use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.

the class GoConfigServiceTest method shouldRegisterListenerWithTheConfigDAO.

@Test
public void shouldRegisterListenerWithTheConfigDAO() {
    final ConfigChangedListener listener = mock(ConfigChangedListener.class);
    goConfigService.register(listener);
    verify(goConfigDao).registerListener(listener);
}
Also used : ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) Test(org.junit.jupiter.api.Test)

Example 8 with ConfigChangedListener

use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.

the class PipelineSchedulerTest method shouldAddPipelineConfigToPipelinesOnPipelineConfigChanged.

@Test
public void shouldAddPipelineConfigToPipelinesOnPipelineConfigChanged() {
    ArgumentCaptor<ConfigChangedListener> captor = ArgumentCaptor.forClass(ConfigChangedListener.class);
    PipelineConfig newPipeline = mock(PipelineConfig.class);
    String pipelineName = "newly-added-pipeline";
    ArrayList<PipelineConfig> pipelineConfigs = new ArrayList<>();
    pipelineConfigs.add(newPipeline);
    when(configService.getAllPipelineConfigs()).thenReturn(pipelineConfigs);
    doNothing().when(configService).register(captor.capture());
    scheduler.initialize();
    List<ConfigChangedListener> listeners = captor.getAllValues();
    assertThat(listeners.contains(scheduler), is(true));
    assertThat(listeners.get(1) instanceof EntityConfigChangedListener, is(true));
    EntityConfigChangedListener<PipelineConfig> entityConfigChangedListener = (EntityConfigChangedListener<PipelineConfig>) listeners.get(1);
    when(newPipeline.name()).thenReturn(new CaseInsensitiveString(pipelineName));
    entityConfigChangedListener.onEntityConfigChange(newPipeline);
    scheduler.checkPipelines();
    verify(queue, times(1)).post(ScheduleCheckMessageMatcher.matchScheduleCheckMessage(pipelineName));
}
Also used : ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.jupiter.api.Test)

Example 9 with ConfigChangedListener

use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.

the class PipelineSchedulerTest method shouldRemovePipelineConfigFromPipelinesOnPipelineConfigDeletion.

@Test
public void shouldRemovePipelineConfigFromPipelinesOnPipelineConfigDeletion() {
    ArgumentCaptor<ConfigChangedListener> captor = ArgumentCaptor.forClass(ConfigChangedListener.class);
    when(configService.getAllPipelineConfigs()).thenReturn(new ArrayList<>());
    doNothing().when(configService).register(captor.capture());
    scheduler.initialize();
    List<ConfigChangedListener> listeners = captor.getAllValues();
    assertThat(listeners.contains(scheduler), is(true));
    assertThat(listeners.get(1) instanceof EntityConfigChangedListener, is(true));
    EntityConfigChangedListener<PipelineConfig> entityConfigChangedListener = (EntityConfigChangedListener<PipelineConfig>) listeners.get(1);
    PipelineConfig newPipeline = mock(PipelineConfig.class);
    String pipelineName = "deleted-pipeline";
    when(newPipeline.name()).thenReturn(new CaseInsensitiveString(pipelineName));
    entityConfigChangedListener.onEntityConfigChange(newPipeline);
    scheduler.checkPipelines();
    verify(queue, times(0)).post(ScheduleCheckMessageMatcher.matchScheduleCheckMessage(pipelineName));
}
Also used : ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.jupiter.api.Test)

Example 10 with ConfigChangedListener

use of com.thoughtworks.go.listener.ConfigChangedListener in project gocd by gocd.

the class TimerSchedulerTest method shouldRescheduleTimerTriggerPipelineWhenItsConfigChanges.

@Test
public void shouldRescheduleTimerTriggerPipelineWhenItsConfigChanges() throws SchedulerException {
    String pipelineName = "timer-based-pipeline";
    when(scheduler.getJobDetail(jobKey(pipelineName, PIPELINE_TRIGGGER_TIMER_GROUP))).thenReturn(mock(JobDetail.class));
    TimerScheduler timerScheduler = new TimerScheduler(scheduler, goConfigService, null, null, maintenanceModeService, systemEnvironment);
    ArgumentCaptor<ConfigChangedListener> captor = ArgumentCaptor.forClass(ConfigChangedListener.class);
    doNothing().when(goConfigService).register(captor.capture());
    timerScheduler.initialize();
    List<ConfigChangedListener> listeners = captor.getAllValues();
    assertThat(listeners.get(1) instanceof EntityConfigChangedListener, is(true));
    EntityConfigChangedListener<PipelineConfig> pipelineConfigChangeListener = (EntityConfigChangedListener<PipelineConfig>) listeners.get(1);
    PipelineConfig pipelineConfig = mock(PipelineConfig.class);
    when(pipelineConfig.name()).thenReturn(new CaseInsensitiveString(pipelineName));
    when(pipelineConfig.getTimer()).thenReturn(new TimerConfig("* * * * * ?", true));
    ArgumentCaptor<JobDetail> jobDetailArgumentCaptor = ArgumentCaptor.forClass(JobDetail.class);
    ArgumentCaptor<CronTrigger> triggerArgumentCaptor = ArgumentCaptor.forClass(CronTrigger.class);
    when(scheduler.scheduleJob(jobDetailArgumentCaptor.capture(), triggerArgumentCaptor.capture())).thenReturn(new Date());
    pipelineConfigChangeListener.onEntityConfigChange(pipelineConfig);
    assertThat(jobDetailArgumentCaptor.getValue().getKey().getName(), is(pipelineName));
    assertThat(triggerArgumentCaptor.getValue().getCronExpression(), is("* * * * * ?"));
    verify(scheduler).getJobDetail(jobKey(pipelineName, PIPELINE_TRIGGGER_TIMER_GROUP));
    verify(scheduler).unscheduleJob(triggerKey(pipelineName, PIPELINE_TRIGGGER_TIMER_GROUP));
    verify(scheduler).deleteJob(jobKey(pipelineName, PIPELINE_TRIGGGER_TIMER_GROUP));
    verify(scheduler).scheduleJob(jobDetailArgumentCaptor.getValue(), triggerArgumentCaptor.getValue());
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) TimerConfig(com.thoughtworks.go.config.TimerConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) 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