Пример #1
0
 // To be called exactly twice by the parent process
 static <T> T rendezvousParent(Process p, Callable<T> callable) throws Throwable {
   p.getInputStream().read();
   T result = callable.call();
   OutputStream os = p.getOutputStream();
   os.write((byte) '\n');
   os.flush();
   return result;
 }
  public static void main(String[] args) throws Exception {
    int counter = 0;
    while (true) {
      Thread outThread = null;
      Thread errThread = null;
      try {
        // org.pitest.mutationtest.instrument.MutationTestUnit#runTestInSeperateProcessForMutationRange

        // *** start slave

        ServerSocket commSocket = new ServerSocket(0);
        int commPort = commSocket.getLocalPort();
        System.out.println("commPort = " + commPort);

        // org.pitest.mutationtest.execute.MutationTestProcess#start
        //   - org.pitest.util.CommunicationThread#start
        FutureTask<Integer> commFuture = createFuture(commSocket);
        //   - org.pitest.util.WrappingProcess#start
        //       - org.pitest.util.JavaProcess#launch
        Process slaveProcess = startSlaveProcess(commPort);
        outThread = new Thread(new ReadFromInputStream(slaveProcess.getInputStream()), "stdout");
        errThread = new Thread(new ReadFromInputStream(slaveProcess.getErrorStream()), "stderr");
        outThread.start();
        errThread.start();

        // *** wait for slave to die

        // org.pitest.mutationtest.execute.MutationTestProcess#waitToDie
        //    - org.pitest.util.CommunicationThread#waitToFinish
        System.out.println("waitToFinish");
        Integer controlReturned = commFuture.get();
        System.out.println("controlReturned = " + controlReturned);
        // NOTE: the following won't get called if commFuture.get() fails!
        //    - org.pitest.util.JavaProcess#destroy
        outThread.interrupt(); // org.pitest.util.AbstractMonitor#requestStop
        errThread.interrupt(); // org.pitest.util.AbstractMonitor#requestStop
        slaveProcess.destroy();
      } catch (Exception e) {
        e.printStackTrace(System.out);
      }

      // test: the threads should exit eventually
      outThread.join();
      errThread.join();
      counter++;
      System.out.println("try " + counter + ": stdout and stderr threads exited normally");
    }
  }
Пример #3
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);
   }
 }
Пример #4
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;
    }
  }
  @Test
  public void testEntriesAddition() throws Exception {

    createSchema(baseDocumentTx);
    createSchema(testDocumentTx);

    System.out.println("Start data propagation");

    List<Future> futures = new ArrayList<Future>();
    for (int i = 0; i < 5; i++) {
      futures.add(executorService.submit(new DataPropagationTask(baseDocumentTx, testDocumentTx)));
    }

    TimeUnit.MINUTES.sleep(5);

    System.out.println("Wait for process to destroy");
    serverProcess.destroy();

    serverProcess.waitFor();
    System.out.println("Process was destroyed");

    for (Future future : futures) {
      try {
        future.get();
      } catch (Exception e) {
        future.cancel(true);
      }
    }

    testDocumentTx =
        new ODatabaseDocumentTx(
            "plocal:" + buildDir.getAbsolutePath() + "/testUniqueIndexCrashRestore");
    testDocumentTx.open("admin", "admin");
    testDocumentTx.close();

    testDocumentTx.open("admin", "admin");

    System.out.println("Start data comparison.");
    compareIndexes();
  }
Пример #6
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();
  }
Пример #7
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;
  }