--- old/test/jdk/jdk/internal/platform/docker/MetricsMemoryTester.java 2020-01-21 20:26:23.196276880 +0100 +++ new/test/jdk/jdk/internal/platform/docker/MetricsMemoryTester.java 2020-01-21 20:26:23.060276575 +0100 @@ -23,6 +23,7 @@ import java.util.Arrays; import jdk.internal.platform.Metrics; +import jdk.internal.platform.MetricsCgroupV1; public class MetricsMemoryTester { public static void main(String[] args) { @@ -107,14 +108,20 @@ } private static void testKernelMemoryLimit(String value) { - long limit = getMemoryValue(value); - long kmemlimit = Metrics.systemMetrics().getKernelMemoryLimit(); - if (kmemlimit != 0 && limit != kmemlimit) { - throw new RuntimeException("Kernel Memory limit not equal, expected : [" - + limit + "]" + ", got : [" - + kmemlimit + "]"); - } - System.out.println("TEST PASSED!!!"); + Metrics m = Metrics.systemMetrics(); + if (m instanceof MetricsCgroupV1) { + MetricsCgroupV1 mCgroupV1 = (MetricsCgroupV1)m; + System.out.println("TEST PASSED!!!"); + long limit = getMemoryValue(value); + long kmemlimit = mCgroupV1.getKernelMemoryLimit(); + if (kmemlimit != 0 && limit != kmemlimit) { + throw new RuntimeException("Kernel Memory limit not equal, expected : [" + + limit + "]" + ", got : [" + + kmemlimit + "]"); + } + } else { + throw new RuntimeException("oomKillFlag test not supported for cgroups v2"); + } } private static void testMemoryAndSwapLimit(String memory, String memAndSwap) { @@ -146,9 +153,17 @@ } private static void testOomKillFlag(boolean oomKillFlag) { - if (!(oomKillFlag ^ Metrics.systemMetrics().isMemoryOOMKillEnabled())) { - throw new RuntimeException("oomKillFlag error"); + Metrics m = Metrics.systemMetrics(); + if (m instanceof MetricsCgroupV1) { + MetricsCgroupV1 mCgroupV1 = (MetricsCgroupV1)m; + Boolean expected = Boolean.valueOf(oomKillFlag); + Boolean actual = mCgroupV1.isMemoryOOMKillEnabled(); + if (!(expected.equals(actual))) { + throw new RuntimeException("oomKillFlag error"); + } + System.out.println("TEST PASSED!!!"); + } else { + throw new RuntimeException("oomKillFlag test not supported for cgroups v2"); } - System.out.println("TEST PASSED!!!"); } }