initialize scheduler in constructor

Original commit: elastic/x-pack-elasticsearch@283ddf3aa3
This commit is contained in:
Areek Zillur 2016-07-06 17:11:08 -04:00
parent 3150bfa876
commit 827d68c7b0
2 changed files with 5 additions and 17 deletions

View File

@ -130,10 +130,8 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
}
populateExpirationCallbacks();
this.clock = clock;
}
protected SchedulerEngine getScheduler() {
return new SchedulerEngine(clock);
this.scheduler = new SchedulerEngine(clock);
this.scheduler.register(this);
}
private void populateExpirationCallbacks() {
@ -395,10 +393,6 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
@Override
protected void doStart() throws ElasticsearchException {
if (scheduler == null) {
this.scheduler = getScheduler();
this.scheduler.register(this);
}
clusterService.add(this);
try {
scheduler.start(Collections.emptyList());
@ -523,7 +517,8 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
scheduler.add(new SchedulerEngine.Job(LICENSE_JOB, new LicenseSchedule(license)));
for (ExpirationCallback expirationCallback : expirationCallbacks) {
scheduler.add(new SchedulerEngine.Job(expirationCallback.getId(),
expirationCallback.schedule(license.expiryDate())));
(startTime, now) ->
expirationCallback.nextScheduledTimeForExpiry(license.expiryDate(), startTime, now)));
}
}
}

View File

@ -33,20 +33,13 @@ public abstract class AbstractLicenseServiceTestCase extends ESTestCase {
protected ClusterService clusterService;
protected TransportService transportService;
protected ClockMock clock;
protected SchedulerEngine schedulerEngine;
@Before
public void init() throws Exception {
clusterService = mock(ClusterService.class);
transportService = mock(TransportService.class);
clock = new ClockMock();
schedulerEngine = mock(SchedulerEngine.class);
licensesService = new LicensesService(Settings.EMPTY, clusterService, transportService, clock) {
@Override
protected SchedulerEngine getScheduler() {
return schedulerEngine;
}
};
licensesService = new LicensesService(Settings.EMPTY, clusterService, transportService, clock);
}
protected void setInitialState(License license) {