summaryrefslogtreecommitdiff
path: root/qadevOOo/runner/helper/ProcessHandler.java
diff options
context:
space:
mode:
authorRelease Engineers <releng@openoffice.org>2009-07-03 10:14:57 +0000
committerRelease Engineers <releng@openoffice.org>2009-07-03 10:14:57 +0000
commitb37f665758a8eebc1cbeb0155d7d24787ca3401e (patch)
treeb864924e5b8d77a106fe477881de7ccdc10bc91a /qadevOOo/runner/helper/ProcessHandler.java
parent6a64591a8774d2cb7057fff5af1af21c6e6c01b2 (diff)
CWS-TOOLING: integrate CWS perftest08
2009-07-02 10:03:16 +0200 lla r273621 : #159516# support systems with no JAVA_HOME 2009-07-02 10:00:25 +0200 lla r273620 : #159516# if path is null this not an error 2009-07-01 14:36:05 +0200 lla r273583 : #159516# add check for wrong cygwin path 2009-06-22 13:18:14 +0200 lla r273223 : #159516# add PipeConnectionString 2009-06-18 21:44:59 +0200 lla r273137 : #159516# cleanups 2009-06-18 21:44:17 +0200 lla r273136 : #159516# handle null 2009-06-18 21:42:56 +0200 lla r273135 : #159516# add getElementCount() function 2009-06-15 10:40:05 +0200 lla r272966 : CWS-TOOLING: rebase CWS perftest08 to trunk@272827 (milestone: DEV300:m50) 2009-06-02 09:06:22 +0200 lla r272480 : CWS-TOOLING: rebase CWS perftest08 to trunk@272291 (milestone: DEV300:m49) 2009-05-08 11:40:22 +0200 mib r271710 : #159717#: File name info for performance test (added void to hasLogFile() parameter list) 2009-05-05 14:14:25 +0200 mib r271514 : #159717#: File name info for performance test 2009-05-04 15:23:01 +0200 mib r271466 : #159717#: File name infor for performance test 2009-05-04 15:22:27 +0200 mib r271465 : #159717#: File name infor for performance test 2009-05-04 15:21:56 +0200 mib r271464 : #159717#: File name infor for performance test 2009-05-04 15:21:18 +0200 mib r271462 : #159717#: File name infor for performance test 2009-04-29 16:23:40 +0200 lla r271383 : #159516# cleanups 2009-04-29 16:23:20 +0200 lla r271382 : #159516# cleanups 2009-04-08 12:23:01 +0200 lla r270631 : #159516# typo 2009-04-07 10:30:35 +0200 lla r270580 : #159516# add prototype 2009-04-07 10:21:15 +0200 lla r270579 : #159516# cleanup 2009-04-03 09:05:26 +0200 lla r270448 : #159516# small cleanups 2009-03-30 13:22:26 +0200 lla r270221 : #159517# merge perftest07
Diffstat (limited to 'qadevOOo/runner/helper/ProcessHandler.java')
-rw-r--r--qadevOOo/runner/helper/ProcessHandler.java340
1 files changed, 228 insertions, 112 deletions
diff --git a/qadevOOo/runner/helper/ProcessHandler.java b/qadevOOo/runner/helper/ProcessHandler.java
index c1892094d093..9939a73bf215 100644
--- a/qadevOOo/runner/helper/ProcessHandler.java
+++ b/qadevOOo/runner/helper/ProcessHandler.java
@@ -51,7 +51,8 @@ import util.utils;
* This class is currently used by ProcesHandler
* internally only.
*/
-class Pump extends Thread {
+class Pump extends Thread
+{
private LineNumberReader reader;
private String pref;
@@ -69,23 +70,29 @@ class Pump extends Thread {
* @param outPrefix A prefix which is printed at the
* beginning of each output line.
*/
- public Pump(InputStream is, PrintWriter log, String outPrefix) {
- this.pref = outPrefix == null ? "" : outPrefix;
+ public Pump(InputStream is, PrintWriter log, String outPrefix)
+ {
+ this.pref = (outPrefix == null) ? "" : outPrefix;
reader = new LineNumberReader(new InputStreamReader(is));
this.log = log;
start();
}
- public void run() {
- try {
+ public void run()
+ {
+ try
+ {
String line = reader.readLine();
- while (line != null) {
+ while (line != null)
+ {
log.println(pref + line);
log.flush();
buf.append(line).append('\n');
line = reader.readLine();
}
- } catch (java.io.IOException e) {
+ }
+ catch (java.io.IOException e)
+ {
log.println(pref + "Exception occured: " + e);
}
}
@@ -93,7 +100,8 @@ class Pump extends Thread {
/**
* Returns the text collected from input stream.
*/
- public String getStringBuffer() {
+ public String getStringBuffer()
+ {
return buf.toString();
}
}
@@ -105,7 +113,8 @@ class Pump extends Thread {
* execution. If you need to execute the same command again you
* should create a new instance for this.
*/
-public class ProcessHandler {
+public class ProcessHandler
+{
private String cmdLine;
private String[] cmdLineArray;
@@ -121,7 +130,7 @@ public class ProcessHandler {
private Pump stdout = null;
private Pump stderr = null;
private PrintStream stdIn = null;
- private Process proc = null;
+ private Process m_aProcess = null;
private TestParameters param = null;
private boolean debug = false;
@@ -131,7 +140,8 @@ public class ProcessHandler {
* of external command is printed to stdout.
* @param cmdLine
*/
- public ProcessHandler(String cmdLine) {
+ public ProcessHandler(String cmdLine)
+ {
this(cmdLine, null, null, null, 0);
}
@@ -142,7 +152,8 @@ public class ProcessHandler {
* of external command is printed to stdout.
* @param cmdLines
*/
- public ProcessHandler(String[] cmdLines) {
+ public ProcessHandler(String[] cmdLines)
+ {
this(null, null, null, null, 0);
cmdLineArray = cmdLines;
}
@@ -157,7 +168,8 @@ public class ProcessHandler {
* @param envVars
* @see java.lang.Runtime exec(String[], String[])
*/
- public ProcessHandler(String[] cmdLines, String[] envVars) {
+ public ProcessHandler(String[] cmdLines, String[] envVars)
+ {
this(null, null, null, envVars, 0);
cmdLineArray = cmdLines;
}
@@ -171,7 +183,8 @@ public class ProcessHandler {
* @param cmdLines
* @param workDir
*/
- public ProcessHandler(String[] cmdLines, File workDir) {
+ public ProcessHandler(String[] cmdLines, File workDir)
+ {
this(null, null, workDir, null, 0);
cmdLineArray = cmdLines;
@@ -185,7 +198,8 @@ public class ProcessHandler {
* @param log
* @param workDir
*/
- public ProcessHandler(String[] cmdLines, PrintWriter log, File workDir) {
+ public ProcessHandler(String[] cmdLines, PrintWriter log, File workDir)
+ {
this(null, log, workDir, null, 0);
cmdLineArray = cmdLines;
}
@@ -197,7 +211,8 @@ public class ProcessHandler {
* @param cmdLine
* @param log
*/
- public ProcessHandler(String cmdLine, PrintWriter log) {
+ public ProcessHandler(String cmdLine, PrintWriter log)
+ {
this(cmdLine, log, null, null, 0);
}
@@ -206,7 +221,8 @@ public class ProcessHandler {
* @param cmdLine
* @param timeOut
*/
- public ProcessHandler(String cmdLine, int timeOut) {
+ public ProcessHandler(String cmdLine, int timeOut)
+ {
this(cmdLine, null, null, null, timeOut);
}
@@ -218,7 +234,8 @@ public class ProcessHandler {
* @param cmdLine
* @param workDir
*/
- public ProcessHandler(String cmdLine, File workDir) {
+ public ProcessHandler(String cmdLine, File workDir)
+ {
this(cmdLine, null, workDir, null, 0);
}
@@ -230,7 +247,8 @@ public class ProcessHandler {
* @param log
* @param workDir
*/
- public ProcessHandler(String cmdLine, PrintWriter log, File workDir) {
+ public ProcessHandler(String cmdLine, PrintWriter log, File workDir)
+ {
this(cmdLine, log, workDir, null, 0);
}
@@ -246,7 +264,8 @@ public class ProcessHandler {
* @param workDir
* @param envVars
*/
- public ProcessHandler(String cmdLine, PrintWriter log, File workDir, String[] envVars) {
+ public ProcessHandler(String cmdLine, PrintWriter log, File workDir, String[] envVars)
+ {
this(cmdLine, log, workDir, envVars, 0);
}
@@ -278,15 +297,19 @@ public class ProcessHandler {
*
*
*/
- public ProcessHandler(String cmdLine, PrintWriter log, File workDir, String[] envVars, long timeOut) {
+ public ProcessHandler(String cmdLine, PrintWriter log, File workDir, String[] envVars, long timeOut)
+ {
this.cmdLine = cmdLine;
this.workDir = workDir;
this.log = log;
this.cmdLine = cmdLine;
this.envVars = envVars;
- if (log == null) {
+ if (log == null)
+ {
this.log = new PrintWriter(new OutputStreamWriter(System.out));
- } else {
+ }
+ else
+ {
this.log = log;
}
this.mTimeOut = timeOut;
@@ -307,13 +330,17 @@ public class ProcessHandler {
* @see lib.TestParameters
* @see helper.OfficeWatcher
*/
- public ProcessHandler(String[] commands, PrintWriter log, File workDir, int shortWait, TestParameters param) {
+ public ProcessHandler(String[] commands, PrintWriter log, File workDir, int shortWait, TestParameters param)
+ {
this(null, log, workDir, null, 0);
this.cmdLineArray = commands;
this.param = param;
- if (shortWait != 0) {
+ if (shortWait != 0)
+ {
this.mTimeOut = shortWait;
- } else {
+ }
+ else
+ {
this.mTimeOut = (long) (param.getInt(PropertyName.TIME_OUT) / 1.3);
}
debug = param.getBool(PropertyName.DEBUG_IS_ACTIVE);
@@ -325,7 +352,8 @@ public class ProcessHandler {
* caused by <CODE>OfficeWatcher</CODE>, the OfficeWatcher get frequently a ping.
* @see helper.OfficeWatcher
*/
- public void runCommand() {
+ public void runCommand()
+ {
boolean changedText = true;
int count = 0;
@@ -334,25 +362,31 @@ public class ProcessHandler {
this.executeAsynchronously();
OfficeWatcher ow = null;
- if (param != null) {
+ if (param != null)
+ {
ow = (OfficeWatcher) param.get(PropertyName.OFFICE_WATCHER);
}
- while (!this.isFinished() && changedText) {
+ while (!this.isFinished() && changedText)
+ {
count++;
- if (ow != null) {
+ if (ow != null)
+ {
ow.ping();
}
dbg("runCommand: waiting " + mTimeOut / 1000 + " seconds while command execution is ongoing... " + count);
shortWait(mTimeOut);
//waitFor(mTimeOut);
- if (ow != null) {
+ if (ow != null)
+ {
ow.ping();
}
// check for changes in the output stream. If there are no changes, the process maybe hangs
- if (!this.isFinished()) {
- if (this.getOutputText().length() == memText.length()) {
+ if (!this.isFinished())
+ {
+ if (this.getOutputText().length() == memText.length())
+ {
changedText = false;
dbg("runCommand Could not detect changes in output stream!!!");
@@ -361,17 +395,20 @@ public class ProcessHandler {
}
}
- if (!this.isFinished()) {
+ if (!this.isFinished())
+ {
dbg("runCommand Process ist not finished but there are no changes in output stream.");
this.kill();
}
}
- public boolean isTimedOut() {
+ public boolean isTimedOut()
+ {
return mbTimedOut;
}
- private void setTimedOut(boolean bTimedOut) {
+ private void setTimedOut(boolean bTimedOut)
+ {
mbTimedOut = bTimedOut;
}
@@ -383,7 +420,8 @@ public class ProcessHandler {
* started and correcly exits (exit code doesn't affect
* to this result).
*/
- public boolean executeSynchronously() {
+ public boolean executeSynchronously()
+ {
execute();
return waitFor(mTimeOut);
}
@@ -396,34 +434,48 @@ public class ProcessHandler {
* @return <code>true</code> if process was successfully
* started.
*/
- public boolean executeAsynchronously() {
+ public boolean executeAsynchronously()
+ {
execute();
return isStarted();
}
- public synchronized void kill() {
- if (!isStarted()) {
+ public synchronized void kill()
+ {
+ if (!isStarted())
+ {
return;
}
boolean exit = false;
int counter = 1;
- while (counter < 3 && !exit) {
- proc.destroy();
+ while (counter < 3 && !exit)
+ {
+ m_aProcess.destroy();
- try {
+ try
+ {
Thread.sleep(1000 * counter); // 5000
- } catch (java.lang.InterruptedException e) {
}
- try {
- final int exit_Value = proc.exitValue();
- if (exit_Value < 1) {
+ catch (java.lang.InterruptedException e)
+ {
+ }
+ try
+ {
+ final int exit_Value = m_aProcess.exitValue();
+ if (exit_Value < 1)
+ {
exit = true;
- } else {
+ }
+ else
+ {
counter++;
}
dbg("kill: process closed with exit code " + exit_Value);
- } catch (java.lang.IllegalThreadStateException e) {
- if (counter < 3) {
+ }
+ catch (java.lang.IllegalThreadStateException e)
+ {
+ if (counter < 3)
+ {
dbg("kill: Couldn't close process after " + counter + " attempts, trying again");
}
counter++;
@@ -432,45 +484,63 @@ public class ProcessHandler {
isStarted = false;
}
- protected void execute() {
- if (isStarted()) {
+ protected void execute()
+ {
+ if (isStarted())
+ {
throw new RuntimeException(
- "The process handler has already been executed.");
+ "The process handler has already been executed.");
}
final Runtime runtime = Runtime.getRuntime();
- try {
- if (cmdLine == null) {
+ try
+ {
+ if (cmdLine == null)
+ {
log.print(utils.getDateTime() + "execute: Starting command from array: ");
- for (int i = 0; i < cmdLineArray.length; i++) {
+ for (int i = 0; i < cmdLineArray.length; i++)
+ {
log.print(cmdLineArray[i]);
log.print(" ");
}
log.println("");
- proc = runtime.exec(cmdLineArray, envVars);
- } else {
- if (workDir != null) {
+ m_aProcess = runtime.exec(cmdLineArray, envVars);
+ }
+ else
+ {
+ if (workDir != null)
+ {
log.println(utils.getDateTime() + "execute: Starting command: " + cmdLine + " " +
- workDir.getAbsolutePath());
- proc = runtime.exec(cmdLine, envVars, workDir);
- } else {
+ workDir.getAbsolutePath());
+ m_aProcess = runtime.exec(cmdLine, envVars, workDir);
+ }
+ else
+ {
log.println(utils.getDateTime() + "execute: Starting command: " + cmdLine);
- proc = runtime.exec(cmdLine, envVars);
+ m_aProcess = runtime.exec(cmdLine, envVars);
}
}
isStarted = true;
- } catch (java.io.IOException e) {
- if (cmdLine == null) {
+ }
+ catch (java.io.IOException e)
+ {
+ if (cmdLine == null)
+ {
log.println(utils.getDateTime() + "execute: The command array can't be started: " + e);
- } else {
+ }
+ else
+ {
log.println(utils.getDateTime() + "execute: The command " + cmdLine + " can't be started: " + e);
}
return;
}
dbg("execute: pump io-streams");
- stdout = new Pump(proc.getInputStream(), log, "out > ");
- stderr = new Pump(proc.getErrorStream(), log, "err > ");
- stdIn = new PrintStream(proc.getOutputStream());
+ stdout = new Pump(m_aProcess.getInputStream(), log, "out > ");
+ stderr = new Pump(m_aProcess.getErrorStream(), log, "err > ");
+ stdIn = new PrintStream(m_aProcess.getOutputStream());
+
+ // int nExitValue = m_aProcess.exitValue();
+ // int dummy = 0;
dbg("execute: flush io-streams");
@@ -485,7 +555,8 @@ public class ProcessHandler {
* @return <code>true</code> if process correctly exited
* (exit code doesn't affect to this result).
*/
- public boolean waitFor() {
+ public boolean waitFor()
+ {
return waitFor(0);
}
@@ -507,49 +578,70 @@ public class ProcessHandler {
* @return <code>true</code> if process correctly exited
* (exit code doesn't affect to this result).
*/
- public boolean waitFor(long timeout) {
- if (isFinished()) {
+ public boolean waitFor(long timeout)
+ {
+ if (isFinished())
+ {
return true;
}
- if (!isStarted()) {
+ if (!isStarted())
+ {
return false;
}
- if (timeout == 0) {
- try {
- proc.waitFor();
- } catch (InterruptedException e) {
+ if (timeout == 0)
+ {
+ try
+ {
+ m_aProcess.waitFor();
+ }
+ catch (InterruptedException e)
+ {
log.println("The process was interrupted: " + e);
}
isFinished = true;
- try {
- exitValue = proc.exitValue();
- } catch (IllegalThreadStateException e) {
+ try
+ {
+ exitValue = m_aProcess.exitValue();
+ }
+ catch (IllegalThreadStateException e)
+ {
}
- } else {
- try {
- while (!isFinished && timeout > 0) {
+ }
+ else
+ {
+ try
+ {
+ while (!isFinished && timeout > 0)
+ {
isFinished = true;
Thread.sleep(1000);
timeout -= 1000;
- try {
- exitValue = proc.exitValue(); // throws exception if not finished
- } catch (IllegalThreadStateException e) {
+ try
+ {
+ exitValue = m_aProcess.exitValue(); // throws exception if not finished
+ }
+ catch (IllegalThreadStateException e)
+ {
isFinished = false;
}
}
- if (timeout < 0) {
+ if (timeout < 0)
+ {
setTimedOut(true);
log.println("The process has timed out!");
}
- } catch (InterruptedException ex) {
+ }
+ catch (InterruptedException ex)
+ {
log.println("The process was interrupted: " + ex);
}
}
- if (!isFinished) {
+ if (!isFinished)
+ {
log.println("Going to destroy the process!!");
- proc.destroy();
+ m_aProcess.destroy();
log.println("Process has been destroyed!");
}
// Removed as hung up in SDK test 'PathSettings'
@@ -561,12 +653,15 @@ public class ProcessHandler {
return isFinished();
}
- protected void flushInput() {
- if (stdIn == null) {
+ protected void flushInput()
+ {
+ if (stdIn == null)
+ {
return;
}
- synchronized (stdInBuff) {
+ synchronized(stdInBuff)
+ {
stdIn.print(stdInBuff);
stdIn.flush();
stdInBuff = "";
@@ -577,10 +672,14 @@ public class ProcessHandler {
* Returns the text output by external command to stdout.
* @return the text output by external command to stdout
*/
- public String getOutputText() {
- if (stdout == null) {
+ public String getOutputText()
+ {
+ if (stdout == null)
+ {
return "";
- } else {
+ }
+ else
+ {
return stdout.getStringBuffer();
}
}
@@ -589,10 +688,14 @@ public class ProcessHandler {
* Returns the text output by external command to stderr.
* @return the text output by external command to stderr
*/
- public String getErrorText() {
- if (stderr == null) {
+ public String getErrorText()
+ {
+ if (stderr == null)
+ {
return "";
- } else {
+ }
+ else
+ {
return stderr.getStringBuffer();
}
}
@@ -607,7 +710,8 @@ public class ProcessHandler {
* and transfered to command when it will be started.
* @param str
*/
- public void printInputText(String str) {
+ public void printInputText(String str)
+ {
stdInBuff += str;
flushInput();
}
@@ -619,7 +723,8 @@ public class ProcessHandler {
* @return <code>true</code> if the external command was
* found and successfully started.
*/
- public boolean isStarted() {
+ public boolean isStarted()
+ {
return isStarted;
}
@@ -630,7 +735,8 @@ public class ProcessHandler {
* @return <code>true</code> if the command correctly starts,
* exits and was not interrupted due to timeout.
*/
- public boolean isFinished() {
+ public boolean isFinished()
+ {
return isFinished;
}
@@ -640,11 +746,15 @@ public class ProcessHandler {
* @return exit code of command if it was finished,
* -1 if not.
*/
- public int getExitCode() {
- try {
- exitValue = proc.exitValue();
- } catch (Exception e) {
- //System.out.println("No ExitValue available");
+ public int getExitCode()
+ {
+ try
+ {
+ exitValue = m_aProcess.exitValue();
+ }
+ catch (Exception e)
+ {
+ //System.out.println("No ExitValue available");
}
return exitValue;
@@ -653,16 +763,22 @@ public class ProcessHandler {
/** Causes the thread to sleep some time.
* @param milliseconds
*/
- public static void shortWait(long milliseconds) {
- try {
+ public static void shortWait(long milliseconds)
+ {
+ try
+ {
Thread.sleep(milliseconds);
- } catch (InterruptedException e) {
+ }
+ catch (InterruptedException e)
+ {
System.out.println("While waiting :" + e);
}
}
- private void dbg(String message) {
- if (debug) {
+ private void dbg(String message)
+ {
+ if (debug)
+ {
log.println(utils.getDateTime() + "PH." + message);
}
}