Path: blob/master/test/hotspot/jtreg/containers/docker/TestJFRNetworkEvents.java
40942 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324/*25* @test26* @summary Test JFR network related events inside a container; make sure27* the reported host ip and host name are correctly reported within28* the container.29* @requires docker.support30* @library /test/lib31* @modules java.base/jdk.internal.misc32* java.management33* jdk.jartool/sun.tools.jar34* @build JfrNetwork35* @run driver TestJFRNetworkEvents36*/37import jdk.test.lib.containers.docker.Common;38import jdk.test.lib.containers.docker.DockerRunOptions;39import jdk.test.lib.containers.docker.DockerTestUtils;40import jdk.test.lib.Utils;414243public class TestJFRNetworkEvents {44private static final String imageName = Common.imageName("jfr-network");45private static final int availableCPUs = Runtime.getRuntime().availableProcessors();4647public static void main(String[] args) throws Exception {48System.out.println("Test Environment: detected availableCPUs = " + availableCPUs);49if (!DockerTestUtils.canTestDocker()) {50return;51}5253DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");5455try {56runTest("jdk.SocketWrite");57} finally {58DockerTestUtils.removeDockerImage(imageName);59}60}6162private static void runTest(String event) throws Exception {63DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java", "JfrNetwork")64.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")65.addJavaOpts("-cp", "/test-classes/")66.addDockerOpts("--hostname", JfrNetwork.HOST_NAME)67.addClassOptions(event);68DockerTestUtils.dockerRunJava(opts)69.shouldHaveExitValue(0)70.shouldContain(JfrNetwork.JFR_REPORTED_CONTAINER_HOSTNAME_TAG + JfrNetwork.HOST_NAME);71}72}737475