|
24 | 24 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
25 | 25 |
|
26 | 26 | class GlobalConfigurationTest extends TestHelper { |
| 27 | + @Test |
| 28 | + void maxPageRAMAutoTune() { |
| 29 | + final long originalValue = GlobalConfiguration.MAX_PAGE_RAM.getValueAsLong(); |
| 30 | + |
| 31 | + try { |
| 32 | + // When reset (no explicit value), maxPageRAM should be auto-tuned to ~25% of max heap |
| 33 | + GlobalConfiguration.MAX_PAGE_RAM.reset(); |
| 34 | + final long autoTunedMB = GlobalConfiguration.MAX_PAGE_RAM.getValueAsLong(); |
| 35 | + final long maxHeapMB = Runtime.getRuntime().maxMemory() / 1024 / 1024; |
| 36 | + |
| 37 | + // Auto-tuned value should be approximately 25% of max heap, in MB |
| 38 | + assertThat(autoTunedMB).isLessThanOrEqualTo(maxHeapMB); |
| 39 | + assertThat(autoTunedMB).isEqualTo(Runtime.getRuntime().maxMemory() / 4 / 1024 / 1024); |
| 40 | + } finally { |
| 41 | + GlobalConfiguration.MAX_PAGE_RAM.setValue(originalValue); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void maxPageRAMCorrectionReturnsMB() { |
| 47 | + final long originalValue = GlobalConfiguration.MAX_PAGE_RAM.getValueAsLong(); |
| 48 | + |
| 49 | + try { |
| 50 | + // Set maxPageRAM to a value exceeding 80% of heap to trigger correction |
| 51 | + final long maxHeapMB = Runtime.getRuntime().maxMemory() / 1024 / 1024; |
| 52 | + final long excessiveValueMB = maxHeapMB; // 100% of heap, definitely > 80% |
| 53 | + |
| 54 | + GlobalConfiguration.MAX_PAGE_RAM.setValue(excessiveValueMB); |
| 55 | + final long correctedValue = GlobalConfiguration.MAX_PAGE_RAM.getValueAsLong(); |
| 56 | + |
| 57 | + // The corrected value must be in MB (should be ~50% of heap in MB) |
| 58 | + // Before the fix, this would return bytes instead of MB |
| 59 | + final long expectedMB = Runtime.getRuntime().maxMemory() / 2 / 1024 / 1024; |
| 60 | + assertThat(correctedValue).isEqualTo(expectedMB); |
| 61 | + assertThat(correctedValue).isLessThanOrEqualTo(maxHeapMB); |
| 62 | + } finally { |
| 63 | + GlobalConfiguration.MAX_PAGE_RAM.setValue(originalValue); |
| 64 | + } |
| 65 | + } |
| 66 | + |
27 | 67 | @Test |
28 | 68 | void serverMode() { |
29 | 69 | final String original = GlobalConfiguration.SERVER_MODE.getValueAsString(); |
|
0 commit comments