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.
This commit is contained in:
Jason Tedor 2020-04-20 21:17:42 -04:00
parent 80f18ad31a
commit 1553e7e620
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
2 changed files with 12 additions and 8 deletions

View File

@ -80,7 +80,11 @@ public class SystemdPlugin extends Plugin implements ClusterPlugin {
enabled = Boolean.TRUE.toString().equals(esSDNotify); 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 @Override
public Collection<Object> createComponents( public Collection<Object> createComponents(

View File

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