Path: blob/master/test/hotspot/jtreg/containers/docker/DockerBasicTest.java
40943 views
/*1* Copyright (c) 2017, 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 Basic (sanity) test for JDK-under-test inside a docker image.27* @requires docker.support28* @library /test/lib29* @modules java.base/jdk.internal.misc30* java.management31* jdk.jartool/sun.tools.jar32* @build HelloDocker33* @run driver DockerBasicTest34*/35import jdk.test.lib.containers.docker.Common;36import jdk.test.lib.containers.docker.DockerRunOptions;37import jdk.test.lib.containers.docker.DockerTestUtils;38import jdk.test.lib.Platform;39import jdk.test.lib.Utils;404142public class DockerBasicTest {43private static final String imageNameAndTag = Common.imageName("basic");4445public static void main(String[] args) throws Exception {46if (!DockerTestUtils.canTestDocker()) {47return;48}4950DockerTestUtils.buildJdkDockerImage(imageNameAndTag, "Dockerfile-BasicTest", "jdk-docker");5152try {53testJavaVersion();54testHelloDocker();55} finally {56if (!DockerTestUtils.RETAIN_IMAGE_AFTER_TEST) {57DockerTestUtils.removeDockerImage(imageNameAndTag);58}59}60}616263private static void testJavaVersion() throws Exception {64DockerRunOptions opts =65new DockerRunOptions(imageNameAndTag, "/jdk/bin/java", "-version");6667DockerTestUtils.dockerRunJava(opts)68.shouldHaveExitValue(0)69.shouldContain(Platform.vmName);70}717273private static void testHelloDocker() throws Exception {74DockerRunOptions opts =75new DockerRunOptions(imageNameAndTag, "/jdk/bin/java", "HelloDocker")76.addJavaOpts("-cp", "/test-classes/")77.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");7879DockerTestUtils.dockerRunJava(opts)80.shouldHaveExitValue(0)81.shouldContain("Hello Docker");82}83}848586