storm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject [1/2] storm git commit: STORM-3137: Fix too strict mock verification in nimbus_test
Date Mon, 02 Jul 2018 14:27:06 GMT
Repository: storm
Updated Branches:
  refs/heads/master 1ffa9167d -> ba7c6a85f


STORM-3137: Fix too strict mock verification in nimbus_test


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

Branch: refs/heads/master
Commit: f964f3fb555b34c5328046ee3044b443d0f191ec
Parents: 10f01f4
Author: Stig Rohde Døssing <srdo@apache.org>
Authored: Sat Jun 30 11:06:29 2018 +0200
Committer: Stig Rohde Døssing <srdo@apache.org>
Committed: Sat Jun 30 11:06:29 2018 +0200

----------------------------------------------------------------------
 .../test/clj/org/apache/storm/nimbus_test.clj   | 44 +++++++-------------
 1 file changed, 15 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/f964f3fb/storm-core/test/clj/org/apache/storm/nimbus_test.clj
----------------------------------------------------------------------
diff --git a/storm-core/test/clj/org/apache/storm/nimbus_test.clj b/storm-core/test/clj/org/apache/storm/nimbus_test.clj
index 19615b6..7d389b3 100644
--- a/storm-core/test/clj/org/apache/storm/nimbus_test.clj
+++ b/storm-core/test/clj/org/apache/storm/nimbus_test.clj
@@ -1829,11 +1829,6 @@
         (.setLogConfig nimbus "foo" mock-config)
         (.setTopologyLogConfig (Mockito/verify cluster-state) (Mockito/any String) (Mockito/eq
expected-config) (Mockito/any Map))))))
 
-(defn teardown-heartbeats [id])
-(defn teardown-topo-errors [id])
-(defn teardown-backpressure-dirs [id])
-(defn teardown-wt-dirs [id])
-
 (defn mock-cluster-state
   ([]
     (mock-cluster-state nil nil))
@@ -1842,16 +1837,13 @@
   ([active-topos hb-topos error-topos bp-topos]
     (mock-cluster-state active-topos hb-topos error-topos bp-topos nil))
   ([active-topos hb-topos error-topos bp-topos wt-topos]
-    (reify IStormClusterState
-      (teardownHeartbeats [this id] (teardown-heartbeats id))
-      (teardownTopologyErrors [this id] (teardown-topo-errors id))
-      (removeBackpressure [this id] (teardown-backpressure-dirs id))
-      (removeAllPrivateWorkerKeys [this id] (teardown-wt-dirs id))
-      (activeStorms [this] active-topos)
-      (heartbeatStorms [this] hb-topos)
-      (errorTopologies [this] error-topos)
-      (backpressureTopologies [this] bp-topos)
-      (idsOfTopologiesWithPrivateWorkerKeys [this] (into #{} wt-topos)))))
+    (let [cluster-state (Mockito/mock IStormClusterState)]
+      (.thenReturn (Mockito/when (.activeStorms cluster-state)) active-topos)
+      (.thenReturn (Mockito/when (.heartbeatStorms cluster-state)) hb-topos)
+      (.thenReturn (Mockito/when (.errorTopologies cluster-state)) error-topos)
+      (.thenReturn (Mockito/when (.backpressureTopologies cluster-state)) bp-topos)
+      (.thenReturn (Mockito/when (.idsOfTopologiesWithPrivateWorkerKeys cluster-state)) (into
#{} wt-topos))
+      cluster-state)))
 
 (deftest cleanup-storm-ids-returns-inactive-topos
          (let [mock-state (mock-cluster-state (list "topo1") (list "topo1" "topo2" "topo3"))
@@ -1892,19 +1884,16 @@
       (let [nimbus (Mockito/spy (Nimbus. conf nil mock-state nil mock-blob-store nil nil))]
         (.set (.getHeartbeatsCache nimbus) hb-cache)
         (.thenReturn (Mockito/when (.storedTopoIds mock-blob-store)) (HashSet. inactive-topos))
-        (mocking
-          [teardown-heartbeats
-           teardown-topo-errors]
 
           (.doCleanup nimbus)
 
           ;; removed heartbeats znode
-          (verify-nth-call-args-for 1 teardown-heartbeats "topo2")
-          (verify-nth-call-args-for 2 teardown-heartbeats "topo3")
+          (.teardownHeartbeats (Mockito/verify mock-state) "topo2")
+          (.teardownHeartbeats (Mockito/verify mock-state) "topo3")
 
           ;; removed topo errors znode
-          (verify-nth-call-args-for 1 teardown-topo-errors "topo2")
-          (verify-nth-call-args-for 2 teardown-topo-errors "topo3")
+          (.teardownTopologyErrors (Mockito/verify mock-state) "topo2")
+          (.teardownTopologyErrors (Mockito/verify mock-state) "topo3")
 
           ;; removed topo directories
           (.forceDeleteTopoDistDir (Mockito/verify nimbus) "topo2")
@@ -1919,7 +1908,7 @@
           (.rmDependencyJarsInTopology (Mockito/verify nimbus) "topo3")
 
           ;; remove topos from heartbeat cache
-          (is (= (count (.get (.getHeartbeatsCache nimbus))) 0)))))))
+          (is (= (count (.get (.getHeartbeatsCache nimbus))) 0))))))
 
 
 (deftest do-cleanup-does-not-teardown-active-topos
@@ -1933,21 +1922,18 @@
       (let [nimbus (Mockito/spy (Nimbus. conf nil mock-state nil mock-blob-store nil nil))]
         (.set (.getHeartbeatsCache nimbus) hb-cache)
         (.thenReturn (Mockito/when (.storedTopoIds mock-blob-store)) (set inactive-topos))
-        (mocking
-          [teardown-heartbeats
-           teardown-topo-errors]
 
           (.doCleanup nimbus)
 
-          (verify-call-times-for teardown-heartbeats 0)
-          (verify-call-times-for teardown-topo-errors 0)
+          (.teardownHeartbeats (Mockito/verify mock-state (Mockito/never)) (Mockito/any))
+          (.teardownTopologyErrors (Mockito/verify mock-state (Mockito/never)) (Mockito/any))
           (.forceDeleteTopoDistDir (Mockito/verify nimbus (Mockito/times 0)) (Mockito/anyObject))
           (.rmTopologyKeys (Mockito/verify nimbus (Mockito/times 0)) (Mockito/anyObject))
 
           ;; hb-cache goes down to 1 because only one topo was inactive
           (is (= (count (.get (.getHeartbeatsCache nimbus))) 2))
           (is (contains? (.get (.getHeartbeatsCache nimbus)) "topo1"))
-          (is (contains? (.get (.getHeartbeatsCache nimbus)) "topo2")))))))
+          (is (contains? (.get (.getHeartbeatsCache nimbus)) "topo2"))))))
 
 (deftest user-topologies-for-supervisor
   (let [assignment (doto (Assignment.)


Mime
View raw message