Skip to content

Commit

Permalink
remove wildcard imports
Browse files Browse the repository at this point in the history
Signed-off-by: Ruirui Zhang <[email protected]>
  • Loading branch information
ruai0511 committed Jul 9, 2024
1 parent daa8c22 commit da1fe8c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.cluster.metadata.QueryGroup;
import org.opensearch.cluster.metadata.QueryGroup.ResiliencyMode;

import org.opensearch.common.UUIDs;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.core.xcontent.XContentParser;
import org.joda.time.Instant;
import org.opensearch.search.ResourceType;
import org.joda.time.Instant;

import java.io.IOException;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;

/**
* A request for create QueryGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
* @param resourceLimits - the resource limit from which to get the allocation value for resourceName
*/
private double getResourceLimitValue(String resourceName, final Map<ResourceType, Object> resourceLimits) {
for (ResourceType resourceType: resourceLimits.keySet()) {
for (ResourceType resourceType : resourceLimits.keySet()) {
if (resourceType.getName().equals(resourceName)) {
return (double) resourceLimits.get(resourceType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
import org.opensearch.search.ResourceType;
import org.opensearch.threadpool.ThreadPool;

import java.util.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.DoubleAdder;

import static org.opensearch.cluster.metadata.QueryGroup.builder;
import static org.opensearch.search.ResourceType.fromName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.opensearch.search.ResourceType.fromName;

public class QueryGroupTestUtils {
public static final String NAME_ONE = "query_group_one";
Expand Down Expand Up @@ -96,14 +99,14 @@ public static List<Object> prepareSandboxPersistenceService(Map<String, QueryGro
public static void compareResourceTypes(Map<ResourceType, Object> resourceLimitMapOne, Map<ResourceType, Object> resourceLimitMapTwo) {
assertTrue(resourceLimitMapOne.keySet().containsAll(resourceLimitMapTwo.keySet()));
assertTrue(resourceLimitMapOne.values().containsAll(resourceLimitMapTwo.values()));
// for (Map.Entry<ResourceType, Object> entryOne : resourceLimitMapOne.entrySet()) {
// String resourceName = entryOne.getKey().getName();
// Optional<Map.Entry<ResourceType, Object>> entryTwo = resourceLimitMapTwo.entrySet().stream()
// .filter(e -> e.getKey().getName().equals(resourceName))
// .findFirst();
// assertTrue(entryTwo.isPresent());
// assertEquals(entryOne.getValue(), entryTwo.get().getValue());
// }
// for (Map.Entry<ResourceType, Object> entryOne : resourceLimitMapOne.entrySet()) {
// String resourceName = entryOne.getKey().getName();
// Optional<Map.Entry<ResourceType, Object>> entryTwo = resourceLimitMapTwo.entrySet().stream()
// .filter(e -> e.getKey().getName().equals(resourceName))
// .findFirst();
// assertTrue(entryTwo.isPresent());
// assertEquals(entryOne.getValue(), entryTwo.get().getValue());
// }
}

public static void compareResourceLimits(Map<String, Object> resourceLimitMapOne, Map<String, Object> resourceLimitMapTwo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,28 @@
import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.threadpool.ThreadPool;

import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.opensearch.cluster.metadata.QueryGroup.builder;
import static org.mockito.Mockito.mock;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils.*;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils.MEMORY_STRING;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils.MONITOR_STRING;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils.NAME_NONE_EXISTED;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils.NAME_ONE;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils.NAME_TWO;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils._ID_ONE;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils.assertInflightValuesAreZero;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils.compareQueryGroups;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils.prepareSandboxPersistenceService;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils.queryGroupList;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils.queryGroupOne;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils.queryGroupPersistenceService;
import static org.opensearch.plugin.wlm.action.QueryGroupTestUtils.queryGroupTwo;
import static org.opensearch.search.query_group.QueryGroupServiceSettings.QUERY_GROUP_COUNT_SETTING_NAME;
import static org.mockito.Mockito.mock;

public class QueryGroupPersistenceServiceTests extends OpenSearchTestCase {

Expand Down Expand Up @@ -63,7 +79,7 @@ public void testCreateQueryGroupDuplicateName() {
QueryGroup toCreate = builder().name(NAME_ONE)
._id("W5iIqHyhgi4K1qIAAAAIHw==")
.mode(MONITOR_STRING)
.resourceLimits(Map.of(ResourceType.fromName(MEMORY_STRING), 0.3))
.resourceLimits(Map.of(ResourceType.fromName(MEMORY_STRING), 0.3))
.updatedAt(1690934400000L)
.build();
assertThrows(RuntimeException.class, () -> queryGroupPersistenceService1.saveQueryGroupInClusterState(toCreate, clusterState));
Expand All @@ -74,7 +90,7 @@ public void testCreateQueryGroupOverflowAllocation() {
QueryGroup toCreate = builder().name(NAME_TWO)
._id("W5iIqHyhgi4K1qIAAAAIHw==")
.mode(MONITOR_STRING)
.resourceLimits(Map.of(ResourceType.fromName(MEMORY_STRING), 0.5))
.resourceLimits(Map.of(ResourceType.fromName(MEMORY_STRING), 0.5))
.updatedAt(1690934400000L)
.build();
QueryGroupPersistenceService queryGroupPersistenceService1 = (QueryGroupPersistenceService) setup.get(0);
Expand All @@ -86,7 +102,7 @@ public void testCreateQueryGroupOverflowCount() {
QueryGroup toCreate = builder().name(NAME_NONE_EXISTED)
._id("W5iIqHyhgi4K1qIAAAAIHw==")
.mode(MONITOR_STRING)
.resourceLimits(Map.of(ResourceType.fromName(MEMORY_STRING), 0.5))
.resourceLimits(Map.of(ResourceType.fromName(MEMORY_STRING), 0.5))
.updatedAt(1690934400000L)
.build();
Metadata metadata = Metadata.builder().queryGroups(Map.of(NAME_ONE, queryGroupOne, NAME_TWO, queryGroupTwo)).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
QueryGroup that = (QueryGroup) o;
return Objects.equals(name, that.name)
&& Objects.equals(resiliencyMode, that.resiliencyMode)
&& Objects.equals(resourceLimits, that.resourceLimits)
&& Objects.equals(_id, that._id)
&& updatedAtInMillis == that.updatedAtInMillis;
Expand Down Expand Up @@ -273,7 +274,6 @@ public static ResiliencyMode fromName(String s) {
}
throw new IllegalArgumentException("Invalid value for QueryGroupMode: " + s);
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@
import org.opensearch.search.backpressure.settings.SearchBackpressureSettings;
import org.opensearch.search.backpressure.settings.SearchShardTaskSettings;
import org.opensearch.search.backpressure.settings.SearchTaskSettings;
import org.opensearch.search.query_group.QueryGroupServiceSettings;
import org.opensearch.search.fetch.subphase.highlight.FastVectorHighlighter;
import org.opensearch.search.query_group.QueryGroupServiceSettings;
import org.opensearch.snapshots.InternalSnapshotsInfoService;
import org.opensearch.snapshots.SnapshotsService;
import org.opensearch.tasks.TaskCancellationMonitoringSettings;
Expand Down

0 comments on commit da1fe8c

Please sign in to comment.