Skip to content

Commit

Permalink
1. if (isCgroupV1) only contains opts.addDockerOpts("--memory-swappin…
Browse files Browse the repository at this point in the history
…ess=60"); 2. delete extra space at the beginning of the line in testSwapMemory
  • Loading branch information
sendaoYan committed Apr 12, 2024
1 parent bd144b7 commit 4e5ea66
Showing 1 changed file with 27 additions and 35 deletions.
62 changes: 27 additions & 35 deletions test/hotspot/jtreg/containers/docker/TestJFREvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,45 +227,37 @@ private static void testMemory(String valueToSet, String expectedValue) throws E


private static void testSwapMemory(String memValueToSet, String swapValueToSet, String expectedTotalValue, String expectedFreeValue) throws Exception {
OutputAnalyzer out;
Common.logNewTestCase("Memory: --memory = " + memValueToSet + " --memory-swap = " + swapValueToSet);
DockerRunOptions opts = commonDockerOpts();
opts.addDockerOpts("--memory=" + memValueToSet)
.addDockerOpts("--memory-swap=" + swapValueToSet)
.addClassOptions("jdk.SwapSpace");
if (isCgroupV1) {
Common.logNewTestCase("Memory: --memory = " + memValueToSet + " --memory-swap = " + swapValueToSet + " --memory-swappiness = 60");
out = DockerTestUtils.dockerRunJava(
commonDockerOpts()
.addDockerOpts("--memory=" + memValueToSet)
.addDockerOpts("--memory-swap=" + swapValueToSet)
// With Cgroupv1, The default memory-swappiness vaule is inherited from the host machine, which maybe 0
.addDockerOpts("--memory-swappiness=60")
.addClassOptions("jdk.SwapSpace"));
} else {
Common.logNewTestCase("Memory: --memory = " + memValueToSet + " --memory-swap = " + swapValueToSet);
out = DockerTestUtils.dockerRunJava(
commonDockerOpts()
.addDockerOpts("--memory=" + memValueToSet)
.addDockerOpts("--memory-swap=" + swapValueToSet)
.addClassOptions("jdk.SwapSpace"));
// With Cgroupv1, The default memory-swappiness vaule is inherited from the host machine, which maybe 0
opts.addDockerOpts("--memory-swappiness=60");
}
out.shouldHaveExitValue(0)
OutputAnalyzer out = DockerTestUtils.dockerRunJava(opts);
out.shouldHaveExitValue(0)
.shouldContain("totalSize = " + expectedTotalValue)
.shouldContain("freeSize = ");
List<String> ls = out.asLinesWithoutVMWarnings();
for (String cur : ls) {
int idx = cur.indexOf("freeSize = ");
if (idx != -1) {
int startNbr = idx+11;
int endNbr = cur.indexOf(' ', startNbr);
if (endNbr == -1) endNbr = cur.length();
String freeSizeStr = cur.substring(startNbr, endNbr);
long freeval = Long.parseLong(freeSizeStr);
long totalval = Long.parseLong(expectedTotalValue);
if (0 <= freeval && freeval <= totalval) {
System.out.println("Found freeSize value " + freeval + " is fine");
} else {
System.out.println("Found freeSize value " + freeval + " is bad");
throw new Exception("Found free size value is bad");
}
}
}
List<String> ls = out.asLinesWithoutVMWarnings();
for (String cur : ls) {
int idx = cur.indexOf("freeSize = ");
if (idx != -1) {
int startNbr = idx+11;
int endNbr = cur.indexOf(' ', startNbr);
if (endNbr == -1) endNbr = cur.length();
String freeSizeStr = cur.substring(startNbr, endNbr);
long freeval = Long.parseLong(freeSizeStr);
long totalval = Long.parseLong(expectedTotalValue);
if (0 <= freeval && freeval <= totalval) {
System.out.println("Found freeSize value " + freeval + " is fine");
} else {
System.out.println("Found freeSize value " + freeval + " is bad");
throw new Exception("Found free size value is bad");
}
}
}
}


Expand Down

0 comments on commit 4e5ea66

Please sign in to comment.