[SYSTEMDS-2786] outputBuffering correctly for R Scripts in Tests
This commit change the outputBuffering to also effect the R scripts
correctly. Such that when the outputBuffering is enabled then no
output is printed from R except in cases where the test fail because of
the R script. If the outputBuffering is disabled then all output from R
is printed after the R execution is done.
diff --git a/src/test/java/org/apache/sysds/test/AutomatedTestBase.java b/src/test/java/org/apache/sysds/test/AutomatedTestBase.java
index 98c6b79..0143fed 100644
--- a/src/test/java/org/apache/sysds/test/AutomatedTestBase.java
+++ b/src/test/java/org/apache/sysds/test/AutomatedTestBase.java
@@ -1182,22 +1182,17 @@
outputR = IOUtils.toString(child.getInputStream());
errorString = IOUtils.toString(child.getErrorStream());
- if(LOG.isTraceEnabled()) {
- LOG.trace("Standard Output from R:" + outputR);
- LOG.trace("Standard Error from R:" + errorString);
- }
-
+
//
// To give any stream enough time to print all data, otherwise there
// are situations where the test case fails, even before everything
// has been printed
//
child.waitFor();
-
try {
if(child.exitValue() != 0) {
throw new Exception(
- "ERROR: R has ended irregularly\n" + outputR + "\nscript file: " + executionFile);
+ "ERROR: R has ended irregularly\n" + buildOutputStringR(outputR, errorString) + "\nscript file: " + executionFile);
}
}
catch(IllegalThreadStateException ie) {
@@ -1207,6 +1202,10 @@
child.destroy();
}
+ if(!outputBuffering) {
+ System.out.println(buildOutputStringR(outputR, errorString));
+ }
+
long t1 = System.nanoTime();
LOG.info("R is finished (in " + ((double) t1 - t0) / 1000000000 + " sec)");
@@ -1232,6 +1231,16 @@
}
}
+ private static String buildOutputStringR(String standardOut, String standardError){
+ StringBuilder sb = new StringBuilder();
+ sb.append("R Standard output :\n");
+ sb.append(standardOut);
+ sb.append("\nR Standard Error :\n");
+ sb.append(standardError);
+ sb.append("\n");
+ return sb.toString();
+ }
+
/**
* <p>
* Runs a test for which no exception is expected.