Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate unit tests for index types #580

Merged
merged 6 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ jobs:
root: /home/circleci/
paths:
- replikativ/dhi
persistent-set-test:
executor: tools/clojurecli
steps:
- attach_workspace:
at: /home/circleci
- run:
name: Run unittests for persistent sorted set index
command: ./bin/run-pss-tests
no_output_timeout: 5m
- save_cache:
key: deps-{{ checksum "deps.edn" }}
paths:
- /home/circleci/.m2
hitchhiker-tree-test:
executor: tools/clojurecli
steps:
- attach_workspace:
at: /home/circleci
- run:
name: Run unittests for hitchhiker-tree index
command: ./bin/run-hht-tests
no_output_timeout: 5m
- save_cache:
key: deps-{{ checksum "deps.edn" }}
paths:
- /home/circleci/.m2
native-image-test:
executor: tools/clojurecli
steps:
Expand All @@ -127,7 +153,7 @@ jobs:
command: mkdir ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
no_output_timeout: 1m
- run:
name: Run Unittests
name: Run backward compatibility test
command: ./bin/run-backward-compatibility-tests
no_output_timeout: 5m
- save_cache:
Expand Down Expand Up @@ -161,7 +187,11 @@ workflows:
context: dockerhub-deploy
requires:
- setup
- tools/unittest:
- persistent-set-test:
context: dockerhub-deploy
requires:
- build
- hitchhiker-tree-test:
context: dockerhub-deploy
requires:
- build
Expand Down Expand Up @@ -191,7 +221,8 @@ workflows:
only: main
requires:
- tools/format
- tools/unittest
- persistent-set-test
- hitchhiker-tree-test
- backward-compatibility-test
- native-image-test
- tools/integrationtest
Expand Down
6 changes: 0 additions & 6 deletions bin/run-unittests

This file was deleted.

57 changes: 32 additions & 25 deletions src/datahike/config.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
[datahike.index :as di])
(:import [java.net URI]))

(def ^:dynamic default-index :datahike.index/persistent-set)
(def ^:dynamic default-search-cache-size 10000)
(def ^:dynamic default-store-cache-size 1000)
(def ^:dynamic *default-index* :datahike.index/persistent-set)
(def ^:dynamic *default-schema-flexibility* :write)
(def ^:dynamic *default-keep-history?* true)
(def ^:dynamic *default-attribute-refs?* false)
(def ^:dynamic *default-search-cache-size* 10000)
(def ^:dynamic *default-store-cache-size* 1000)
(def ^:dynamic *default-crypto-hash?* false)
(def ^:dynamic *default-store* :mem) ;; store-less = in-memory?
(def ^:dynamic *default-db-name* nil) ;; when nil creates random name
(def ^:dynamic *default-db-branch* :db) ;; when nil creates random name

(s/def ::index #{:datahike.index/hitchhiker-tree :datahike.index/persistent-set})
(s/def ::keep-history? boolean?)
Expand Down Expand Up @@ -74,13 +81,13 @@
:index index
:index-config (di/default-index-config index)
:keep-history? temporal-index
:attribute-refs? false
:attribute-refs? *default-attribute-refs?*
:initial-tx initial-tx
:schema-flexibility (if (true? schema-on-read) :read :write)
:crypto-hash? false
:branch :db
:search-cache-size default-search-cache-size
:store-cache-size default-store-cache-size})
:branch *default-db-branch*
:crypto-hash? *default-crypto-hash?*
:search-cache-size *default-search-cache-size*
:store-cache-size *default-store-cache-size*})

(defn int-from-env
[key default]
Expand Down Expand Up @@ -115,14 +122,14 @@
{:store nil
:keep-history? false
:schema-flexibility :read
:name (z/rand-german-mammal)
:name (or *default-db-name* (z/rand-german-mammal))
:attribute-refs? false
:index default-index
:search-cache-size default-search-cache-size
:store-cache-size default-store-cache-size
:crypto-hash? false
:branch :db
:index-config (di/default-index-config default-index)})
:index *default-index*
:search-cache-size *default-search-cache-size*
:store-cache-size *default-store-cache-size*
:crypto-hash? *default-crypto-hash?*
:branch *default-db-branch*
:index-config (di/default-index-config *default-index*)})

(defn remove-nils
"Thanks to https://stackoverflow.com/a/34221816"
Expand All @@ -145,22 +152,22 @@
(apply from-deprecated config-as-arg (first opts))
config-as-arg)
store-config (ds/default-config (merge
{:backend (keyword (:datahike-store-backend env :mem))}
{:backend (keyword (:datahike-store-backend env *default-store*))}
(:store config-as-arg)))
index (if (:datahike-index env)
(keyword "datahike.index" (:datahike-index env))
default-index)
*default-index*)
config {:store store-config
:initial-tx (:datahike-intial-tx env)
:keep-history? (bool-from-env :datahike-keep-history true)
:attribute-refs? (bool-from-env :datahike-attribute-refs false)
:name (:datahike-name env (z/rand-german-mammal))
:schema-flexibility (keyword (:datahike-schema-flexibility env :write))
:keep-history? (bool-from-env :datahike-keep-history *default-keep-history?*)
:attribute-refs? (bool-from-env :datahike-attribute-refs *default-attribute-refs?*)
:name (:datahike-name env (or *default-db-name* (z/rand-german-mammal)))
:schema-flexibility (keyword (:datahike-schema-flexibility env *default-schema-flexibility*))
:index index
:crypto-hash? false
:branch :db
:search-cache-size (int-from-env :datahike-search-cache-size default-search-cache-size)
:store-cache-size (int-from-env :datahike-store-cache-size default-store-cache-size)
:branch *default-db-branch*
:crypto-hash? *default-crypto-hash?*
:search-cache-size (int-from-env :datahike-search-cache-size *default-search-cache-size*)
:store-cache-size (int-from-env :datahike-store-cache-size *default-store-cache-size*)
:index-config (if-let [index-config (map-from-env :datahike-index-config nil)]
index-config
(di/default-index-config index))}
Expand Down
44 changes: 0 additions & 44 deletions test/datahike/test/config.clj

This file was deleted.

24 changes: 12 additions & 12 deletions test/datahike/test/config_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
:schema-flexibility :write
:crypto-hash? false
:branch :db
:search-cache-size c/default-search-cache-size
:store-cache-size c/default-store-cache-size}]
:search-cache-size c/*default-search-cache-size*
:store-cache-size c/*default-store-cache-size*}]
(is (= (merge default-new-cfg
{:store {:backend :mem :id "deprecated-test"}})
(c/from-deprecated mem-cfg)))
Expand All @@ -56,16 +56,16 @@
(let [config (c/load-config)]
(is (= (merge {:store {:backend :mem
:id "default"}
:attribute-refs? false
:keep-history? true
:schema-flexibility :write
:index c/default-index
:crypto-hash? false
:branch :db
:search-cache-size c/default-search-cache-size
:store-cache-size c/default-store-cache-size}
(when (seq (di/default-index-config c/default-index))
{:index-config (di/default-index-config c/default-index)}))
:attribute-refs? c/*default-attribute-refs?*
:keep-history? c/*default-keep-history?*
:schema-flexibility c/*default-schema-flexibility*
:index c/*default-index*
:crypto-hash? c/*default-crypto-hash?*
:branch c/*default-db-branch*
:search-cache-size c/*default-search-cache-size*
:store-cache-size c/*default-store-cache-size*}
(when (seq (di/default-index-config c/*default-index*))
{:index-config (di/default-index-config c/*default-index*)}))
(-> config (dissoc :name)))))))

(deftest core-config-test
Expand Down
16 changes: 6 additions & 10 deletions tests.edn
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
#kaocha/v1
#meta-merge [{:tests [{:id :clj
#meta-merge [{:tests [{:id :clj-pss
:focus-meta [:focused]
jsmassa marked this conversation as resolved.
Show resolved Hide resolved
:ns-patterns ["datahike.test."]}
:ns-patterns ["datahike.test."]
:bindings {datahike.config/*default-index* :datahike.index/persistent-set}}
{:id :clj-hht
:ns-patterns ["datahike.test."]
:bindings {datahike.config/*default-index* :datahike.index/hitchhiker-tree}}
#_{:id :cljs
:type :kaocha.type/cljs
:ns-patterns ["datahike.test."]}
{:id :quick
:focus-meta [:focused]
:ns-patterns ["datahike.test."]
:bindings {datahike.test.config/*user-filter-map* [{:index :datahike.index/persistent-set
:backend :mem
:schema-flexibility :read
}]}}
{:id :integration
:focus-meta [:focused]
:test-paths ["test/datahike/integration_test"]}]
:reporter kaocha.report/documentation}
#include "tests.user.edn"]