You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2011/08/18 20:15:00 UTC
svn commit: r1159337 -
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
Author: kmarsden
Date: Thu Aug 18 18:15:00 2011
New Revision: 1159337
URL: http://svn.apache.org/viewvc?rev=1159337&view=rev
Log:
DERBY-4249 Create a simple store recovery test in JUnit
On failure print launched process error stream as well as ouput.
patch derby4249_showlaunchederr_diff.txt
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=1159337&r1=1159336&r2=1159337&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Thu Aug 18 18:15:00 2011
@@ -732,33 +732,24 @@ public abstract class BaseTestCase
* This will block until the process terminates.
*
* @param pr a running process
- * @return output of the process
+ * @return output of the process, both STDOUT and STDERR
* @throws InterruptedException
*/
public static String readProcessOutput(Process pr) throws InterruptedException {
InputStream is = pr.getInputStream();
+ InputStream es = pr.getErrorStream();
if (is == null) {
fail("Unexpectedly receiving no text from the process");
}
-
String output = "";
try {
- char[] ca = new char[1024];
- // Create an InputStreamReader with default encoding; we're hoping
- // this to be en. If not, we may not match the expected string.
- InputStreamReader inStream;
- inStream = new InputStreamReader(is);
+ output += "<STDOUT> " + inputStreamToString(is) + "<END STDOUT>\n";
+ output += "<STDERR>" + inputStreamToString(es) + "<END STDERR>\n";
- // keep reading from the stream until all done
- int charsRead;
- while ((charsRead = inStream.read(ca, 0, ca.length)) != -1)
- {
- output = output + new String(ca, 0, charsRead);
- }
} catch (Exception e) {
fail("Exception accessing inputstream from process", e);
}
-
+
// wait until the process exits
pr.waitFor();
@@ -766,6 +757,30 @@ public abstract class BaseTestCase
}
/**
+ * Read contents of an input stream to a String
+ *
+ * @param is
+ * @return String with input stream contents
+ * @throws IOException
+ */
+ private static String inputStreamToString(InputStream is) throws IOException {
+
+ String isout = "";
+ char[] ca = new char[1024];
+ // Create an InputStreamReader with default encoding; we're hoping
+ // this to be en.
+ InputStreamReader inStream;
+ inStream = new InputStreamReader(is);
+
+ // keep reading from the stream until all done
+ int charsRead;
+ while ((charsRead = inStream.read(ca, 0, ca.length)) != -1) {
+ isout = isout + new String(ca, 0, charsRead);
+ }
+ return isout;
+ }
+
+ /**
* Remove the directory and its contents.
* @param path Path of the directory
*/