Merge branch 'master' into nested-tx

This commit is contained in:
Sean Corfield 2020-06-06 17:26:53 -07:00
commit fd37ed8d19
8 changed files with 83 additions and 19 deletions

View file

@ -2,6 +2,11 @@
Only accretive/fixative changes will be made from now on.
Changes made on master since 1.0.462:
* Add tests for `"jtds"` database driver (against MS SQL Server), making it officially supported.
* Switch from OpenTable Embedded PostgreSQL to Zonky's version, so that testing can move forward from PostgreSQL 10.11 to 12.2.0.
* Add log4j2 as a test dependency so that I have better control over logging (which makes debugging easier!).
## Stable Builds
* 2020-05-31 -- 1.0.462

View file

@ -19,12 +19,21 @@
org.mariadb.jdbc/mariadb-java-client {:mvn/version "2.5.4"}
mysql/mysql-connector-java {:mvn/version "8.0.19"}
org.postgresql/postgresql {:mvn/version "42.2.10"}
com.opentable.components/otj-pg-embedded {:mvn/version "0.13.3"}
com.impossibl.pgjdbc-ng/pgjdbc-ng {:mvn/version "0.8.3"}
io.zonky.test/embedded-postgres {:mvn/version "1.2.6"}
io.zonky.test.postgres/embedded-postgres-binaries-darwin-amd64 {:mvn/version "12.2.0"}
io.zonky.test.postgres/embedded-postgres-binaries-linux-amd64 {:mvn/version "12.2.0"}
io.zonky.test.postgres/embedded-postgres-binaries-windows-amd64 {:mvn/version "12.2.0"}
org.xerial/sqlite-jdbc {:mvn/version "3.30.1"}
com.microsoft.sqlserver/mssql-jdbc {:mvn/version "8.2.1.jre8"}
;; supplementary test stuff
org.slf4j/slf4j-nop {:mvn/version "1.7.30"}}}
;; use log4j 2.x:
org.apache.logging.log4j/log4j-api {:mvn/version "2.13.3"}
;; bridge into log4j:
org.apache.logging.log4j/log4j-1.2-api {:mvn/version "2.13.3"}
org.apache.logging.log4j/log4j-jcl {:mvn/version "2.13.3"}
org.apache.logging.log4j/log4j-jul {:mvn/version "2.13.3"}
org.apache.logging.log4j/log4j-slf4j-impl {:mvn/version "2.13.3"}}
:jvm-opts ["-Dlog4j2.configurationFile=log4j2-info.properties"]}
:runner
{:extra-deps {com.cognitect/test-runner
{:git/url "https://github.com/cognitect-labs/test-runner"

View file

@ -0,0 +1,28 @@
# Sean's normal mode, shows INFO and above, with highlighting:
rootLogger.level = info
rootLogger.appenderRef.stdout.ref = STDOUT
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%c] %highlight{%m}%n
# I do not care about any of c3p0's INFO messages...
logger.c3p0.name = com.mchange.v2
logger.c3p0.level = warn
logger.c3p0.appenderRef.stdout.ref = STDOUT
# ...nor HikariCP...
logger.hikari.name = com.zaxxer.hikari
logger.hikari.level = warn
logger.hikari.appenderRef.stdout.ref = STDOUT
# ...nor embedded HSQLDB...
logger.hsqldb.name = hsqldb.db
logger.hsqldb.level = warn
logger.hsqldb.appenderRef.stdout.ref = STDOUT
# ...nor embedded PostgreSQL...
logger.postgres.name = io.zonky.test.db.postgres.embedded
logger.postgres.level = warn
logger.postgres.appenderRef.stdout.ref = STDOUT

View file

@ -9,8 +9,9 @@
[next.jdbc.datafy]
[next.jdbc.result-set :as rs]
[next.jdbc.specs :as specs]
[next.jdbc.test-fixtures :refer [with-test-db db ds
derby? mysql? postgres? sqlite?]]))
[next.jdbc.test-fixtures
:refer [with-test-db db ds
derby? jtds? mysql? postgres? sqlite?]]))
(set! *warn-on-reflection* true)
@ -32,7 +33,11 @@
(with-open [con (jdbc/get-connection (ds))]
(let [reference-keys (cond-> basic-connection-keys
(derby?) (-> (disj :networkTimeout)
(conj :networkTimeout/exception)))
(conj :networkTimeout/exception))
(jtds?) (-> (disj :clientInfo :networkTimeout :schema)
(conj :clientInfo/exception
:networkTimeout/exception
:schema/exception)))
data (set (keys (d/datafy con)))]
(when-let [diff (seq (set/difference data reference-keys))]
(println (:dbtype (db)) :connection (sort diff)))
@ -72,11 +77,14 @@
(testing "database metadata datafication"
(with-open [con (jdbc/get-connection (ds))]
(let [reference-keys (cond-> basic-database-metadata-keys
(jtds?) (-> (disj :clientInfoProperties :rowIdLifetime)
(conj :clientInfoProperties/exception
:rowIdLifetime/exception))
(postgres?) (-> (disj :rowIdLifetime)
(conj :rowIdLifetime/exception))
(sqlite?) (-> (disj :clientInfoProperties :rowIdLifetime)
(conj :clientInfoProperties/exception
:rowIdLifetime/exception)))
(sqlite?) (-> (disj :clientInfoProperties :rowIdLifetime)
(conj :clientInfoProperties/exception
:rowIdLifetime/exception)))
data (set (keys (d/datafy (.getMetaData con))))]
(when-let [diff (seq (set/difference data reference-keys))]
(println (:dbtype (db)) :db-meta (sort diff)))
@ -86,6 +94,7 @@
(with-open [con (jdbc/get-connection (ds))]
(let [data (d/datafy (.getMetaData con))]
(doseq [k (cond-> #{:catalogs :clientInfoProperties :schemas :tableTypes :typeInfo}
(jtds?) (disj :clientInfoProperties)
(sqlite?) (disj :clientInfoProperties))]
(let [rs (d/nav data k nil)]
(is (vector? rs))

View file

@ -8,7 +8,8 @@
`execute-batch!` here."
(:require [clojure.test :refer [deftest is testing use-fixtures]]
[next.jdbc :as jdbc]
[next.jdbc.test-fixtures :refer [with-test-db ds postgres? sqlite?]]
[next.jdbc.test-fixtures
:refer [with-test-db ds jtds? postgres? sqlite?]]
[next.jdbc.prepare :as prep]
[next.jdbc.specs :as specs]))
@ -73,7 +74,7 @@ INSERT INTO fruit (name, appearance) VALUES (?,?)
(conj result (count (jdbc/execute! t ["select * from fruit"]))))))))
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"])))))
(testing "large batch insert"
(when-not (or (postgres?) (sqlite?))
(when-not (or (jtds?) (postgres?) (sqlite?))
(is (= [1 1 1 1 1 1 1 1 1 13]
(jdbc/with-transaction [t (ds) {:rollback-only true}]
(with-open [ps (jdbc/prepare t ["

View file

@ -7,7 +7,7 @@
[next.jdbc.sql :as sql]
[next.jdbc.test-fixtures
:refer [with-test-db ds column default-options
derby? maria? mssql? mysql? postgres? sqlite?]]))
derby? jtds? maria? mssql? mysql? postgres? sqlite?]]))
(set! *warn-on-reflection* true)
@ -67,6 +67,7 @@
(deftest test-insert-delete
(let [new-key (cond (derby?) :1
(jtds?) :ID
(maria?) :insert_id
(mssql?) :GENERATED_KEYS
(mysql?) :GENERATED_KEY

View file

@ -5,7 +5,7 @@
(:require [clojure.string :as str]
[next.jdbc :as jdbc]
[next.jdbc.sql :as sql])
(:import (com.opentable.db.postgres.embedded EmbeddedPostgres)))
(:import (io.zonky.test.db.postgres.embedded EmbeddedPostgres)))
(set! *warn-on-reflection* true)
@ -39,18 +39,26 @@
(def ^:private test-mssql
(when (System/getenv "NEXT_JDBC_TEST_MSSQL") test-mssql-map))
(def ^:private test-jtds-map
{:dbtype "jtds" :dbname "model"
:user "sa" :password (System/getenv "MSSQL_SA_PASSWORD")})
(def ^:private test-jtds
(when (System/getenv "NEXT_JDBC_TEST_MSSQL") test-jtds-map))
(def ^:private test-db-specs
(cond-> [test-derby test-h2-mem test-h2 test-hsql test-sqlite test-postgres]
test-mysql (conj test-mysql)
test-mssql (conj test-mssql)))
test-mssql (conj test-mssql test-jtds)))
(def ^:private test-db-spec (atom nil))
(defn derby? [] (= "derby" (:dbtype @test-db-spec)))
(defn jtds? [] (= "jtds" (:dbtype @test-db-spec)))
(defn maria? [] (= "mariadb" (:dbtype @test-db-spec)))
(defn mssql? [] (= "mssql" (:dbtype @test-db-spec)))
(defn mssql? [] (#{"jtds" "mssql"} (:dbtype @test-db-spec)))
(defn mysql? [] (#{"mariadb" "mysql"} (:dbtype @test-db-spec)))

View file

@ -8,7 +8,7 @@
[next.jdbc.connection :as c]
[next.jdbc.test-fixtures :refer [with-test-db db ds column
default-options
derby? mssql? mysql? postgres?]]
derby? jtds? mssql? mysql? postgres?]]
[next.jdbc.prepare :as prep]
[next.jdbc.result-set :as rs]
[next.jdbc.specs :as specs])
@ -302,9 +302,12 @@ VALUES ('Pear', 'green', 49, 47)
:else (is (= {} etc)))
(is (instance? javax.sql.DataSource ds))
(is (str/index-of (pr-str ds) (str "jdbc:"
(if (mssql?)
"sqlserver" ; mssql is the alias
(:dbtype (db))))))
(cond (jtds?)
"jtds:sqlserver"
(mssql?)
"sqlserver"
:else
(:dbtype (db))))))
;; checks get-datasource on a DataSource is identity
(is (identical? ds (jdbc/get-datasource ds)))
(with-open [con (jdbc/get-connection ds {})]