You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by kn...@apache.org on 2015/06/25 22:02:38 UTC

[4/8] storm git commit: Improved the collection of log messages, so when Runtime.halt is called errors still show up

Improved the collection of log messages, so when Runtime.halt is called errors still show up


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/b554cc90
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/b554cc90
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/b554cc90

Branch: refs/heads/master
Commit: b554cc900d27a2375bcf71a07ba6e467525cd98a
Parents: fcd0d9e
Author: Robert (Bobby) Evans <ev...@yahoo-inc.com>
Authored: Wed Jun 17 13:52:45 2015 -0500
Committer: Robert (Bobby) Evans <ev...@yahoo-inc.com>
Committed: Wed Jun 17 13:52:45 2015 -0500

----------------------------------------------------------------------
 .../storm/utils/XMLEscapeOutputStream.java      | 74 ++++++++++++++++++++
 storm-core/test/resources/test_runner.clj       | 58 ++++++++-------
 2 files changed, 107 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/b554cc90/storm-core/test/jvm/backtype/storm/utils/XMLEscapeOutputStream.java
----------------------------------------------------------------------
diff --git a/storm-core/test/jvm/backtype/storm/utils/XMLEscapeOutputStream.java b/storm-core/test/jvm/backtype/storm/utils/XMLEscapeOutputStream.java
new file mode 100644
index 0000000..ec6350a
--- /dev/null
+++ b/storm-core/test/jvm/backtype/storm/utils/XMLEscapeOutputStream.java
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package backtype.storm.utils;
+
+import java.io.FilterOutputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+
+import java.util.HashMap;
+
+/**
+ * OutputStream that escapes XML characters.  This is really slow and should only
+ * be used for testing.
+ */
+public class XMLEscapeOutputStream extends FilterOutputStream {
+
+    private static final HashMap<Byte, byte[]> ESCAPE_MAP = new HashMap<Byte, byte[]>();
+    private static void addMapping(String key, String val) {
+        ESCAPE_MAP.put(key.getBytes()[0], val.getBytes());
+    }
+    static {
+	addMapping("\"", "&quot;");
+        addMapping("'", "&apos;");
+        addMapping("<", "&lt;");
+        addMapping(">", "&gt;");
+        addMapping("&", "&amp;");
+    }
+
+    public XMLEscapeOutputStream(OutputStream other) {
+        super(other);
+    }
+
+    public void write(byte[] b) throws IOException {
+        this.write(b, 0, b.length);
+    }
+
+    public void write(byte[] b, int off, int len) throws IOException {
+        ByteArrayOutputStream buff = new ByteArrayOutputStream();
+        for (int i = 0; i < len; i++) {
+            byte[] mapped = ESCAPE_MAP.get(b[i+off]);
+            if (mapped == null) {
+                buff.write(b[i+off]);
+            } else {
+                buff.write(mapped);
+            }
+        }
+        out.write(buff.toByteArray());
+    }
+
+    public void write(int b) throws IOException {
+        byte[] mapped = ESCAPE_MAP.get((byte)b);
+        if (mapped == null) {
+            out.write(b);
+        } else {
+            out.write(mapped);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/storm/blob/b554cc90/storm-core/test/resources/test_runner.clj
----------------------------------------------------------------------
diff --git a/storm-core/test/resources/test_runner.clj b/storm-core/test/resources/test_runner.clj
index ed13837..952a52c 100644
--- a/storm-core/test/resources/test_runner.clj
+++ b/storm-core/test/resources/test_runner.clj
@@ -23,8 +23,10 @@
 (import `java.io.FileWriter)
 (import `java.io.File)
 (import `java.io.OutputStream)
+(import `java.io.OutputStreamWriter)
 (import `java.io.PrintStream)
 (import `java.io.PrintWriter)
+(import `backtype.storm.utils.XMLEscapeOutputStream)
 (use 'clojure.test)
 (use 'clojure.test.junit)
 
@@ -47,43 +49,49 @@
       sys-err System/err
       num-bad (atom 0)
       original-junit-report junit-report
-      cached-out (atom nil)
-      test-error (atom 0)
       orig-out *out*]
   (dorun (for [ns namespaces]
-    (with-open [writer (FileWriter. (str output-dir "/" ns ".xml"))
-                out-stream (FileOutputStream. (str output-dir "/" ns "-output.txt"))
-                out-writer (PrintStream. out-stream true)]
+    (with-open [out-stream (FileOutputStream. (str output-dir "/" ns ".xml"))
+                escape-out-stream (XMLEscapeOutputStream. out-stream)
+                test-print-writer (PrintWriter. out-stream true)
+                print-writer (PrintWriter. escape-out-stream true)
+                print-stream (PrintStream. escape-out-stream true)]
+      (System/setOut print-stream)
+      (System/setErr print-stream)
       (.println sys-out (str "Running " ns))
       (try
-        (System/setOut out-writer)
-        (System/setErr out-writer)
-        (binding [*test-out* writer
-                  *out* (PrintWriter. out-stream true)
+        (let [in-sys-out (atom false)]
+        (binding [*test-out* test-print-writer
+                  *out* print-writer
                   junit-report (fn [data]
                                    (let [type (data :type)]
                                      (cond
                                        (= type :begin-test-var) (do
-                                                                   (reset! cached-out (ByteArrayOutputStream.))
-                                                                   (let [writer (PrintStream. @cached-out true)]
-                                                                     (set! *out* (PrintWriter. @cached-out true))
-                                                                     (System/setOut writer)
-                                                                     (System/setErr writer))
-                                                                   (reset! test-error 0))
-                                       (= type :end-test-var) (do
-                                                                  (.write out-writer (.toByteArray @cached-out))
-                                                                  (when (> @test-error 0)
+                                                                  (when @in-sys-out
+                                                                    (reset! in-sys-out false)
                                                                     (with-test-out
-                                                                      (start-element 'system-out true)
-                                                                      (element-content (String. (.toByteArray @cached-out)))
-                                                                      (finish-element 'system-out true))))
-                                       (= type :fail) (swap! test-error inc)
-                                       (= type :error) (swap! test-error inc)))
-                                   (original-junit-report data))]
+                                                                      (finish-element 'system-out true)))
+                                                                   (original-junit-report data)
+                                                                   (reset! in-sys-out true)
+                                                                   (with-test-out
+                                                                     (start-element 'system-out true)))
+                                       (= type :end-test-var) (when @in-sys-out
+                                                                (reset! in-sys-out false)
+                                                                (with-test-out
+                                                                  (finish-element 'system-out true)))
+                                       (= type :fail) (when @in-sys-out
+                                                                (reset! in-sys-out false)
+                                                                (with-test-out
+                                                                  (finish-element 'system-out true)))
+                                       (= type :error) (when @in-sys-out
+                                                                (reset! in-sys-out false)
+                                                                (with-test-out
+                                                                  (finish-element 'system-out true))))
+                                     (if (not (= type :begin-test-var)) (original-junit-report data))))]
           (with-junit-output
             (let [result (run-tests ns)]
                (.println sys-out (str "Tests run: " (result :test) ", Passed: " (result :pass) ", Failures: " (result :fail) ", Errors: " (result :error)))
-               (reset! num-bad (+ @num-bad (result :error) (result :fail))))))
+               (reset! num-bad (+ @num-bad (result :error) (result :fail)))))))
         (finally 
           (System/setOut sys-out)
           (System/setErr sys-err))))))