Skip to content

Commit

Permalink
replace StateApplier with StateListener interface
Browse files Browse the repository at this point in the history
Signed-off-by: Kaushal Kumar <[email protected]>
  • Loading branch information
kaushalmahi12 committed Oct 7, 2024
1 parent e2b203c commit 623078a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.apache.logging.log4j.Logger;
import org.opensearch.action.search.SearchShardTask;
import org.opensearch.cluster.ClusterChangedEvent;
import org.opensearch.cluster.ClusterStateApplier;
import org.opensearch.cluster.ClusterStateListener;
import org.opensearch.cluster.metadata.Metadata;
import org.opensearch.cluster.metadata.QueryGroup;
import org.opensearch.cluster.service.ClusterService;
Expand Down Expand Up @@ -45,7 +45,7 @@
*/
public class QueryGroupService extends AbstractLifecycleComponent
implements
ClusterStateApplier,
ClusterStateListener,
TaskResourceTrackingService.TaskCompletionListener {

private static final Logger logger = LogManager.getLogger(QueryGroupService.class);
Expand Down Expand Up @@ -116,7 +116,7 @@ public QueryGroupService(
this.queryGroupsStateAccessor = queryGroupsStateAccessor;
activeQueryGroups.forEach(queryGroup -> this.queryGroupsStateAccessor.addNewQueryGroup(queryGroup.get_id()));
this.queryGroupsStateAccessor.addNewQueryGroup(QueryGroupTask.DEFAULT_QUERY_GROUP_ID_SUPPLIER.get());
clusterService.addStateApplier(this);
this.clusterService.addListener(this);
}

/**
Expand Down Expand Up @@ -155,7 +155,7 @@ protected void doStop() {
protected void doClose() throws IOException {}

@Override
public void applyClusterState(ClusterChangedEvent event) {
public void clusterChanged(ClusterChangedEvent event) {
// Retrieve the current and previous cluster states
Metadata previousMetadata = event.previousState().metadata();
Metadata currentMetadata = event.state().metadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void tearDown() throws Exception {
mockThreadPool.shutdown();
}

public void testApplyClusterState() {
public void testClusterChanged() {
ClusterChangedEvent mockClusterChangedEvent = Mockito.mock(ClusterChangedEvent.class);
ClusterState mockPreviousClusterState = Mockito.mock(ClusterState.class);
ClusterState mockClusterState = Mockito.mock(ClusterState.class);
Expand Down Expand Up @@ -115,7 +115,7 @@ public void testApplyClusterState() {
when(mockClusterState.metadata()).thenReturn(mockMetadata);
when(mockPreviousMetadata.queryGroups()).thenReturn(previousQueryGroups);
when(mockMetadata.queryGroups()).thenReturn(currentQueryGroups);
queryGroupService.applyClusterState(mockClusterChangedEvent);
queryGroupService.clusterChanged(mockClusterChangedEvent);

Set<QueryGroup> currentQueryGroupsExpected = Set.of(currentQueryGroups.get("4241"));
Set<QueryGroup> previousQueryGroupsExpected = Set.of(previousQueryGroups.get("4242"));
Expand Down

0 comments on commit 623078a

Please sign in to comment.