Selaa lähdekoodia

Encapsulate systemd extender

The systemd extender is a scheduled execution that ensures we
repeatedly let systemd know during startup that we are still starting
up. We cancel this scheduled execution once the node has successfully
started up. This extender is wrapped in a set once, which we expose
directly. This commit addresses this by putting the extender behind a
getter, which hides the implementation detail that the extener is
wrapped in a set once. This cleans up some issues in tests, that
ensures we are not making assertions about the set once, but instead
about the extender.
Jason Tedor 5 vuotta sitten
vanhempi
commit
501b26b9fb

+ 5 - 1
modules/systemd/src/main/java/org/elasticsearch/systemd/SystemdPlugin.java

@@ -80,7 +80,11 @@ public class SystemdPlugin extends Plugin implements ClusterPlugin {
         enabled = Boolean.TRUE.toString().equals(esSDNotify);
     }
 
-    final SetOnce<Scheduler.Cancellable> extender = new SetOnce<>();
+    private final SetOnce<Scheduler.Cancellable> extender = new SetOnce<>();
+
+    Scheduler.Cancellable extender() {
+        return extender.get();
+    }
 
     @Override
     public Collection<Object> createComponents(

+ 7 - 7
modules/systemd/src/test/java/org/elasticsearch/systemd/SystemdPluginTests.java

@@ -63,28 +63,28 @@ public class SystemdPluginTests extends ESTestCase {
         final SystemdPlugin plugin = new SystemdPlugin(false, randomPackageBuildType, Boolean.TRUE.toString());
         plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null);
         assertTrue(plugin.isEnabled());
-        assertNotNull(plugin.extender.get());
+        assertNotNull(plugin.extender());
     }
 
     public void testIsNotPackageDistribution() {
         final SystemdPlugin plugin = new SystemdPlugin(false, randomNonPackageBuildType, Boolean.TRUE.toString());
         plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null);
         assertFalse(plugin.isEnabled());
-        assertNull(plugin.extender.get());
+        assertNull(plugin.extender());
     }
 
     public void testIsImplicitlyNotEnabled() {
         final SystemdPlugin plugin = new SystemdPlugin(false, randomPackageBuildType, null);
         plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null);
         assertFalse(plugin.isEnabled());
-        assertNull(plugin.extender.get());
+        assertNull(plugin.extender());
     }
 
     public void testIsExplicitlyNotEnabled() {
         final SystemdPlugin plugin = new SystemdPlugin(false, randomPackageBuildType, Boolean.FALSE.toString());
         plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null);
         assertFalse(plugin.isEnabled());
-        assertNull(plugin.extender.get());
+        assertNull(plugin.extender());
     }
 
     public void testInvalid() {
@@ -102,7 +102,7 @@ public class SystemdPluginTests extends ESTestCase {
             randomIntBetween(0, Integer.MAX_VALUE),
             (maybe, plugin) -> {
                 assertThat(maybe, OptionalMatchers.isEmpty());
-                verify(plugin.extender.get()).cancel();
+                verify(plugin.extender()).cancel();
             });
     }
 
@@ -183,9 +183,9 @@ public class SystemdPluginTests extends ESTestCase {
         };
         plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null);
         if (Boolean.TRUE.toString().equals(esSDNotify)) {
-            assertNotNull(plugin.extender);
+            assertNotNull(plugin.extender());
         } else {
-            assertNull(plugin.extender.get());
+            assertNull(plugin.extender());
         }
 
         boolean success = false;