Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
Signed-off-by: Kiran Prakash <[email protected]>
  • Loading branch information
kiranprakash154 committed Sep 2, 2024
1 parent 06994fb commit e7a8fa0
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 74 deletions.
7 changes: 5 additions & 2 deletions server/src/main/java/org/opensearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -1025,15 +1025,18 @@ protected Node(
QueryGroupResourceUsageTrackerService queryGroupResourceUsageTrackerService = new QueryGroupResourceUsageTrackerService(
taskResourceTrackingService
);
WorkloadManagementSettings workloadManagementSettings = new WorkloadManagementSettings(settings, settingsModule.getClusterSettings());
WorkloadManagementSettings workloadManagementSettings = new WorkloadManagementSettings(
settings,
settingsModule.getClusterSettings()
);
final QueryGroupService queryGroupService = new QueryGroupService(
queryGroupResourceUsageTrackerService,
clusterService,
threadPool,
workloadManagementSettings,
new HashMap<>()
); // We will need to replace this with actual instance of the
// queryGroupService
// queryGroupService
final QueryGroupRequestOperationListener queryGroupRequestOperationListener = new QueryGroupRequestOperationListener(
queryGroupService,
threadPool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.stream.Collectors;

Expand Down
123 changes: 61 additions & 62 deletions server/src/test/java/org/opensearch/wlm/QueryGroupServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package org.opensearch.wlm;

import org.junit.After;
import org.junit.Before;
import org.opensearch.cluster.ClusterChangedEvent;
import org.opensearch.cluster.ClusterState;
import org.opensearch.cluster.metadata.Metadata;
Expand All @@ -21,6 +19,7 @@
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.wlm.stats.QueryGroupState;
import org.opensearch.wlm.tracker.QueryGroupResourceUsageTrackerService;
import org.junit.Before;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -34,71 +33,71 @@
import static org.mockito.Mockito.when;

public class QueryGroupServiceTests extends OpenSearchTestCase {
private QueryGroupService queryGroupService;
private QueryGroupResourceUsageTrackerService mockQueryGroupUsageTracker;
private ClusterService mockClusterService;
private ThreadPool mockThreadPool;
private WorkloadManagementSettings mockWorkloadManagementSettings;
private Scheduler.Cancellable mockScheduledFuture;
private Map<String, QueryGroupState> mockQueryGroupStateMap;
private QueryGroupService queryGroupService;
private QueryGroupResourceUsageTrackerService mockQueryGroupUsageTracker;
private ClusterService mockClusterService;
private ThreadPool mockThreadPool;
private WorkloadManagementSettings mockWorkloadManagementSettings;
private Scheduler.Cancellable mockScheduledFuture;
private Map<String, QueryGroupState> mockQueryGroupStateMap;

@Before
public void setup() {
mockQueryGroupUsageTracker = mock(QueryGroupResourceUsageTrackerService.class);
mockClusterService = mock(ClusterService.class);
mockThreadPool = mock(ThreadPool.class);
mockScheduledFuture = mock(Scheduler.Cancellable.class);
mockWorkloadManagementSettings = mock(WorkloadManagementSettings.class);
mockQueryGroupStateMap = new HashMap<>();
@Before
public void setup() {
mockQueryGroupUsageTracker = mock(QueryGroupResourceUsageTrackerService.class);
mockClusterService = mock(ClusterService.class);
mockThreadPool = mock(ThreadPool.class);
mockScheduledFuture = mock(Scheduler.Cancellable.class);
mockWorkloadManagementSettings = mock(WorkloadManagementSettings.class);
mockQueryGroupStateMap = new HashMap<>();

queryGroupService = new QueryGroupService(
mockQueryGroupUsageTracker,
mockClusterService,
mockThreadPool,
mockWorkloadManagementSettings,
mockQueryGroupStateMap
);
}
queryGroupService = new QueryGroupService(
mockQueryGroupUsageTracker,
mockClusterService,
mockThreadPool,
mockWorkloadManagementSettings,
mockQueryGroupStateMap
);
}

public void testApplyClusterState() {
ClusterChangedEvent mockClusterChangedEvent = mock(ClusterChangedEvent.class);
ClusterState mockPreviousClusterState = mock(ClusterState.class);
ClusterState mockClusterState = mock(ClusterState.class);
Metadata mockPreviousMetadata = mock(Metadata.class);
Metadata mockMetadata = mock(Metadata.class);
QueryGroup addedQueryGroup = new QueryGroup(
"addedQueryGroup",
"4242",
QueryGroup.ResiliencyMode.ENFORCED,
Map.of(ResourceType.MEMORY, 0.5),
1L
);
QueryGroup deletedQueryGroup = new QueryGroup(
"deletedQueryGroup",
"4241",
QueryGroup.ResiliencyMode.ENFORCED,
Map.of(ResourceType.MEMORY, 0.5),
1L
);
Map<String, QueryGroup> previousQueryGroups = new HashMap<>();
previousQueryGroups.put("4242", addedQueryGroup);
Map<String, QueryGroup> currentQueryGroups = new HashMap<>();
currentQueryGroups.put("4241", deletedQueryGroup);
public void testApplyClusterState() {
ClusterChangedEvent mockClusterChangedEvent = mock(ClusterChangedEvent.class);
ClusterState mockPreviousClusterState = mock(ClusterState.class);
ClusterState mockClusterState = mock(ClusterState.class);
Metadata mockPreviousMetadata = mock(Metadata.class);
Metadata mockMetadata = mock(Metadata.class);
QueryGroup addedQueryGroup = new QueryGroup(
"addedQueryGroup",
"4242",
QueryGroup.ResiliencyMode.ENFORCED,
Map.of(ResourceType.MEMORY, 0.5),
1L
);
QueryGroup deletedQueryGroup = new QueryGroup(
"deletedQueryGroup",
"4241",
QueryGroup.ResiliencyMode.ENFORCED,
Map.of(ResourceType.MEMORY, 0.5),
1L
);
Map<String, QueryGroup> previousQueryGroups = new HashMap<>();
previousQueryGroups.put("4242", addedQueryGroup);
Map<String, QueryGroup> currentQueryGroups = new HashMap<>();
currentQueryGroups.put("4241", deletedQueryGroup);

when(mockClusterChangedEvent.previousState()).thenReturn(mockPreviousClusterState);
when(mockClusterChangedEvent.state()).thenReturn(mockClusterState);
when(mockPreviousClusterState.metadata()).thenReturn(mockPreviousMetadata);
when(mockClusterState.metadata()).thenReturn(mockMetadata);
when(mockPreviousMetadata.queryGroups()).thenReturn(previousQueryGroups);
when(mockMetadata.queryGroups()).thenReturn(currentQueryGroups);
queryGroupService.applyClusterState(mockClusterChangedEvent);
when(mockClusterChangedEvent.previousState()).thenReturn(mockPreviousClusterState);
when(mockClusterChangedEvent.state()).thenReturn(mockClusterState);
when(mockPreviousClusterState.metadata()).thenReturn(mockPreviousMetadata);
when(mockClusterState.metadata()).thenReturn(mockMetadata);
when(mockPreviousMetadata.queryGroups()).thenReturn(previousQueryGroups);
when(mockMetadata.queryGroups()).thenReturn(currentQueryGroups);
queryGroupService.applyClusterState(mockClusterChangedEvent);

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

assertEquals(currentQueryGroupsExpected, queryGroupService.getActiveQueryGroups());
assertEquals(previousQueryGroupsExpected, queryGroupService.getDeletedQueryGroups());
}
assertEquals(currentQueryGroupsExpected, queryGroupService.getActiveQueryGroups());
assertEquals(previousQueryGroupsExpected, queryGroupService.getDeletedQueryGroups());
}

public void testDoStart_SchedulesTask() {
when(mockWorkloadManagementSettings.queryGroupServiceEnabled()).thenReturn(true);
Expand Down Expand Up @@ -131,4 +130,4 @@ public void testDoStop_DoesNOTCancelsScheduledTask_WhenQueryGroupServiceDisabled
queryGroupService.doStop();
verify(mockScheduledFuture, never()).cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.HashMap;
import java.util.Map;

import static org.mockito.Mockito.mock;
import static org.opensearch.threadpool.ThreadPool.Names.SAME;
import static org.mockito.Mockito.mock;

public class WorkloadManagementTransportInterceptorTests extends OpenSearchTestCase {

Expand All @@ -46,7 +46,8 @@ public void setUp() throws Exception {
mockWorkloadManagementSettings = mock(WorkloadManagementSettings.class);
mockQueryGroupStateMap = new HashMap<>();
threadPool = new TestThreadPool(getTestName());
sut = new WorkloadManagementTransportInterceptor(threadPool,
sut = new WorkloadManagementTransportInterceptor(
threadPool,
new QueryGroupService(
mockQueryGroupUsageTracker,
mockClusterService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ public TestTaskCancellationImpl(
Set<QueryGroup> deletedQueryGroups,
BooleanSupplier isNodeInDuress
) {
super(
workloadManagementSettings,
defaultTaskSelectionStrategy,
queryGroupLevelViews,
activeQueryGroups,
deletedQueryGroups
);
super(workloadManagementSettings, defaultTaskSelectionStrategy, queryGroupLevelViews, activeQueryGroups, deletedQueryGroups);
}
}

Expand Down

0 comments on commit e7a8fa0

Please sign in to comment.