From 73aea0ceef6ba96610e148caa902e6274a2fef90 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 6 Jun 2020 14:30:27 -0700 Subject: [PATCH 1/3] Add in jTDS tests --- test/next/jdbc/datafy_test.clj | 21 +++++++++++++++------ test/next/jdbc/prepare_test.clj | 5 +++-- test/next/jdbc/sql_test.clj | 3 ++- test/next/jdbc/test_fixtures.clj | 2 ++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/test/next/jdbc/datafy_test.clj b/test/next/jdbc/datafy_test.clj index 9be5452..0ed73f1 100644 --- a/test/next/jdbc/datafy_test.clj +++ b/test/next/jdbc/datafy_test.clj @@ -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)) diff --git a/test/next/jdbc/prepare_test.clj b/test/next/jdbc/prepare_test.clj index 04e71c0..00780a3 100644 --- a/test/next/jdbc/prepare_test.clj +++ b/test/next/jdbc/prepare_test.clj @@ -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 [" diff --git a/test/next/jdbc/sql_test.clj b/test/next/jdbc/sql_test.clj index fd21a60..15cae96 100644 --- a/test/next/jdbc/sql_test.clj +++ b/test/next/jdbc/sql_test.clj @@ -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 diff --git a/test/next/jdbc/test_fixtures.clj b/test/next/jdbc/test_fixtures.clj index 7701dad..ee25b9e 100644 --- a/test/next/jdbc/test_fixtures.clj +++ b/test/next/jdbc/test_fixtures.clj @@ -48,6 +48,8 @@ (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))) From 5e98c828a56266590ed7bb9beeb593bf43d02e9e Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 6 Jun 2020 17:06:11 -0700 Subject: [PATCH 2/3] Add jTDS testing --- deps.edn | 15 ++++++++++++--- test/log4j2-info.properties | 28 ++++++++++++++++++++++++++++ test/next/jdbc_test.clj | 11 +++++++---- 3 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 test/log4j2-info.properties diff --git a/deps.edn b/deps.edn index df5ed63..6cc599e 100644 --- a/deps.edn +++ b/deps.edn @@ -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" diff --git a/test/log4j2-info.properties b/test/log4j2-info.properties new file mode 100644 index 0000000..a3bc4d3 --- /dev/null +++ b/test/log4j2-info.properties @@ -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 diff --git a/test/next/jdbc_test.clj b/test/next/jdbc_test.clj index 65217bd..5fb5ecd 100644 --- a/test/next/jdbc_test.clj +++ b/test/next/jdbc_test.clj @@ -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:server" + (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 {})] From 61674405009de079870fdc0ff30d892b7a82ad53 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 6 Jun 2020 17:16:17 -0700 Subject: [PATCH 3/3] jTDS support; PostgreSQL 12.2.0 support --- CHANGELOG.md | 5 +++++ test/next/jdbc/test_fixtures.clj | 12 +++++++++--- test/next/jdbc_test.clj | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40798f9..d87b06b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/test/next/jdbc/test_fixtures.clj b/test/next/jdbc/test_fixtures.clj index ee25b9e..9b3da86 100644 --- a/test/next/jdbc/test_fixtures.clj +++ b/test/next/jdbc/test_fixtures.clj @@ -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,10 +39,16 @@ (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)) @@ -52,7 +58,7 @@ (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))) diff --git a/test/next/jdbc_test.clj b/test/next/jdbc_test.clj index 5fb5ecd..db82825 100644 --- a/test/next/jdbc_test.clj +++ b/test/next/jdbc_test.clj @@ -303,7 +303,7 @@ VALUES ('Pear', 'green', 49, 47) (is (instance? javax.sql.DataSource ds)) (is (str/index-of (pr-str ds) (str "jdbc:" (cond (jtds?) - "jtds:server" + "jtds:sqlserver" (mssql?) "sqlserver" :else