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