23 |
23 |
24 import jdk.test.lib.Utils; |
24 import jdk.test.lib.Utils; |
25 import jdk.test.lib.containers.docker.Common; |
25 import jdk.test.lib.containers.docker.Common; |
26 import jdk.test.lib.containers.docker.DockerRunOptions; |
26 import jdk.test.lib.containers.docker.DockerRunOptions; |
27 import jdk.test.lib.containers.docker.DockerTestUtils; |
27 import jdk.test.lib.containers.docker.DockerTestUtils; |
|
28 import jdk.test.lib.process.OutputAnalyzer; |
28 |
29 |
29 /* |
30 /* |
30 * @test |
31 * @test |
31 * @summary Test JDK Metrics class when running inside docker container |
32 * @summary Test JDK Metrics class when running inside docker container |
32 * @requires docker.support |
33 * @requires docker.support |
117 opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/") |
118 opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/") |
118 .addDockerOpts("--kernel-memory=" + value) |
119 .addDockerOpts("--kernel-memory=" + value) |
119 .addJavaOpts("-cp", "/test-classes/") |
120 .addJavaOpts("-cp", "/test-classes/") |
120 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED") |
121 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED") |
121 .addClassOptions("kernelmem", value); |
122 .addClassOptions("kernelmem", value); |
122 DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!"); |
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!!!"); |
123 } |
136 } |
124 |
137 |
125 private static void testOomKillFlag(String value, boolean oomKillFlag) throws Exception { |
138 private static void testOomKillFlag(String value, boolean oomKillFlag) throws Exception { |
126 Common.logNewTestCase("testOomKillFlag, oomKillFlag = " + oomKillFlag); |
139 Common.logNewTestCase("testOomKillFlag, oomKillFlag = " + oomKillFlag); |
127 DockerRunOptions opts = |
140 DockerRunOptions opts = |