Ejemplo n.º 1
0
  static void realMain(String[] args) throws Throwable {
    // jmap doesn't work on Windows
    if (System.getProperty("os.name").startsWith("Windows")) return;

    final String childClassName = Job.class.getName();
    final String classToCheckForLeaks = Job.classToCheckForLeaks();
    final String uniqueID = String.valueOf(new Random().nextInt(Integer.MAX_VALUE));

    final String[] jobCmd = {
      java,
      "-Xmx8m",
      "-classpath",
      System.getProperty("test.classes", "."),
      childClassName,
      uniqueID
    };
    final Process p = new ProcessBuilder(jobCmd).start();

    final String childPid =
        match(
            commandOutputOf(jps, "-m"),
            "(?m)^ *([0-9]+) +\\Q" + childClassName + "\\E *" + uniqueID + "$",
            1);

    final int n0 = objectsInUse(p, childPid, classToCheckForLeaks);
    final int n1 = objectsInUse(p, childPid, classToCheckForLeaks);
    equal(p.waitFor(), 0);
    equal(p.exitValue(), 0);
    failed += p.exitValue();

    // Check that no objects were leaked.
    System.out.printf("%d -> %d%n", n0, n1);
    check(Math.abs(n1 - n0) < 2); // Almost always n0 == n1
    check(n1 < 20);
    drainers.shutdown();
  }
Ejemplo n.º 2
0
 static String outputOf(final Process p) {
   try {
     Future<String> outputFuture = futureOutputOf(p.getInputStream());
     Future<String> errorFuture = futureOutputOf(p.getErrorStream());
     final String output = outputFuture.get();
     final String error = errorFuture.get();
     // Check for successful process completion
     equal(error, "");
     equal(p.waitFor(), 0);
     equal(p.exitValue(), 0);
     return output;
   } catch (Throwable t) {
     unexpected(t);
     throw new Error(t);
   }
 }
Ejemplo n.º 3
0
  /**
   * Checks if address can be reached using one argument InetAddress.isReachable() version or ping
   * command if failed.
   *
   * @param addr Address to check.
   * @param reachTimeout Timeout for the check.
   * @return {@code True} if address is reachable.
   */
  public static boolean reachableByPing(InetAddress addr, int reachTimeout) {
    try {
      if (addr.isReachable(reachTimeout)) return true;

      String cmd = String.format("ping -%s 1 %s", U.isWindows() ? "n" : "c", addr.getHostAddress());

      Process myProc = Runtime.getRuntime().exec(cmd);

      myProc.waitFor();

      return myProc.exitValue() == 0;
    } catch (IOException ignore) {
      return false;
    } catch (InterruptedException ignored) {
      Thread.currentThread().interrupt();

      return false;
    }
  }
Ejemplo n.º 4
0
  private void execute(String[] process_command) {

    this.running = true;
    // ProcessBuilder pb = new ProcessBuilder("C:\\Archivos de programa\\python2.5\\python",
    // "C:\\Archivos de programa\\python2.5\\test.py");
    // ProcessBuilder pb = new ProcessBuilder(Executables.PYTHON_EXEC, "C:\\Archivos de
    // programa\\python2.5\\test.py", "--parameter2", "--parameter3", "--parameter4=\\\"C:\\Archivos
    // de programa\\python2.5\\test.py\\\"");
    // System.err.println("Executing "+process_command);
    StringBuffer str = new StringBuffer();
    for (int i = 0; i < process_command.length; i++) {
      str.append(process_command[i]);
      // str.append("\n");
    }
    System.err.println("Executing " + str.toString());
    ProcessBuilder pb = new ProcessBuilder(process_command);
    pb.redirectErrorStream(true);

    Process p = null;
    boolean started = false;

    try {
      p = pb.start();
      BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
      started = true;
      this.current_process++;
      FileOutputStream fout = null;
      try {
        File temp = File.createTempFile("bianaParser", ".txt");
        temp.deleteOnExit();
        fout = new FileOutputStream(temp.getAbsoluteFile());
        this.window.setCurrentOutput(this.current_process, temp.getAbsolutePath());

      } catch (IOException err) {
        System.err.println("Error in creating parser out temp file");
      }
      // this.window.setCurrentOutput(this.current_process,"process_"+this.current_process);
      this.window.change_process_status(current_process, "Running");
      int c;
      while (true) {
        c = in.read();
        if (c == -1) {
          break;
        }
        fout.write(c);
      }
      fout.close();
    } catch (IOException exc) {
      exc.printStackTrace();
      if (started) p.destroy();
      return;
    }

    try {
      // System.err.println("Going to wait to finish process...");
      System.err.println(p.waitFor());
      // System.err.println("Process "+this.current_process+" really finished...");
      System.err.println("Status: " + p.exitValue());
      if (p.exitValue() == 0) {
        this.window.change_process_status(current_process, "Finished");
      } else {
        this.window.change_process_status(current_process, "Error in parsing");
      }
    } catch (InterruptedException e) {
      p.destroy();
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
    // System.err.println("Going to destroy...");

    // p.destroy();
    this.running = false;
  }