Skip to content

Commit

Permalink
Adding unit test for test isHeapUsageDominatedBySearch (#6463) (#6465)
Browse files Browse the repository at this point in the history
(cherry picked from commit 55cc109)

Signed-off-by: PritLadani <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 87a62f6 commit 0fa4a61
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 0fa4a61

Please sign in to comment.