Skip to content
Permalink
Browse files
8236617: jtreg test containers/docker/TestMemoryAwareness.java fails …
…after 8226575

Reviewed-by: yan
Backport-of: 44f7fe5
  • Loading branch information
Ekaterina Vergizova authored and Yuri Nesterenko committed Nov 27, 2020
1 parent c6f81a5 commit e91e43b0cb9348e086bb9169930c571e6fc37f38
Showing 2 changed files with 17 additions and 11 deletions.
@@ -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,14 +144,19 @@ 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.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]+")
.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");
}
}

}

1 comment on commit e91e43b

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on e91e43b Nov 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.