From 81cd0eabaf97ec13d81c9741613827377119bc2e Mon Sep 17 00:00:00 2001 From: Preben Ingvaldsen Date: Thu, 17 Jul 2014 11:06:13 -0700 Subject: [PATCH] (TK-27) Remove persistent namespaces Remove persistent-async and persistent-sync namespaces, moving their contents into async and sync, respectively. --- src/clj/puppetlabs/http/client/async.clj | 26 +++++++++++++ .../http/client/persistent_async.clj | 36 ------------------ .../http/client/persistent_sync.clj | 37 ------------------- src/clj/puppetlabs/http/client/sync.clj | 31 +++++++++++++++- .../http/client/async_plaintext_test.clj | 3 +- .../http/client/sync_plaintext_test.clj | 3 +- 6 files changed, 58 insertions(+), 78 deletions(-) delete mode 100644 src/clj/puppetlabs/http/client/persistent_async.clj delete mode 100644 src/clj/puppetlabs/http/client/persistent_sync.clj diff --git a/src/clj/puppetlabs/http/client/async.clj b/src/clj/puppetlabs/http/client/async.clj index dfa8261..2cc68b9 100644 --- a/src/clj/puppetlabs/http/client/async.clj +++ b/src/clj/puppetlabs/http/client/async.clj @@ -301,6 +301,32 @@ (future-callback client result opts callback)) result))) +(schema/defn create-client :- common/HTTPClient + [opts :- common/ClientOptions] + (let [opts (configure-ssl opts) + client (if (:ssl-context opts) + (.. (HttpAsyncClients/custom) (setSSLContext (:ssl-context opts)) build) + (HttpAsyncClients/createDefault))] + (.start client) + (reify common/HTTPClient + (get [this url] (common/get this url {})) + (get [_ url opts] (request (assoc opts :method :get :url url) nil client)) + (head [this url] (common/head this url {})) + (head [_ url opts] (request (assoc opts :method :head :url url) nil client)) + (post [this url] (common/post this url {})) + (post [_ url opts] (request (assoc opts :method :post :url url) nil client)) + (put [this url] (common/put this url {})) + (put [_ url opts] (request (assoc opts :method :put :url url) nil client)) + (delete [this url] (common/delete this url {})) + (delete [_ url opts] (request (assoc opts :method :delete :url url) nil client)) + (trace [this url] (common/trace this url {})) + (trace [_ url opts] (request (assoc opts :method :trace :url url) nil client)) + (options [this url] (common/options this url {})) + (options [_ url opts] (request (assoc opts :method :options :url url) nil client)) + (patch [this url] (common/patch this url {})) + (patch [_ url opts] (request (assoc opts :method :patch :url url) nil client)) + (close [_] (.close client))))) + (defn get "Issue an asynchronous HTTP GET request. This will raise an exception if an error is returned." diff --git a/src/clj/puppetlabs/http/client/persistent_async.clj b/src/clj/puppetlabs/http/client/persistent_async.clj deleted file mode 100644 index 7506b9d..0000000 --- a/src/clj/puppetlabs/http/client/persistent_async.clj +++ /dev/null @@ -1,36 +0,0 @@ -(ns puppetlabs.http.client.persistent-async - (:import (org.apache.http.impl.nio.client HttpAsyncClients)) - (:require [schema.core :as schema] - [puppetlabs.http.client.common :as common] - [puppetlabs.http.client.common :as common] - [puppetlabs.http.client.async :refer [request configure-ssl]]) - (:refer-clojure :exclude (get))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; Public - -(schema/defn create-client :- common/HTTPClient - [opts :- common/ClientOptions] - (let [opts (configure-ssl opts) - client (if (:ssl-context opts) - (.. (HttpAsyncClients/custom) (setSSLContext (:ssl-context opts)) build) - (HttpAsyncClients/createDefault))] - (.start client) - (reify common/HTTPClient - (get [this url] (common/get this url {})) - (get [_ url opts] (request (assoc opts :method :get :url url) nil client)) - (head [this url] (common/head this url {})) - (head [_ url opts] (request (assoc opts :method :head :url url) nil client)) - (post [this url] (common/post this url {})) - (post [_ url opts] (request (assoc opts :method :post :url url) nil client)) - (put [this url] (common/put this url {})) - (put [_ url opts] (request (assoc opts :method :put :url url) nil client)) - (delete [this url] (common/delete this url {})) - (delete [_ url opts] (request (assoc opts :method :delete :url url) nil client)) - (trace [this url] (common/trace this url {})) - (trace [_ url opts] (request (assoc opts :method :trace :url url) nil client)) - (options [this url] (common/options this url {})) - (options [_ url opts] (request (assoc opts :method :options :url url) nil client)) - (patch [this url] (common/patch this url {})) - (patch [_ url opts] (request (assoc opts :method :patch :url url) nil client)) - (close [_] (.close client))))) \ No newline at end of file diff --git a/src/clj/puppetlabs/http/client/persistent_sync.clj b/src/clj/puppetlabs/http/client/persistent_sync.clj deleted file mode 100644 index 7f8f06c..0000000 --- a/src/clj/puppetlabs/http/client/persistent_sync.clj +++ /dev/null @@ -1,37 +0,0 @@ -(ns puppetlabs.http.client.persistent-sync - (:import (org.apache.http.impl.nio.client HttpAsyncClients)) - (:require [schema.core :as schema] - [puppetlabs.http.client.common :as common] - [puppetlabs.http.client.common :as common] - [puppetlabs.http.client.sync :refer [request]] - [puppetlabs.http.client.async :refer [configure-ssl]]) - (:refer-clojure :exclude (get))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; Public - -(schema/defn create-client :- common/HTTPClient - [opts :- common/ClientOptions] - (let [opts (configure-ssl opts) - client (if (:ssl-context opts) - (.. (HttpAsyncClients/custom) (setSSLContext (:ssl-context opts)) build) - (HttpAsyncClients/createDefault))] - (.start client) - (reify common/HTTPClient - (get [this url] (common/get this url {})) - (get [_ url opts] (request (assoc opts :method :get :url url) client)) - (head [this url] (common/head this url {})) - (head [_ url opts] (request (assoc opts :method :head :url url) client)) - (post [this url] (common/post this url {})) - (post [_ url opts] (request (assoc opts :method :post :url url) client)) - (put [this url] (common/put this url {})) - (put [_ url opts] (request (assoc opts :method :put :url url) client)) - (delete [this url] (common/delete this url {})) - (delete [_ url opts] (request (assoc opts :method :delete :url url) client)) - (trace [this url] (common/trace this url {})) - (trace [_ url opts] (request (assoc opts :method :trace :url url) client)) - (options [this url] (common/options this url {})) - (options [_ url opts] (request (assoc opts :method :options :url url) client)) - (patch [this url] (common/patch this url {})) - (patch [_ url opts] (request (assoc opts :method :patch :url url) client)) - (close [_] (.close client))))) \ No newline at end of file diff --git a/src/clj/puppetlabs/http/client/sync.clj b/src/clj/puppetlabs/http/client/sync.clj index 72d1b30..b935621 100644 --- a/src/clj/puppetlabs/http/client/sync.clj +++ b/src/clj/puppetlabs/http/client/sync.clj @@ -2,7 +2,10 @@ ;; defined in puppetlabs.http.client (ns puppetlabs.http.client.sync - (:require [puppetlabs.http.client.async :as async]) + (:import (org.apache.http.impl.nio.client HttpAsyncClients)) + (:require [puppetlabs.http.client.async :as async] + [schema.core :as schema] + [puppetlabs.http.client.common :as common]) (:refer-clojure :exclude (get))) (defn request @@ -17,6 +20,32 @@ (throw error) resp)))) +(schema/defn create-client :- common/HTTPClient + [opts :- common/ClientOptions] + (let [opts (async/configure-ssl opts) + client (if (:ssl-context opts) + (.. (HttpAsyncClients/custom) (setSSLContext (:ssl-context opts)) build) + (HttpAsyncClients/createDefault))] + (.start client) + (reify common/HTTPClient + (get [this url] (common/get this url {})) + (get [_ url opts] (request (assoc opts :method :get :url url) client)) + (head [this url] (common/head this url {})) + (head [_ url opts] (request (assoc opts :method :head :url url) client)) + (post [this url] (common/post this url {})) + (post [_ url opts] (request (assoc opts :method :post :url url) client)) + (put [this url] (common/put this url {})) + (put [_ url opts] (request (assoc opts :method :put :url url) client)) + (delete [this url] (common/delete this url {})) + (delete [_ url opts] (request (assoc opts :method :delete :url url) client)) + (trace [this url] (common/trace this url {})) + (trace [_ url opts] (request (assoc opts :method :trace :url url) client)) + (options [this url] (common/options this url {})) + (options [_ url opts] (request (assoc opts :method :options :url url) client)) + (patch [this url] (common/patch this url {})) + (patch [_ url opts] (request (assoc opts :method :patch :url url) client)) + (close [_] (.close client))))) + (defn get "Issue a synchronous HTTP GET request. This will raise an exception if an error is returned." diff --git a/test/puppetlabs/http/client/async_plaintext_test.clj b/test/puppetlabs/http/client/async_plaintext_test.clj index 12f24d3..1611b3d 100644 --- a/test/puppetlabs/http/client/async_plaintext_test.clj +++ b/test/puppetlabs/http/client/async_plaintext_test.clj @@ -7,7 +7,6 @@ [puppetlabs.trapperkeeper.services.webserver.jetty9-service :as jetty9] [puppetlabs.http.client.common :as common] [puppetlabs.http.client.async :as async] - [puppetlabs.http.client.persistent-async :as p-async] [schema.test :as schema-test])) (use-fixtures :once schema-test/validate-schemas) @@ -81,7 +80,7 @@ (testutils/with-app-with-config app [jetty9/jetty9-service test-web-service] {:webserver {:port 10000}} - (let [client (p-async/create-client {})] + (let [client (async/create-client {})] (testing "HEAD request with persistent async client" (let [response (common/head client "http://localhost:10000/hello/")] (is (= 200 (:status @response))) diff --git a/test/puppetlabs/http/client/sync_plaintext_test.clj b/test/puppetlabs/http/client/sync_plaintext_test.clj index 9a2e84b..3bbc7b4 100644 --- a/test/puppetlabs/http/client/sync_plaintext_test.clj +++ b/test/puppetlabs/http/client/sync_plaintext_test.clj @@ -10,7 +10,6 @@ [puppetlabs.trapperkeeper.testutils.logging :as testlogging] [puppetlabs.trapperkeeper.services.webserver.jetty9-service :as jetty9] [puppetlabs.http.client.sync :as sync] - [puppetlabs.http.client.persistent-sync :as p-sync] [puppetlabs.http.client.common :as common] [schema.test :as schema-test] [clojure.java.io :as io])) @@ -86,7 +85,7 @@ (testutils/with-app-with-config app [jetty9/jetty9-service test-web-service] {:webserver {:port 10000}} - (let [client (p-sync/create-client {})] + (let [client (sync/create-client {})] (testing "HEAD request with persistent sync client" (let [response (common/head client "http://localhost:10000/hello/")] (is (= 200 (:status response)))