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:39 UTC
[5/8] storm git commit: Switched to using CDATA for output and fixed
race conditions around XML output
Switched to using CDATA for output and fixed race conditions around XML output
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/6e249537
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/6e249537
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/6e249537
Branch: refs/heads/master
Commit: 6e2495378ba7e3e715a4a940736d3c4713bc8c48
Parents: b554cc9
Author: Robert (Bobby) Evans <ev...@yahoo-inc.com>
Authored: Thu Jun 18 12:30:39 2015 -0500
Committer: Robert (Bobby) Evans <ev...@yahoo-inc.com>
Committed: Thu Jun 18 12:30:39 2015 -0500
----------------------------------------------------------------------
.../storm/utils/XMLEscapeOutputStream.java | 74 --------------------
storm-core/test/resources/test_runner.clj | 35 ++++++---
2 files changed, 25 insertions(+), 84 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/storm/blob/6e249537/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
deleted file mode 100644
index ec6350a..0000000
--- a/storm-core/test/jvm/backtype/storm/utils/XMLEscapeOutputStream.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * 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("\"", """);
- addMapping("'", "'");
- addMapping("<", "<");
- addMapping(">", ">");
- addMapping("&", "&");
- }
-
- 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/6e249537/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 952a52c..c10fec3 100644
--- a/storm-core/test/resources/test_runner.clj
+++ b/storm-core/test/resources/test_runner.clj
@@ -26,7 +26,6 @@
(import `java.io.OutputStreamWriter)
(import `java.io.PrintStream)
(import `java.io.PrintWriter)
-(import `backtype.storm.utils.XMLEscapeOutputStream)
(use 'clojure.test)
(use 'clojure.test.junit)
@@ -52,40 +51,56 @@
orig-out *out*]
(dorun (for [ns namespaces]
(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)
+ print-writer (PrintWriter. out-stream true)
+ print-stream (PrintStream. out-stream true)]
(.println sys-out (str "Running " ns))
(try
(let [in-sys-out (atom false)]
- (binding [*test-out* test-print-writer
- *out* print-writer
+ (binding [*test-out* print-writer
+ *out* orig-out
junit-report (fn [data]
(let [type (data :type)]
(cond
(= type :begin-test-var) (do
(when @in-sys-out
(reset! in-sys-out false)
+ (System/setOut sys-out)
+ (System/setErr sys-err)
+ (set! *out* orig-out)
(with-test-out
+ (print "]]>")
(finish-element 'system-out true)))
(original-junit-report data)
(reset! in-sys-out true)
(with-test-out
- (start-element 'system-out true)))
+ (start-element 'system-out true)
+ (print "<![CDATA[") (flush))
+ (System/setOut print-stream)
+ (System/setErr print-stream)
+ (set! *out* print-writer))
(= type :end-test-var) (when @in-sys-out
(reset! in-sys-out false)
+ (System/setOut sys-out)
+ (System/setErr sys-err)
+ (set! *out* orig-out)
(with-test-out
+ (print "]]>")
(finish-element 'system-out true)))
(= type :fail) (when @in-sys-out
(reset! in-sys-out false)
+ (System/setOut sys-out)
+ (System/setErr sys-err)
+ (set! *out* orig-out)
(with-test-out
+ (print "]]>")
(finish-element 'system-out true)))
(= type :error) (when @in-sys-out
(reset! in-sys-out false)
+ (System/setOut sys-out)
+ (System/setErr sys-err)
+ (set! *out* orig-out)
(with-test-out
+ (print "]]>")
(finish-element 'system-out true))))
(if (not (= type :begin-test-var)) (original-junit-report data))))]
(with-junit-output