Skip to content
Snippets Groups Projects
Commit c315e7eb authored by Cam Saul's avatar Cam Saul
Browse files

Make test databases in memory

parent 75a7f1a9
No related branches found
No related tags found
No related merge requests found
......@@ -82,7 +82,7 @@
:expectations {:injections [(require 'metabase.test-setup)]
:resource-paths ["test_resources"]
:env {:mb-test-setting-1 "ABCDEFG"}
:jvm-opts ["-Dmb.db.file=target/metabase-test"
:jvm-opts ["-Dmb.db.in.memory=true"
"-Dmb.jetty.join=false"
"-Dmb.jetty.port=3010"
"-Dmb.api.key=test-api-key"
......
......@@ -16,17 +16,23 @@
;; ## DB FILE, JDBC/KORMA DEFINITONS
(defn db-file
(def db-file
"Path to our H2 DB file from env var or app config."
[]
(let [db-file-name (config/config-str :mb-db-file)
db-file (clojure.java.io/file db-file-name)
options ";AUTO_SERVER=TRUE;MV_STORE=FALSE;DB_CLOSE_DELAY=-1"] ; see http://h2database.com/html/features.html for explanation of options
(if (.isAbsolute db-file)
;; when an absolute path is given for the db file then don't mess with it
(str "file:" db-file-name options)
;; if we don't have an absolute path then make sure we start from "user.dir"
(str "file:" (str (System/getProperty "user.dir") "/" db-file-name options)))))
(memoize
(fn []
;; see http://h2database.com/html/features.html for explanation of options
(if (config/config-bool :mb-db-in-memory)
;; In-memory (i.e. test) DB
"mem:metabase;DB_CLOSE_DELAY=-1"
;; File-based DB
(let [db-file-name (config/config-str :mb-db-file)
db-file (clojure.java.io/file db-file-name)
options ";AUTO_SERVER=TRUE;MV_STORE=FALSE;DB_CLOSE_DELAY=-1"]
(apply str "file:" (if (.isAbsolute db-file)
;; when an absolute path is given for the db file then don't mess with it
[db-file-name options]
;; if we don't have an absolute path then make sure we start from "user.dir"
[(System/getProperty "user.dir") "/" db-file-name options])))))))
(defn setup-jdbc-db
......
......@@ -34,9 +34,11 @@
(defn- connection-details
"Return a Metabase `Database.details` for H2 database defined by DATABASE-DEFINITION."
[^DatabaseDefinition {:keys [short-lived?], :as database-definition}]
{:db (format (if short-lived? "file:%s" ; for short-lived connections don't create a server thread and don't use a keep-alive connection
"file:%s;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1")
(filename database-definition))
{:db (format (if short-lived?
;; for so-called 'short-lived' (temp) DBs create them in-memory
"mem:%s"
"file:%s;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1")
(filename database-definition))
:short-lived? short-lived?})
(defn- korma-connection-pool
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment