Skip to content

Commit 01f5911

Browse files
committed
refactor: fix tests for useCompressedOops and max heap size
1 parent 7a47f58 commit 01f5911

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

HyperAlloc/src/main/java/com/amazon/corretto/benchmark/hyperalloc/SimpleRunConfig.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SimpleRunConfig {
2020
private boolean useCompressedOops;
2121
private int pruneRatio = ObjectStore.DEFAULT_PRUNE_RATIO;
2222
private int reshuffleRatio = ObjectStore.DEFAULT_RESHUFFLE_RATIO;
23-
private int heapSizeInMb = (int)(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getCommitted() / 1048576L);
23+
private int heapSizeInMb = (int)(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() / 1048576L);
2424
private String logFile = "output.csv";
2525
private String allocationLogFile = null;
2626
private Double allocationSmoothnessFactor = null;
@@ -117,7 +117,6 @@ public SimpleRunConfig(final long allocRateInMbPerSecond, final double allocSmoo
117117
final String allocationLogFile, final double rampUpSeconds) {
118118
this.allocRateInMbPerSecond = allocRateInMbPerSecond;
119119
this.allocationSmoothnessFactor = allocSmoothnessFactor;
120-
this.heapSizeInMb = heapSizeInMb;
121120
this.longLivedInMb = longLivedInMb;
122121
this.midAgedInMb = midAgedInMb;
123122
this.durationInSecond = durationInSecond;
@@ -126,7 +125,6 @@ public SimpleRunConfig(final long allocRateInMbPerSecond, final double allocSmoo
126125
this.maxObjectSize = maxObjectSize;
127126
this.pruneRatio = pruneRatio;
128127
this.reshuffleRatio = reshuffleRatio;
129-
this.useCompressedOops = useCompressedOops;
130128
this.logFile = logFile;
131129
this.allocationLogFile = allocationLogFile;
132130
this.rampUpSeconds = rampUpSeconds;

HyperAlloc/src/test/java/com/amazon/corretto/benchmark/hyperalloc/SimpleRunConfigTest.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@
22
// SPDX-License-Identifier: Apache-2.0
33
package com.amazon.corretto.benchmark.hyperalloc;
44

5+
import com.sun.management.HotSpotDiagnosticMXBean;
6+
import org.junit.jupiter.api.BeforeAll;
7+
import org.junit.jupiter.api.BeforeEach;
58
import org.junit.jupiter.api.Test;
69

10+
import java.lang.management.ManagementFactory;
11+
712
import static com.github.stefanbirkner.systemlambda.SystemLambda.catchSystemExit;
813
import static org.hamcrest.MatcherAssert.assertThat;
914
import static org.hamcrest.CoreMatchers.is;
1015
import static org.junit.jupiter.api.Assertions.*;
1116

1217
class SimpleRunConfigTest {
18+
19+
// value will change depending on how much memory the test machine has.
20+
int maxHeap = (int)(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() / 1048576L);
21+
boolean useCompressedOops;
22+
23+
{
24+
HotSpotDiagnosticMXBean mxBeanServer = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
25+
useCompressedOops = Boolean.parseBoolean(mxBeanServer.getVMOption("UseCompressedOops").getValue());
26+
}
27+
1328
@Test
1429
void DefaultStringsTest() {
1530
final SimpleRunConfig config = new SimpleRunConfig(new String[0]);
@@ -19,7 +34,7 @@ void DefaultStringsTest() {
1934
assertThat(config.getDurationInSecond(), is(60));
2035
assertThat(config.getMaxObjectSize(), is(1024));
2136
assertThat(config.getMinObjectSize(), is(128));
22-
assertThat(config.getHeapSizeInMb(), is(1024));
37+
assertThat(config.getHeapSizeInMb(), is(maxHeap));
2338
assertThat(config.getLongLivedInMb(), is(64));
2439
assertThat(config.getMidAgedInMb(), is(64));
2540
assertThat(config.getPruneRatio(), is(50));
@@ -39,13 +54,13 @@ void ConstructorTest() {
3954
assertThat(config.getDurationInSecond(), is(3000));
4055
assertThat(config.getMaxObjectSize(), is(512));
4156
assertThat(config.getMinObjectSize(), is(256));
42-
assertThat(config.getHeapSizeInMb(), is(32768));
57+
assertThat(config.getHeapSizeInMb(), is(maxHeap));
4358
assertThat(config.getLongLivedInMb(), is(256));
4459
assertThat(config.getMidAgedInMb(), is(32));
4560
assertThat(config.getPruneRatio(), is(10));
4661
assertThat(config.getReshuffleRatio(), is(20));
4762
assertThat(config.getLogFile(), is("nosuch.csv"));
48-
assertFalse(config.isUseCompressedOops());
63+
assertEquals(useCompressedOops,config.isUseCompressedOops());
4964
}
5065

5166
@Test
@@ -54,26 +69,26 @@ void StringArgsTest() {
5469
"-d", "3000", "-m", "32", "-t", "16",
5570
"-f", "20", "-r", "10", "-x", "512", "-u", "simple",
5671
"-n", "256", "-c", "false", "-l", "nosuch.csv"});
57-
5872
assertThat(config.getNumOfThreads(), is(16));
5973
assertThat(config.getAllocRateInMbPerSecond(), is(16384L));
6074
assertThat(config.getDurationInSecond(), is(3000));
6175
assertThat(config.getMaxObjectSize(), is(512));
6276
assertThat(config.getMinObjectSize(), is(256));
63-
assertThat(config.getHeapSizeInMb(), is(32768));
77+
assertThat(config.getHeapSizeInMb(), is(maxHeap));
6478
assertThat(config.getLongLivedInMb(), is(256));
6579
assertThat(config.getMidAgedInMb(), is(32));
6680
assertThat(config.getPruneRatio(), is(10));
6781
assertThat(config.getReshuffleRatio(), is(20));
6882
assertThat(config.getLogFile(), is("nosuch.csv"));
69-
assertFalse(config.isUseCompressedOops());
83+
assertEquals(useCompressedOops,config.isUseCompressedOops());
7084
}
7185

7286
@Test
7387
void UnknownParameterShouldExitTest() throws Exception {
7488
int status = catchSystemExit(
7589
() -> new SimpleRunConfig(new String[]{"-w", "who"}));
76-
7790
assertThat(status, is(1));
7891
}
92+
93+
class MySecurityManager extends SecurityManager {}
7994
}

0 commit comments

Comments
 (0)