You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2014/11/02 15:25:19 UTC

[07/50] git commit: SLIDER-584 ensure that all of stdout/stderr gets through the test run

SLIDER-584 ensure that all of stdout/stderr gets through the test run


Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/035dbe7f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/035dbe7f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/035dbe7f

Branch: refs/heads/feature/SLIDER-531-registry-enhancements
Commit: 035dbe7fec92baf97f97b45038f0882ff3306a44
Parents: 20b071e
Author: Steve Loughran <st...@apache.org>
Authored: Thu Oct 30 12:37:43 2014 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Thu Oct 30 12:37:43 2014 +0000

----------------------------------------------------------------------
 slider-assembly/src/main/scripts/slider.py      | 30 +++++++++++++----
 .../slider/core/main/ServiceLauncher.java       |  2 ++
 .../slider/funtest/framework/SliderShell.groovy | 35 +++++++++++---------
 3 files changed, 44 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/035dbe7f/slider-assembly/src/main/scripts/slider.py
----------------------------------------------------------------------
diff --git a/slider-assembly/src/main/scripts/slider.py b/slider-assembly/src/main/scripts/slider.py
index f3c3902..38ff68d 100644
--- a/slider-assembly/src/main/scripts/slider.py
+++ b/slider-assembly/src/main/scripts/slider.py
@@ -109,6 +109,19 @@ def info(text):
   sys.stdout.flush()
 
 
+def out(toStdErr, text) :
+  """
+  Write to one of the system output channels.
+  This action does not add newlines. If you want that: write them yourself
+  :param toStdErr: flag set if stderr is to be the dest
+  :param text: text to write.
+  :return:
+  """
+  if toStdErr:
+    sys.stderr.write(text)
+  else:
+    sys.stdout.write(text)
+
 def read(pipe, line):
   """
   read a char, append to the listing if there is a char that is not \n
@@ -129,7 +142,7 @@ def read(pipe, line):
     return line, False
 
 
-def print_output(name, src):
+def print_output(name, src, toStdErr):
   """
   Relay the output stream to stdout line by line 
   :param name: 
@@ -142,11 +155,14 @@ def print_output(name, src):
   while not finished:
     (line, done) = read(src, line)
     if done:
-      if DEBUG:
-        info(name +': ' + line)
-      else:
-        info(line)
+      out(toStdErr, line + "\n")
       line = ""
+  # closedown: read remainder of stream
+  c = src.read(1)
+  while c!="" :
+    out(toStdErr, c)
+    c = src.read(1)
+    
   src.close()
 
 
@@ -166,10 +182,10 @@ def runProcess(commandline):
                          bufsize=1, 
                          close_fds=ON_POSIX)
 
-  t = Thread(target=print_output, args=("stdout", exe.stdout))
+  t = Thread(target=print_output, args=("stdout", exe.stdout, False))
   t.daemon = True 
   t.start()
-  t2 = Thread(target=print_output, args=("stderr", exe.stderr,))
+  t2 = Thread(target=print_output, args=("stderr", exe.stderr, True))
   t2.daemon = True 
   t2.start()
 

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/035dbe7f/slider-core/src/main/java/org/apache/slider/core/main/ServiceLauncher.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/core/main/ServiceLauncher.java b/slider-core/src/main/java/org/apache/slider/core/main/ServiceLauncher.java
index 29b1d4e..498a8ad 100644
--- a/slider-core/src/main/java/org/apache/slider/core/main/ServiceLauncher.java
+++ b/slider-core/src/main/java/org/apache/slider/core/main/ServiceLauncher.java
@@ -401,6 +401,8 @@ public class ServiceLauncher<S extends Service>
     Configuration conf = new Configuration();
     String[] processedArgs = extractConfigurationArgs(conf, args);
     ExitUtil.ExitException ee = launchServiceRobustly(conf, processedArgs);
+    System.out.flush();
+    System.err.flush();
     exit(ee);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/035dbe7f/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/SliderShell.groovy
----------------------------------------------------------------------
diff --git a/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/SliderShell.groovy b/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/SliderShell.groovy
index e278981..15bf339 100644
--- a/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/SliderShell.groovy
+++ b/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/SliderShell.groovy
@@ -228,7 +228,6 @@ class SliderShell extends Shell {
 
   /**
    * Execute shell script consisting of as many Strings as we have arguments,
-   * possibly under an explicit username (requires sudoers privileges).
    * NOTE: individual strings are concatenated into a single script as though
    * they were delimited with new line character. All quoting rules are exactly
    * what one would expect in standalone shell script.
@@ -251,21 +250,15 @@ class SliderShell extends Shell {
       writer.close()
     }
     ByteArrayOutputStream baosErr = new ByteArrayOutputStream(4096);
-    proc.consumeProcessErrorStream(baosErr);
-    out = proc.in.readLines()
-
-    // Possibly a bug in String.split as it generates a 1-element array on an
-    // empty String
-    
-    if (baosErr.size() != 0) {
-      err = baosErr.toString().split('\n');
-    } else {
-      err = [];
-    }
+    ByteArrayOutputStream baosOut = new ByteArrayOutputStream(4096);
+    proc.consumeProcessOutput(baosOut, baosErr)
 
     proc.waitFor()
     ret = proc.exitValue()
 
+    out = streamToLines(baosOut)
+    err = streamToLines(baosErr)
+    
     if (LOG.isTraceEnabled()) {
       if (ret != 0) {
         LOG.trace("return: $ret");
@@ -274,15 +267,25 @@ class SliderShell extends Shell {
         LOG.trace("\n<stdout>\n${out.join('\n')}\n</stdout>");
       }
 
-      def stderror = super.err
-      if (stderror.size() != 0) {
-        LOG.trace("\n<stderr>\n${stderror.join('\n')}\n</stderr>");
+      if (err.size() != 0) {
+        LOG.trace("\n<stderr>\n${err.join('\n')}\n</stderr>");
       }
     }
-
     return this
   }
 
+  /**
+   * Convert a stream to lines in an array
+   * @param out output stream
+   * @return the list of entries
+   */
+  protected List<String> streamToLines(ByteArrayOutputStream out) {
+    if (out.size() != 0) {
+      return out.toString().split('\n');
+    } else {
+      return [];
+    }
+  }
 
   public String findLineEntry(String[] locaters) {
     int index = 0;