8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
Introduced unique environment variable Reviewed-by: egahlin, lmesnik, sgehwolf
This commit is contained in:
parent
508601bd9f
commit
d81e2cc4fe
test
hotspot/jtreg/containers/docker
lib/jdk/test/lib/containers/docker
@ -36,6 +36,7 @@
|
||||
* @build JfrReporter
|
||||
* @run driver TestJFREvents
|
||||
*/
|
||||
import java.util.List;
|
||||
import jdk.test.lib.containers.docker.Common;
|
||||
import jdk.test.lib.containers.docker.DockerRunOptions;
|
||||
import jdk.test.lib.containers.docker.DockerTestUtils;
|
||||
@ -46,6 +47,8 @@ import jdk.test.lib.Utils;
|
||||
|
||||
public class TestJFREvents {
|
||||
private static final String imageName = Common.imageName("jfr-events");
|
||||
private static final String TEST_ENV_VARIABLE = "UNIQUE_VARIABLE_ABC592903XYZ";
|
||||
private static final String TEST_ENV_VALUE = "unique_value_abc592903xyz";
|
||||
private static final int availableCPUs = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
@ -119,26 +122,29 @@ public class TestJFREvents {
|
||||
}
|
||||
|
||||
|
||||
// JTReg always defines the environment variable JAVA_MAIN_CLASS_<SOME_NUMBER>.
|
||||
// This variable fits well for use in this test, since it is rather unique.
|
||||
private static String getTestEnvironmentVariable() throws Exception {
|
||||
for (String key : System.getenv().keySet()) {
|
||||
if (key.startsWith("JAVA_MAIN_CLASS")) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("JAVA_MAIN_CLASS_* is not defined");
|
||||
}
|
||||
|
||||
|
||||
private static void testEnvironmentVariables() throws Exception {
|
||||
Common.logNewTestCase("EnvironmentVariables");
|
||||
|
||||
DockerTestUtils.dockerRunJava(
|
||||
List<String> cmd = DockerTestUtils.buildJavaCommand(
|
||||
commonDockerOpts()
|
||||
.addClassOptions("jdk.InitialEnvironmentVariable"))
|
||||
.shouldHaveExitValue(0)
|
||||
.addClassOptions("jdk.InitialEnvironmentVariable"));
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(cmd);
|
||||
// Container has JAVA_HOME defined via the Dockerfile; make sure
|
||||
// it is reported by JFR event.
|
||||
// Environment variable set in host system should not be visible inside a container,
|
||||
// and should not be reported by JFR.
|
||||
pb.environment().put(TEST_ENV_VARIABLE, TEST_ENV_VALUE);
|
||||
|
||||
System.out.println("[COMMAND]\n" + Utils.getCommandLine(pb));
|
||||
OutputAnalyzer out = new OutputAnalyzer(pb.start());
|
||||
System.out.println("[STDERR]\n" + out.getStderr());
|
||||
System.out.println("[STDOUT]\n" + out.getStdout());
|
||||
|
||||
out.shouldHaveExitValue(0)
|
||||
.shouldContain("key = JAVA_HOME")
|
||||
.shouldNotContain(getTestEnvironmentVariable());
|
||||
.shouldContain("value = /jdk")
|
||||
.shouldNotContain(TEST_ENV_VARIABLE)
|
||||
.shouldNotContain(TEST_ENV_VALUE);
|
||||
}
|
||||
}
|
||||
|
@ -184,15 +184,15 @@ public class DockerTestUtils {
|
||||
|
||||
|
||||
/**
|
||||
* Run Java inside the docker image with specified parameters and options.
|
||||
* Build the docker command to run java inside a container
|
||||
*
|
||||
* @param DockerRunOptions optins for running docker
|
||||
*
|
||||
* @return output of the run command
|
||||
* @return command
|
||||
* @throws Exception
|
||||
*/
|
||||
public static OutputAnalyzer dockerRunJava(DockerRunOptions opts) throws Exception {
|
||||
ArrayList<String> cmd = new ArrayList<>();
|
||||
public static List<String> buildJavaCommand(DockerRunOptions opts) throws Exception {
|
||||
List<String> cmd = new ArrayList<>();
|
||||
|
||||
cmd.add(DOCKER_COMMAND);
|
||||
cmd.add("run");
|
||||
@ -213,7 +213,19 @@ public class DockerTestUtils {
|
||||
cmd.add(opts.classToRun);
|
||||
cmd.addAll(opts.classParams);
|
||||
|
||||
return execute(cmd);
|
||||
return cmd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Java inside the docker image with specified parameters and options.
|
||||
*
|
||||
* @param DockerRunOptions optins for running docker
|
||||
*
|
||||
* @return output of the run command
|
||||
* @throws Exception
|
||||
*/
|
||||
public static OutputAnalyzer dockerRunJava(DockerRunOptions opts) throws Exception {
|
||||
return execute(buildJavaCommand(opts));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user