< prev index next >
test/hotspot/jtreg/containers/docker/TestJcmdWithSideCar.java
Print this page
*** 66,80 ****
try {
// Start the loop process in the "main" container, then run test cases
// using a sidecar container.
DockerThread t = startMainContainer();
! waitForMainContainerToStart(500, 10);
t.checkForErrors();
OutputAnalyzer jcmdOut = testCase01();
! long mainProcPid = findProcess(jcmdOut, "EventGeneratorLoop");
t.assertIsAlive();
testCase02(mainProcPid);
// JCMD does not work in sidecar configuration, except for "jcmd -l".
--- 66,80 ----
try {
// Start the loop process in the "main" container, then run test cases
// using a sidecar container.
DockerThread t = startMainContainer();
! DockerTestUtils.waitForContainerToStart(MAIN_CONTAINER_NAME, 2000, 500, 10);
t.checkForErrors();
OutputAnalyzer jcmdOut = testCase01();
! long mainProcPid = Common.findPidFromJcmdOutput(jcmdOut, "EventGeneratorLoop");
t.assertIsAlive();
testCase02(mainProcPid);
// JCMD does not work in sidecar configuration, except for "jcmd -l".
*** 129,161 ****
t.start();
return t;
}
- private static void waitForMainContainerToStart(int delayMillis, int count) throws Exception {
- boolean started = false;
- for(int i=0; i < count; i++) {
- try {
- Thread.sleep(delayMillis);
- } catch (InterruptedException e) {}
- if (isMainContainerRunning()) {
- started = true;
- break;
- }
- }
- if (!started) {
- throw new RuntimeException("Main container did not start");
- }
- }
-
- private static boolean isMainContainerRunning() throws Exception {
- OutputAnalyzer out =
- DockerTestUtils.execute(Container.ENGINE_COMMAND,
- "ps", "--no-trunc",
- "--filter", "name=" + MAIN_CONTAINER_NAME);
- return out.getStdout().contains(MAIN_CONTAINER_NAME);
- }
// JCMD relies on the attach mechanism (com.sun.tools.attach),
// which in turn relies on JVMSTAT mechanism, which puts its mapped
// buffers in /tmp directory (hsperfdata_<user>). Thus, in sidecar
// we mount /tmp via --volumes-from from the main container.
--- 129,138 ----
*** 174,197 ****
cmd.addAll(Arrays.asList(command));
cmd.addAll(Arrays.asList(args));
return DockerTestUtils.execute(cmd);
}
- private static long findProcess(OutputAnalyzer out, String name) throws Exception {
- List<String> l = out.asLines()
- .stream()
- .filter(s -> s.contains(name))
- .collect(Collectors.toList());
- if (l.isEmpty()) {
- throw new RuntimeException("Could not find matching process");
- }
- String psInfo = l.get(0);
- System.out.println("findProcess(): psInfo: " + psInfo);
- String pid = psInfo.substring(0, psInfo.indexOf(' '));
- System.out.println("findProcess(): pid: " + pid);
- return Long.parseLong(pid);
- }
private static DockerRunOptions commonDockerOpts(String className) {
return new DockerRunOptions(IMAGE_NAME, "/jdk/bin/java", className)
.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
.addJavaOpts("-cp", "/test-classes/");
--- 151,160 ----
< prev index next >