< prev index next >

test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV2.java

Print this page
@  rev 57734 : Review feedback
|
o  rev 57733 : 8231111: Cgroups v2: Rework Metrics in java.base so as to recognize unified hierarchy
|  Reviewed-by: bobv, mchung
~
o  rev 56862 : 8231111: Cgroups v2: Rework Metrics in java.base so as to recognize unified hierarchy
|  Reviewed-by: bobv
~

@@ -32,17 +32,16 @@
 import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
+import jdk.internal.platform.CgroupSubsystem;
 import jdk.internal.platform.Metrics;
-import jdk.test.lib.Asserts;
 
 public class MetricsTesterCgroupV2 implements CgroupMetricsTester {
 
     private static final long UNLIMITED = -1;
-    private static final long NOT_SUPPORTED = -2;
     private static final UnifiedController UNIFIED = new UnifiedController();
     private static final String MAX = "max";
     private static final int PER_CPU_SHARES = 1024;
 
     private final long startSysVal;

@@ -151,25 +150,10 @@
 
     private void warn(String metric, long oldVal, long newVal) {
         CgroupMetricsTester.warn(UnifiedController.NAME, metric, oldVal, newVal);
     }
 
-    private void verifyNotSupported(long metricVal) {
-        Asserts.assertEquals(metricVal, NOT_SUPPORTED, "Expected metric to be not supported!");
-    }
-
-    private void verifyNotSupported(double metricVal) {
-        if (!CgroupMetricsTester.compareWithErrorMargin(NOT_SUPPORTED, metricVal)) {
-            throw new RuntimeException("Metric not supported, got: " + metricVal +
-                                       " expected: " + NOT_SUPPORTED);
-        }
-    }
-
-    private void verifyPerCpuNotSupported(long[] perCpuUsage) {
-        Asserts.assertNull(perCpuUsage, "perCpuUsage expected to be not supported");
-    }
-
     private long getCpuShares(String file) {
         long rawVal = getLongValueFromFile(file);
         if (rawVal == 0 || rawVal == 100) {
             return UNLIMITED;
         }

@@ -241,33 +225,17 @@
         oldVal = metrics.getMemoryUsage();
         newVal = getLongValueFromFile("memory.current");
         if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
             fail("memory.current", oldVal, newVal);
         }
-        verifyNotSupported(metrics.getMemoryMaxUsage());
-
-        // Kernel memory
-        verifyNotSupported(metrics.getKernelMemoryFailCount());
-        verifyNotSupported(metrics.getKernelMemoryLimit());
-        verifyNotSupported(metrics.getKernelMemoryMaxUsage());
-        verifyNotSupported(metrics.getKernelMemoryUsage());
-
-        //TCP Memory
-        verifyNotSupported(metrics.getTcpMemoryFailCount());
-        verifyNotSupported(metrics.getTcpMemoryLimit());
-        verifyNotSupported(metrics.getTcpMemoryMaxUsage());
 
         oldVal = metrics.getTcpMemoryUsage();
         newVal = getLongValueEntryFromFile("memory.stat", "sock");
         if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
             fail("memory.stat[sock]", oldVal, newVal);
         }
 
-        //  Memory and Swap
-        verifyNotSupported(metrics.getMemoryAndSwapFailCount());
-        verifyNotSupported(metrics.getMemoryAndSwapMaxUsage());
-
         oldVal = metrics.getMemoryAndSwapLimit();
         newVal = getLongLimitValueFromFile("memory.swap.max");
         if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
             fail("memory.swap.max", oldVal, newVal);
         }

@@ -282,11 +250,10 @@
         newVal = getLongLimitValueFromFile("memory.high");
         if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
             fail("memory.high", oldVal, newVal);
         }
 
-        Asserts.assertNull(metrics.isMemoryOOMKillEnabled(), "Not supported");
     }
 
     @Override
     public void testCpuAccounting() {
         Metrics metrics = Metrics.systemMetrics();

@@ -295,12 +262,10 @@
 
         if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
             warn("cpu.stat[usage_usec]", oldVal, newVal);
         }
 
-        verifyPerCpuNotSupported(metrics.getPerCpuUsage());
-
         oldVal = metrics.getCpuUserUsage();
         newVal = TimeUnit.MICROSECONDS.toNanos(getLongValueEntryFromFile("cpu.stat", "user_usec"));
         if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
             warn("cpu.stat[user_usec]", oldVal, newVal);
         }

@@ -398,13 +363,10 @@
         Arrays.sort(newVal);
         if (Arrays.compare(oldVal, newVal) != 0) {
             fail("cpuset.mems.effective", Arrays.toString(oldVal),
                                           Arrays.toString(newVal));
         }
-
-        verifyNotSupported(metrics.getCpuSetMemoryPressure());
-        Asserts.assertNull(metrics.isCpuSetMemoryPressureEnabled(), "Should be not supported");
     }
 
     private int[] mapNullToEmpty(int[] cpus) {
         if (cpus == null) {
             // Not available. For sake of testing continue with an

@@ -420,12 +382,10 @@
         // make system call
         long newSysVal = metrics.getCpuSystemUsage();
         long newUserVal = metrics.getCpuUserUsage();
         long newUsage = metrics.getCpuUsage();
 
-        verifyPerCpuNotSupported(metrics.getPerCpuUsage());
-
         // system/user CPU usage counters may be slowly increasing.
         // allow for equal values for a pass
         if (newSysVal < startSysVal) {
             fail("getCpuSystemUsage", newSysVal, startSysVal);
         }

@@ -442,13 +402,12 @@
     }
 
     @Override
     public void testMemoryUsage() {
         Metrics metrics = Metrics.systemMetrics();
-        long memoryMaxUsage = metrics.getMemoryMaxUsage();
         long memoryUsage = metrics.getMemoryUsage();
-        long newMemoryMaxUsage = 0, newMemoryUsage = 0;
+        long newMemoryUsage = 0;
 
         // allocate memory in a loop and check more than once for new values
         // otherwise we might occasionally see the effect of decreasing new memory
         // values. For example because the system could free up memory
         byte[][] bytes = new byte[32][];

@@ -457,16 +416,10 @@
             newMemoryUsage = metrics.getMemoryUsage();
             if (newMemoryUsage > memoryUsage) {
                 break;
             }
         }
-        newMemoryMaxUsage = metrics.getMemoryMaxUsage();
-
-        if (newMemoryMaxUsage < memoryMaxUsage) {
-            fail("getMemoryMaxUsage", memoryMaxUsage,
-                                      newMemoryMaxUsage);
-        }
 
         if (newMemoryUsage < memoryUsage) {
             fail("getMemoryUsage", memoryUsage, newMemoryUsage);
         }
     }

@@ -509,9 +462,9 @@
                             }
                         }
                         return accumulator;
                     }).collect(Collectors.summingLong(e -> e));
         } catch (IOException e) {
-            return Metrics.LONG_RETVAL_NOT_SUPPORTED;
+            return CgroupSubsystem.LONG_RETVAL_UNLIMITED;
         }
     }
 }
< prev index next >