diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/engine/SchedulerScheduleTriggerEngine.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/engine/SchedulerScheduleTriggerEngine.java index ad70f728158..64e50b3e2f6 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/engine/SchedulerScheduleTriggerEngine.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/engine/SchedulerScheduleTriggerEngine.java @@ -168,7 +168,7 @@ public class SchedulerScheduleTriggerEngine extends ScheduleTriggerEngine { ImmutableMap.Builder builder = ImmutableMap.builder(); for (int i = 0; i < schedules.length; i++) { ActiveSchedule sched = schedules[i].name.equals(schedule.name) ? schedule : schedules[i]; - schedules[i] = sched; + newSchedules[i] = sched; builder.put(sched.name, sched); } return new Schedules(newSchedules, builder.build()); diff --git a/src/test/java/org/elasticsearch/watcher/trigger/schedule/engine/BaseTriggerEngineTests.java b/src/test/java/org/elasticsearch/watcher/trigger/schedule/engine/BaseTriggerEngineTests.java index a5a3e269e9e..83a50832cff 100644 --- a/src/test/java/org/elasticsearch/watcher/trigger/schedule/engine/BaseTriggerEngineTests.java +++ b/src/test/java/org/elasticsearch/watcher/trigger/schedule/engine/BaseTriggerEngineTests.java @@ -193,6 +193,23 @@ public abstract class BaseTriggerEngineTests extends ElasticsearchTestCase { } } + @Test + public void testAddSameJobSeveralTimes() { + engine.start(Collections.emptySet()); + engine.register(new TriggerEngine.Listener() { + + @Override + public void triggered(Iterable events) { + logger.info("triggered job on [{}]", new DateTime()); + } + }); + + int times = scaledRandomIntBetween(3, 30); + for (int i = 0; i < times; i++) { + engine.add(new SimpleJob("_id", interval("10s"))); + } + } + static class SimpleJob implements TriggerEngine.Job { private final String name;