storm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kabh...@apache.org
Subject [1/3] storm git commit: STORM-1290 port backtype.storm.local-state-test to java
Date Sat, 17 Jun 2017 11:38:07 GMT
Repository: storm
Updated Branches:
  refs/heads/master 38e997ed9 -> ed130ac7a


STORM-1290 port backtype.storm.local-state-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/b3389abb
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/b3389abb
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/b3389abb

Branch: refs/heads/master
Commit: b3389abbfdc37fb89d838547769703fedcd82d27
Parents: 38e997e
Author: kamleshbhatt <kbhatt2005@gmail.com>
Authored: Sat Jun 10 14:45:52 2017 +0530
Committer: Jungtaek Lim <kabhwan@gmail.com>
Committed: Sat Jun 17 20:37:25 2017 +0900

----------------------------------------------------------------------
 .../clj/org/apache/storm/local_state_test.clj   | 59 ---------------
 .../java/org/apache/storm/LocalStateTest.java   | 79 ++++++++++++++++++++
 2 files changed, 79 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/b3389abb/storm-core/test/clj/org/apache/storm/local_state_test.clj
----------------------------------------------------------------------
diff --git a/storm-core/test/clj/org/apache/storm/local_state_test.clj b/storm-core/test/clj/org/apache/storm/local_state_test.clj
deleted file mode 100644
index e5baa67..0000000
--- a/storm-core/test/clj/org/apache/storm/local_state_test.clj
+++ /dev/null
@@ -1,59 +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.local-state-test
-  (:use [clojure test])
-  (:import [org.apache.storm.testing TmpPath])
-  (:import [org.apache.storm.utils LocalState]
-           [org.apache.storm.generated GlobalStreamId]
-           [org.apache.commons.io FileUtils]
-           [java.io File]))
-
-(deftest test-local-state
-  (with-open [dir1-tmp (TmpPath.) 
-              dir2-tmp (TmpPath.)]
-    (let [dir1 (.getPath dir1-tmp)
-          dir2 (.getPath dir2-tmp)
-          gs-a (GlobalStreamId. "a" "a")
-          gs-b (GlobalStreamId. "b" "b")
-          gs-c (GlobalStreamId. "c" "c")
-          gs-d (GlobalStreamId. "d" "d")
-          ls1 (LocalState. dir1)
-          ls2 (LocalState. dir2)]
-      (is (= {} (.snapshot ls1)))
-      (.put ls1 "a" gs-a)
-      (.put ls1 "b" gs-b)
-      (is (= {"a" gs-a "b" gs-b} (.snapshot ls1)))
-      (is (= {} (.snapshot ls2)))
-      (is (= gs-a (.get ls1 "a")))
-      (is (= nil (.get ls1 "c")))
-      (is (= gs-b (.get ls1 "b")))
-      (is (= {"a" gs-a "b" gs-b} (.snapshot (LocalState. dir1))))
-      (.put ls2 "b" gs-a)
-      (.put ls2 "b" gs-b)
-      (.put ls2 "b" gs-c)
-      (.put ls2 "b" gs-d)
-      (is (= gs-d (.get ls2 "b"))))))
-
-(deftest empty-state
-  (with-open [tmp-dir (TmpPath.)]
-    (let [dir (.getPath tmp-dir)
-          ls (LocalState. dir)
-          gs-a (GlobalStreamId. "a" "a")
-          data (FileUtils/openOutputStream (File. dir "12345"))
-          version (FileUtils/openOutputStream (File. dir "12345.version"))]
-      (is (= nil (.get ls "c")))
-      (.put ls "a" gs-a)
-      (is (= gs-a (.get ls "a"))))))

http://git-wip-us.apache.org/repos/asf/storm/blob/b3389abb/storm-server/src/test/java/org/apache/storm/LocalStateTest.java
----------------------------------------------------------------------
diff --git a/storm-server/src/test/java/org/apache/storm/LocalStateTest.java b/storm-server/src/test/java/org/apache/storm/LocalStateTest.java
new file mode 100644
index 0000000..2860482
--- /dev/null
+++ b/storm-server/src/test/java/org/apache/storm/LocalStateTest.java
@@ -0,0 +1,79 @@
+/**
+ * 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;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.storm.generated.GlobalStreamId;
+import org.apache.storm.testing.TmpPath;
+import org.apache.storm.utils.LocalState;
+import org.apache.thrift.TBase;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+public class LocalStateTest {
+
+    @Test
+    public void testLocalState() throws Exception{
+        try(TmpPath dir1_tmp = new TmpPath();  TmpPath dir2_tmp = new TmpPath() ) {
+            GlobalStreamId globalStreamId_a = new GlobalStreamId("a", "a");
+            GlobalStreamId globalStreamId_b = new GlobalStreamId("b", "b");
+            GlobalStreamId globalStreamId_c = new GlobalStreamId("c", "c");
+            GlobalStreamId globalStreamId_d = new GlobalStreamId("d", "d");
+
+            LocalState ls1 = new LocalState(dir1_tmp.getPath());
+            LocalState ls2 = new LocalState(dir2_tmp.getPath());
+            Assert.assertTrue(ls1.snapshot().isEmpty());
+
+            ls1.put("a", globalStreamId_a);
+            ls1.put("b", globalStreamId_b);
+            Map<String, GlobalStreamId> expected = new HashMap<>();
+            expected.put("a", globalStreamId_a);
+            expected.put("b", globalStreamId_b);
+            Assert.assertEquals(expected, ls1.snapshot());
+            Assert.assertEquals(expected, new LocalState(dir1_tmp.getPath()).snapshot());
+
+            Assert.assertTrue(ls2.snapshot().isEmpty());
+            ls2.put("b", globalStreamId_a);
+            ls2.put("b", globalStreamId_b);
+            ls2.put("b", globalStreamId_c);
+            ls2.put("b", globalStreamId_d);
+            Assert.assertEquals(globalStreamId_d, ls2.get("b"));
+        }
+    }
+
+    @Test
+    public void testEmptyState() throws IOException {
+        TmpPath tmp_dir = new TmpPath();
+        String dir = tmp_dir.getPath();
+        LocalState ls = new LocalState(dir);
+        GlobalStreamId gs_a = new GlobalStreamId("a", "a");
+        FileOutputStream data = FileUtils.openOutputStream(new File(dir,"12345"));
+        FileOutputStream version = FileUtils.openOutputStream(new File(dir,"12345.version"));
+        Assert.assertNull(ls.get("c"));
+        ls.put("a", gs_a);
+        Assert.assertEquals(gs_a, ls.get("a"));
+
+    }
+}


Mime
View raw message