|
21 | 21 |
|
22 | 22 | import org.apache.lucene.util.BytesRef;
|
23 | 23 | import org.apache.lucene.util.BytesRefBuilder;
|
| 24 | +import org.apache.lucene.util.Constants; |
24 | 25 | import org.apache.lucene.util.RamUsageTester;
|
25 | 26 | import org.apache.lucene.util.TestUtil;
|
26 |
| -import org.elasticsearch.Assertions; |
27 |
| -import org.elasticsearch.bootstrap.JavaVersion; |
28 | 27 | import org.elasticsearch.common.lease.Releasable;
|
29 | 28 | import org.elasticsearch.test.ESTestCase;
|
30 | 29 |
|
|
43 | 42 | public class LiveVersionMapTests extends ESTestCase {
|
44 | 43 |
|
45 | 44 | public void testRamBytesUsed() throws Exception {
|
46 |
| - assumeTrue("Test disabled for JDK 9", JavaVersion.current().compareTo(JavaVersion.parse("9")) < 0); |
47 | 45 | LiveVersionMap map = new LiveVersionMap();
|
48 | 46 | for (int i = 0; i < 100000; ++i) {
|
49 | 47 | BytesRefBuilder uid = new BytesRefBuilder();
|
@@ -72,8 +70,23 @@ public void testRamBytesUsed() throws Exception {
|
72 | 70 | }
|
73 | 71 | actualRamBytesUsed = RamUsageTester.sizeOf(map);
|
74 | 72 | estimatedRamBytesUsed = map.ramBytesUsed();
|
75 |
| - // less than 25% off |
76 |
| - assertEquals(actualRamBytesUsed, estimatedRamBytesUsed, actualRamBytesUsed / 4); |
| 73 | + long tolerance; |
| 74 | + if (Constants.JRE_IS_MINIMUM_JAVA9) { |
| 75 | + // With Java 9, RamUsageTester computes the memory usage of maps as |
| 76 | + // the memory usage of an array that would contain exactly all keys |
| 77 | + // and values. This is an under-estimation of the actual memory |
| 78 | + // usage since it ignores the impact of the load factor and of the |
| 79 | + // linked list/tree that is used to store collisions. Se we use a |
| 80 | + // bigger tolerance. |
| 81 | + // less than 50% off |
| 82 | + tolerance = actualRamBytesUsed / 2; |
| 83 | + } else { |
| 84 | + // Java 8 is more accurate by doing reflection into the actual JDK classes |
| 85 | + // so we give it a lower error bound. |
| 86 | + // less than 25% off |
| 87 | + tolerance = actualRamBytesUsed / 4; |
| 88 | + } |
| 89 | + assertEquals(actualRamBytesUsed, estimatedRamBytesUsed, tolerance); |
77 | 90 | }
|
78 | 91 |
|
79 | 92 | private BytesRef uid(String string) {
|
|
0 commit comments