From 827d68c7b013cad0ef37d9abdf136461dc8934af Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Wed, 6 Jul 2016 17:11:08 -0400 Subject: [PATCH] initialize scheduler in constructor Original commit: elastic/x-pack-elasticsearch@283ddf3aa37762797336b5ecdda953513f2b2649 --- .../license/plugin/core/LicensesService.java | 13 ++++--------- .../plugin/core/AbstractLicenseServiceTestCase.java | 9 +-------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java index 090b2d32369..55aa1a71139 100644 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java +++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java @@ -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))); } } } diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseServiceTestCase.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseServiceTestCase.java index c9f9e97656c..4f49c2bc116 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseServiceTestCase.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseServiceTestCase.java @@ -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) {