diff --git a/src/main/java/org/opensearch/geospatial/plugin/GeospatialPlugin.java b/src/main/java/org/opensearch/geospatial/plugin/GeospatialPlugin.java index 8882bb72..14f4ac42 100644 --- a/src/main/java/org/opensearch/geospatial/plugin/GeospatialPlugin.java +++ b/src/main/java/org/opensearch/geospatial/plugin/GeospatialPlugin.java @@ -144,9 +144,9 @@ public void onIndexModule(IndexModule indexModule) { @Override public Collection> getGuiceServiceClasses() { - final List> services = new ArrayList<>(1); - services.add(GuiceHolder.class); + final List> services = new ArrayList<>(2); services.add(Ip2GeoListener.class); + services.add(GuiceHolder.class); return services; } diff --git a/src/test/java/org/opensearch/geospatial/ClusterSettingHelper.java b/src/test/java/org/opensearch/geospatial/ClusterSettingHelper.java index 93bde1b6..c979a075 100644 --- a/src/test/java/org/opensearch/geospatial/ClusterSettingHelper.java +++ b/src/test/java/org/opensearch/geospatial/ClusterSettingHelper.java @@ -24,7 +24,6 @@ import org.opensearch.common.network.NetworkModule; import org.opensearch.common.settings.Settings; import org.opensearch.env.Environment; -import org.opensearch.geospatial.plugin.GeospatialPlugin; import org.opensearch.node.MockNode; import org.opensearch.node.Node; import org.opensearch.plugins.Plugin; @@ -49,7 +48,7 @@ private List> basePlugins() { List> plugins = new ArrayList<>(); plugins.add(getTestTransportPlugin()); plugins.add(MockHttpTransport.TestPlugin.class); - plugins.add(GeospatialPlugin.class); + plugins.add(TestGeospatialPlugin.class); return plugins; } diff --git a/src/test/java/org/opensearch/geospatial/TestGeospatialPlugin.java b/src/test/java/org/opensearch/geospatial/TestGeospatialPlugin.java new file mode 100644 index 00000000..291c384a --- /dev/null +++ b/src/test/java/org/opensearch/geospatial/TestGeospatialPlugin.java @@ -0,0 +1,29 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.geospatial; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.opensearch.common.lifecycle.LifecycleComponent; +import org.opensearch.geospatial.ip2geo.listener.Ip2GeoListener; +import org.opensearch.geospatial.plugin.GeospatialPlugin; + +/** + * This class is needed for ClusterSettingsHelper.createMockNode to instantiate a test instance of the + * GeospatialPlugin without the JobSchedulerPlugin installed. Without overriding this class, the + * GeospatialPlugin would try to Inject JobScheduler's LockService in the GuiceHolder which will + * fail because JobScheduler is not installed + */ +public class TestGeospatialPlugin extends GeospatialPlugin { + @Override + public Collection> getGuiceServiceClasses() { + final List> services = new ArrayList<>(1); + services.add(Ip2GeoListener.class); + return services; + } +} diff --git a/src/test/java/org/opensearch/geospatial/plugin/GeospatialPluginTests.java b/src/test/java/org/opensearch/geospatial/plugin/GeospatialPluginTests.java index 5bfb489d..0ac04e29 100644 --- a/src/test/java/org/opensearch/geospatial/plugin/GeospatialPluginTests.java +++ b/src/test/java/org/opensearch/geospatial/plugin/GeospatialPluginTests.java @@ -167,7 +167,7 @@ public void testCreateComponents() { } public void testGetGuiceServiceClasses() { - Collection> classes = List.of(Ip2GeoListener.class); + Collection> classes = List.of(Ip2GeoListener.class, GeospatialPlugin.GuiceHolder.class); assertEquals(classes, plugin.getGuiceServiceClasses()); }