Skip to content

Commit

Permalink
Adding unit test for test isHeapUsageDominatedBySearch (#6463)
Browse files Browse the repository at this point in the history
Signed-off-by: PritLadani <pritkladani@gmail.com>
  • Loading branch information
PritLadani committed Feb 23, 2023
1 parent d439244 commit 55cc109
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import org.opensearch.action.search.SearchTask;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.Settings;
import org.opensearch.monitor.jvm.JvmStats;
import org.opensearch.search.backpressure.settings.SearchBackpressureSettings;
import org.opensearch.search.backpressure.settings.SearchShardTaskSettings;
import org.opensearch.search.backpressure.settings.SearchTaskSettings;
import org.opensearch.tasks.CancellableTask;
import org.opensearch.tasks.Task;
import org.opensearch.tasks.TaskCancellation;
import org.opensearch.test.OpenSearchTestCase;

import java.util.List;
import java.util.Optional;

import static org.mockito.Mockito.spy;
Expand Down Expand Up @@ -140,4 +143,17 @@ public void testNotEligibleForCancellation() {
reason = tracker.checkAndMaybeGetCancellationReason(task);
assertFalse(reason.isPresent());
}

public void testIsHeapUsageDominatedBySearch() {
assumeTrue("Skip the test if the hardware doesn't support heap usage tracking", HeapUsageTracker.isHeapTrackingSupported());

// task with 1 byte of heap usage so that it does not breach the threshold
CancellableTask task = createMockTaskWithResourceStats(SearchShardTask.class, 1, 1);
assertFalse(HeapUsageTracker.isHeapUsageDominatedBySearch(List.of(task), 0.5));

long totalHeap = JvmStats.jvmStats().getMem().getHeapMax().getBytes();
// task with heap usage of [totalHeap - 1] so that it breaches the threshold
task = createMockTaskWithResourceStats(SearchShardTask.class, 1, totalHeap - 1);
assertTrue(HeapUsageTracker.isHeapUsageDominatedBySearch(List.of(task), 0.5));
}
}

0 comments on commit 55cc109

Please sign in to comment.