|
|
@@ -27,7 +27,9 @@ import java.io.IOException;
|
|
|
import java.nio.file.Files;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import static org.hamcrest.Matchers.anyOf;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
|
|
|
|
|
public class EvilJNANativesTests extends ESTestCase {
|
|
|
|
|
|
@@ -49,4 +51,26 @@ public class EvilJNANativesTests extends ESTestCase {
|
|
|
assertThat(JNANatives.MAX_NUMBER_OF_THREADS, equalTo(-1L));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void testSetMaxSizeVirtualMemory() throws IOException {
|
|
|
+ if (Constants.LINUX) {
|
|
|
+ final List<String> lines = Files.readAllLines(PathUtils.get("/proc/self/limits"));
|
|
|
+ if (!lines.isEmpty()) {
|
|
|
+ for (String line : lines) {
|
|
|
+ if (line != null && line.startsWith("Max address space")) {
|
|
|
+ final String[] fields = line.split("\\s+");
|
|
|
+ final String limit = fields[3];
|
|
|
+ assertEquals(JNANatives.rlimitToString(JNANatives.MAX_SIZE_VIRTUAL_MEMORY), limit);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fail("should have read max size virtual memory from /proc/self/limits");
|
|
|
+ } else if (Constants.MAC_OS_X) {
|
|
|
+ assertThat(JNANatives.MAX_SIZE_VIRTUAL_MEMORY, anyOf(equalTo(Long.MIN_VALUE), greaterThanOrEqualTo(0L)));
|
|
|
+ } else {
|
|
|
+ assertThat(JNANatives.MAX_SIZE_VIRTUAL_MEMORY, equalTo(Long.MIN_VALUE));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|