Skip to content

Commit

Permalink
Merge pull request #4 from metabase/parse-properties-correctly
Browse files Browse the repository at this point in the history
Make sure properties are parsed correctly
  • Loading branch information
camsaul authored Oct 8, 2019
2 parents a4e66d6 + 45dee74 commit e072f4f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
18 changes: 6 additions & 12 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject metabase/connection-pool "1.0.2"
(defproject metabase/connection-pool "1.0.3"
:description "Connection pools for JDBC databases. Simple wrapper around C3P0."
:url "https://github.com/metabase/connection-pool"
:min-lein-version "2.5.0"
Expand All @@ -7,8 +7,7 @@
:url "https://raw.githubusercontent.com/metabase/connection-pool/master/LICENSE"}

:aliases
{"test" ["with-profile" "+expectations" "expectations"]
"bikeshed" ["with-profile" "+bikeshed" "bikeshed" "--max-line-length" "120"]
{"bikeshed" ["with-profile" "+bikeshed" "bikeshed" "--max-line-length" "120"]
"check-namespace-decls" ["with-profile" "+check-namespace-decls" "check-namespace-decls"]
"eastwood" ["with-profile" "+eastwood" "eastwood"]
"docstring-checker" ["with-profile" "+docstring-checker" "docstring-checker"]
Expand All @@ -22,18 +21,12 @@
{:dev
{:dependencies
[[org.clojure/clojure "1.10.1"]
[expectations "2.2.0-beta2"]]

:injections
[(require 'expectations)
((resolve 'expectations/disable-run-on-shutdown))]
[com.h2database/h2 "1.4.197"]
[pjstadig/humane-test-output "0.9.0"]]

:jvm-opts
["-Xverify:none"]}

:expectations
{:plugins [[lein-expectations "0.0.8" :exclusions [expectations]]]}

:eastwood
{:plugins
[[jonase/eastwood "0.3.6" :exclusions [org.clojure/clojure]]]
Expand All @@ -56,7 +49,8 @@

:bikeshed
{:plugins
[[lein-bikeshed "0.5.2"]]}
[[lein-bikeshed "0.5.2"
:exclusions [org.clojure/tools.namespace]]]}

:check-namespace-decls
{:plugins [[lein-check-namespace-decls "1.0.2"]]
Expand Down
6 changes: 3 additions & 3 deletions src/metabase/connection_pool.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
for the options, which are c3p0-specific -- consider abstracting those as well?)"
(:import com.mchange.v2.c3p0.DataSources
[java.sql Driver DriverManager]
[java.util Map Properties]
java.util.Properties
javax.sql.DataSource))

;;; ------------------------------------------------ Proxy DataSource ------------------------------------------------
Expand Down Expand Up @@ -54,8 +54,8 @@
([spec]
(DataSources/pooledDataSource (unpooled-data-source spec)))

([spec, ^Map pool-properties]
(DataSources/pooledDataSource (unpooled-data-source spec), pool-properties)))
([spec pool-properties-map]
(DataSources/pooledDataSource (unpooled-data-source spec) (map->properties pool-properties-map))))

(defn connection-pool-spec
"Create a new connection pool for a JDBC `spec` and return a spec for it. Optionally pass a map of connection pool
Expand Down
19 changes: 19 additions & 0 deletions test/metabase/connection_pool_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(ns metabase.connection-pool-test
(:require [clojure.test :as t]
[metabase.connection-pool :as connection-pool]))

(def ^:private spec
{:classname "org.h2.Driver", :subprotocol "h2", :subname "mem:db"})

(t/deftest properties-test
(t/testing "Options passed in to `connection-pool-spec` should get parsed correctly"
(let [description (-> (connection-pool/connection-pool-spec spec {"acquireIncrement" 1
"testConnectionOnCheckin" true})
:datasource
str)]
(t/is (= "acquireIncrement -> 1"
(re-find #"acquireIncrement -> \d" description))
"numeric options should get converted correctly")
(t/is (= "testConnectionOnCheckin -> true"
(re-find #"testConnectionOnCheckin -> \w+" description))
"boolean options should get converted correctly"))))

0 comments on commit e072f4f

Please sign in to comment.