Skip to content
Permalink
Browse files

8236617: jtreg test containers/docker/TestMemoryAwareness.java fails …

…after 8226575

Reviewed-by: bobv, clanger, mdoerr
  • Loading branch information
Matthias Baesken
Matthias Baesken committed Jan 3, 2020
1 parent 9549cd2 commit 44f7fe57a8e90f31875bb50cd55eaf4d57b1a6f6
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -61,7 +61,8 @@ public long getTotalSwapSpaceSize() {
// it can use as much memory as the host's OS allows.
long memLimit = containerMetrics.getMemoryLimit();
if (limit >= 0 && memLimit >= 0) {
return limit - memLimit;
// we see a limit == 0 on some machines where "kernel does not support swap limit capabilities"
return (limit < memLimit) ? 0 : limit - memLimit;
}
}
return getTotalSwapSpaceSize0();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -144,16 +144,21 @@ private static void testOperatingSystemMXBeanAwareness(String memoryAllocation,
"--memory-swap", swapAllocation
);

DockerTestUtils.dockerRunJava(opts)
.shouldHaveExitValue(0)
.shouldContain("Checking OperatingSystemMXBean")
.shouldContain("OperatingSystemMXBean.getTotalPhysicalMemorySize: " + expectedMemory)
.shouldMatch("OperatingSystemMXBean\\.getFreePhysicalMemorySize: [1-9][0-9]+")
.shouldContain("OperatingSystemMXBean.getTotalMemorySize: " + expectedMemory)
.shouldMatch("OperatingSystemMXBean\\.getFreeMemorySize: [1-9][0-9]+")
.shouldContain("OperatingSystemMXBean.getTotalSwapSpaceSize: " + expectedSwap)
.shouldMatch("OperatingSystemMXBean\\.getFreeSwapSpaceSize: [1-9][0-9]+")
;
OutputAnalyzer out = DockerTestUtils.dockerRunJava(opts);
out.shouldHaveExitValue(0)
.shouldContain("Checking OperatingSystemMXBean")
.shouldContain("OperatingSystemMXBean.getTotalPhysicalMemorySize: " + expectedMemory)
.shouldMatch("OperatingSystemMXBean\\.getFreePhysicalMemorySize: [1-9][0-9]+")
.shouldContain("OperatingSystemMXBean.getTotalMemorySize: " + expectedMemory)
.shouldMatch("OperatingSystemMXBean\\.getFreeMemorySize: [1-9][0-9]+")
.shouldMatch("OperatingSystemMXBean\\.getFreeSwapSpaceSize: [1-9][0-9]+");
// in case of warnings like : "Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap."
// the getTotalSwapSpaceSize does not return the expected result, but 0
try {
out.shouldContain("OperatingSystemMXBean.getTotalSwapSpaceSize: " + expectedSwap);
} catch(RuntimeException ex) {
out.shouldContain("OperatingSystemMXBean.getTotalSwapSpaceSize: 0");
}
}

}

0 comments on commit 44f7fe5

Please sign in to comment.