changeset 56128:72bc9a29fd7e

8229284: jdk/internal/platform/cgroup/TestCgroupMetrics.java fails for - memory:getMemoryUsage Reviewed-by: mseledtsov, sgehwolf
author mbaesken
date Wed, 28 Aug 2019 14:22:56 +0200
parents e29b6ddfd9f4
children e09c993ac476
files test/lib/jdk/test/lib/containers/cgroup/MetricsTester.java
diffstat 1 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/test/lib/jdk/test/lib/containers/cgroup/MetricsTester.java	Thu Aug 29 08:35:31 2019 -0700
+++ b/test/lib/jdk/test/lib/containers/cgroup/MetricsTester.java	Wed Aug 28 14:22:56 2019 +0200
@@ -582,19 +582,28 @@
         Metrics metrics = Metrics.systemMetrics();
         long memoryMaxUsage = metrics.getMemoryMaxUsage();
         long memoryUsage = metrics.getMemoryUsage();
+        long newMemoryMaxUsage = 0, newMemoryUsage = 0;
 
-        byte[] bb = new byte[64*1024*1024]; // 64M
+        // allocate memory in a loop and check more than once for new values
+        // otherwise we might see seldom the effect of decreasing new memory values
+        // e.g. because the system could free up memory
+        byte[][] bytes = new byte[32][];
+        for (int i = 0; i < 32; i++) {
+            bytes[i] = new byte[8*1024*1024];
+            newMemoryUsage = metrics.getMemoryUsage();
+            if (newMemoryUsage > memoryUsage) {
+                break;
+            }
+        }
+        newMemoryMaxUsage = metrics.getMemoryMaxUsage();
 
-        long newMemoryMaxUsage = metrics.getMemoryMaxUsage();
-        long newMemoryUsage = metrics.getMemoryUsage();
-
-        if(newMemoryMaxUsage < memoryMaxUsage) {
-            fail(SubSystem.MEMORY, "getMemoryMaxUsage", newMemoryMaxUsage,
-                    memoryMaxUsage);
+        if (newMemoryMaxUsage < memoryMaxUsage) {
+            fail(SubSystem.MEMORY, "getMemoryMaxUsage", memoryMaxUsage,
+                    newMemoryMaxUsage);
         }
 
-        if(newMemoryUsage < memoryUsage) {
-            fail(SubSystem.MEMORY, "getMemoryUsage", newMemoryUsage, memoryUsage);
+        if (newMemoryUsage < memoryUsage) {
+            fail(SubSystem.MEMORY, "getMemoryUsage", memoryUsage, newMemoryUsage);
         }
     }