Mercurial > hg > openjdk > jdk8u > hotspot
changeset 9343:1a2714e736d0
8221710: [TESTBUG] more configurable parameters for docker testing
Summary: Introduced docker test config properties
Reviewed-by: lmesnik, iignatyev, egahlin, phh
author | mseledtsov |
---|---|
date | Thu, 04 Apr 2019 12:29:43 -0700 |
parents | 1825208d432f |
children | 739dd6193ede |
files | test/runtime/containers/docker/DockerBasicTest.java test/testlibrary/com/oracle/java/testlibrary/DockerTestUtils.java |
diffstat | 2 files changed, 25 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/test/runtime/containers/docker/DockerBasicTest.java Mon Sep 26 14:38:35 2016 -0400 +++ b/test/runtime/containers/docker/DockerBasicTest.java Thu Apr 04 12:29:43 2019 -0700 @@ -37,8 +37,6 @@ public class DockerBasicTest { private static final String imageNameAndTag = "jdk8-internal:test"; - // Diganostics: set to false to examine image after the test - private static final boolean removeImageAfterTest = true; public static void main(String[] args) throws Exception { if (!DockerTestUtils.canTestDocker()) { @@ -50,8 +48,9 @@ testJavaVersion(); testHelloDocker(); } finally { - if (removeImageAfterTest) + if (!DockerTestUtils.RETAIN_IMAGE_AFTER_TEST) { DockerTestUtils.removeDockerImage(imageNameAndTag); + } } }
--- a/test/testlibrary/com/oracle/java/testlibrary/DockerTestUtils.java Mon Sep 26 14:38:35 2016 -0400 +++ b/test/testlibrary/com/oracle/java/testlibrary/DockerTestUtils.java Thu Apr 04 12:29:43 2019 -0700 @@ -47,8 +47,23 @@ private static boolean isDockerEngineAvailable = false; private static boolean wasDockerEngineChecked = false; - // Diagnostics: set to true to enable more diagnostic info - private static final boolean DEBUG = false; + // Use this property to specify docker location on your system. + // E.g.: "/usr/local/bin/docker". + private static final String DOCKER_COMMAND = + System.getProperty("jdk.test.docker.command", "docker"); + + // Set this property to true to retain image after test. By default + // images are removed after test execution completes. + // Retaining the image can be useful for diagnostics and image inspection. + // E.g.: start image interactively: docker run -it <IMAGE_NAME>. + public static final boolean RETAIN_IMAGE_AFTER_TEST = + Boolean.getBoolean("jdk.test.docker.retain.image"); + + // Path to a JDK under test. + // This may be useful when developing tests on non-Linux platforms. + public static final String JDK_UNDER_TEST = + System.getProperty("jdk.test.docker.jdk", Utils.TEST_JDK); + /** * Optimized check of whether the docker engine is available in a given @@ -96,7 +111,7 @@ */ private static boolean isDockerEngineAvailableCheck() throws Exception { try { - execute("docker", "ps") + execute(DOCKER_COMMAND, "ps") .shouldHaveExitValue(0) .shouldContain("CONTAINER") .shouldContain("IMAGE"); @@ -127,7 +142,7 @@ throw new RuntimeException("The docker build directory already exists: " + buildDir); } - Path jdkSrcDir = Paths.get(Utils.TEST_JDK); + Path jdkSrcDir = Paths.get(JDK_UNDER_TEST); Path jdkDstDir = buildDir.resolve("jdk"); Files.createDirectories(jdkDstDir); @@ -157,7 +172,7 @@ DockerfileConfig.getBaseImageVersion()); // Build the docker - execute("docker", "build", "--no-cache", "--tag", imageName, buildDir.toString()) + execute(DOCKER_COMMAND, "build", "--no-cache", "--tag", imageName, buildDir.toString()) .shouldHaveExitValue(0) .shouldContain("Successfully built"); } @@ -174,7 +189,7 @@ public static OutputAnalyzer dockerRunJava(DockerRunOptions opts) throws Exception { ArrayList<String> cmd = new ArrayList<>(); - cmd.add("docker"); + cmd.add(DOCKER_COMMAND); cmd.add("run"); if (opts.tty) cmd.add("--tty=true"); @@ -200,11 +215,10 @@ * Remove docker image * * @param DockerRunOptions optins for running docker - * @return output of the command * @throws Exception */ - public static OutputAnalyzer removeDockerImage(String imageNameAndTag) throws Exception { - return execute("docker", "rmi", "--force", imageNameAndTag); + public static void removeDockerImage(String imageNameAndTag) throws Exception { + execute(DOCKER_COMMAND, "rmi", "--force", imageNameAndTag); }