2
2
// SPDX-License-Identifier: Apache-2.0
3
3
package com .amazon .corretto .benchmark .hyperalloc ;
4
4
5
+ import com .sun .management .HotSpotDiagnosticMXBean ;
6
+ import org .junit .jupiter .api .BeforeAll ;
7
+ import org .junit .jupiter .api .BeforeEach ;
5
8
import org .junit .jupiter .api .Test ;
6
9
10
+ import java .lang .management .ManagementFactory ;
11
+
7
12
import static com .github .stefanbirkner .systemlambda .SystemLambda .catchSystemExit ;
8
13
import static org .hamcrest .MatcherAssert .assertThat ;
9
14
import static org .hamcrest .CoreMatchers .is ;
10
15
import static org .junit .jupiter .api .Assertions .*;
11
16
12
17
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
+
13
28
@ Test
14
29
void DefaultStringsTest () {
15
30
final SimpleRunConfig config = new SimpleRunConfig (new String [0 ]);
@@ -19,7 +34,7 @@ void DefaultStringsTest() {
19
34
assertThat (config .getDurationInSecond (), is (60 ));
20
35
assertThat (config .getMaxObjectSize (), is (1024 ));
21
36
assertThat (config .getMinObjectSize (), is (128 ));
22
- assertThat (config .getHeapSizeInMb (), is (1024 ));
37
+ assertThat (config .getHeapSizeInMb (), is (maxHeap ));
23
38
assertThat (config .getLongLivedInMb (), is (64 ));
24
39
assertThat (config .getMidAgedInMb (), is (64 ));
25
40
assertThat (config .getPruneRatio (), is (50 ));
@@ -39,13 +54,13 @@ void ConstructorTest() {
39
54
assertThat (config .getDurationInSecond (), is (3000 ));
40
55
assertThat (config .getMaxObjectSize (), is (512 ));
41
56
assertThat (config .getMinObjectSize (), is (256 ));
42
- assertThat (config .getHeapSizeInMb (), is (32768 ));
57
+ assertThat (config .getHeapSizeInMb (), is (maxHeap ));
43
58
assertThat (config .getLongLivedInMb (), is (256 ));
44
59
assertThat (config .getMidAgedInMb (), is (32 ));
45
60
assertThat (config .getPruneRatio (), is (10 ));
46
61
assertThat (config .getReshuffleRatio (), is (20 ));
47
62
assertThat (config .getLogFile (), is ("nosuch.csv" ));
48
- assertFalse ( config .isUseCompressedOops ());
63
+ assertEquals ( useCompressedOops , config .isUseCompressedOops ());
49
64
}
50
65
51
66
@ Test
@@ -54,26 +69,26 @@ void StringArgsTest() {
54
69
"-d" , "3000" , "-m" , "32" , "-t" , "16" ,
55
70
"-f" , "20" , "-r" , "10" , "-x" , "512" , "-u" , "simple" ,
56
71
"-n" , "256" , "-c" , "false" , "-l" , "nosuch.csv" });
57
-
58
72
assertThat (config .getNumOfThreads (), is (16 ));
59
73
assertThat (config .getAllocRateInMbPerSecond (), is (16384L ));
60
74
assertThat (config .getDurationInSecond (), is (3000 ));
61
75
assertThat (config .getMaxObjectSize (), is (512 ));
62
76
assertThat (config .getMinObjectSize (), is (256 ));
63
- assertThat (config .getHeapSizeInMb (), is (32768 ));
77
+ assertThat (config .getHeapSizeInMb (), is (maxHeap ));
64
78
assertThat (config .getLongLivedInMb (), is (256 ));
65
79
assertThat (config .getMidAgedInMb (), is (32 ));
66
80
assertThat (config .getPruneRatio (), is (10 ));
67
81
assertThat (config .getReshuffleRatio (), is (20 ));
68
82
assertThat (config .getLogFile (), is ("nosuch.csv" ));
69
- assertFalse ( config .isUseCompressedOops ());
83
+ assertEquals ( useCompressedOops , config .isUseCompressedOops ());
70
84
}
71
85
72
86
@ Test
73
87
void UnknownParameterShouldExitTest () throws Exception {
74
88
int status = catchSystemExit (
75
89
() -> new SimpleRunConfig (new String []{"-w" , "who" }));
76
-
77
90
assertThat (status , is (1 ));
78
91
}
92
+
93
+ class MySecurityManager extends SecurityManager {}
79
94
}
0 commit comments