8327946: containers/docker/TestJFREvents.java fails when host kernel config vm.swappiness=0 after JDK-8325139
Reviewed-by: sgehwolf
This commit is contained in:
parent
9d63fee49c
commit
7744b0046a
@ -30,6 +30,7 @@
|
||||
* Also make sure that PIDs are based on value provided by container,
|
||||
* not by the host system.
|
||||
* @requires (docker.support & os.maxMemory >= 2g)
|
||||
* @modules java.base/jdk.internal.platform
|
||||
* @library /test/lib
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* java.management
|
||||
@ -44,6 +45,7 @@ import jdk.test.lib.containers.docker.DockerTestUtils;
|
||||
import jdk.test.lib.Asserts;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.internal.platform.Metrics;
|
||||
|
||||
|
||||
public class TestJFREvents {
|
||||
@ -52,6 +54,7 @@ public class TestJFREvents {
|
||||
private static final String TEST_ENV_VALUE = "unique_value_abc592903xyz";
|
||||
private static final int availableCPUs = Runtime.getRuntime().availableProcessors();
|
||||
private static final int UNKNOWN = -100;
|
||||
private static boolean isCgroupV1 = false;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("Test Environment: detected availableCPUs = " + availableCPUs);
|
||||
@ -59,6 +62,14 @@ public class TestJFREvents {
|
||||
return;
|
||||
}
|
||||
|
||||
// If cgroups is not configured, report success.
|
||||
Metrics metrics = Metrics.systemMetrics();
|
||||
if (metrics == null) {
|
||||
System.out.println("TEST PASSED!!!");
|
||||
return;
|
||||
}
|
||||
isCgroupV1 = "cgroupv1".equals(metrics.getProvider());
|
||||
|
||||
DockerTestUtils.buildJdkContainerImage(imageName);
|
||||
|
||||
try {
|
||||
@ -217,32 +228,36 @@ public class TestJFREvents {
|
||||
|
||||
private static void testSwapMemory(String memValueToSet, String swapValueToSet, String expectedTotalValue, String expectedFreeValue) throws Exception {
|
||||
Common.logNewTestCase("Memory: --memory = " + memValueToSet + " --memory-swap = " + swapValueToSet);
|
||||
OutputAnalyzer out = DockerTestUtils.dockerRunJava(
|
||||
commonDockerOpts()
|
||||
.addDockerOpts("--memory=" + memValueToSet)
|
||||
.addDockerOpts("--memory-swap=" + swapValueToSet)
|
||||
.addClassOptions("jdk.SwapSpace"));
|
||||
out.shouldHaveExitValue(0)
|
||||
DockerRunOptions opts = commonDockerOpts();
|
||||
opts.addDockerOpts("--memory=" + memValueToSet)
|
||||
.addDockerOpts("--memory-swap=" + swapValueToSet)
|
||||
.addClassOptions("jdk.SwapSpace");
|
||||
if (isCgroupV1) {
|
||||
// With Cgroupv1, The default memory-swappiness vaule is inherited from the host machine, which maybe 0
|
||||
opts.addDockerOpts("--memory-swappiness=60");
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user