Mock rlimit infinity in virtual memory size test
This commit mocks the value of rlimit infinity in the max size virtual memory check test. This is to avoid attempting to load the native C library during the test on Windows which would lead to a permissions violation (the native C library needs to be loaded before the security manager is setup).
This commit is contained in:
parent
f8e84f0bbb
commit
d5e408b273
|
@ -254,7 +254,7 @@ final class BootstrapCheck {
|
|||
|
||||
@Override
|
||||
public boolean check() {
|
||||
return getMaxSizeVirtualMemory() != Long.MIN_VALUE && getMaxSizeVirtualMemory() != JNACLibrary.RLIM_INFINITY;
|
||||
return getMaxSizeVirtualMemory() != Long.MIN_VALUE && getMaxSizeVirtualMemory() != getRlimInfinity();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -266,6 +266,11 @@ final class BootstrapCheck {
|
|||
BootstrapInfo.getSystemProperties().get("user.name"));
|
||||
}
|
||||
|
||||
// visible for testing
|
||||
long getRlimInfinity() {
|
||||
return JNACLibrary.RLIM_INFINITY;
|
||||
}
|
||||
|
||||
// visible for testing
|
||||
long getMaxSizeVirtualMemory() {
|
||||
return JNANatives.MAX_SIZE_VIRTUAL_MEMORY;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.bootstrap;
|
||||
|
||||
import org.apache.lucene.util.Constants;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -158,13 +159,18 @@ public class BootstrapCheckTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testMaxSizeVirtualMemory() {
|
||||
final long limit = JNACLibrary.RLIM_INFINITY;
|
||||
final AtomicLong maxSizeVirtualMemory = new AtomicLong(randomInt());
|
||||
final long rlimInfinity = Constants.MAC_OS_X ? 9223372036854775807L : -1L;
|
||||
final AtomicLong maxSizeVirtualMemory = new AtomicLong(randomIntBetween(0, Integer.MAX_VALUE));
|
||||
final BootstrapCheck.MaxSizeVirtualMemoryCheck check = new BootstrapCheck.MaxSizeVirtualMemoryCheck() {
|
||||
@Override
|
||||
long getMaxSizeVirtualMemory() {
|
||||
return maxSizeVirtualMemory.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
long getRlimInfinity() {
|
||||
return rlimInfinity;
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
|
@ -174,7 +180,7 @@ public class BootstrapCheckTests extends ESTestCase {
|
|||
assertThat(e.getMessage(), containsString("max size virtual memory"));
|
||||
}
|
||||
|
||||
maxSizeVirtualMemory.set(limit);
|
||||
maxSizeVirtualMemory.set(rlimInfinity);
|
||||
|
||||
BootstrapCheck.check(true, Collections.singletonList(check));
|
||||
|
||||
|
|
Loading…
Reference in New Issue