Skip to content

Instantly share code, notes, and snippets.

@olegakbarov
Created March 5, 2017 21:11
Show Gist options
  • Save olegakbarov/137ebff5a16851f6318d712d06f56244 to your computer and use it in GitHub Desktop.
Save olegakbarov/137ebff5a16851f6318d712d06f56244 to your computer and use it in GitHub Desktop.
(ns my.app
(:require
[aleph.http :refer :all]
[compojure.core :refer [defroutes GET]]
[compojure.handler :as handler]
[lamina.core :refer :all]
[com.netflix.hystrix.core :as hystrix]
[clj-http.client :as client]))
(defn get-pants []
(client/get "http://pants-service"))
(hystrix/defcommand find-pants
{:hystrix/fallback-fn (constantly {})}
[]
(let [response (get-pants)]
(if (= 200 (:status response))
(:body response)
{})))
(defn- find-pants-observable [] (hystrix/observe #'find-pants))
(defn- pants-request-handler [channel request]
(-> (find-pants-observable)
(.subscribe
#(enqueue channel {:status 200 :body %})
#(println "ERROR " %))))
(defroutes routes
(GET "/pants" [] (wrap-aleph-handler pants-request-handler)))
(defn make-app []
(handler/api routes))
(ns my.integration.t-app
(:require
[midje.sweet :refer :all]
[aleph.http :refer :all]
[lamina.core :refer :all]
[clj-http.client :as client]
[my.app :refer :all]))
(defn do-get ([uri] (do-get uri {}))
([uri params]
(let [app (wrap-ring-handler (make-app))]
(app ch {:uri uri :params params :request-method :get})
(:body @(read-channel ch)))))
(fact "pants are not trousers"
(do-get "/pants") => "are not trousers"
(provided
(client/get anything) => "are not trousers"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment