Skip to content

Commit

Permalink
Move test case for thread pool to correct context
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Sep 20, 2017
1 parent f722aee commit d29a9d4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
8 changes: 7 additions & 1 deletion test/hbase_packet_inspector/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 [])]
Expand Down
56 changes: 27 additions & 29 deletions test/hbase_packet_inspector/db_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))))

0 comments on commit d29a9d4

Please sign in to comment.