Fri, 24 Jul 2020 14:31:02 +0200
8250627: Use -XX:+/-UseContainerSupport for enabling/disabling Java container metrics
Reviewed-by: aph, dholmes, bobv, shade
sgehwolf@14169 | 1 | /* |
sgehwolf@14169 | 2 | * Copyright (c) 2020, Red Hat, Inc. |
sgehwolf@14169 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
sgehwolf@14169 | 4 | * |
sgehwolf@14169 | 5 | * This code is free software; you can redistribute it and/or modify it |
sgehwolf@14169 | 6 | * under the terms of the GNU General Public License version 2 only, as |
sgehwolf@14169 | 7 | * published by the Free Software Foundation. |
sgehwolf@14169 | 8 | * |
sgehwolf@14169 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
sgehwolf@14169 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
sgehwolf@14169 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
sgehwolf@14169 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
sgehwolf@14169 | 13 | * accompanied this code). |
sgehwolf@14169 | 14 | * |
sgehwolf@14169 | 15 | * You should have received a copy of the GNU General Public License version |
sgehwolf@14169 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
sgehwolf@14169 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
sgehwolf@14169 | 18 | * |
sgehwolf@14169 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
sgehwolf@14169 | 20 | * or visit www.oracle.com if you need additional information or have any |
sgehwolf@14169 | 21 | * questions. |
sgehwolf@14169 | 22 | */ |
sgehwolf@14169 | 23 | |
sgehwolf@14169 | 24 | /* |
sgehwolf@14169 | 25 | * @test |
sgehwolf@14169 | 26 | * @summary UseContainerSupport flag should reflect Metrics being available |
sgehwolf@14169 | 27 | * @library /lib |
sgehwolf@14169 | 28 | * @build CheckUseContainerSupport |
sgehwolf@14169 | 29 | * @run main/timeout=360 TestUseContainerSupport |
sgehwolf@14169 | 30 | */ |
sgehwolf@14169 | 31 | |
sgehwolf@14169 | 32 | import jdk.test.lib.Utils; |
sgehwolf@14169 | 33 | import jdk.test.lib.containers.docker.Common; |
sgehwolf@14169 | 34 | import jdk.test.lib.containers.docker.DockerRunOptions; |
sgehwolf@14169 | 35 | import jdk.test.lib.containers.docker.DockerTestUtils; |
sgehwolf@14169 | 36 | |
sgehwolf@14169 | 37 | public class TestUseContainerSupport { |
sgehwolf@14169 | 38 | private static final String imageName = Common.imageName("useContainerSupport"); |
sgehwolf@14169 | 39 | |
sgehwolf@14169 | 40 | public static void main(String[] args) throws Exception { |
sgehwolf@14169 | 41 | if (!DockerTestUtils.canTestDocker()) { |
sgehwolf@14169 | 42 | return; |
sgehwolf@14169 | 43 | } |
sgehwolf@14169 | 44 | |
sgehwolf@14169 | 45 | DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker"); |
sgehwolf@14169 | 46 | |
sgehwolf@14169 | 47 | try { |
sgehwolf@14169 | 48 | testUseContainerSupport(true); |
sgehwolf@14169 | 49 | testUseContainerSupport(false); |
sgehwolf@14169 | 50 | } finally { |
sgehwolf@14169 | 51 | DockerTestUtils.removeDockerImage(imageName); |
sgehwolf@14169 | 52 | } |
sgehwolf@14169 | 53 | } |
sgehwolf@14169 | 54 | |
sgehwolf@14169 | 55 | private static void testUseContainerSupport(boolean useContainerSupport) throws Exception { |
sgehwolf@14169 | 56 | String testMsg = " with -XX:" + (useContainerSupport ? "+" : "-") + "UseContainerSupport"; |
sgehwolf@14169 | 57 | Common.logNewTestCase("Test TestUseContainerSupport" + testMsg); |
sgehwolf@14169 | 58 | DockerRunOptions opts = |
sgehwolf@14169 | 59 | new DockerRunOptions(imageName, "/jdk/bin/java", "CheckUseContainerSupport"); |
sgehwolf@14169 | 60 | opts.addClassOptions(Boolean.valueOf(useContainerSupport).toString()); |
sgehwolf@14169 | 61 | opts.addDockerOpts("--memory", "200m") |
sgehwolf@14169 | 62 | .addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/"); |
sgehwolf@14169 | 63 | if (useContainerSupport) { |
sgehwolf@14169 | 64 | opts.addJavaOpts("-XX:+UseContainerSupport"); |
sgehwolf@14169 | 65 | } else { |
sgehwolf@14169 | 66 | opts.addJavaOpts("-XX:-UseContainerSupport"); |
sgehwolf@14169 | 67 | } |
sgehwolf@14169 | 68 | opts.addJavaOpts("-cp", "/test-classes/"); |
sgehwolf@14169 | 69 | DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!"); |
sgehwolf@14169 | 70 | } |
sgehwolf@14169 | 71 | } |