Browse Source

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).
Jason Tedor 9 years ago
parent
commit
d5e408b273

+ 6 - 1
core/src/main/java/org/elasticsearch/bootstrap/BootstrapCheck.java

@@ -254,7 +254,7 @@ final class BootstrapCheck {
 
 
         @Override
         @Override
         public boolean check() {
         public boolean check() {
-            return getMaxSizeVirtualMemory() != Long.MIN_VALUE && getMaxSizeVirtualMemory() != JNACLibrary.RLIM_INFINITY;
+            return getMaxSizeVirtualMemory() != Long.MIN_VALUE && getMaxSizeVirtualMemory() != getRlimInfinity();
         }
         }
 
 
         @Override
         @Override
@@ -266,6 +266,11 @@ final class BootstrapCheck {
                 BootstrapInfo.getSystemProperties().get("user.name"));
                 BootstrapInfo.getSystemProperties().get("user.name"));
         }
         }
 
 
+        // visible for testing
+        long getRlimInfinity() {
+            return JNACLibrary.RLIM_INFINITY;
+        }
+
         // visible for testing
         // visible for testing
         long getMaxSizeVirtualMemory() {
         long getMaxSizeVirtualMemory() {
             return JNANatives.MAX_SIZE_VIRTUAL_MEMORY;
             return JNANatives.MAX_SIZE_VIRTUAL_MEMORY;

+ 9 - 3
core/src/test/java/org/elasticsearch/bootstrap/BootstrapCheckTests.java

@@ -19,6 +19,7 @@
 
 
 package org.elasticsearch.bootstrap;
 package org.elasticsearch.bootstrap;
 
 
+import org.apache.lucene.util.Constants;
 import org.elasticsearch.common.settings.Setting;
 import org.elasticsearch.common.settings.Setting;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.test.ESTestCase;
 import org.elasticsearch.test.ESTestCase;
@@ -158,13 +159,18 @@ public class BootstrapCheckTests extends ESTestCase {
     }
     }
 
 
     public void testMaxSizeVirtualMemory() {
     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() {
         final BootstrapCheck.MaxSizeVirtualMemoryCheck check = new BootstrapCheck.MaxSizeVirtualMemoryCheck() {
             @Override
             @Override
             long getMaxSizeVirtualMemory() {
             long getMaxSizeVirtualMemory() {
                 return maxSizeVirtualMemory.get();
                 return maxSizeVirtualMemory.get();
             }
             }
+
+            @Override
+            long getRlimInfinity() {
+                return rlimInfinity;
+            }
         };
         };
 
 
         try {
         try {
@@ -174,7 +180,7 @@ public class BootstrapCheckTests extends ESTestCase {
             assertThat(e.getMessage(), containsString("max size virtual memory"));
             assertThat(e.getMessage(), containsString("max size virtual memory"));
         }
         }
 
 
-        maxSizeVirtualMemory.set(limit);
+        maxSizeVirtualMemory.set(rlimInfinity);
 
 
         BootstrapCheck.check(true, Collections.singletonList(check));
         BootstrapCheck.check(true, Collections.singletonList(check));