Fixed NPE when adding same job several times.
Closes elastic/elasticsearch#277 Original commit: elastic/x-pack-elasticsearch@42831113da
This commit is contained in:
parent
47a08171bd
commit
02a1c84c72
|
@ -168,7 +168,7 @@ public class SchedulerScheduleTriggerEngine extends ScheduleTriggerEngine {
|
||||||
ImmutableMap.Builder<String, ActiveSchedule> builder = ImmutableMap.builder();
|
ImmutableMap.Builder<String, ActiveSchedule> builder = ImmutableMap.builder();
|
||||||
for (int i = 0; i < schedules.length; i++) {
|
for (int i = 0; i < schedules.length; i++) {
|
||||||
ActiveSchedule sched = schedules[i].name.equals(schedule.name) ? schedule : schedules[i];
|
ActiveSchedule sched = schedules[i].name.equals(schedule.name) ? schedule : schedules[i];
|
||||||
schedules[i] = sched;
|
newSchedules[i] = sched;
|
||||||
builder.put(sched.name, sched);
|
builder.put(sched.name, sched);
|
||||||
}
|
}
|
||||||
return new Schedules(newSchedules, builder.build());
|
return new Schedules(newSchedules, builder.build());
|
||||||
|
|
|
@ -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 {
|
static class SimpleJob implements TriggerEngine.Job {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
Loading…
Reference in New Issue