more xtdb test progress
Signed-off-by: Sean Corfield <sean@corfield.org>
This commit is contained in:
parent
0c50cf28b5
commit
5f0c93642a
4 changed files with 105 additions and 49 deletions
|
|
@ -2,16 +2,17 @@
|
|||
|
||||
(ns next.jdbc.datafy-test
|
||||
"Tests for the datafy extensions over JDBC types."
|
||||
(:require [clojure.datafy :as d]
|
||||
[clojure.set :as set]
|
||||
[clojure.test :refer [deftest is testing use-fixtures]]
|
||||
[next.jdbc :as jdbc]
|
||||
[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? jtds? mysql? postgres? sqlite?]]))
|
||||
(:require
|
||||
[clojure.datafy :as d]
|
||||
[clojure.set :as set]
|
||||
[clojure.test :refer [deftest is testing use-fixtures]]
|
||||
[next.jdbc :as jdbc]
|
||||
[next.jdbc.datafy]
|
||||
[next.jdbc.result-set :as rs]
|
||||
[next.jdbc.specs :as specs]
|
||||
[next.jdbc.test-fixtures
|
||||
:refer [db derby? ds jtds? mysql? postgres? sqlite? with-test-db
|
||||
xtdb?]]))
|
||||
|
||||
(set! *warn-on-reflection* true)
|
||||
|
||||
|
|
@ -83,6 +84,26 @@
|
|||
:rowIdLifetime/exception))
|
||||
(postgres?) (-> (disj :rowIdLifetime)
|
||||
(conj :rowIdLifetime/exception))
|
||||
(xtdb?) (-> (disj :clientInfoProperties
|
||||
:defaultTransactionIsolation
|
||||
:maxCatalogNameLength
|
||||
:maxColumnNameLength
|
||||
:maxCursorNameLength
|
||||
:maxProcedureNameLength
|
||||
:maxSchemaNameLength
|
||||
:maxTableNameLength
|
||||
:maxUserNameLength
|
||||
:rowIdLifetime)
|
||||
(conj :clientInfoProperties/exception
|
||||
:defaultTransactionIsolation/exception
|
||||
:maxCatalogNameLength/exception
|
||||
:maxColumnNameLength/exception
|
||||
:maxCursorNameLength/exception
|
||||
:maxProcedureNameLength/exception
|
||||
:maxSchemaNameLength/exception
|
||||
:maxTableNameLength/exception
|
||||
:maxUserNameLength/exception
|
||||
:rowIdLifetime/exception))
|
||||
(sqlite?) (-> (disj :clientInfoProperties :rowIdLifetime)
|
||||
(conj :clientInfoProperties/exception
|
||||
:rowIdLifetime/exception)))
|
||||
|
|
@ -97,7 +118,8 @@
|
|||
(let [data (d/datafy (.getMetaData con))]
|
||||
(doseq [k (cond-> #{:catalogs :clientInfoProperties :schemas :tableTypes :typeInfo}
|
||||
(jtds?) (disj :clientInfoProperties)
|
||||
(sqlite?) (disj :clientInfoProperties))]
|
||||
(sqlite?) (disj :clientInfoProperties)
|
||||
(xtdb?) (disj :clientInfoProperties))]
|
||||
(let [rs (d/nav data k nil)]
|
||||
(is (vector? rs))
|
||||
(is (every? map? rs))))))))
|
||||
|
|
@ -122,4 +144,25 @@
|
|||
(.execute ps)
|
||||
(.getResultSet ps)
|
||||
(.close ps)
|
||||
(.close con))
|
||||
(.close con)
|
||||
#{
|
||||
}
|
||||
(= #{:driverMinorVersion :numericFunctions :catalogTerm :maxStatements :maxIndexLength :maxColumnsInOrderBy
|
||||
:maxBinaryLiteralLength :driverName :procedureTerm :all-tables :SQLStateType :maxCharLiteralLength :JDBCMajorVersion
|
||||
:catalogs :maxColumnsInTable :timeDateFunctions
|
||||
:maxConnections
|
||||
:systemFunctions :databaseMajorVersion :databaseProductVersion :JDBCMinorVersion :schemas :readOnly :driverVersion :class :maxTablesInSelect :maxColumnsInGroupBy
|
||||
:identifierQuoteString :maxColumnsInIndex :driverMajorVersion :typeInfo :tableTypes
|
||||
:maxRowSize :stringFunctions :resultSetHoldability
|
||||
:SQLKeywords :searchStringEscape :URL :databaseProductName :catalogSeparator
|
||||
:connection :catalogAtStart :maxStatementLength :extraNameCharacters :userName :databaseMinorVersion :maxColumnsInSelect :schemaTerm
|
||||
}
|
||||
#{:driverMinorVersion :numericFunctions :catalogTerm :maxStatements :maxIndexLength :maxColumnsInOrderBy
|
||||
:maxBinaryLiteralLength :driverName :procedureTerm :all-tables :SQLStateType :maxCharLiteralLength :JDBCMajorVersion
|
||||
:catalogs :maxColumnsInTable :timeDateFunctions
|
||||
:maxConnections
|
||||
:systemFunctions :databaseMajorVersion :databaseProductVersion :JDBCMinorVersion :schemas :readOnly :driverVersion :class :maxTablesInSelect :maxColumnsInGroupBy
|
||||
:identifierQuoteString :maxColumnsInIndex :driverMajorVersion :typeInfo :tableTypes
|
||||
:maxRowSize :stringFunctions :resultSetHoldability
|
||||
:SQLKeywords :searchStringEscape :URL :databaseProductName :catalogSeparator
|
||||
:connection :catalogAtStart :maxStatementLength :extraNameCharacters :userName :databaseMinorVersion :maxColumnsInSelect :schemaTerm}))
|
||||
|
|
|
|||
|
|
@ -15,39 +15,40 @@
|
|||
[next.jdbc :as jdbc]
|
||||
[next.jdbc.defer :as sut]
|
||||
[next.jdbc.test-fixtures
|
||||
:refer [ds with-test-db]]))
|
||||
:refer [ds with-test-db xtdb?]]))
|
||||
|
||||
(set! *warn-on-reflection* true)
|
||||
|
||||
(use-fixtures :once with-test-db)
|
||||
|
||||
(deftest basic-test
|
||||
(testing "data structures"
|
||||
(is (= [{:sql-p ["INSERT INTO foo (name) VALUES (?)" "Sean"]
|
||||
:key-fn :GENERATED_KEY
|
||||
:key :id
|
||||
:opts {:key-fn :GENERATED_KEY :key :id}}]
|
||||
@(sut/defer-ops
|
||||
#(sut/insert! :foo {:name "Sean"} {:key-fn :GENERATED_KEY :key :id})))))
|
||||
(testing "execution"
|
||||
(let [effects (sut/with-deferred (ds)
|
||||
(sut/insert! :fruit {:name "Mango"} {:key :test}))]
|
||||
(is (= {:test 1} @effects))
|
||||
(is (= 1 (count (jdbc/execute! (ds)
|
||||
["select * from fruit where name = ?"
|
||||
"Mango"])))))
|
||||
(let [effects (sut/with-deferred (ds)
|
||||
(sut/insert! :fruit {:name "Dragonfruit"} {:key :test})
|
||||
(sut/update! :fruit {:cost 123} {:name "Dragonfruit"})
|
||||
(sut/delete! :fruit {:name "Dragonfruit"}))]
|
||||
(is (= {:test 1} @effects))
|
||||
(is (= 0 (count (jdbc/execute! (ds)
|
||||
["select * from fruit where name = ?"
|
||||
"Dragonfruit"])))))
|
||||
(let [effects (sut/with-deferred (ds)
|
||||
(sut/insert! :fruit {:name "Grapefruit" :bad_column 0} {:key :test}))]
|
||||
(is (= :failed (try @effects
|
||||
(catch Exception _ :failed))))
|
||||
(is (= 0 (count (jdbc/execute! (ds)
|
||||
["select * from fruit where name = ?"
|
||||
"Grapefruit"])))))))
|
||||
(when-not (xtdb?)
|
||||
(testing "data structures"
|
||||
(is (= [{:sql-p ["INSERT INTO foo (name) VALUES (?)" "Sean"]
|
||||
:key-fn :GENERATED_KEY
|
||||
:key :id
|
||||
:opts {:key-fn :GENERATED_KEY :key :id}}]
|
||||
@(sut/defer-ops
|
||||
#(sut/insert! :foo {:name "Sean"} {:key-fn :GENERATED_KEY :key :id})))))
|
||||
(testing "execution"
|
||||
(let [effects (sut/with-deferred (ds)
|
||||
(sut/insert! :fruit {:name "Mango"} {:key :test}))]
|
||||
(is (= {:test 1} @effects))
|
||||
(is (= 1 (count (jdbc/execute! (ds)
|
||||
["select * from fruit where name = ?"
|
||||
"Mango"])))))
|
||||
(let [effects (sut/with-deferred (ds)
|
||||
(sut/insert! :fruit {:name "Dragonfruit"} {:key :test})
|
||||
(sut/update! :fruit {:cost 123} {:name "Dragonfruit"})
|
||||
(sut/delete! :fruit {:name "Dragonfruit"}))]
|
||||
(is (= {:test 1} @effects))
|
||||
(is (= 0 (count (jdbc/execute! (ds)
|
||||
["select * from fruit where name = ?"
|
||||
"Dragonfruit"])))))
|
||||
(let [effects (sut/with-deferred (ds)
|
||||
(sut/insert! :fruit {:name "Grapefruit" :bad_column 0} {:key :test}))]
|
||||
(is (= :failed (try @effects
|
||||
(catch Exception _ :failed))))
|
||||
(is (= 0 (count (jdbc/execute! (ds)
|
||||
["select * from fruit where name = ?"
|
||||
"Grapefruit"]))))))))
|
||||
|
|
|
|||
|
|
@ -114,7 +114,10 @@
|
|||
(mssql?) :GENERATED_KEYS
|
||||
(mysql?) :GENERATED_KEY
|
||||
(postgres?) :fruit/id
|
||||
(xtdb?) :_id
|
||||
;; XTDB does not return the generated key so we fix it
|
||||
;; to be the one we insert here, and then fake it in all
|
||||
;; the other tests.
|
||||
(xtdb?) (constantly 5)
|
||||
:else :FRUIT/ID)]
|
||||
(testing "single insert/delete"
|
||||
(is (== 5 (new-key (doto
|
||||
|
|
@ -139,6 +142,8 @@
|
|||
[8M]
|
||||
(maria?)
|
||||
[6]
|
||||
(xtdb?)
|
||||
[]
|
||||
:else
|
||||
[6 7 8])
|
||||
(mapv new-key
|
||||
|
|
@ -167,6 +172,8 @@
|
|||
[11M]
|
||||
(maria?)
|
||||
[9]
|
||||
(xtdb?)
|
||||
[]
|
||||
:else
|
||||
[9 10 11])
|
||||
(mapv new-key
|
||||
|
|
@ -195,6 +202,8 @@
|
|||
[14M]
|
||||
(maria?)
|
||||
[12]
|
||||
(xtdb?)
|
||||
[]
|
||||
:else
|
||||
[12 13 14])
|
||||
(mapv new-key
|
||||
|
|
|
|||
|
|
@ -120,8 +120,9 @@
|
|||
(when (xtdb?) (println (first rs)
|
||||
(.indexOf ^java.util.List (first rs) :name)
|
||||
(.indexOf (first rs) :name)))
|
||||
(let [n (.indexOf ^java.util.List (first rs) :name)]
|
||||
(is (every? string? (map #(nth % n) (rest rs)))))))
|
||||
(let [n (or (.indexOf ^java.util.List (first rs) :name) 1)]
|
||||
(is (try (every? string? (map #(nth % n) (rest rs)))
|
||||
(catch Throwable _ (println (rest rs))))))))
|
||||
(testing "execute! with adapter"
|
||||
(let [rs (jdbc/execute! ; test again, with adapter and lower columns
|
||||
ds-opts
|
||||
|
|
@ -142,8 +143,9 @@
|
|||
(when (xtdb?) (println (first rs)
|
||||
(.indexOf ^java.util.List (first rs) :name)
|
||||
(.indexOf (first rs) :name)))
|
||||
(let [n (.indexOf ^java.util.List (first rs) :name)]
|
||||
(is (every? string? (map #(nth % n) (rest rs)))))))
|
||||
(let [n (or (.indexOf ^java.util.List (first rs) :name) 1)]
|
||||
(is (try (every? string? (map #(nth % n) (rest rs)))
|
||||
(catch Throwable _ (println (rest rs))))))))
|
||||
(testing "execute! with unqualified"
|
||||
(let [rs (jdbc/execute!
|
||||
(ds)
|
||||
|
|
@ -170,8 +172,9 @@
|
|||
(when (xtdb?) (println (first rs)
|
||||
(.indexOf ^java.util.List (first rs) :name)
|
||||
(.indexOf (first rs) :name)))
|
||||
(let [n (.indexOf ^java.util.List (first rs) :name)]
|
||||
(is (every? string? (map #(nth % n) (rest rs)))))))
|
||||
(let [n (or (.indexOf ^java.util.List (first rs) :name) 1)]
|
||||
(is (try (every? string? (map #(nth % n) (rest rs)))
|
||||
(catch Throwable _ (println (rest rs))))))))
|
||||
(testing "execute! with :max-rows / :maxRows"
|
||||
(let [rs (jdbc/execute!
|
||||
ds-opts
|
||||
|
|
|
|||
Loading…
Reference in a new issue