You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by sr...@apache.org on 2016/03/13 06:22:14 UTC

[1/4] storm git commit: STORM-1250: port backtype.storm.serialization-test to java

Repository: storm
Updated Branches:
  refs/heads/master 5f818b9ad -> c2cf3befc


STORM-1250: port backtype.storm.serialization-test to java


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

Branch: refs/heads/master
Commit: 43ca7950609573dc0ba1d7b016083bdf6fcea4ee
Parents: dd00bc0
Author: Jark Wu <im...@gmail.com>
Authored: Thu Feb 25 09:59:36 2016 +0800
Committer: Jark Wu <wu...@alibaba-inc.com>
Committed: Fri Feb 26 14:05:32 2016 +0800

----------------------------------------------------------------------
 .../clj/org/apache/storm/serialization_test.clj |  85 ++-----------
 .../org/apache/storm/TestConfigValidate.java    |  20 +++
 .../storm/serialization/SerializationTest.java  | 125 +++++++++++++++++++
 3 files changed, 154 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/43ca7950/storm-core/test/clj/org/apache/storm/serialization_test.clj
----------------------------------------------------------------------
diff --git a/storm-core/test/clj/org/apache/storm/serialization_test.clj b/storm-core/test/clj/org/apache/storm/serialization_test.clj
index 23c45ba..7b244a6 100644
--- a/storm-core/test/clj/org/apache/storm/serialization_test.clj
+++ b/storm-core/test/clj/org/apache/storm/serialization_test.clj
@@ -15,82 +15,15 @@
 ;; limitations under the License.
 (ns org.apache.storm.serialization-test
   (:use [clojure test])
-  (:import [org.apache.storm.serialization KryoTupleSerializer KryoTupleDeserializer
-            KryoValuesSerializer KryoValuesDeserializer])
-  (:import [org.apache.storm.testing TestSerObject TestKryoDecorator])
-  (:import [org.apache.storm.validation ConfigValidation$KryoRegValidator])
-  (:import [org.apache.storm.utils Utils])
-  (:use [org.apache.storm util config]))
+  (:import [org.apache.storm.serialization  SerializationTest]))
 
-(defn mk-conf [extra]
-  (merge (clojurify-structure (Utils/readDefaultConfig)) extra))
-
-(defn serialize [vals conf]
-  (let [serializer (KryoValuesSerializer. (mk-conf conf))]
-    (.serialize serializer vals)
-    ))
-
-(defn deserialize [bytes conf]
-  (let [deserializer (KryoValuesDeserializer. (mk-conf conf))]
-    (.deserialize deserializer bytes)
-    ))
-
-(defn roundtrip
-  ([vals] (roundtrip vals {}))
-  ([vals conf]
-    (deserialize (serialize vals conf) conf)))
-
-(deftest validate-kryo-conf-basic
-  (.validateField (ConfigValidation$KryoRegValidator. ) "test" ["a" "b" "c" {"d" "e"} {"f" "g"}]))
-
-(deftest validate-kryo-conf-fail
-  (try
-    (.validateField (ConfigValidation$KryoRegValidator. ) "test" {"f" "g"})
-    (assert false)
-    (catch IllegalArgumentException e))
-  (try
-    (.validateField (ConfigValidation$KryoRegValidator. ) "test" [1])
-    (assert false)
-    (catch IllegalArgumentException e))
-  (try
-    (.validateField (ConfigValidation$KryoRegValidator. ) "test" [{"a" 1}])
-    (assert false)
-    (catch IllegalArgumentException e))
-)
-
-(deftest test-java-serialization
-  (let [obj (TestSerObject. 1 2)]
-    (is (thrown? Exception
-      (roundtrip [obj] {TOPOLOGY-KRYO-REGISTER {"org.apache.storm.testing.TestSerObject" nil}
-                        TOPOLOGY-FALL-BACK-ON-JAVA-SERIALIZATION false})))
-    (is (= [obj] (roundtrip [obj] {TOPOLOGY-FALL-BACK-ON-JAVA-SERIALIZATION true})))))
-
-(deftest test-kryo-decorator
-  (let [obj (TestSerObject. 1 2)]
-    (is (thrown? Exception
-                 (roundtrip [obj] {TOPOLOGY-FALL-BACK-ON-JAVA-SERIALIZATION false})))
-    (is (= [obj] (roundtrip [obj] {TOPOLOGY-KRYO-DECORATORS ["org.apache.storm.testing.TestKryoDecorator"]
-                                   TOPOLOGY-FALL-BACK-ON-JAVA-SERIALIZATION false})))))
-
-(defn mk-string [size]
-  (let [builder (StringBuilder.)]
-    (doseq [i (range size)]
-      (.append builder "a"))
-    (.toString builder)))
-
-(defn is-roundtrip [vals]
-  (is (= vals (roundtrip vals))))
-
-(deftest test-string-serialization
-  (is-roundtrip ["a" "bb" "cde"])
-  (is-roundtrip [(mk-string (* 64 1024))])
-  (is-roundtrip [(mk-string (* 1024 1024))])
-  (is-roundtrip [(mk-string (* 1024 1024 2))])
-  )
 
+;TODO: We have moved needed tests to SerializationTest.
+;TODO: When we move to java totally, we can remove this test file entirely
 (deftest test-clojure-serialization
-  (is-roundtrip [:a])
-  (is-roundtrip [["a" 1 2 :a] 2 "aaa"])
-  (is-roundtrip [#{:a :b :c}])
-  (is-roundtrip [#{:a :b} 1 2 ["a" 3 5 #{5 6}]])
-  (is-roundtrip [{:a [1 2 #{:a :b 1}] :b 3}]))
+  (let [serializationTest (SerializationTest.)]
+    (.isRoundtrip serializationTest [:a])
+    (.isRoundtrip serializationTest [["a" 1 2 :a] 2 "aaa"])
+    (.isRoundtrip serializationTest [#{:a :b :c}])
+    (.isRoundtrip serializationTest [#{:a :b} 1 2 ["a" 3 5 #{5 6}]])
+    (.isRoundtrip serializationTest [{:a [1 2 #{:a :b 1}] :b 3}])))
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/storm/blob/43ca7950/storm-core/test/jvm/org/apache/storm/TestConfigValidate.java
----------------------------------------------------------------------
diff --git a/storm-core/test/jvm/org/apache/storm/TestConfigValidate.java b/storm-core/test/jvm/org/apache/storm/TestConfigValidate.java
index 5fe8033..2884a45 100644
--- a/storm-core/test/jvm/org/apache/storm/TestConfigValidate.java
+++ b/storm-core/test/jvm/org/apache/storm/TestConfigValidate.java
@@ -18,6 +18,8 @@
 
 package org.apache.storm;
 
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import org.apache.storm.utils.Utils;
 import org.apache.storm.validation.ConfigValidation;
 import org.apache.storm.validation.ConfigValidation.*;
@@ -231,6 +233,24 @@ public class TestConfigValidate {
     }
 
     @Test
+    public void testKryoRegValidator() {
+        KryoRegValidator validator = new KryoRegValidator();
+
+        // fail cases
+        Object[] failCases = {ImmutableMap.of("f", "g"), ImmutableList.of(1), Arrays.asList(ImmutableMap.of("a", 1))};
+        for (Object value : failCases) {
+            try {
+                validator.validateField("test", value);
+                Assert.fail("Expected Exception not Thrown for value: " + value);
+            } catch (IllegalArgumentException e) {
+            }
+        }
+
+        // pass cases
+        validator.validateField("test", Arrays.asList("a", "b", "c", ImmutableMap.of("d", "e"), ImmutableMap.of("f", "g")));
+    }
+
+    @Test
     public void testPowerOf2Validator() {
         PowerOf2Validator validator = new PowerOf2Validator();
 

http://git-wip-us.apache.org/repos/asf/storm/blob/43ca7950/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java
----------------------------------------------------------------------
diff --git a/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java b/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java
new file mode 100644
index 0000000..a5501ed
--- /dev/null
+++ b/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java
@@ -0,0 +1,125 @@
+/**
+ * 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 org.apache.storm.serialization;
+
+import com.google.common.collect.Lists;
+import org.apache.storm.Config;
+import org.apache.storm.testing.TestSerObject;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SerializationTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SerializationTest.class);
+
+    @Test
+    public void testJavaSerialization() {
+        Object obj = new TestSerObject(1, 2);
+        List<Object> vals = Lists.newArrayList(obj);
+
+        Map<String, Object> conf = new HashMap<>();
+        conf.put(Config.TOPOLOGY_KRYO_REGISTER, new HashMap<String, String>() {{
+            put("org.apache.storm.testing.TestSerObject", null);
+        }});
+        conf.put(Config.TOPOLOGY_FALL_BACK_ON_JAVA_SERIALIZATION, false);
+        try {
+            roundtrip(vals, conf);
+            Assert.fail("Expected Exception not Thrown for config: " + conf);
+        } catch (Exception e) {
+        }
+
+        conf.clear();
+        conf.put(Config.TOPOLOGY_FALL_BACK_ON_JAVA_SERIALIZATION, true);
+        Assert.assertEquals(vals, roundtrip(vals, conf));
+    }
+
+    @Test
+    public void testKryoDecorator() {
+        Object obj = new TestSerObject(1, 2);
+        List<Object> vals = Lists.newArrayList(obj);
+
+        Map<String, Object> conf = new HashMap<>();
+        conf.put(Config.TOPOLOGY_FALL_BACK_ON_JAVA_SERIALIZATION, false);
+        try {
+            roundtrip(vals, conf);
+            Assert.fail("Expected Exception not Thrown for config: " + conf);
+        } catch (Exception e) {
+        }
+
+        conf.put(Config.TOPOLOGY_KRYO_DECORATORS, Lists.newArrayList("org.apache.storm.testing.TestKryoDecorator"));
+        Assert.assertEquals(vals, roundtrip(vals, conf));
+    }
+
+    @Test
+    public void testStringSerialization() {
+        isRoundtrip(Lists.newArrayList("a", "bb", "cbe"));
+        isRoundtrip(Lists.newArrayList(mkString(64 * 1024)));
+        isRoundtrip(Lists.newArrayList(mkString(1024 * 1024)));
+        isRoundtrip(Lists.newArrayList(mkString(1024 * 1024 * 2)));
+    }
+
+    private Map mkConf(Map extra) {
+        Map config = Utils.readDefaultConfig();
+        config.putAll(extra);
+        return config;
+    }
+
+    private byte[] serialize(List vals, Map conf) throws IOException {
+        KryoValuesSerializer serializer = new KryoValuesSerializer(mkConf(conf));
+        return serializer.serialize(vals);
+    }
+
+    private List deserialize(byte[] bytes, Map conf) throws IOException {
+        KryoValuesDeserializer deserializer = new KryoValuesDeserializer(mkConf(conf));
+        return deserializer.deserialize(bytes);
+    }
+
+    private List roundtrip(List vals) {
+        return roundtrip(vals, new HashMap());
+    }
+
+    private List roundtrip(List vals, Map conf) {
+        List ret = null;
+        try {
+            ret = deserialize(serialize(vals, conf), conf);
+        } catch (IOException e) {
+            LOG.error("Exception when serialize/deserialize ", e);
+        }
+        return ret;
+    }
+
+    private String mkString(int size) {
+        StringBuilder sb = new StringBuilder();
+        while (size-- > 0) {
+            sb.append("a");
+        }
+        return sb.toString();
+    }
+
+    public void isRoundtrip(List vals) {
+        Assert.assertEquals(vals, roundtrip(vals));
+    }
+}
\ No newline at end of file


[4/4] storm git commit: Added STORM-1250 to CHANGELOG.

Posted by sr...@apache.org.
Added STORM-1250 to CHANGELOG.


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

Branch: refs/heads/master
Commit: c2cf3befce15ed79e41c1c02752f168194e9a1bf
Parents: fd0fb02
Author: Sriharsha Chintalapani <ha...@hortonworks.com>
Authored: Sat Mar 12 21:21:13 2016 -0800
Committer: Sriharsha Chintalapani <ha...@hortonworks.com>
Committed: Sat Mar 12 21:21:13 2016 -0800

----------------------------------------------------------------------
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/c2cf3bef/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4f31ec3..173cfce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
 ## 2.0.0
+ * STORM-1250: port backtype.storm.serialization-test to java
  * STORM-1605: use '/usr/bin/env python' to check python version
  * STORM-1618: Add the option of passing config directory
  * STORM-1269: port backtype.storm.daemon.common to java


[2/4] storm git commit: address review comment

Posted by sr...@apache.org.
address review comment


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

Branch: refs/heads/master
Commit: cdc041e0e590059cb81dcb038139b297c6f21e9c
Parents: 43ca795
Author: Jark Wu <wu...@alibaba-inc.com>
Authored: Sun Mar 6 11:14:40 2016 +0800
Committer: Jark Wu <wu...@alibaba-inc.com>
Committed: Sun Mar 6 11:14:40 2016 +0800

----------------------------------------------------------------------
 .../storm/serialization/SerializationTest.java  | 28 +++++++-------------
 1 file changed, 9 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/cdc041e0/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java
----------------------------------------------------------------------
diff --git a/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java b/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java
index a5501ed..e485518 100644
--- a/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java
+++ b/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java
@@ -6,9 +6,9 @@
  * 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
- *
+ * <p/>
  * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p/>
  * 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.
@@ -23,8 +23,6 @@ import org.apache.storm.testing.TestSerObject;
 import org.apache.storm.utils.Utils;
 import org.junit.Assert;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.util.HashMap;
@@ -33,10 +31,8 @@ import java.util.Map;
 
 public class SerializationTest {
 
-    private static final Logger LOG = LoggerFactory.getLogger(SerializationTest.class);
-
     @Test
-    public void testJavaSerialization() {
+    public void testJavaSerialization() throws IOException {
         Object obj = new TestSerObject(1, 2);
         List<Object> vals = Lists.newArrayList(obj);
 
@@ -57,7 +53,7 @@ public class SerializationTest {
     }
 
     @Test
-    public void testKryoDecorator() {
+    public void testKryoDecorator() throws IOException {
         Object obj = new TestSerObject(1, 2);
         List<Object> vals = Lists.newArrayList(obj);
 
@@ -74,7 +70,7 @@ public class SerializationTest {
     }
 
     @Test
-    public void testStringSerialization() {
+    public void testStringSerialization() throws IOException {
         isRoundtrip(Lists.newArrayList("a", "bb", "cbe"));
         isRoundtrip(Lists.newArrayList(mkString(64 * 1024)));
         isRoundtrip(Lists.newArrayList(mkString(1024 * 1024)));
@@ -97,18 +93,12 @@ public class SerializationTest {
         return deserializer.deserialize(bytes);
     }
 
-    private List roundtrip(List vals) {
+    private List roundtrip(List vals) throws IOException {
         return roundtrip(vals, new HashMap());
     }
 
-    private List roundtrip(List vals, Map conf) {
-        List ret = null;
-        try {
-            ret = deserialize(serialize(vals, conf), conf);
-        } catch (IOException e) {
-            LOG.error("Exception when serialize/deserialize ", e);
-        }
-        return ret;
+    private List roundtrip(List vals, Map conf) throws IOException {
+        return deserialize(serialize(vals, conf), conf);
     }
 
     private String mkString(int size) {
@@ -119,7 +109,7 @@ public class SerializationTest {
         return sb.toString();
     }
 
-    public void isRoundtrip(List vals) {
+    public void isRoundtrip(List vals) throws IOException {
         Assert.assertEquals(vals, roundtrip(vals));
     }
 }
\ No newline at end of file


[3/4] storm git commit: Merge branch 'STORM-1250' of https://github.com/wuchong/storm into STORM-1250

Posted by sr...@apache.org.
Merge branch 'STORM-1250' of https://github.com/wuchong/storm into STORM-1250


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

Branch: refs/heads/master
Commit: fd0fb02e8a183f0b184d3895f439e543a5ffd530
Parents: 5f818b9 cdc041e
Author: Sriharsha Chintalapani <ha...@hortonworks.com>
Authored: Sat Mar 12 20:53:50 2016 -0800
Committer: Sriharsha Chintalapani <ha...@hortonworks.com>
Committed: Sat Mar 12 20:53:50 2016 -0800

----------------------------------------------------------------------
 .../clj/org/apache/storm/serialization_test.clj |  85 ++------------
 .../org/apache/storm/TestConfigValidate.java    |  20 ++++
 .../storm/serialization/SerializationTest.java  | 115 +++++++++++++++++++
 3 files changed, 144 insertions(+), 76 deletions(-)
----------------------------------------------------------------------