Skip to content

Commit

Permalink
(feat) added support for :unavailable-value
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 committed Jul 7, 2015
1 parent 55adb4a commit d57650b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/slacker/client/cluster.clj
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@
valid-results))
(if (fn? grouping-results-config)
(grouping-results-config valid-results)
(throw (ex-info "Unsupported grouping-results value" {}))))}))))
(throw (ex-info "Unsupported grouping-results value"
{:grouping-results grouping-results-config
:results valid-results}))))}))))

(deftype GroupedPromise [grouping-fn promises]
IDeref
Expand Down Expand Up @@ -244,7 +246,9 @@
target-servers (find-server slacker-ns-servers ns-name grouping*)
target-conns (filter identity (map @slacker-clients target-servers))]
(if (empty? target-conns)
{:cause {:error :unavailable :servers target-servers}}
(if (contains? call-options :unavailable-value)
{:result (:unavailable-value call-options)}
{:cause {:error :unavailable :servers target-servers}})
(do
(logging/debug (str "calling " ns-name "/"
func-name " on " target-servers))
Expand Down Expand Up @@ -280,7 +284,9 @@
(count target-servers))
(cb (grouping-fn @cb-results))))]
(if (empty? target-conns)
(doto (promise) (deliver {:cause {:error :unavailable :servers target-servers}}))
(doto (promise) (deliver (if (contains? call-options :unavailable-value)
{:result (:unavailable-value call-options)}
{:cause {:error :unavailable :servers target-servers}})))
(do
(logging/debug (str "calling " ns-name "/"
func-name " on " target-servers))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
(ns slacker.test.client.cluster
(:use [clojure.test])
(:use [slacker.client common cluster])
(:use [slacker.serialization])
(:use [slacker.utils :only [zk-path]]))
(ns slacker.client.cluster-test
(:require [clojure.test :refer :all]
[slacker.client.common :refer :all]
[slacker.client.cluster :refer :all]
[slacker.serialization :refer :all]
[slacker.utils :refer [zk-path]]
[slacker.zk :as zk])
(:import [slacker.client.cluster ClusterEnabledSlackerClient]))

(deftest test-group-promise []
(let [prmss (take 5 (repeatedly promise))
Expand Down Expand Up @@ -60,3 +63,20 @@
[{:result 1}
{:result 2}])]
(is (= 3 (:result r)))))

(deftest sync-call-test
(testing "unavialble-value"
(let [client (ClusterEnabledSlackerClient. "dummy-cluster"
nil (atom {}) (atom {}) {})
d-ns "dummy-ns"
unavailable-value "N/A"]
(with-redefs [zk-path (constantly "dummy-path")
zk/children (constantly ["a" "b"])
zk/data (constantly (.getBytes "dummy-dataq" "utf-8"))]
(is (= (sync-call-remote client d-ns "dummy-fn" []
{:grouping (constantly [])
:unavailable-value unavailable-value})
{:result unavailable-value}))
(is (= (sync-call-remote client d-ns "dummy-fn" []
{:grouping (constantly [])})
{:cause {:error :unavailable :servers []}}))))))

0 comments on commit d57650b

Please sign in to comment.