1 ! Copyright (C) 2014 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types alien.data alien.strings
4 alien.syntax arrays assocs classes.struct combinators
5 combinators.short-circuit constructors continuations destructors
6 forestdb.ffi forestdb.utils fry generalizations io.directories
7 io.encodings.string io.encodings.utf8 io.files.temp io.pathnames
8 kernel layouts libc make math math.parser math.ranges multiline
9 namespaces sequences system tools.test nested-comments ;
12 { [ cell-bits 32 = ] [ os windows? ] } 0&& [
14 { } [ [ delete-test-db-0 ] ignore-errors ] unit-test
15 { } [ [ delete-test-db-1 ] ignore-errors ] unit-test
17 ! Get/set by key/value
22 "key123" "val123" fdb-set-kv
32 "key123" "val12345" fdb-set-kv
43 delete-test-db-1 test-db-1 [
47 fdb_doc>doc [ key>> ] [ body>> ] bi 2array
49 ] with-forestdb-tester
56 delete-test-db-1 test-db-1 [
59 "key1" "no meta" "going away" [
61 fdb_doc>doc [ key>> ] [ meta>> ] [ body>> ] tri 3array
63 ] with-forestdb-tester
70 delete-test-db-1 test-db-1 [
74 fdb-get-byseq fdb_doc>doc
75 [ key>> ] [ meta>> ] [ body>> ] tri 3array
77 ] with-forestdb-tester
83 delete-test-db-1 test-db-1 [
87 fdb-get-byseq fdb_doc>doc
88 [ key>> ] [ meta>> ] [ body>> ] tri 3array
90 ] with-forestdb-tester
93 ! Filename is only valid inside with-forestdb
97 fdb-get-info filename>> alien>native-string empty?
98 ] with-forestdb-tester
101 ! Test fdb_doc_create
105 "key123" "meta blah" "some body" [
106 [ keylen>> ] [ metalen>> ] [ bodylen>> ] tri
108 ] with-forestdb-tester
114 "key1234" "meta blah" "some body" [
115 [ "new meta" "some other body" fdb-doc-update ]
116 [ [ keylen>> ] [ metalen>> ] [ bodylen>> ] tri ] bi
118 ] with-forestdb-tester
126 fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
127 ] with-forestdb-tester
136 fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
137 ] with-forestdb-tester
145 fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
146 ] with-forestdb-tester
158 fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
159 ] with-forestdb-snapshot
160 ] with-forestdb-tester
166 ! Snapshots can only occur on commits. If you commit five keys at once,
167 ! and then try to open a snapshot on the second key, it should fail.
169 ! XXX: Buggy, fails in _fdb_open with FDB_RESULT_NO_DB_INSTANCE
176 fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
177 ] with-forestdb-snapshot
178 ] with-forestdb-tester
180 T{ fdb-error { error FDB_RESULT_NO_DB_INSTANCE } } =
183 ! Test that we take two snapshots and their seqnums/doc counts are right.
184 ! XXX: Buggy, want to see the first snapshot's document count at 5 too
198 fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi 2array
199 ] with-forestdb-snapshot
202 fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi 2array
203 ] with-forestdb-snapshot
204 ] with-forestdb-tester
208 ! Same test as above, but with buggy behavior for now so it passes
222 fdb-get-kvs-info last_seqnum>>
223 ] with-forestdb-snapshot
226 fdb-get-kvs-info last_seqnum>>
227 ] with-forestdb-snapshot
228 ] with-forestdb-tester
235 ! Make sure the doc_count is correct after a rollback
249 fdb-get-kvs-info last_seqnum>>
250 ] with-forestdb-snapshot
255 fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi 2array
256 ] with-forestdb-snapshot
257 ] with-forestdb-tester
274 fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
275 ] with-fdb-normal-iterator
277 ] with-forestdb-tester
296 fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
297 ] with-fdb-normal-iterator
299 ] with-forestdb-tester
302 ! Test that keys at extremes get returned
314 fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
315 ] with-fdb-normal-iterator
317 ] with-forestdb-tester
331 fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
332 ] with-fdb-normal-iterator
334 ] with-forestdb-tester
350 ] with-forestdb-tester
353 ! Deleting 5 keys gives you 5 new seqnums that are those docs, but deleted
355 V{ { 6 t } { 7 t } { 8 t } { 9 t } { 10 t } }
365 [ [ seqnum>> ] [ deleted?>> ] bi 2array ] map
366 ] with-forestdb-tester
379 delete-test-db-1 test-db-1 [
385 [ [ key>> ] [ keylen>> ] bi alien/length>string ] bi 2array ,
386 ] with-fdb-byseq-each
388 ] with-forestdb-tester