Skip to content

Commit

Permalink
apply spotless
Browse files Browse the repository at this point in the history
Signed-off-by: Kaushal Kumar <[email protected]>
  • Loading branch information
kaushalmahi12 committed Sep 6, 2024
1 parent 9e2e3ea commit 34184ef
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
7 changes: 6 additions & 1 deletion server/src/main/java/org/opensearch/wlm/ResourceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ protected double getNormalisedThreshold(QueryGroup queryGroup) {
private final QueryGroupUsageHelper queryGroupUsageHelper;
private static List<ResourceType> sortedValues = List.of(CPU, MEMORY);

ResourceType(String name, boolean statsEnabled, ResourceUsageCalculator resourceUsageCalculator, QueryGroupUsageHelper queryGroupUsageHelper) {
ResourceType(
String name,
boolean statsEnabled,
ResourceUsageCalculator resourceUsageCalculator,
QueryGroupUsageHelper queryGroupUsageHelper
) {
this.name = name;
this.statsEnabled = statsEnabled;
this.resourceUsageCalculator = resourceUsageCalculator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public HighestResourceConsumingTaskFirstSelectionStrategy(Supplier<Long> nanoTim
* @return The comparator
*/
private Comparator<QueryGroupTask> sortingCondition(ResourceType resourceType) {
return Comparator.comparingDouble(task -> resourceType.getResourceUsageCalculator().calculateTaskResourceUsage(task, nanoTimeSupplier));
return Comparator.comparingDouble(
task -> resourceType.getResourceUsageCalculator().calculateTaskResourceUsage(task, nanoTimeSupplier)
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public Map<String, QueryGroupLevelResourceUsageView> constructQueryGroupLevelUsa
// Compute the QueryGroup resource usage
final Map<ResourceType, Double> resourceUsage = new HashMap<>();
for (ResourceType resourceType : TRACKED_RESOURCES) {
double usage = resourceType.getResourceUsageCalculator().calculateResourceUsage(queryGroupEntry.getValue(), nanoTimeSupplier);
double usage = resourceType.getResourceUsageCalculator()
.calculateResourceUsage(queryGroupEntry.getValue(), nanoTimeSupplier);
resourceUsage.put(resourceType, usage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ public void testSelectTasksToCancelSelectsTasksMeetingThreshold_ifReduceByIsGrea
assertFalse(selectedTasks.isEmpty());
boolean sortedInDescendingResourceUsage = IntStream.range(0, selectedTasks.size() - 1)
.noneMatch(
index -> ResourceType.MEMORY.getResourceUsageCalculator().calculateTaskResourceUsage(selectedTasks.get(index), null) < ResourceType.MEMORY.getResourceUsageCalculator().calculateTaskResourceUsage(
selectedTasks.get(index + 1),
null
)
index -> ResourceType.MEMORY.getResourceUsageCalculator()
.calculateTaskResourceUsage(selectedTasks.get(index), null) < ResourceType.MEMORY.getResourceUsageCalculator()
.calculateTaskResourceUsage(selectedTasks.get(index + 1), null)
);
assertTrue(sortedInDescendingResourceUsage);
assertTrue(tasksUsageMeetsThreshold(selectedTasks, reduceBy));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@ public void testQueryGroupMemoryUsage() {
TestClock clock = new TestClock();

QueryGroupTask mockTask = createMockTaskWithResourceStats(QueryGroupTask.class, 100, 200, 0, 123);
double actualMemoryUsage = ResourceType.MEMORY.getResourceUsageCalculator().calculateResourceUsage(List.of(mockTask), clock::getTime);
double actualMemoryUsage = ResourceType.MEMORY.getResourceUsageCalculator()
.calculateResourceUsage(List.of(mockTask), clock::getTime);
double expectedMemoryUsage = 200.0 / HEAP_SIZE_BYTES;

assertEquals(expectedMemoryUsage, actualMemoryUsage, MIN_VALUE);
assertEquals(200.0 / HEAP_SIZE_BYTES, ResourceType.MEMORY.getResourceUsageCalculator().calculateTaskResourceUsage(mockTask, clock::getTime), MIN_VALUE);
assertEquals(
200.0 / HEAP_SIZE_BYTES,
ResourceType.MEMORY.getResourceUsageCalculator().calculateTaskResourceUsage(mockTask, clock::getTime),
MIN_VALUE
);
}

public static <T extends QueryGroupTask> T createMockTaskWithResourceStats(
Expand Down

0 comments on commit 34184ef

Please sign in to comment.