Skip to content

Commit

Permalink
Confirm that the Solr cluster is ready multiple times during wait (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuck Gala authored and bruceadams committed Aug 23, 2016
1 parent 8746429 commit 08145b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/kale/create.clj
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,14 @@
[endpoint cluster-id]
(let [start-time (t/now)
update-time (atom (t/now))
wait-time (fn [target] (t/in-minutes (t/interval target (t/now))))]
(while (and (= "NOT_AVAILABLE"
(:solr_cluster_status (rnr/get-cluster endpoint
cluster-id)))
wait-time (fn [target] (t/in-minutes (t/interval target (t/now))))
available-count (atom 0)]
(while (and (< @available-count 5)
(< (wait-time start-time) 30))
(if (= "READY"
(:solr_cluster_status (rnr/get-cluster endpoint cluster-id)))
(swap! available-count inc)
(reset! available-count 0))
(print ".")
(when (>= (wait-time @update-time) 5)
;; Inform the user that we're still waiting
Expand Down
22 changes: 18 additions & 4 deletions test/kale/create_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,23 @@
(with-redefs [rnr/get-cluster
(fn [_ _]
(swap! counter inc)
(if (= @counter 4)
(if (> @counter 3)
{:solr_cluster_status "READY"}
{:solr_cluster_status "NOT_AVAILABLE"}))]
(is (= (str "..." new-line)
(is (= (str "........" new-line)
(with-out-str
(sut/wait-for-cluster {} "CLUSTER-ID")))))))

(deftest wait-for-cluster-restart-availability-count
(let [counter (atom 0)]
(with-redefs [rnr/get-cluster
(fn [_ _]
(swap! counter inc)
(if (or (> @counter 3)
(= @counter 6))
{:solr_cluster_status "READY"}
{:solr_cluster_status "NOT_AVAILABLE"}))]
(is (= (str "........" new-line)
(with-out-str
(sut/wait-for-cluster {} "CLUSTER-ID")))))))

Expand All @@ -272,12 +285,13 @@
(with-redefs [rnr/get-cluster
(fn [_ _]
(swap! counter inc)
(if (= @counter 4)
(if (> @counter 3)
{:solr_cluster_status "READY"}
{:solr_cluster_status "NOT_AVAILABLE"}))
in-minutes (fn [_] (if (< @counter 3) 0 5))]
in-minutes (fn [_] (if (= @counter 3) 5 0))]
(is (= (str "..." new-line
"Still waiting on cluster to become ready." new-line
"....."
new-line)
(with-out-str
(sut/wait-for-cluster {} "CLUSTER-ID")))))))
Expand Down

0 comments on commit 08145b7

Please sign in to comment.