mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Normalize unavailable load average
This commit normalizes the one-minute load average obtained from OperatingSystemMXBean#getSystemLoadAverage to -1 when it is not available. This is to reflect the Javadocs for this method saying "If the load average is not available, a negative value is returned."
This commit is contained in:
parent
3be12ed9fd
commit
2aa94a5133
@ -124,7 +124,7 @@ public class OsProbe {
|
||||
}
|
||||
try {
|
||||
double oneMinuteLoadAverage = (double) getSystemLoadAverage.invoke(osMxBean);
|
||||
return new double[] { oneMinuteLoadAverage, -1, -1 };
|
||||
return new double[] { oneMinuteLoadAverage >= 0 ? oneMinuteLoadAverage : -1, -1, -1 };
|
||||
} catch (Throwable t) {
|
||||
return null;
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.hamcrest.Matchers.lessThanOrEqualTo;
|
||||
|
||||
public class OsProbeTests extends ESTestCase {
|
||||
@ -71,7 +70,7 @@ public class OsProbeTests extends ESTestCase {
|
||||
// one minute load average is available, but 10-minute and 15-minute load averages are not
|
||||
// load average can be negative if not available or not computed yet, otherwise it should be >= 0
|
||||
if (loadAverage != null) {
|
||||
assertThat(loadAverage[0], anyOf(lessThan((double) 0), greaterThanOrEqualTo((double) 0)));
|
||||
assertThat(loadAverage[0], anyOf(equalTo((double) -1), greaterThanOrEqualTo((double) 0)));
|
||||
assertThat(loadAverage[1], equalTo((double) -1));
|
||||
assertThat(loadAverage[2], equalTo((double) -1));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user