-
Notifications
You must be signed in to change notification settings - Fork 5
/
simple_test.clj
113 lines (96 loc) · 2.7 KB
/
simple_test.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
(ns clj-lmdb.simple-test
(:require [clojure.test :refer :all]
[clj-lmdb.simple :refer :all]))
(deftest non-txn-test
(testing "Put + get without using a txn"
(let [db (make-db "/tmp")]
(put! db
"foo"
"bar")
(is
(= (get! db
"foo")
"bar"))
(delete! db "foo")
(is
(nil?
(get! db "foo"))))))
(deftest with-txn-test
(testing "Results with a txn"
(let [db (make-db "/tmp")]
(with-txn [txn (write-txn db)]
(put! db
txn
"foo"
"bar")
(put! db
txn
"foo1"
"bar1"))
(with-txn [txn (read-txn db)]
(is (= (get! db
txn
"foo")
"bar"))
(is (= (get! db
txn
"foo1")
"bar1")))
(delete! db "foo")
(delete! db "foo1"))))
(deftest iteration-test
(testing "Iteration"
(let [db (make-db "/tmp")]
(with-txn [txn (write-txn db)]
(doall
(map
(fn [i]
(put! db txn (str i) (str i)))
(range 1000))))
(with-txn [txn (read-txn db)]
(let [num-items (count
(doall
(map
(fn [[k v]]
(is (= k v))
[k v])
(items db txn))))]
(is (= num-items 1000))))
(with-txn [txn (read-txn db)]
(let [num-items (count
(doall
(map
(fn [[k v]]
(is (= k v))
[k v])
(items-from db txn "500"))))]
(is (= num-items 553)))) ; items are sorted in alphabetical order - not numerical
(with-txn [txn (write-txn db)]
(doall
(map
#(->> %
str
(delete! db txn))
(range 1000)))
(is (= (count (items-from db txn "400"))
0))))))
(deftest named-db-test
(testing "Create multiple databases in a single env."
(let [db-record1 (make-named-db "/tmp"
"db1")
db-record2 (make-named-db "/tmp"
"db2")]
(put! db-record1
"foo"
"bar")
(put! db-record2
"foo"
"baz")
(is (= (get! db-record1
"foo")
"bar"))
(is (= (get! db-record2
"foo")
"baz"))
(drop-db! db-record1)
(drop-db! db-record2))))