Skip to content

Commit 33a2983

Browse files
authored
Merge pull request #27 from taabrcr/addTestRunner
Add Test Runner and Override data-warehouse-connection-pool-properties
2 parents b116f06 + 4f06d07 commit 33a2983

File tree

4 files changed

+77
-9
lines changed

4 files changed

+77
-9
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,35 @@ You require metabase to be installed alongside of your project
6767
2. `clojure -X:build :project-dir "\"$(pwd)\""`
6868

6969
This will build a file called `target/teradata.metabase-driver.jar`; copy this to your Metabase `./plugins` directory.
70+
71+
72+
## Tests
73+
74+
Invoking the test-runner with `clojure -X` will call the test function with a map of arguments,
75+
which can be supplied either in the alias (via `:exec-args`) or on the command-line, or both.
76+
77+
Invoke it with:
78+
79+
```bash
80+
clj -X:test ...args...
81+
```
82+
83+
This will scan your project's `test` directory for any tests defined
84+
using `clojure.test` and run them.
85+
86+
You may also supply any of the additional command line options:
87+
88+
```
89+
:dirs - coll of directories containing tests, default= ["test"]
90+
:nses - coll of namespace symbols to test
91+
:patterns - coll of regex strings to match namespaces
92+
:vars - coll of fully qualified symbols to run tests on
93+
:includes - coll of test metadata keywords to include
94+
:excludes - coll of test metadata keywords to exclude"
95+
```
96+
97+
If neither :dirs or :nses is supplied, will use:
98+
99+
```
100+
:patterns [".*-test$"]
101+
```

deps.edn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
:deps {
1010
org.clojure/clojure {:mvn/version "1.11.1"}
11+
expectations/clojure-test {:mvn/version "1.2.1"}
1112
; replace also the version in metabase-plugin.yaml
1213
metabase/metabase-core {:git/url "https://github.com/metabase/metabase.git" :git/tag "v0.43.0" :git/sha "ee686fcfe5"}
1314
metabase/build-drivers {:git/url "https://github.com/metabase/metabase.git" :git/tag "v0.43.0" :git/sha "ee686fcfe5" :deps/root "bin/build-drivers"}
@@ -24,5 +25,11 @@
2425
}
2526
; We don't want to include metabase nor clojure in the uber jar
2627
:oss {:replace-deps {} }
28+
29+
:test {:extra-paths ["test"]
30+
:extra-deps {io.github.cognitect-labs/test-runner
31+
{:git/tag "v0.5.1" :git/sha "dfb30dd"}}
32+
:main-opts ["-m" "cognitect.test-runner"]
33+
:exec-fn cognitect.test-runner.api/test}
2734
}
2835
}

src/metabase/driver/teradata.clj

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
[java-time :as t]
99
[metabase
1010
[driver :as driver]
11-
[util :as u]]
11+
[util :as u]
12+
[config :as config]]
1213
[metabase.driver.sql-jdbc
1314
[common :as sql-jdbc.common]
1415
[connection :as sql-jdbc.conn]
@@ -308,3 +309,25 @@
308309

309310
; TODO check if overriding apply-top-level-clause could make nested queries work
310311
(defmethod driver/supports? [:teradata :nested-queries] [_ _] false)
312+
313+
;; Overridden to customise the C3P0 properties which can be used to avoid the high number of logins against Teradata
314+
;; In case of such problem increase the value of acquireRetryDelay
315+
;; https://github.com/metabase/metabase/blob/master/src/metabase/driver/sql_jdbc/connection.clj#L42
316+
;; https://www.mchange.com/projects/c3p0/#acquireRetryDelay
317+
(defmethod sql-jdbc.conn/data-warehouse-connection-pool-properties :teradata
318+
[driver database]
319+
{
320+
"acquireRetryDelay" (or (config/config-int :mb-jdbc-c3po-acquire-retry-delay) 1000)
321+
"acquireIncrement" 1
322+
"maxIdleTime" (* 3 60 60) ; 3 hours
323+
"minPoolSize" 1
324+
"initialPoolSize" 1
325+
"maxPoolSize" (or (config/config-int :mb-jdbc-data-warehouse-max-connection-pool-size) 15)
326+
"testConnectionOnCheckout" true
327+
"maxIdleTimeExcessConnections" (* 5 60)
328+
"dataSourceName" (format "db-%d-%s-%s" (u/the-id database) (name driver) (->> database
329+
:details
330+
((some-fn :db
331+
:dbname
332+
:sid
333+
:catalog))))})
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
(ns metabase.driver.teradata-test
2-
(:require [expectations :refer :all]
2+
(:require [expectations.clojure.test :refer [defexpect expect expecting]]
33
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]))
44

5+
(def result
6+
(sql-jdbc.conn/connection-details->spec :teradata {:host "localhost"
7+
:additional-options "CONNECT_FAILURE_TTL=300,ERROR_QUERY_INTERVAL=300000,RECONNECT_INTERVAL=300,COP=OFF,REDRIVE=0"}))
8+
9+
(def hardcoded
10+
{:classname "com.teradata.jdbc.TeraDriver"
11+
:subprotocol "teradata"
12+
:subname "//localhost/CHARSET=UTF8,TMODE=ANSI,ENCRYPTDATA=ON,FINALIZE_AUTO_CLOSE=ON,LOB_SUPPORT=OFF,CONNECT_FAILURE_TTL=300,ERROR_QUERY_INTERVAL=300000,RECONNECT_INTERVAL=300,COP=OFF,REDRIVE=0"})
13+
514
;; Check that additional JDBC options are handled correctly. This is comma separated for Teradata.
6-
(expect
7-
{:classname "com.teradata.jdbc.TeraDriver"
8-
:subprotocol "teradata"
9-
:subname "//localhost/CHARSET=UTF8,TMODE=ANSI,ENCRYPTDATA=ON,FINALIZE_AUTO_CLOSE=ON,LOB_SUPPORT=OFF,COP=OFF"
10-
:delimiters "`"}
11-
(-> (sql-jdbc.conn/connection-details->spec :teradata {:host "localhost"
12-
:additional-options "COP=OFF"})))
15+
(defexpect db-test
16+
(expect
17+
hardcoded
18+
result))

0 commit comments

Comments
 (0)