示例#1
0
 private void execute(Path image, String moduleName) throws Throwable {
   String cmd = image.resolve("bin").resolve(moduleName).toString();
   OutputAnalyzer analyzer;
   if (System.getProperty("os.name").startsWith("Windows")) {
     analyzer = ProcessTools.executeProcess("sh.exe", cmd, "1", "2", "3");
   } else {
     analyzer = ProcessTools.executeProcess(cmd, "1", "2", "3");
   }
   if (analyzer.getExitValue() != 0) {
     throw new AssertionError("Image invocation failed: rc=" + analyzer.getExitValue());
   }
 }
示例#2
0
 /**
  * Executes a process, waits for it to finish, prints the process output to stdout and returns the
  * process output.
  *
  * <p>The process will have exited before this method returns.
  *
  * @param pb The ProcessBuilder to execute.
  * @return The {@linkplain OutputAnalyzer} instance wrapping the process.
  */
 public static OutputAnalyzer executeCommand(ProcessBuilder pb) throws Throwable {
   String cmdLine = pb.command().stream().collect(Collectors.joining(" "));
   System.out.println("Command line: [" + cmdLine + "]");
   OutputAnalyzer analyzer = ProcessTools.executeProcess(pb);
   System.out.println(analyzer.getOutput());
   return analyzer;
 }
示例#3
0
 /**
  * Executes a process, waits for it to finish, prints the process output to stdout, and returns
  * the process output.
  *
  * <p>The process will have exited before this method returns.
  *
  * @param cmds The command line to execute.
  * @return The {@linkplain OutputAnalyzer} instance wrapping the process.
  */
 public static OutputAnalyzer executeCommand(String... cmds) throws Throwable {
   String cmdLine = Arrays.stream(cmds).collect(Collectors.joining(" "));
   System.out.println("Command line: [" + cmdLine + "]");
   OutputAnalyzer analyzer = ProcessTools.executeProcess(cmds);
   System.out.println(analyzer.getOutput());
   return analyzer;
 }
  private static boolean doTest(String testId, String arg) throws Exception {
    List<String> args = new ArrayList<>();
    args.add("-XX:+UsePerfData");
    args.addAll(Utils.getVmOptions());
    args.add("-cp");
    args.add(TEST_CLASSPATH);

    if (arg != null) {
      args.add(arg);
    }
    args.add("TestApplication");
    ProcessBuilder server =
        ProcessTools.createJavaProcessBuilder(args.toArray(new String[args.size()]));

    Process serverPrc = null, clientPrc = null;
    try {
      final AtomicReference<String> port = new AtomicReference<>();

      serverPrc =
          ProcessTools.startProcess(
              "TestApplication(" + testId + ")",
              server,
              (String line) -> {
                if (line.startsWith("port:")) {
                  port.set(line.split("\\:")[1]);
                } else if (line.startsWith("waiting")) {
                  return true;
                }
                return false;
              });

      System.out.println("Attaching test manager:");
      System.out.println("=========================");
      System.out.println("  PID           : " + serverPrc.getPid());
      System.out.println("  shutdown port : " + port.get());

      ProcessBuilder client =
          ProcessTools.createJavaProcessBuilder(
              "-cp",
              TEST_CLASSPATH,
              "--add-exports",
              "java.management/sun.management=ALL-UNNAMED",
              "TestManager",
              String.valueOf(serverPrc.getPid()),
              port.get(),
              "true");

      clientPrc =
          ProcessTools.startProcess(
              "TestManager",
              client,
              (String line) -> line.startsWith("Starting TestManager for PID"));

      int clientExitCode = clientPrc.waitFor();
      int serverExitCode = serverPrc.waitFor();
      return clientExitCode == 0 && serverExitCode == 0;
    } finally {
      if (clientPrc != null) {
        System.out.println("Stopping process " + clientPrc);
        clientPrc.destroy();
        clientPrc.waitFor();
      }
      if (serverPrc != null) {
        System.out.println("Stopping process " + serverPrc);
        serverPrc.destroy();
        serverPrc.waitFor();
      }
    }
  }
 @BeforeMethod
 public void startTestApp() throws Exception {
   testApp =
       ProcessTools.startProcess(
           TEST_APP_NAME, testAppPb, (Predicate<String>) l -> l.trim().equals("main enter"));
 }
 @BeforeClass
 public static void setupClass() throws Exception {
   testAppPb =
       ProcessTools.createJavaProcessBuilder(
           "-XX:+UsePerfData", "-cp", System.getProperty("test.class.path"), TEST_APP_NAME);
 }