forestdb.lib: testing in auto-compact mode needs a pair of unique files.

locals-and-roots
Doug Coleman 2016-05-23 13:47:25 -07:00
parent 48d9b2b4eb
commit 88fa8b6bba
3 changed files with 84 additions and 50 deletions

View File

@ -15,8 +15,8 @@ IN: forestdb.lib
"test123" [
"key123" "val123" fdb-set-kv
"key123" fdb-get-kv
] with-kvs
] with-forestdb-test-db
] with-kvs-name
] with-forestdb-test-manual
] unit-test
{ "val12345" } [
@ -24,8 +24,8 @@ IN: forestdb.lib
"test123" [
"key123" "val12345" fdb-set-kv
"key123" fdb-get-kv
] with-kvs
] with-forestdb-test-db
] with-kvs-name
] with-forestdb-test-manual
] unit-test
! Get
@ -39,7 +39,7 @@ IN: forestdb.lib
"key1" "meta" "val" [
fdb_doc>doc [ key>> ] [ body>> ] bi 2array
] with-create-doc
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
@ -53,7 +53,7 @@ IN: forestdb.lib
fdb-get
fdb_doc>doc [ key>> ] [ meta>> ] [ body>> ] tri 3array
] with-create-doc
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
@ -67,7 +67,7 @@ IN: forestdb.lib
fdb-get-byseq fdb_doc>doc
[ key>> ] [ meta>> ] [ body>> ] tri 3array
] with-doc
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
{
@ -80,14 +80,14 @@ IN: forestdb.lib
fdb-get-byseq fdb_doc>doc
[ key>> ] [ meta>> ] [ body>> ] tri 3array
] with-doc
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
! Filename is only valid inside with-forestdb
{ f } [
[
fdb-get-info filename>> alien>native-string empty?
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
! Test fdb_doc_create
@ -96,7 +96,7 @@ IN: forestdb.lib
"key123" "meta blah" "some body" [
[ keylen>> ] [ metalen>> ] [ bodylen>> ] tri
] with-create-doc
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
{ 7 8 15 } [
@ -105,7 +105,7 @@ IN: forestdb.lib
[ "new meta" "some other body" fdb-doc-update ]
[ [ keylen>> ] [ metalen>> ] [ bodylen>> ] tri ] bi
] with-create-doc
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
{ 1 1 } [
@ -113,7 +113,7 @@ IN: forestdb.lib
1 set-kv-n
fdb-commit-normal
fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
{ 6 5 } [
@ -122,7 +122,7 @@ IN: forestdb.lib
5 set-kv-nth
fdb-commit-normal
fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
{ 5 5 } [
@ -130,7 +130,7 @@ IN: forestdb.lib
5 set-kv-n
fdb-commit-normal
fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
! Snapshots
@ -143,7 +143,7 @@ IN: forestdb.lib
FDB_SNAPSHOT_INMEM [
fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
] with-forestdb-snapshot
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
*/
@ -259,7 +259,7 @@ IN: forestdb.lib
fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
] with-fdb-normal-iterator
] { } make
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
! All the keys
@ -280,7 +280,7 @@ IN: forestdb.lib
fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
] with-fdb-normal-iterator
] { } make
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
! Test that keys at extremes get returned
@ -297,7 +297,7 @@ IN: forestdb.lib
fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
] with-fdb-normal-iterator
] { } make
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
{
@ -313,7 +313,7 @@ IN: forestdb.lib
fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
] with-fdb-normal-iterator
] { } make
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
@ -328,7 +328,7 @@ IN: forestdb.lib
fdb_doc>doc
] with-fdb-byseq-map
[ seqnum>> ] map
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
! XXX: Behavior changed here
@ -345,7 +345,7 @@ IN: forestdb.lib
! fdb_doc>doc
! ] with-fdb-byseq-map
! [ [ seqnum>> ] [ deleted?>> ] bi 2array ] map
! ] with-forestdb-test-db
! ] with-forestdb-test-manual
! ] unit-test
! Test new behavior
@ -360,7 +360,7 @@ IN: forestdb.lib
fdb_doc>doc
] with-fdb-byseq-map
[ [ seqnum>> ] [ deleted?>> ] bi 2array ] map
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test
{
@ -382,5 +382,5 @@ IN: forestdb.lib
[ [ key>> ] [ keylen>> ] bi alien/length>string ] bi 2array ,
] with-fdb-byseq-each
] { } make
] with-forestdb-test-db
] with-forestdb-test-manual
] unit-test

View File

@ -339,7 +339,7 @@ PRIVATE>
[ fdb_kvs_open fdb-check-error ] 3keep 2drop
void* deref <fdb-kvs-handle> ;
: fdb-kvs-open ( name -- kvs-handle )
: fdb-kvs-open-default-config ( name -- kvs-handle )
get-kvs-default-config fdb-kvs-open-config ;
: with-fdb-map ( start-key end-key fdb_iterator_opt_t iterator-init iterator-next quot: ( obj -- ) -- )
@ -371,24 +371,30 @@ PRIVATE>
! : fdb-changes-since ( seqnum iterator_opt cb ctx -- seq )
! f 101 FDB_ITR_NONE fdb_changes_since ;
: with-kvs ( name quot -- )
[
[ fdb-kvs-open &dispose current-fdb-kvs-handle ] dip with-variable
] with-destructors ; inline
: with-default-kvs ( quot -- )
[ "default" ] dip with-kvs ; inline
: with-forestdb ( path quot -- )
[
[ fdb-open-normal-commit &dispose current-fdb-file-handle ] dip with-variable
] with-destructors ; inline
: with-forestdb-kvs ( path name quot -- )
: with-kvs-name-config ( name config quot -- )
'[
_ _ with-kvs
] with-forestdb ; inline
_ _ fdb-kvs-open-config &dispose current-fdb-kvs-handle _ with-variable
] with-destructors ; inline
: with-kvs-name ( name quot -- )
[ fdb_get_default_kvs_config ] dip with-kvs-name-config ; inline
: with-forestdb-file-handle ( path config quot -- )
'[
_ _ fdb-open &dispose current-fdb-file-handle _ with-variable
] with-destructors ; inline
: with-forestdb-path-config-kvs-name-config ( path config kvs-name kvs-config quot -- )
'[
_ _ with-kvs-name-config
] with-forestdb-file-handle ; inline
: with-forestdb-path-config-kvs-name ( path config kvs-name quot -- )
'[
_ _ with-kvs-name
] with-forestdb-file-handle ; inline
/*
! Do not try to commit here, as it will fail with FDB_RESULT_RONLY_VIOLATION

View File

@ -1,24 +1,52 @@
! Copyright (C) 2014 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: assocs continuations forestdb.lib fry io.directories
io.files.temp io.files.unique kernel math.parser math.ranges
sequences ;
USING: accessors assocs continuations forestdb.ffi forestdb.lib
fry io.directories io.files.temp io.files.unique
io.files.unique.private io.pathnames kernel locals math.parser
math.ranges namespaces sequences splitting ;
IN: forestdb.utils
: with-forestdb-test-db-kvs ( name quot -- )
: fdb-test-config-seqtree-auto ( -- config )
fdb_get_default_config
FDB_COMPACTION_AUTO >>compaction_mode
FDB_SEQTREE_USE >>seqtree_opt ;
: fdb-test-config-seqtree-manual ( -- config )
fdb_get_default_config
FDB_COMPACTION_MANUAL >>compaction_mode
FDB_SEQTREE_USE >>seqtree_opt ;
! Manual naming scheme: foo.db
: do-forestdb-test-db-manual ( config quot -- )
'[
"forestdb-test" ".db" [
_ _ with-forestdb-kvs
"forestdb-test-manual" ".db" [
_
"default" _ with-forestdb-path-config-kvs-name
] cleanup-unique-file
] with-temp-directory ; inline
: with-forestdb-test-db ( quot -- )
! Auto naming scheme: foo.db.0 foo.db.meta
: do-forestdb-test-db-auto ( config quot -- )
'[
"forestdb-test" ".db" [
"default" _ with-forestdb-kvs
] cleanup-unique-file
"forestdb-test-auto" { ".db.0" ".db.meta" } [
first ".0" ?tail drop
_ "default" _ with-forestdb-path-config-kvs-name
] cleanup-unique-files
] with-temp-directory ; inline
: with-forestdb-test-db ( config quot -- )
over [
do-forestdb-test-db-manual
] [
do-forestdb-test-db-auto
] if ; inline
: with-forestdb-test-manual ( quot -- )
[ fdb-test-config-seqtree-manual ] dip do-forestdb-test-db-manual ; inline
: with-forestdb-test-auto ( quot -- )
[ fdb-test-config-seqtree-auto ] dip do-forestdb-test-db-auto ; inline
: make-kv-nth ( n -- key val )
number>string [ "key" prepend ] [ "val" prepend ] bi ;