Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Sep 5, 2024
1 parent 6a5d01b commit bc6544b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public void onIndexModule(IndexModule indexModule) {

@Override
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
final List<Class<? extends LifecycleComponent>> services = new ArrayList<>(1);
services.add(GuiceHolder.class);
final List<Class<? extends LifecycleComponent>> services = new ArrayList<>(2);
services.add(Ip2GeoListener.class);
services.add(GuiceHolder.class);
return services;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,7 +48,7 @@ private List<Class<? extends Plugin>> basePlugins() {
List<Class<? extends Plugin>> plugins = new ArrayList<>();
plugins.add(getTestTransportPlugin());
plugins.add(MockHttpTransport.TestPlugin.class);
plugins.add(GeospatialPlugin.class);
plugins.add(TestGeospatialPlugin.class);
return plugins;
}

Expand Down
29 changes: 29 additions & 0 deletions src/test/java/org/opensearch/geospatial/TestGeospatialPlugin.java
Original file line number Diff line number Diff line change
@@ -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<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
final List<Class<? extends LifecycleComponent>> services = new ArrayList<>(1);
services.add(Ip2GeoListener.class);
return services;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void testCreateComponents() {
}

public void testGetGuiceServiceClasses() {
Collection<Class<? extends LifecycleComponent>> classes = List.of(Ip2GeoListener.class);
Collection<Class<? extends LifecycleComponent>> classes = List.of(Ip2GeoListener.class, GeospatialPlugin.GuiceHolder.class);
assertEquals(classes, plugin.getGuiceServiceClasses());
}

Expand Down

0 comments on commit bc6544b

Please sign in to comment.