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"); } }
@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(); }
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; }