< prev index next >

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

Print this page




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import jdk.test.lib.Utils;
  25 import jdk.test.lib.containers.docker.Common;
  26 import jdk.test.lib.containers.docker.DockerRunOptions;
  27 import jdk.test.lib.containers.docker.DockerTestUtils;

  28 
  29 /*
  30  * @test
  31  * @summary Test JDK Metrics class when running inside docker container
  32  * @requires docker.support
  33  * @library /test/lib
  34  * @modules java.base/jdk.internal.platform
  35  * @build MetricsMemoryTester
  36  * @run main/timeout=360 TestDockerMemoryMetrics
  37  */
  38 
  39 public class TestDockerMemoryMetrics {
  40     private static final String imageName = Common.imageName("metrics-memory");
  41 
  42     public static void main(String[] args) throws Exception {
  43         if (!DockerTestUtils.canTestDocker()) {
  44             return;
  45         }
  46 
  47         // These tests create a docker image and run this image with


 102         DockerRunOptions opts =
 103                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
 104         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
 105                 .addDockerOpts("--memory=" + memory)
 106                 .addDockerOpts("--memory-swap=" + memandswap)
 107                 .addJavaOpts("-cp", "/test-classes/")
 108                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
 109                 .addClassOptions("memoryswap", memory, memandswap);
 110         DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
 111     }
 112 
 113     private static void testKernelMemoryLimit(String value) throws Exception {
 114         Common.logNewTestCase("testKernelMemoryLimit, value = " + value);
 115         DockerRunOptions opts =
 116                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
 117         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
 118                 .addDockerOpts("--kernel-memory=" + value)
 119                 .addJavaOpts("-cp", "/test-classes/")
 120                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
 121                 .addClassOptions("kernelmem", value);
 122         DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");






 123     }
 124 
 125     private static void testOomKillFlag(String value, boolean oomKillFlag) throws Exception {
 126         Common.logNewTestCase("testOomKillFlag, oomKillFlag = " + oomKillFlag);
 127         DockerRunOptions opts =
 128                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
 129         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
 130                 .addDockerOpts("--memory=" + value);
 131         if (!oomKillFlag) {
 132             opts.addDockerOpts("--oom-kill-disable");
 133         }
 134         opts.addJavaOpts("-cp", "/test-classes/")
 135                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
 136                 .addClassOptions("memory", value, oomKillFlag + "");
 137         DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
 138     }
 139 
 140     private static void testMemorySoftLimit(String mem, String softLimit) throws Exception {
 141         Common.logNewTestCase("testMemorySoftLimit, memory = " + mem + ", soft limit = " + softLimit);
 142         DockerRunOptions opts =


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import jdk.test.lib.Utils;
  25 import jdk.test.lib.containers.docker.Common;
  26 import jdk.test.lib.containers.docker.DockerRunOptions;
  27 import jdk.test.lib.containers.docker.DockerTestUtils;
  28 import jdk.test.lib.process.OutputAnalyzer;
  29 
  30 /*
  31  * @test
  32  * @summary Test JDK Metrics class when running inside docker container
  33  * @requires docker.support
  34  * @library /test/lib
  35  * @modules java.base/jdk.internal.platform
  36  * @build MetricsMemoryTester
  37  * @run main/timeout=360 TestDockerMemoryMetrics
  38  */
  39 
  40 public class TestDockerMemoryMetrics {
  41     private static final String imageName = Common.imageName("metrics-memory");
  42 
  43     public static void main(String[] args) throws Exception {
  44         if (!DockerTestUtils.canTestDocker()) {
  45             return;
  46         }
  47 
  48         // These tests create a docker image and run this image with


 103         DockerRunOptions opts =
 104                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
 105         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
 106                 .addDockerOpts("--memory=" + memory)
 107                 .addDockerOpts("--memory-swap=" + memandswap)
 108                 .addJavaOpts("-cp", "/test-classes/")
 109                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
 110                 .addClassOptions("memoryswap", memory, memandswap);
 111         DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
 112     }
 113 
 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         if (oa.getStderr().contains("kernel memory accounting disabled")) {
 125             System.out.println("Kernel memory accounting disabled on this system, " +
 126                                        "skipping the test case");
 127             return;
 128         }
 129         oa.shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
 130     }
 131 
 132     private static void testOomKillFlag(String value, boolean oomKillFlag) throws Exception {
 133         Common.logNewTestCase("testOomKillFlag, oomKillFlag = " + oomKillFlag);
 134         DockerRunOptions opts =
 135                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");
 136         opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
 137                 .addDockerOpts("--memory=" + value);
 138         if (!oomKillFlag) {
 139             opts.addDockerOpts("--oom-kill-disable");
 140         }
 141         opts.addJavaOpts("-cp", "/test-classes/")
 142                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
 143                 .addClassOptions("memory", value, oomKillFlag + "");
 144         DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
 145     }
 146 
 147     private static void testMemorySoftLimit(String mem, String softLimit) throws Exception {
 148         Common.logNewTestCase("testMemorySoftLimit, memory = " + mem + ", soft limit = " + softLimit);
 149         DockerRunOptions opts =
< prev index next >