Fixed NPE when adding same job several times.

Closes elastic/elasticsearch#277

Original commit: elastic/x-pack-elasticsearch@42831113da
This commit is contained in:
Martijn van Groningen 2015-04-29 20:10:51 +02:00
parent 47a08171bd
commit 02a1c84c72
2 changed files with 18 additions and 1 deletions

View File

@ -168,7 +168,7 @@ public class SchedulerScheduleTriggerEngine extends ScheduleTriggerEngine {
ImmutableMap.Builder<String, ActiveSchedule> 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());

View File

@ -193,6 +193,23 @@ public abstract class BaseTriggerEngineTests extends ElasticsearchTestCase {
}
}
@Test
public void testAddSameJobSeveralTimes() {
engine.start(Collections.<TriggerEngine.Job>emptySet());
engine.register(new TriggerEngine.Listener() {
@Override
public void triggered(Iterable<TriggerEvent> 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;