< prev index next >

test/hotspot/jtreg/containers/docker/TestJcmdWithSideCar.java

Print this page

        

*** 69,83 **** 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". // Including this test case to assist in reproduction of the problem. // t.assertIsAlive(); // testCase03(mainProcPid); --- 69,86 ---- DockerThread t = startMainContainer(); waitForMainContainerToStart(500, 10); t.checkForErrors(); ! long mainProcPid = testCase01(); t.assertIsAlive(); ! ! // Excluding the test case below until JDK-8228850 is fixed ! // JDK-8228850: jhsdb jinfo fails with ClassCastException: ! // s.j.h.oops.TypeArray cannot be cast to s.j.h.oops.Instance ! // testCase02(mainProcPid); // JCMD does not work in sidecar configuration, except for "jcmd -l". // Including this test case to assist in reproduction of the problem. // t.assertIsAlive(); // testCase03(mainProcPid);
*** 88,103 **** DockerTestUtils.removeDockerImage(IMAGE_NAME); } } ! // Run "jcmd -l" in a sidecar container and find a process that runs EventGeneratorLoop ! private static OutputAnalyzer testCase01() throws Exception { ! return runSideCar(MAIN_CONTAINER_NAME, "/jdk/bin/jcmd", "-l") .shouldHaveExitValue(0) ! .shouldContain("sun.tools.jcmd.JCmd") ! .shouldContain("EventGeneratorLoop"); } // run jhsdb jinfo <PID> (jhsdb uses PTRACE) private static void testCase02(long pid) throws Exception { runSideCar(MAIN_CONTAINER_NAME, "/jdk/bin/jhsdb", "jinfo", "--pid", "" + pid) --- 91,125 ---- DockerTestUtils.removeDockerImage(IMAGE_NAME); } } ! // Run "jcmd -l" in a sidecar container, find a process that runs EventGeneratorLoop and ! // return it's PID. Try several times. It is possible that container and JVM has started, ! // but but the JVM has not loaded main class yet. In such case, JCMD reports ! // "Unknown" as the name of the main class, but exits without failure. That is OK, just ! // try again after a short delay. ! private static long testCase01() throws Exception { ! long pid = -1; ! for (int i=1; i<5; i++) { ! OutputAnalyzer out = runSideCar(MAIN_CONTAINER_NAME, "/jdk/bin/jcmd", "-l") .shouldHaveExitValue(0) ! .shouldContain("sun.tools.jcmd.JCmd"); ! pid = findProcess(out, "EventGeneratorLoop"); ! if (pid != -1) { ! break; ! } ! try { ! Thread.sleep(500); ! } catch (InterruptedException e) {} ! } ! ! if (pid == -1) { ! throw new RuntimeException("Could not find the target process"); ! } ! ! return pid; } // run jhsdb jinfo <PID> (jhsdb uses PTRACE) private static void testCase02(long pid) throws Exception { runSideCar(MAIN_CONTAINER_NAME, "/jdk/bin/jhsdb", "jinfo", "--pid", "" + pid)
*** 174,190 **** 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); --- 196,213 ---- cmd.addAll(Arrays.asList(command)); cmd.addAll(Arrays.asList(args)); return DockerTestUtils.execute(cmd); } + // will return -1 if matching process could not be found 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()) { ! return -1; } String psInfo = l.get(0); System.out.println("findProcess(): psInfo: " + psInfo); String pid = psInfo.substring(0, psInfo.indexOf(' ')); System.out.println("findProcess(): pid: " + pid);
< prev index next >