use of com.thoughtworks.go.listener.EntityConfigChangedListener in project gocd by gocd.
the class PipelineSchedulerTest method shouldAddPipelineConfigToPipelinesOnPipelineConfigChanged.
@Test
public void shouldAddPipelineConfigToPipelinesOnPipelineConfigChanged() {
ArgumentCaptor<ConfigChangedListener> captor = ArgumentCaptor.forClass(ConfigChangedListener.class);
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 = "newly-added-pipeline";
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.EntityConfigChangedListener in project gocd by gocd.
the class TimerSchedulerTest method shouldRescheduleTimerTriggerPipelineWhenItsConfigChanges.
@Test
public void shouldRescheduleTimerTriggerPipelineWhenItsConfigChanges() throws SchedulerException {
GoConfigService goConfigService = mock(GoConfigService.class);
when(schedulerFactory.getScheduler()).thenReturn(scheduler);
String pipelineName = "timer-based-pipeline";
when(scheduler.getJobDetail(pipelineName, TimerScheduler.QUARTZ_GROUP)).thenReturn(mock(JobDetail.class));
TimerScheduler timerScheduler = new TimerScheduler(schedulerFactory, goConfigService, null, null);
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().getName(), is(pipelineName));
assertThat(triggerArgumentCaptor.getValue().getCronExpression(), is("* * * * * ?"));
verify(schedulerFactory).getScheduler();
verify(scheduler).start();
verify(scheduler).getJobDetail(pipelineName, TimerScheduler.QUARTZ_GROUP);
verify(scheduler).unscheduleJob(pipelineName, TimerScheduler.QUARTZ_GROUP);
verify(scheduler).deleteJob(pipelineName, TimerScheduler.QUARTZ_GROUP);
verify(scheduler).scheduleJob(jobDetailArgumentCaptor.getValue(), triggerArgumentCaptor.getValue());
}
Aggregations