[Git][clojure-team/puppetlabs-http-client-clojure][debian/main] 7 commits: re-enable build tests
Jérôme Charaoui (@lavamind)
gitlab at salsa.debian.org
Tue Feb 7 21:14:29 GMT 2023
Jérôme Charaoui pushed to branch debian/main at Debian Clojure Maintainers / puppetlabs-http-client-clojure
Commits:
c0b02d6b by Jérôme Charaoui at 2023-02-07T16:01:46-05:00
re-enable build tests
- - - - -
58415ed3 by Jérôme Charaoui at 2023-02-07T16:02:17-05:00
New upstream version 2.1.1
- - - - -
dd09e11e by Jérôme Charaoui at 2023-02-07T16:02:20-05:00
Update upstream source from tag 'upstream/2.1.1'
Update to upstream version '2.1.1'
with Debian dir 6a0b9e54e319369ade2b08f1baec537ce489e6b0
- - - - -
c1010fc7 by Jérôme Charaoui at 2023-02-07T16:05:42-05:00
d/patches: refresh patches for new upstream version
- - - - -
481ab927 by Jérôme Charaoui at 2023-02-07T16:06:33-05:00
d/patches: target clojure 1.x in project.clj
- - - - -
c25cb6f3 by Jérôme Charaoui at 2023-02-07T16:07:11-05:00
d/control: drop obsolete libcomplete test-dep
- - - - -
c8d1662e by Jérôme Charaoui at 2023-02-07T16:08:06-05:00
Update changelog for 2.1.1-1 release
- - - - -
10 changed files:
- CHANGELOG.md
- debian/changelog
- debian/control
- debian/patches/0001_Lein_Local.patch
- debian/rules
- project.clj
- src/java/com/puppetlabs/http/client/impl/JavaClient.java
- test/puppetlabs/http/client/async_plaintext_test.clj
- test/puppetlabs/http/client/async_unbuffered_test.clj
- test/puppetlabs/http/client/metrics_test.clj
Changes:
=====================================
CHANGELOG.md
=====================================
@@ -1,5 +1,9 @@
## Unreleased
+# 2.1.1
+* [PE-34843](https://tickets.puppetlabs.com/browse/PE-34843) Properly reuse connections when using a client certificate
+* Update to clj-parent 5.2.11
+
# 2.1.0
* update to clj-parent 5.2.6 to move from bouncy-castle `15on` libraries to the `18on` version
* Use `OPTIONS` request method when calling the synchronous client's `options` function.
=====================================
debian/changelog
=====================================
@@ -1,3 +1,13 @@
+puppetlabs-http-client-clojure (2.1.1-1) unstable; urgency=medium
+
+ * New upstream version 2.1.1
+ * re-enable build tests
+ * d/patches: refresh patches for new upstream version
+ * d/patches: target clojure 1.x in project.clj
+ * d/control: drop obsolete libcomplete test-dep
+
+ -- Jérôme Charaoui <jerome at riseup.net> Tue, 07 Feb 2023 16:07:57 -0500
+
puppetlabs-http-client-clojure (2.1.0-4) unstable; urgency=medium
* d/rules: build without tests temporarily (Closes: #1030480, #1030488)
=====================================
debian/control
=====================================
@@ -10,7 +10,7 @@ Build-Depends:
default-jdk-headless,
javahelper,
maven-repo-helper,
- libclojure-java,
+ libclojure-java (>= 1.11.1-2),
libhttpclient-java,
libhttpasyncclient-java (>= 4.1.5),
libhttpcore-java,
@@ -21,15 +21,14 @@ Build-Depends:
libpuppetlabs-i18n-clojure (>= 0.9.2-2),
libservlet-api-java,
libslf4j-java,
-# libcheshire-clojure (>= 5.11.0-2) <!nocheck>,
-# libkitchensink-clojure (>= 3.2.1) <!nocheck>,
-# libtrapperkeeper-clojure (>= 3.1.0) <!nocheck>,
-# libtrapperkeeper-webserver-jetty9-clojure (>= 4.1.0-2) <!nocheck>,
-# libpuppetlabs-ring-middleware-clojure (>= 1.3.0) <!nocheck>,
-# libbcpkix-java <!nocheck>,
-# libcomplete-clojure <!nocheck>,
+ libcheshire-clojure (>= 5.11.0-2) <!nocheck>,
+ libkitchensink-clojure (>= 3.2.1) <!nocheck>,
+ libtrapperkeeper-clojure (>= 3.1.0) <!nocheck>,
+ libtrapperkeeper-webserver-jetty9-clojure (>= 4.1.0-2) <!nocheck>,
+ libpuppetlabs-ring-middleware-clojure (>= 1.3.0) <!nocheck>,
+ libbcpkix-java <!nocheck>,
leiningen,
-# openssl <!nocheck>
+ openssl <!nocheck>
Standards-Version: 4.6.2
Vcs-Git: https://salsa.debian.org/clojure-team/puppetlabs-http-client-clojure.git
Vcs-Browser: https://salsa.debian.org/clojure-team/puppetlabs-http-client-clojure
=====================================
debian/patches/0001_Lein_Local.patch
=====================================
@@ -8,16 +8,16 @@ Forwarded: not-needed
1 file changed, 19 insertions(+), 44 deletions(-)
diff --git a/project.clj b/project.clj
-index f78cb04..15ebb87 100644
+index 669765d..5edba9b 100644
--- a/project.clj
+++ b/project.clj
@@ -5,25 +5,17 @@
:min-lein-version "2.9.1"
-- :parent-project {:coords [puppetlabs/clj-parent "5.2.6"]
+- :parent-project {:coords [puppetlabs/clj-parent "5.2.11"]
- :inherit [:managed-dependencies]}
-+ :dependencies [[org.clojure/clojure "1.10.x"]
++ :dependencies [[org.clojure/clojure "1.x"]
- ;; Abort when version ranges or version conflicts are detected in
- ;; dependencies. Also supports :warn to simply emit warnings.
=====================================
debian/rules
=====================================
@@ -24,10 +24,10 @@ override_dh_auto_build:
cd target && ln -sf $(NAME)-$(DEB_VERSION_UPSTREAM).jar $(NAME).jar
override_dh_auto_test:
-#ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
-# ./dev-resources/gen-pki.sh
-# lein test
-#endif
+ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
+ ./dev-resources/gen-pki.sh
+ lein test
+endif
override_dh_clean:
rm -f debian/maven-repo
=====================================
project.clj
=====================================
@@ -1,11 +1,11 @@
-(defproject puppetlabs/http-client "2.1.0"
+(defproject puppetlabs/http-client "2.1.1"
:description "HTTP client wrapper"
:license {:name "Apache License, Version 2.0"
:url "http://www.apache.org/licenses/LICENSE-2.0.html"}
:min-lein-version "2.9.1"
- :parent-project {:coords [puppetlabs/clj-parent "5.2.6"]
+ :parent-project {:coords [puppetlabs/clj-parent "5.2.11"]
:inherit [:managed-dependencies]}
;; Abort when version ranges or version conflicts are detected in
=====================================
src/java/com/puppetlabs/http/client/impl/JavaClient.java
=====================================
@@ -532,6 +532,15 @@ public class JavaClient {
HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom();
clientBuilder.setMaxConnPerRoute(clientOptions.getMaxConnectionsPerRoute());
clientBuilder.setMaxConnTotal(clientOptions.getMaxConnectionsTotal());
+ // Typically, the HttpClient library tracks the "user token" for a
+ // connection, which in our case is the SSL certificate name, and
+ // refuses to reuse a connection if the SSL certificate is different
+ // for the next request. Because we create a new HttpClientContext for
+ // every request, this tracking doesn't work in our case. However,
+ // since we bake the SSL context in at the time we create the client,
+ // it's impossible for it to change from request to request, so we can
+ // simply disable that tracking altogether.
+ clientBuilder.disableConnectionState();
SSLContext context = coercedOptions.getSslContext();
if (context != null) {
=====================================
test/puppetlabs/http/client/async_plaintext_test.clj
=====================================
@@ -56,6 +56,11 @@
{:status 200
:body "cookie has been set"}))
+(defn clear-latch
+ [latch]
+ (dotimes [_ (.getCount latch)]
+ (.countDown latch)))
+
(tk/defservice test-cookie-service
[[:WebserverService add-ring-handler]]
(init [this context]
@@ -671,8 +676,10 @@
(testing "clojure persistent async client"
(with-open [client (async/create-client {})]
(dotimes [n 10] (future (common/get client url {:as :text})))
- (is (= false (.await countdown 5 TimeUnit/SECONDS)))
- (is (= 2 @actual-count)))))))))
+ (is (= false (.await countdown 1 TimeUnit/SECONDS)))
+ (is (= 2 @actual-count))
+ ;; Clear the latch so the webserver can shutdown
+ (clear-latch countdown))))))))
(testing "passing client route limit of 0 selects default behavior (a limit of 2)"
(let [actual-count (atom 0)
@@ -689,8 +696,10 @@
(testing "clojure persistent async client"
(with-open [client (async/create-client {:max-connections-per-route 0})]
(dotimes [n 10] (future (common/get client url {:as :text})))
- (is (= false (.await countdown 5 TimeUnit/SECONDS)))
- (is (= 2 @actual-count)))))))))
+ (is (= false (.await countdown 1 TimeUnit/SECONDS)))
+ (is (= 2 @actual-count))
+ ;; Clear the latch so the webserver can shutdown
+ (clear-latch countdown))))))))
(testing "client limits specified requests per route"
@@ -708,8 +717,10 @@
(testing "clojure persistent async client"
(with-open [client (async/create-client {:max-connections-per-route 3})]
(dotimes [n 10] (future (common/get client url {:as :text})))
- (is (= false (.await countdown 5 TimeUnit/SECONDS)))
- (is (= 3 @actual-count)))))))))
+ (is (= false (.await countdown 1 TimeUnit/SECONDS)))
+ (is (= 3 @actual-count))
+ ;; Clear the latch so the webserver can shutdown
+ (clear-latch countdown))))))))
(testing "client route limit of 11 does not limit requests per route when less than 11"
(let [actual-count (atom 0)
@@ -745,5 +756,7 @@
(with-open [client (async/create-client {:max-connections-per-route 11
:max-connections-total 3})]
(dotimes [n 10] (future (common/get client url {:as :text})))
- (is (= false (.await countdown 5 TimeUnit/SECONDS)))
- (is (= 3 @actual-count))))))))))
+ (is (= false (.await countdown 1 TimeUnit/SECONDS)))
+ (is (= 3 @actual-count))
+ ;; Clear the latch so the webserver can shutdown
+ (clear-latch countdown)))))))))
=====================================
test/puppetlabs/http/client/async_unbuffered_test.clj
=====================================
@@ -19,7 +19,7 @@
[data-size]
(apply str "xxxx" (repeatedly (/ data-size 35) #(UUID/randomUUID))))
-(defn successful-handler
+(defn streaming-handler
"A Ring handler that asynchronously sends some data, waits for confirmation the data has been received then sends
some more data"
[data send-more-data]
@@ -39,32 +39,19 @@
{:status 200
:body instream})))
-(defn blocking-handler
- "A Ring handler that sends some data but then never closes the socket"
- [data]
- (fn [_]
- (let [outstream (PipedOutputStream.)
- instream (PipedInputStream.)]
- (.connect instream outstream)
- ;; Return the response immediately and asynchronously stream some data into it
- (future
- (.write outstream (.getBytes data)))
- {:status 200
- :body instream})))
-
(defn- clojure-non-blocking-streaming
- "Stream 32M of data (roughly) which is large enough to ensure the client won't buffer it all. Checks the data is
+ "Stream 1M of data (roughly) which is large enough to ensure the client won't buffer it all. Checks the data is
streamed in a non-blocking manner i.e some data is received by the client before the server has finished
transmission"
[decompress-body?]
(testlogging/with-test-logging
- (let [data (generate-data (* 32 1024 1024))
+ (let [data (generate-data (* 1024 1024))
opts {:as :unbuffered-stream :decompress-body decompress-body?}]
(testing " - check data can be streamed successfully"
(let [send-more-data (promise)]
(testwebserver/with-test-webserver-and-config
- (successful-handler data send-more-data) port {:shutdown-timeout-seconds 1}
+ (streaming-handler data send-more-data) port {:shutdown-timeout-seconds 1}
(with-open [client (async/create-client {:connect-timeout-milliseconds 100
:socket-timeout-milliseconds 20000})]
(let [response @(common/get client (str "http://localhost:" port "/hello") opts)
@@ -78,19 +65,21 @@
(is (= (str data "yyyy") (str "xxxx" (slurp instream)))))))))) ;; Read the rest and validate
(testing " - check socket timeout is handled"
- (try
- (testwebserver/with-test-webserver-and-config
- (blocking-handler data) port {:shutdown-timeout-seconds 1}
- (with-open [client (async/create-client {:connect-timeout-milliseconds 100
- :socket-timeout-milliseconds 200})]
- (let [response @(common/get client (str "http://localhost:" port "/hello") opts)
- {:keys [body error]} response]
- (is (nil? error))
- ;; Consume the body to get the exception
- (is (thrown? SocketTimeoutException (slurp body))))))
- (catch TimeoutException e
- ;; Expected whenever a server-side failure is generated
- nil)))
+ (let [send-more-data (promise)]
+ (try
+ (testwebserver/with-test-webserver-and-config
+ (streaming-handler data send-more-data) port {:shutdown-timeout-seconds 1}
+ (with-open [client (async/create-client {:connect-timeout-milliseconds 100
+ :socket-timeout-milliseconds 200})]
+ (let [response @(common/get client (str "http://localhost:" port "/hello") opts)
+ {:keys [body error]} response]
+ (is (nil? error))
+ ;; Consume the body to get the exception
+ (is (thrown? SocketTimeoutException (slurp body)))))
+ (deliver send-more-data true))
+ (catch TimeoutException e
+ ;; Expected whenever a server-side failure is generated
+ nil))))
(testing " - check connection timeout is handled"
(with-open [client (async/create-client {:connect-timeout-milliseconds 100})]
@@ -100,11 +89,11 @@
(is (instance? ConnectException error))))))))
(deftest clojure-non-blocking-streaming-without-decompression
- (testing "clojure :unbuffered-stream with 32MB payload and no decompression"
+ (testing "clojure :unbuffered-stream with 1MB payload and no decompression"
(clojure-non-blocking-streaming false)))
(deftest clojure-non-blocking-streaming-with-decompression
- (testing "clojure :unbuffered-stream with 32MB payload and decompression"
+ (testing "clojure :unbuffered-stream with 1MB payload and decompression"
(clojure-non-blocking-streaming true)))
(defn- clojure-blocking-streaming
@@ -114,7 +103,7 @@
(testing " - check data can be streamed successfully"
(testwebserver/with-test-webserver-and-config
- (successful-handler data nil) port {:shutdown-timeout-seconds 1}
+ (streaming-handler data nil) port {:shutdown-timeout-seconds 1}
(with-open [client (async/create-client {:connect-timeout-milliseconds 100
:socket-timeout-milliseconds 20000})]
(let [response @(common/get client (str "http://localhost:" port "/hello") opts)
@@ -127,17 +116,19 @@
(is (= (str data "yyyy") (str "xxxx" (slurp instream))))))))) ;; Read the rest and validate
(testing " - check socket timeout is handled"
- (try
- (testwebserver/with-test-webserver-and-config
- (blocking-handler data) port {:shutdown-timeout-seconds 1}
- (with-open [client (async/create-client {:connect-timeout-milliseconds 100
- :socket-timeout-milliseconds 200})]
- (let [response @(common/get client (str "http://localhost:" port "/hello") opts)
- {:keys [error]} response]
- (is (instance? SocketTimeoutException error)))))
- (catch TimeoutException e
- ;; Expected whenever a server-side failure is generated
- nil)))
+ (let [send-more-data (promise)]
+ (try
+ (testwebserver/with-test-webserver-and-config
+ (streaming-handler data send-more-data) port {:shutdown-timeout-seconds 1}
+ (with-open [client (async/create-client {:connect-timeout-milliseconds 100
+ :socket-timeout-milliseconds 200})]
+ (let [response @(common/get client (str "http://localhost:" port "/hello") opts)
+ {:keys [error]} response]
+ (is (instance? SocketTimeoutException error))))
+ (deliver send-more-data true))
+ (catch TimeoutException e
+ ;; Expected whenever a server-side failure is generated
+ nil))))
(testing " - check connection timeout is handled"
@@ -168,25 +159,25 @@
(clojure-blocking-streaming (generate-data 1024) {:as :stream :decompress-body true})))
(deftest clojure-existing-streaming-with-large-payload-without-decompression
- (testing "clojure :stream with 32M payload and no decompression"
- (clojure-blocking-streaming (generate-data (* 32 1024 1024)) {:as :stream :decompress-body false})))
+ (testing "clojure :stream with 1M payload and no decompression"
+ (clojure-blocking-streaming (generate-data (* 1024 1024)) {:as :stream :decompress-body false})))
(deftest clojure-existing-streaming-with-large-payload-with-decompression
- (testing "clojure :stream with 32M payload and decompression"
- (clojure-blocking-streaming (generate-data (* 32 1024 1024)) {:as :stream :decompress-body true})))
+ (testing "clojure :stream with 1M payload and decompression"
+ (clojure-blocking-streaming (generate-data (* 1024 1024)) {:as :stream :decompress-body true})))
(defn- java-non-blocking-streaming
- "Stream 32M of data (roughly) which is large enough to ensure the client won't buffer it all. Checks the data is
- streamed in a non-blocking manner i.e some data is received by the client before the server has finished
- transmission"
+ "Stream 1M of data (roughly) which is large enough to ensure the client won't
+ buffer it all. Checks the data is streamed in a non-blocking manner i.e some
+ data is received by the client before the server has finished transmission"
[decompress-body?]
(testlogging/with-test-logging
- (let [data (generate-data (* 32 1024 1024))]
+ (let [data (generate-data (* 1024 1024))]
(testing " - check data can be streamed successfully"
(let [send-more-data (promise)]
(testwebserver/with-test-webserver-and-config
- (successful-handler data send-more-data) port {:shutdown-timeout-seconds 1}
+ (streaming-handler data send-more-data) port {:shutdown-timeout-seconds 1}
(with-open [client (-> (ClientOptions.)
(.setSocketTimeoutMilliseconds 20000)
(.setConnectTimeoutMilliseconds 100)
@@ -206,25 +197,27 @@
(is (= (str data "yyyy") (str "xxxx" (slurp instream)))))))))) ;; Read the rest and validate
(testing " - check socket timeout is handled"
- (try
- (testwebserver/with-test-webserver-and-config
- (blocking-handler data) port {:shutdown-timeout-seconds 1}
- (with-open [client (-> (ClientOptions.)
- (.setSocketTimeoutMilliseconds 200)
- (.setConnectTimeoutMilliseconds 100)
- (Async/createClient))]
- (let [request-options (doto (RequestOptions. (str "http://localhost:" port "/hello"))
- (.setAs ResponseBodyType/UNBUFFERED_STREAM)
- (.setDecompressBody decompress-body?))
- response (-> client (.get request-options) .deref)
- body (.getBody response)
- error (.getError response)]
- (is (nil? error))
- ;; Consume the body to get the exception
- (is (thrown? SocketTimeoutException (slurp body))))))
- (catch TimeoutException e
- ;; Expected whenever a server-side failure is generated
- nil)))
+ (let [send-more-data (promise)]
+ (try
+ (testwebserver/with-test-webserver-and-config
+ (streaming-handler data send-more-data) port {:shutdown-timeout-seconds 1}
+ (with-open [client (-> (ClientOptions.)
+ (.setSocketTimeoutMilliseconds 200)
+ (.setConnectTimeoutMilliseconds 100)
+ (Async/createClient))]
+ (let [request-options (doto (RequestOptions. (str "http://localhost:" port "/hello"))
+ (.setAs ResponseBodyType/UNBUFFERED_STREAM)
+ (.setDecompressBody decompress-body?))
+ response (-> client (.get request-options) .deref)
+ body (.getBody response)
+ error (.getError response)]
+ (is (nil? error))
+ ;; Consume the body to get the exception
+ (is (thrown? SocketTimeoutException (slurp body)))))
+ (deliver send-more-data true))
+ (catch TimeoutException e
+ ;; Expected whenever a server-side failure is generated
+ nil))))
(testing " - check connection timeout is handled"
@@ -240,11 +233,11 @@
(is (instance? ConnectException error))))))))
(deftest java-non-blocking-streaming-without-decompression
- (testing "java :unbuffered-stream with 32MB payload and no decompression"
+ (testing "java :unbuffered-stream with 1MB payload and no decompression"
(java-non-blocking-streaming false)))
(deftest java-non-blocking-streaming-with-decompression
- (testing "java :unbuffered-stream with 32MB payload and decompression"
+ (testing "java :unbuffered-stream with 1MB payload and decompression"
(java-non-blocking-streaming true)))
(defn- java-blocking-streaming
@@ -254,7 +247,7 @@
(testing " - check data can be streamed successfully"
(testwebserver/with-test-webserver-and-config
- (successful-handler data nil) port {:shutdown-timeout-seconds 1}
+ (streaming-handler data nil) port {:shutdown-timeout-seconds 1}
(with-open [client (-> (ClientOptions.)
(.setSocketTimeoutMilliseconds 20000)
(.setConnectTimeoutMilliseconds 100)
@@ -273,22 +266,24 @@
(is (= (str data "yyyy") (str "xxxx" (slurp instream))))))))) ;; Read the rest and validate
(testing " - check socket timeout is handled"
- (try
- (testwebserver/with-test-webserver-and-config
- (blocking-handler data) port {:shutdown-timeout-seconds 1}
- (with-open [client (-> (ClientOptions.)
- (.setSocketTimeoutMilliseconds 200)
- (.setConnectTimeoutMilliseconds 100)
- (Async/createClient))]
- (let [request-options (doto (RequestOptions. (str "http://localhost:" port "/hello"))
- (.setAs response-body-type)
- (.setDecompressBody decompress-body?))
- response (-> client (.get request-options) .deref)
- error (.getError response)]
- (is (instance? SocketTimeoutException error)))))
- (catch TimeoutException e
- ;; Expected whenever a server-side failure is generated
- nil)))
+ (let [send-more-data (promise)]
+ (try
+ (testwebserver/with-test-webserver-and-config
+ (streaming-handler data send-more-data) port {:shutdown-timeout-seconds 1}
+ (with-open [client (-> (ClientOptions.)
+ (.setSocketTimeoutMilliseconds 200)
+ (.setConnectTimeoutMilliseconds 100)
+ (Async/createClient))]
+ (let [request-options (doto (RequestOptions. (str "http://localhost:" port "/hello"))
+ (.setAs response-body-type)
+ (.setDecompressBody decompress-body?))
+ response (-> client (.get request-options) .deref)
+ error (.getError response)]
+ (is (instance? SocketTimeoutException error))))
+ (deliver send-more-data true))
+ (catch TimeoutException e
+ ;; Expected whenever a server-side failure is generated
+ nil))))
(testing " - check connection timeout is handled"
@@ -324,9 +319,9 @@
(java-blocking-streaming (generate-data 1024) ResponseBodyType/STREAM true)))
(deftest java-existing-streaming-with-large-payload-without-decompression
- (testing "java :stream with 32M payload and no decompression"
- (java-blocking-streaming (generate-data (* 32 1024 1024)) ResponseBodyType/STREAM false)))
+ (testing "java :stream with 1M payload and no decompression"
+ (java-blocking-streaming (generate-data (* 1024 1024)) ResponseBodyType/STREAM false)))
(deftest java-existing-streaming-with-large-payload-with-decompression
- (testing "java :stream with 32M payload and decompression"
- (java-blocking-streaming (generate-data (* 32 1024 1024)) ResponseBodyType/STREAM true)))
+ (testing "java :stream with 1M payload and decompression"
+ (java-blocking-streaming (generate-data (* 1024 1024)) ResponseBodyType/STREAM true)))
=====================================
test/puppetlabs/http/client/metrics_test.clj
=====================================
@@ -441,7 +441,7 @@
(testing "metrics work for a successful request"
(let [metric-registry (MetricRegistry.)]
(testwebserver/with-test-webserver-and-config
- (unbuffered-test/successful-handler data nil) port {:shutdown-timeout-seconds 1}
+ (unbuffered-test/streaming-handler data nil) port {:shutdown-timeout-seconds 1}
(with-open [client (-> (ClientOptions.)
(.setSocketTimeoutMilliseconds 20000)
(.setConnectTimeoutMilliseconds 100)
@@ -486,52 +486,54 @@
(is (<= 1000 (.getMean full-response-data)))
(is (<= 1000 (.getAggregate full-response-data))))))))))
(testing "metrics work for failed request"
- (try
- (testwebserver/with-test-webserver-and-config
- (unbuffered-test/blocking-handler data) port {:shutdown-timeout-seconds 1}
- (let [metric-registry (MetricRegistry.)]
- (with-open [client (-> (ClientOptions.)
- (.setSocketTimeoutMilliseconds 200)
- (.setConnectTimeoutMilliseconds 100)
- (.setMetricRegistry metric-registry)
- (Async/createClient))]
- (let [url (str "http://localhost:" port "/hello")
- request-options (doto (RequestOptions. url)
- (.setAs ResponseBodyType/UNBUFFERED_STREAM))
- response (-> client (.get request-options) .deref)
- error (.getError response)
- body (.getBody response)]
- (is (nil? error))
- (is (thrown? SocketTimeoutException (slurp body)))
- (let [client-metric-registry (.getMetricRegistry client)
- client-metrics (Metrics/getClientMetrics client-metric-registry)
- client-metrics-data (Metrics/getClientMetricsData client-metric-registry)
- full-response-name (format "%s.with-url.%s.full-response" metric-namespace url)
- full-response-name-with-method (format "%s.with-url-and-method.%s.GET.full-response"
- metric-namespace url)]
- (is (= [full-response-name]
- (map #(.getMetricName %) (.getUrlTimers client-metrics))
- (map #(.getMetricName %) (.getUrlData client-metrics-data))))
- (is (= [full-response-name-with-method]
- (map #(.getMetricName %) (.getUrlAndMethodTimers client-metrics))
- (map #(.getMetricName %) (.getUrlAndMethodData client-metrics-data))))
- (is (= [] (.getMetricIdTimers client-metrics)
- (.getMetricIdData client-metrics-data)))
- (is (every? #(instance? ClientTimer %)
- (concat (.getUrlTimers client-metrics)
- (.getUrlAndMethodTimers client-metrics))))
- (let [full-response-data (first (.getUrlData client-metrics-data))]
- (is (every? #(instance? ClientMetricData %)
- (concat (.getUrlData client-metrics-data)
- (.getUrlAndMethodData client-metrics-data))))
-
- (is (= 1 (.getCount full-response-data)))
- (is (= full-response-name (.getMetricName full-response-data)))
- (is (<= 200 (.getMean full-response-data)))
- (is (<= 200 (.getAggregate full-response-data)))))))))
- (catch TimeoutException e
- ;; Expected whenever a server-side failure is generated
- ))))))
+ (let [send-more-data (promise)]
+ (try
+ (testwebserver/with-test-webserver-and-config
+ (unbuffered-test/streaming-handler data send-more-data) port {:shutdown-timeout-seconds 1}
+ (let [metric-registry (MetricRegistry.)]
+ (with-open [client (-> (ClientOptions.)
+ (.setSocketTimeoutMilliseconds 200)
+ (.setConnectTimeoutMilliseconds 100)
+ (.setMetricRegistry metric-registry)
+ (Async/createClient))]
+ (let [url (str "http://localhost:" port "/hello")
+ request-options (doto (RequestOptions. url)
+ (.setAs ResponseBodyType/UNBUFFERED_STREAM))
+ response (-> client (.get request-options) .deref)
+ error (.getError response)
+ body (.getBody response)]
+ (is (nil? error))
+ (is (thrown? SocketTimeoutException (slurp body)))
+ (let [client-metric-registry (.getMetricRegistry client)
+ client-metrics (Metrics/getClientMetrics client-metric-registry)
+ client-metrics-data (Metrics/getClientMetricsData client-metric-registry)
+ full-response-name (format "%s.with-url.%s.full-response" metric-namespace url)
+ full-response-name-with-method (format "%s.with-url-and-method.%s.GET.full-response"
+ metric-namespace url)]
+ (is (= [full-response-name]
+ (map #(.getMetricName %) (.getUrlTimers client-metrics))
+ (map #(.getMetricName %) (.getUrlData client-metrics-data))))
+ (is (= [full-response-name-with-method]
+ (map #(.getMetricName %) (.getUrlAndMethodTimers client-metrics))
+ (map #(.getMetricName %) (.getUrlAndMethodData client-metrics-data))))
+ (is (= [] (.getMetricIdTimers client-metrics)
+ (.getMetricIdData client-metrics-data)))
+ (is (every? #(instance? ClientTimer %)
+ (concat (.getUrlTimers client-metrics)
+ (.getUrlAndMethodTimers client-metrics))))
+ (let [full-response-data (first (.getUrlData client-metrics-data))]
+ (is (every? #(instance? ClientMetricData %)
+ (concat (.getUrlData client-metrics-data)
+ (.getUrlAndMethodData client-metrics-data))))
+
+ (is (= 1 (.getCount full-response-data)))
+ (is (= full-response-name (.getMetricName full-response-data)))
+ (is (<= 200 (.getMean full-response-data)))
+ (is (<= 200 (.getAggregate full-response-data)))))))
+ (deliver send-more-data true)))
+ (catch TimeoutException e
+ ;; Expected whenever a server-side failure is generated
+ )))))))
(deftest clojure-metrics-for-unbuffered-streaming-test
(testlogging/with-test-logging
@@ -540,7 +542,7 @@
(testing "metrics work for a successful request"
(let [metric-registry (MetricRegistry.)]
(testwebserver/with-test-webserver-and-config
- (unbuffered-test/successful-handler data nil) port {:shutdown-timeout-seconds 1}
+ (unbuffered-test/streaming-handler data nil) port {:shutdown-timeout-seconds 1}
(with-open [client (async/create-client {:connect-timeout-milliseconds 100
:socket-timeout-milliseconds 20000
:metric-registry metric-registry})]
@@ -576,43 +578,45 @@
(is (<= 1000 (:mean full-response-data)))
(is (<= 1000 (:aggregate full-response-data))))))))))
(testing "metrics work for a failed request"
- (try
- (testwebserver/with-test-webserver-and-config
- (unbuffered-test/blocking-handler data) port {:shutdown-timeout-seconds 1}
- (let [metric-registry (MetricRegistry.)
- url (str "http://localhost:" port "/hello")]
- (with-open [client (async/create-client {:connect-timeout-milliseconds 100
- :socket-timeout-milliseconds 200
- :metric-registry metric-registry})]
- (let [response @(common/get client url opts)
- {:keys [body error]} response]
- (is (nil? error))
- ;; Consume the body to get the exception
- (is (thrown? SocketTimeoutException (slurp body))))
- (let [client-metric-registry (common/get-client-metric-registry client)
- client-metrics (metrics/get-client-metrics client-metric-registry)
- client-metrics-data (metrics/get-client-metrics-data client-metric-registry)
- full-response-name (format "%s.with-url.%s.full-response" metric-namespace url)
- full-response-name-with-method (format "%s.with-url-and-method.%s.GET.full-response"
- metric-namespace url)]
- (is (= [full-response-name]
- (map #(.getMetricName %) (:url client-metrics))
- (map :metric-name (:url client-metrics-data))))
- (is (= [full-response-name-with-method]
- (map #(.getMetricName %) (:url-and-method client-metrics))
- (map :metric-name (:url-and-method client-metrics-data))))
- (is (= [] (:metric-id client-metrics) (:metric-id client-metrics-data)))
- (is (every? #(instance? ClientTimer %)
- (concat (:url client-metrics)
- (:url-and-method client-metrics))))
- (let [full-response-data (first (:url client-metrics-data))]
- (is (= {:count 1 :metric-name full-response-name}
- (select-keys full-response-data [:metric-name :count])))
- (is (<= 200 (:mean full-response-data)))
- (is (<= 200 (:aggregate full-response-data))))))))
- (catch TimeoutException e
- ;; Expected whenever a server-side failure is generated
- ))))))
+ (let [send-more-data (promise)]
+ (try
+ (testwebserver/with-test-webserver-and-config
+ (unbuffered-test/streaming-handler data send-more-data) port {:shutdown-timeout-seconds 1}
+ (let [metric-registry (MetricRegistry.)
+ url (str "http://localhost:" port "/hello")]
+ (with-open [client (async/create-client {:connect-timeout-milliseconds 100
+ :socket-timeout-milliseconds 200
+ :metric-registry metric-registry})]
+ (let [response @(common/get client url opts)
+ {:keys [body error]} response]
+ (is (nil? error))
+ ;; Consume the body to get the exception
+ (is (thrown? SocketTimeoutException (slurp body))))
+ (let [client-metric-registry (common/get-client-metric-registry client)
+ client-metrics (metrics/get-client-metrics client-metric-registry)
+ client-metrics-data (metrics/get-client-metrics-data client-metric-registry)
+ full-response-name (format "%s.with-url.%s.full-response" metric-namespace url)
+ full-response-name-with-method (format "%s.with-url-and-method.%s.GET.full-response"
+ metric-namespace url)]
+ (is (= [full-response-name]
+ (map #(.getMetricName %) (:url client-metrics))
+ (map :metric-name (:url client-metrics-data))))
+ (is (= [full-response-name-with-method]
+ (map #(.getMetricName %) (:url-and-method client-metrics))
+ (map :metric-name (:url-and-method client-metrics-data))))
+ (is (= [] (:metric-id client-metrics) (:metric-id client-metrics-data)))
+ (is (every? #(instance? ClientTimer %)
+ (concat (:url client-metrics)
+ (:url-and-method client-metrics))))
+ (let [full-response-data (first (:url client-metrics-data))]
+ (is (= {:count 1 :metric-name full-response-name}
+ (select-keys full-response-data [:metric-name :count])))
+ (is (<= 200 (:mean full-response-data)))
+ (is (<= 200 (:aggregate full-response-data))))))
+ (deliver send-more-data true)))
+ (catch TimeoutException e
+ ;; Expected whenever a server-side failure is generated
+ )))))))
(deftest metric-namespace-test
(let [metric-prefix "my-metric-prefix"
@@ -797,4 +801,4 @@
metric-names (set (map #(.getMetricName %) (.getMetricIdTimers client-metrics)))]
(is (.isEmpty (.getUrlTimers client-metrics)))
(is (.isEmpty (.getUrlAndMethodTimers client-metrics)))
- (is (= #{long-foo-name long-foo-bar-name} metric-names)))))))))
\ No newline at end of file
+ (is (= #{long-foo-name long-foo-bar-name} metric-names)))))))))
View it on GitLab: https://salsa.debian.org/clojure-team/puppetlabs-http-client-clojure/-/compare/989ecac5fd50e22c7ff13cb086964fcf066f7f84...c8d1662e83953a619711c09ac33a67441f8fde53
--
View it on GitLab: https://salsa.debian.org/clojure-team/puppetlabs-http-client-clojure/-/compare/989ecac5fd50e22c7ff13cb086964fcf066f7f84...c8d1662e83953a619711c09ac33a67441f8fde53
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20230207/1743e47a/attachment.htm>
More information about the pkg-java-commits
mailing list