Search in sources :

Example 11 with EntityConfigChangedListener

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));
}
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.Test)

Example 12 with EntityConfigChangedListener

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

Aggregations

EntityConfigChangedListener (com.thoughtworks.go.listener.EntityConfigChangedListener)12 Test (org.junit.Test)10 ConfigChangedListener (com.thoughtworks.go.listener.ConfigChangedListener)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)4 DefaultLocalizedOperationResult (com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult)2 TimerConfig (com.thoughtworks.go.config.TimerConfig)1 EntityConfigUpdateCommand (com.thoughtworks.go.config.commands.EntityConfigUpdateCommand)1 Username (com.thoughtworks.go.server.domain.Username)1 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)1 HealthStateScope (com.thoughtworks.go.serverhealth.HealthStateScope)1 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)1 Date (java.util.Date)1 Closure (org.apache.commons.collections.Closure)1