From d29a9d44340a511fe06446c283be6ded033db49d Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 20 Sep 2017 10:41:48 +0900 Subject: [PATCH] Move test case for thread pool to correct context --- test/hbase_packet_inspector/core_test.clj | 8 +++- test/hbase_packet_inspector/db_test.clj | 56 +++++++++++------------ 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/test/hbase_packet_inspector/core_test.clj b/test/hbase_packet_inspector/core_test.clj index e54824d..0f83db3 100644 --- a/test/hbase_packet_inspector/core_test.clj +++ b/test/hbase_packet_inspector/core_test.clj @@ -5,6 +5,7 @@ [clojure.tools.logging :as log] [clojure.tools.cli :refer [parse-opts]] [hbase-packet-inspector.core :refer :all :as core] + [hbase-packet-inspector.pool :as pool] [hbase-packet-inspector.sink.kafka :as kafka] [hbase-packet-inspector.kafka-test :as kt]) (:import (java.sql Timestamp) @@ -357,7 +358,12 @@ log/log* (fn [& _] (swap! observed inc))] (read-fixture :increment {:verbose true}) ;; 2 logs for each entry + completion log - (is (> @observed (+ (* 2 all-count) 1))))))) + (is (> @observed (+ (* 2 all-count) 1)))))) + + (testing "With different number of threads" + (doseq [cores [1 2 4 8 16]] + (with-redefs [pool/num-cores (constantly cores)] + (is (= all-count (count (read-fixture :increment)))))))) (deftest test-with-kafka* (let [history (atom [])] diff --git a/test/hbase_packet_inspector/db_test.clj b/test/hbase_packet_inspector/db_test.clj index 6a4ab5b..37b032f 100644 --- a/test/hbase_packet_inspector/db_test.clj +++ b/test/hbase_packet_inspector/db_test.clj @@ -12,34 +12,32 @@ (is (instance? java.sql.Connection connection)) (is (re-find #"h2:mem" (str connection))) - (doseq [cores [1 2 4 8 16]] - (with-redefs [pool/num-cores (constantly cores)] - (db/create connection) - (is (= (set tables) - (set (map (comp keyword str/lower-case :table_name) - (q "show tables"))))) - (doseq [table tables] - (is (empty? (q (str "select * from " (name table)))))) + (db/create connection) + (is (= (set tables) + (set (map (comp keyword str/lower-case :table_name) + (q "show tables"))))) + (doseq [table tables] + (is (empty? (q (str "select * from " (name table)))))) - (let [load (db/load-fn connection)] - (load {:client :foo - :port 1000 - :row nil - :inbound? true - :actions [{:client :bar} {:client :baz}]}) - (load {:client :FOO - :port 2000 - :row "row" - :inbound? false - :results [{:client :BAR} {:client :BAZ}]})) + (let [load (db/load-fn connection)] + (load {:client :foo + :port 1000 + :row nil + :inbound? true + :actions [{:client :bar} {:client :baz}]}) + (load {:client :FOO + :port 2000 + :row "row" + :inbound? false + :results [{:client :BAR} {:client :BAZ}]})) - (let [rows (into {} (for [table tables] - [table (q (str "select * from " (name table)))]))] - (is (= #{"foo"} (set (map :client (:requests rows))))) - (is (= #{1000} (set (map :port (:requests rows))))) - (is (= #{nil} (set (map :row (:requests rows))))) - (is (= #{"bar" "baz"} (set (map :client (:actions rows))))) - (is (= #{"FOO"} (set (map :client (:responses rows))))) - (is (= #{2000} (set (map :port (:responses rows))))) - (is (= #{"row"} (set (map :row (:responses rows))))) - (is (= #{"BAR" "BAZ"} (set (map :client (:results rows)))))))))) + (let [rows (into {} (for [table tables] + [table (q (str "select * from " (name table)))]))] + (is (= #{"foo"} (set (map :client (:requests rows))))) + (is (= #{1000} (set (map :port (:requests rows))))) + (is (= #{nil} (set (map :row (:requests rows))))) + (is (= #{"bar" "baz"} (set (map :client (:actions rows))))) + (is (= #{"FOO"} (set (map :client (:responses rows))))) + (is (= #{2000} (set (map :port (:responses rows))))) + (is (= #{"row"} (set (map :row (:responses rows))))) + (is (= #{"BAR" "BAZ"} (set (map :client (:results rows))))))))