Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Adding unit test for test isHeapUsageDominatedBySearch #6465

Merged
merged 1 commit into from
Feb 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}