diff --git a/hystrix-contrib/hystrix-clj/src/main/clojure/com/netflix/hystrix/core.clj b/hystrix-contrib/hystrix-clj/src/main/clojure/com/netflix/hystrix/core.clj index 353568bbd..bc4589d5e 100644 --- a/hystrix-contrib/hystrix-clj/src/main/clojure/com/netflix/hystrix/core.clj +++ b/hystrix-contrib/hystrix-clj/src/main/clojure/com/netflix/hystrix/core.clj @@ -408,12 +408,15 @@ [name & opts] (let [command-key (str *ns* "/" name ) group-key (str *ns*) - [m [params & body]] (split-def-meta opts) + [m body] (split-def-meta opts) + params (if (vector? (first body)) + (list (first body)) + (map first body)) m (if-not (contains? m :arglists) - (assoc m :arglists `(list (quote ~params))) + (assoc m :arglists `(quote ~params)) m)] `(let [meta-options# (#'com.netflix.hystrix.core/extract-hystrix-command-options ~m) - run-fn# (fn ~name ~params ~@body) + run-fn# (fn ~name ~@body) command-map# (com.netflix.hystrix.core/command (merge {:command-key ~command-key :group-key ~group-key :run-fn run-fn# } diff --git a/hystrix-contrib/hystrix-clj/src/test/clojure/com/netflix/hystrix/core_test.clj b/hystrix-contrib/hystrix-clj/src/test/clojure/com/netflix/hystrix/core_test.clj index 8b5063918..97deb3a5b 100644 --- a/hystrix-contrib/hystrix-clj/src/test/clojure/com/netflix/hystrix/core_test.clj +++ b/hystrix-contrib/hystrix-clj/src/test/clojure/com/netflix/hystrix/core_test.clj @@ -301,6 +301,15 @@ [a b] (+ a b)) +(defcommand my-overload-fn-command + "A doc string" + {:meta :data + :hystrix/fallback-fn (constantly 500)} + ([a b] + (+ a b)) + ([a b c] + (+ a b c))) + (deftest test-defcommand (let [hm (-> #'my-fn-command meta :hystrix)] (testing "defines a fn in a var" @@ -318,7 +327,24 @@ (is (= 105 (wait-for-observable (observe-later #'my-fn-command 91 14)))) (is (= 107 (wait-for-observable (observe-later-on #'my-fn-command (rx.schedulers.Schedulers/newThread) - 92 15))))))) + 92 15))))) + (testing "overload functioning command" + (is (= 99 (my-overload-fn-command 88 11))) + (is (= 100 (my-overload-fn-command 88 11 1))) + (is (= 100 (execute #'my-overload-fn-command 89 11))) + (is (= 100 (execute #'my-overload-fn-command 88 11 1))) + (is (= 101 (deref (queue #'my-overload-fn-command 89 12)))) + (is (= 102 (deref (queue #'my-overload-fn-command 89 12 1)))) + (is (= 103 (wait-for-observable (observe #'my-overload-fn-command 90 13)))) + (is (= 104 (wait-for-observable (observe #'my-overload-fn-command 90 13 1)))) + (is (= 105 (wait-for-observable (observe-later #'my-overload-fn-command 91 14)))) + (is (= 106 (wait-for-observable (observe-later #'my-overload-fn-command 91 14 1)))) + (is (= 107 (wait-for-observable (observe-later-on #'my-overload-fn-command + (rx.schedulers.Schedulers/newThread) + 92 15)))) + (is (= 108 (wait-for-observable (observe-later-on #'my-overload-fn-command + (rx.schedulers.Schedulers/newThread) + 92 15 1))))))) (defcollapser my-collapser "a doc string"