Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding observe to Clojure adapter. #171

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,21 @@
(let [^HystrixExecutable instance (apply instantiate definition args)]
(queued-command instance (.queue instance))))

(defn observe
"The same as queue but returns a rx.Observable (http://netflix.github.io/RxJava/javadoc/rx/Observable.html).

Examples:

(let [ob (observe my-command 1 2 3)]
... subscribe to observer ...)

See:
http://netflix.github.com/Hystrix/javadoc/com/netflix/hystrix/HystrixCommand.html#observe()
"
[definition & args]
(let [^HystrixExecutable instance (apply instantiate definition args)]
(.observe instance)))

;################################################################################
; :command impl

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
(:use com.netflix.hystrix.core)
(:require [clojure.test :refer [deftest testing is are use-fixtures]])
(:import [com.netflix.hystrix Hystrix HystrixExecutable]
[com.netflix.hystrix.strategy.concurrency HystrixRequestContext]))
[com.netflix.hystrix.strategy.concurrency HystrixRequestContext]
[rx Observable]))

; reset hystrix after each execution, for consistency and sanity
(defn reset-fixture
Expand Down Expand Up @@ -172,6 +173,15 @@
(is (= "hello-world" (.get qc) @qc))
(is (.isDone qc))))))

(deftest test-observe
(let [base-def {:type :command
:group-key :my-group
:command-key :my-command
:run-fn + }]
(testing "returns an observable"
(let [ob (observe (normalize (assoc base-def :run-fn str)) "")]
(is (instance? Observable ob))))))

(deftest test-this-command-binding
(let [base-def {:type :command
:group-key :test-this-command-binding-group
Expand Down