storm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kabh...@apache.org
Subject [1/7] storm git commit: STORM-1249: port backtype.storm.security.serialization.BlowfishTupleSerializer-test to java
Date Thu, 07 Jul 2016 14:26:33 GMT
Repository: storm
Updated Branches:
  refs/heads/master d1280c2b9 -> 0348624ae


STORM-1249: port backtype.storm.security.serialization.BlowfishTupleSerializer-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/473770d8
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/473770d8
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/473770d8

Branch: refs/heads/master
Commit: 473770d8bcd3f7cfc406643f79279e6ae8117328
Parents: b477939
Author: Abhishek Agarwal <abhishek.agarwal@inmobi.com>
Authored: Wed Mar 9 21:07:51 2016 +0530
Committer: Abhishek Agarwal <abhishek.agarwal@inmobi.com>
Committed: Thu Mar 10 18:08:08 2016 +0530

----------------------------------------------------------------------
 .../BlowfishTupleSerializer_test.clj            | 77 ------------------
 .../BlowfishTupleSerializerTest.java            | 86 ++++++++++++++++++++
 2 files changed, 86 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/473770d8/storm-core/test/clj/org/apache/storm/security/serialization/BlowfishTupleSerializer_test.clj
----------------------------------------------------------------------
diff --git a/storm-core/test/clj/org/apache/storm/security/serialization/BlowfishTupleSerializer_test.clj
b/storm-core/test/clj/org/apache/storm/security/serialization/BlowfishTupleSerializer_test.clj
deleted file mode 100644
index 824e1d8..0000000
--- a/storm-core/test/clj/org/apache/storm/security/serialization/BlowfishTupleSerializer_test.clj
+++ /dev/null
@@ -1,77 +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.
-(ns org.apache.storm.security.serialization.BlowfishTupleSerializer-test
-  (:use [clojure test]
-        [clojure.string :only (join split)]
-  )
-  (:import [org.apache.storm.security.serialization BlowfishTupleSerializer]
-           [org.apache.storm.utils ListDelegate]
-           [com.esotericsoftware.kryo Kryo]
-           [com.esotericsoftware.kryo.io Input Output]
-  )
-)
-
-(deftest test-constructor-throws-on-null-key
-  (is (thrown? RuntimeException (new BlowfishTupleSerializer nil {}))
-      "Throws RuntimeException when no encryption key is given.")
-)
-
-(deftest test-constructor-throws-on-invalid-key
-  ; The encryption key must be hexadecimal.
-  (let [conf {BlowfishTupleSerializer/SECRET_KEY "0123456789abcdefg"}]
-    (is (thrown? RuntimeException (new BlowfishTupleSerializer nil conf))
-        "Throws RuntimeException when an invalid encryption key is given.")
-  )
-)
-
-(deftest test-encrypts-and-decrypts-message
-  (let [
-        test-text (str
-"Tetraodontidae is a family of primarily marine and estuarine fish of the order"
-" Tetraodontiformes. The family includes many familiar species, which are"
-" variously called pufferfish, puffers, balloonfish, blowfish, bubblefish,"
-" globefish, swellfish, toadfish, toadies, honey toads, sugar toads, and sea"
-" squab.[1] They are morphologically similar to the closely related"
-" porcupinefish, which have large external spines (unlike the thinner, hidden"
-" spines of Tetraodontidae, which are only visible when the fish has puffed up)."
-" The scientific name refers to the four large teeth, fused into an upper and"
-" lower plate, which are used for crushing the shells of crustaceans and"
-" mollusks, their natural prey."
-)
-        kryo (new Kryo)
-        arbitrary-key "7dd6fb3203878381b08f9c89d25ed105"
-        storm_conf {BlowfishTupleSerializer/SECRET_KEY arbitrary-key}
-        writer-bts (new BlowfishTupleSerializer kryo storm_conf)
-        reader-bts (new BlowfishTupleSerializer kryo storm_conf)
-        buf-size 1024
-        output (new Output buf-size buf-size)
-        input (new Input buf-size)
-        strlist (split test-text #" ")
-        delegate (new ListDelegate)
-       ]
-    (-> delegate (.addAll strlist))
-    (-> writer-bts (.write kryo output delegate))
-    (.setBuffer input (.getBuffer output))
-    (is 
-      (=
-        test-text
-        (join " " (map (fn [e] (str e)) 
-          (-> reader-bts (.read kryo input ListDelegate) (.toArray))))
-      )
-      "Reads a string encrypted by another instance with a shared key"
-    )
-  )
-)

http://git-wip-us.apache.org/repos/asf/storm/blob/473770d8/storm-core/test/jvm/org/apache/storm/security/serialization/BlowfishTupleSerializerTest.java
----------------------------------------------------------------------
diff --git a/storm-core/test/jvm/org/apache/storm/security/serialization/BlowfishTupleSerializerTest.java
b/storm-core/test/jvm/org/apache/storm/security/serialization/BlowfishTupleSerializerTest.java
new file mode 100644
index 0000000..08ada9f
--- /dev/null
+++ b/storm-core/test/jvm/org/apache/storm/security/serialization/BlowfishTupleSerializerTest.java
@@ -0,0 +1,86 @@
+/**
+ * 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.security.serialization;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableMap;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+import org.apache.storm.utils.ListDelegate;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+public class BlowfishTupleSerializerTest {
+
+    /**
+     * Throws RuntimeException when no encryption key is given.
+     */
+    @Test(expected = RuntimeException.class)
+    public void testConstructorThrowsOnNullKey() {
+        new BlowfishTupleSerializer(null, new HashMap());
+    }
+
+    /**
+     * Throws RuntimeException when an invalid encryption key is given.
+     */
+    @Test(expected = RuntimeException.class)
+    public void testConstructorThrowsOnInvalidKey() {
+        // The encryption key must be hexadecimal.
+        new BlowfishTupleSerializer(null, ImmutableMap.of(BlowfishTupleSerializer.SECRET_KEY,
"0123456789abcdefg"));
+    }
+
+    /**
+     * Reads a string encrypted by another instance with a shared key
+     */
+    @Test
+    public void testEncryptsAndDecryptsMessage() {
+        String testText = "Tetraodontidae is a family of primarily marine and estuarine fish
of the order" +
+                          " Tetraodontiformes. The family includes many familiar species,
which are" +
+                          " variously called pufferfish, puffers, balloonfish, blowfish,
bubblefish," +
+                          " globefish, swellfish, toadfish, toadies, honey toads, sugar toads,
and sea" +
+                          " squab.[1] They are morphologically similar to the closely related"
+
+                          " porcupinefish, which have large external spines (unlike the thinner,
hidden" +
+                          " spines of Tetraodontidae, which are only visible when the fish
has puffed up)." +
+                          " The scientific name refers to the four large teeth, fused into
an upper and" +
+                          " lower plate, which are used for crushing the shells of crustaceans
and" +
+                          " mollusks, their natural prey.";
+        Kryo kryo = new Kryo();
+        String arbitraryKey = "7dd6fb3203878381b08f9c89d25ed105";
+        Map stormConf = ImmutableMap.of(BlowfishTupleSerializer.SECRET_KEY, arbitraryKey);
+        BlowfishTupleSerializer writerBTS = new BlowfishTupleSerializer(kryo, stormConf);
+        BlowfishTupleSerializer readerBTS = new BlowfishTupleSerializer(kryo, stormConf);
+        int bufferSize = 1024;
+        Output output = new Output(bufferSize, bufferSize);
+        Input input = new Input(bufferSize);
+        String[] stringList = testText.split(" ");
+        ListDelegate delegate = new ListDelegate();
+        delegate.addAll(Arrays.asList(stringList));
+
+        writerBTS.write(kryo, output, delegate);
+        input.setBuffer(output.getBuffer());
+        ListDelegate outDelegate = readerBTS.read(kryo, input, ListDelegate.class);
+        Assert.assertEquals(testText, Joiner.on(" ").join(outDelegate.toArray()));
+    }
+}


Mime
View raw message