< prev index next >

test/jdk/jdk/internal/platform/docker/TestDockerMemoryMetrics.java

Print this page
@  rev 56863 : 8231111: Cgroups v2: Rework Metrics in java.base so as to recognize unified hierarchy
|  Reviewed-by: bobv
~


  52 
  53         DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
  54         try {
  55             testMemoryLimit("200m");
  56             testMemoryLimit("1g");
  57 
  58             testMemoryAndSwapLimit("200m", "1g");
  59             testMemoryAndSwapLimit("100m", "200m");
  60 
  61             testKernelMemoryLimit("100m");
  62             testKernelMemoryLimit("1g");
  63 
  64             testOomKillFlag("100m", false);
  65             testOomKillFlag("100m", true);
  66 
  67             testMemoryFailCount("64m");
  68 
  69             testMemorySoftLimit("500m","200m");
  70 
  71         } finally {

  72             DockerTestUtils.removeDockerImage(imageName);
  73         }
  74     }

  75 
  76     private static void testMemoryLimit(String value) throws Exception {
  77         Common.logNewTestCase("testMemoryLimit, value = " + value);
  78         DockerRunOptions opts =
  79                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
  80         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
  81                 .addDockerOpts("--memory=" + value)
  82                 .addJavaOpts("-cp", "/test-classes/")
  83                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
  84                 .addClassOptions("memory", value);
  85         DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
  86     }
  87 
  88     private static void testMemoryFailCount(String value) throws Exception {
  89         Common.logNewTestCase("testMemoryFailCount" + value);
  90         DockerRunOptions opts =
  91                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
  92         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
  93                 .addDockerOpts("--memory=" + value)
  94                 .addJavaOpts("-Xmx" + value)


 114     private static void testKernelMemoryLimit(String value) throws Exception {
 115         Common.logNewTestCase("testKernelMemoryLimit, value = " + value);
 116         DockerRunOptions opts =
 117                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
 118         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
 119                 .addDockerOpts("--kernel-memory=" + value)
 120                 .addJavaOpts("-cp", "/test-classes/")
 121                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
 122                 .addClassOptions("kernelmem", value);
 123         OutputAnalyzer oa = DockerTestUtils.dockerRunJava(opts);
 124 
 125         // Some container runtimes (e.g. runc, docker 18.09)
 126         // have been built without kernel memory accounting. In
 127         // that case, the runtime issues a message on stderr saying
 128         // so. Skip the test in that case.
 129         if (oa.getStderr().contains("kernel memory accounting disabled")) {
 130             System.out.println("Kernel memory accounting disabled, " +
 131                                        "skipping the test case");
 132             return;
 133         }





 134 
 135         oa.shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
 136     }
 137 
 138     private static void testOomKillFlag(String value, boolean oomKillFlag) throws Exception {
 139         Common.logNewTestCase("testOomKillFlag, oomKillFlag = " + oomKillFlag);
 140         DockerRunOptions opts =
 141                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
 142         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
 143                 .addDockerOpts("--memory=" + value);
 144         if (!oomKillFlag) {
 145             opts.addDockerOpts("--oom-kill-disable");
 146         }
 147         opts.addJavaOpts("-cp", "/test-classes/")
 148                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
 149                 .addClassOptions("memory", value, oomKillFlag + "");
 150         DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");







 151     }
 152 
 153     private static void testMemorySoftLimit(String mem, String softLimit) throws Exception {
 154         Common.logNewTestCase("testMemorySoftLimit, memory = " + mem + ", soft limit = " + softLimit);
 155         DockerRunOptions opts =
 156                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
 157         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
 158                 .addDockerOpts("--memory=" + mem)
 159                 .addDockerOpts("--memory-reservation=" + softLimit);
 160         opts.addJavaOpts("-cp", "/test-classes/")
 161                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
 162                 .addClassOptions("softlimit", softLimit);
 163         DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
 164     }
 165 }


  52 
  53         DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
  54         try {
  55             testMemoryLimit("200m");
  56             testMemoryLimit("1g");
  57 
  58             testMemoryAndSwapLimit("200m", "1g");
  59             testMemoryAndSwapLimit("100m", "200m");
  60 
  61             testKernelMemoryLimit("100m");
  62             testKernelMemoryLimit("1g");
  63 
  64             testOomKillFlag("100m", false);
  65             testOomKillFlag("100m", true);
  66 
  67             testMemoryFailCount("64m");
  68 
  69             testMemorySoftLimit("500m","200m");
  70 
  71         } finally {
  72             if (!DockerTestUtils.RETAIN_IMAGE_AFTER_TEST) {
  73                 DockerTestUtils.removeDockerImage(imageName);
  74             }
  75         }
  76     }
  77 
  78     private static void testMemoryLimit(String value) throws Exception {
  79         Common.logNewTestCase("testMemoryLimit, value = " + value);
  80         DockerRunOptions opts =
  81                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
  82         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
  83                 .addDockerOpts("--memory=" + value)
  84                 .addJavaOpts("-cp", "/test-classes/")
  85                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
  86                 .addClassOptions("memory", value);
  87         DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
  88     }
  89 
  90     private static void testMemoryFailCount(String value) throws Exception {
  91         Common.logNewTestCase("testMemoryFailCount" + value);
  92         DockerRunOptions opts =
  93                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
  94         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
  95                 .addDockerOpts("--memory=" + value)
  96                 .addJavaOpts("-Xmx" + value)


 116     private static void testKernelMemoryLimit(String value) throws Exception {
 117         Common.logNewTestCase("testKernelMemoryLimit, value = " + value);
 118         DockerRunOptions opts =
 119                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
 120         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
 121                 .addDockerOpts("--kernel-memory=" + value)
 122                 .addJavaOpts("-cp", "/test-classes/")
 123                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
 124                 .addClassOptions("kernelmem", value);
 125         OutputAnalyzer oa = DockerTestUtils.dockerRunJava(opts);
 126 
 127         // Some container runtimes (e.g. runc, docker 18.09)
 128         // have been built without kernel memory accounting. In
 129         // that case, the runtime issues a message on stderr saying
 130         // so. Skip the test in that case.
 131         if (oa.getStderr().contains("kernel memory accounting disabled")) {
 132             System.out.println("Kernel memory accounting disabled, " +
 133                                        "skipping the test case");
 134             return;
 135         }
 136         if (oa.getStderr().contains("cannot set kernel memory with cgroupv2")) {
 137             System.out.println("Kernel memory settings not possible with cgroupv2, " +
 138                                        "skipping the test case");
 139             return;
 140         }
 141 
 142         oa.shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
 143     }
 144 
 145     private static void testOomKillFlag(String value, boolean oomKillFlag) throws Exception {
 146         Common.logNewTestCase("testOomKillFlag, oomKillFlag = " + oomKillFlag);
 147         DockerRunOptions opts =
 148                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
 149         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
 150                 .addDockerOpts("--memory=" + value);
 151         if (!oomKillFlag) {
 152             opts.addDockerOpts("--oom-kill-disable");
 153         }
 154         opts.addJavaOpts("-cp", "/test-classes/")
 155                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
 156                 .addClassOptions("memory", value, oomKillFlag + "");
 157         OutputAnalyzer oa = DockerTestUtils.dockerRunJava(opts);
 158         if (oa.getStderr().contains("cannot disable OOM killer with cgroupv2")) {
 159             System.out.println("Disabling OOM killer not possible with cgroupv2, " +
 160                                        "skipping the test case");
 161             return;
 162         }
 163 
 164         oa.shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
 165     }
 166 
 167     private static void testMemorySoftLimit(String mem, String softLimit) throws Exception {
 168         Common.logNewTestCase("testMemorySoftLimit, memory = " + mem + ", soft limit = " + softLimit);
 169         DockerRunOptions opts =
 170                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
 171         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
 172                 .addDockerOpts("--memory=" + mem)
 173                 .addDockerOpts("--memory-reservation=" + softLimit);
 174         opts.addJavaOpts("-cp", "/test-classes/")
 175                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
 176                 .addClassOptions("softlimit", softLimit);
 177         DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
 178     }
 179 }
< prev index next >