forestdb.lib: testing in auto-compact mode needs a pair of unique files.
parent
48d9b2b4eb
commit
88fa8b6bba
|
@ -15,8 +15,8 @@ IN: forestdb.lib
|
||||||
"test123" [
|
"test123" [
|
||||||
"key123" "val123" fdb-set-kv
|
"key123" "val123" fdb-set-kv
|
||||||
"key123" fdb-get-kv
|
"key123" fdb-get-kv
|
||||||
] with-kvs
|
] with-kvs-name
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
{ "val12345" } [
|
{ "val12345" } [
|
||||||
|
@ -24,8 +24,8 @@ IN: forestdb.lib
|
||||||
"test123" [
|
"test123" [
|
||||||
"key123" "val12345" fdb-set-kv
|
"key123" "val12345" fdb-set-kv
|
||||||
"key123" fdb-get-kv
|
"key123" fdb-get-kv
|
||||||
] with-kvs
|
] with-kvs-name
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
! Get
|
! Get
|
||||||
|
@ -39,7 +39,7 @@ IN: forestdb.lib
|
||||||
"key1" "meta" "val" [
|
"key1" "meta" "val" [
|
||||||
fdb_doc>doc [ key>> ] [ body>> ] bi 2array
|
fdb_doc>doc [ key>> ] [ body>> ] bi 2array
|
||||||
] with-create-doc
|
] with-create-doc
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ IN: forestdb.lib
|
||||||
fdb-get
|
fdb-get
|
||||||
fdb_doc>doc [ key>> ] [ meta>> ] [ body>> ] tri 3array
|
fdb_doc>doc [ key>> ] [ meta>> ] [ body>> ] tri 3array
|
||||||
] with-create-doc
|
] with-create-doc
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ IN: forestdb.lib
|
||||||
fdb-get-byseq fdb_doc>doc
|
fdb-get-byseq fdb_doc>doc
|
||||||
[ key>> ] [ meta>> ] [ body>> ] tri 3array
|
[ key>> ] [ meta>> ] [ body>> ] tri 3array
|
||||||
] with-doc
|
] with-doc
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -80,14 +80,14 @@ IN: forestdb.lib
|
||||||
fdb-get-byseq fdb_doc>doc
|
fdb-get-byseq fdb_doc>doc
|
||||||
[ key>> ] [ meta>> ] [ body>> ] tri 3array
|
[ key>> ] [ meta>> ] [ body>> ] tri 3array
|
||||||
] with-doc
|
] with-doc
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
! Filename is only valid inside with-forestdb
|
! Filename is only valid inside with-forestdb
|
||||||
{ f } [
|
{ f } [
|
||||||
[
|
[
|
||||||
fdb-get-info filename>> alien>native-string empty?
|
fdb-get-info filename>> alien>native-string empty?
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
! Test fdb_doc_create
|
! Test fdb_doc_create
|
||||||
|
@ -96,7 +96,7 @@ IN: forestdb.lib
|
||||||
"key123" "meta blah" "some body" [
|
"key123" "meta blah" "some body" [
|
||||||
[ keylen>> ] [ metalen>> ] [ bodylen>> ] tri
|
[ keylen>> ] [ metalen>> ] [ bodylen>> ] tri
|
||||||
] with-create-doc
|
] with-create-doc
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
{ 7 8 15 } [
|
{ 7 8 15 } [
|
||||||
|
@ -105,7 +105,7 @@ IN: forestdb.lib
|
||||||
[ "new meta" "some other body" fdb-doc-update ]
|
[ "new meta" "some other body" fdb-doc-update ]
|
||||||
[ [ keylen>> ] [ metalen>> ] [ bodylen>> ] tri ] bi
|
[ [ keylen>> ] [ metalen>> ] [ bodylen>> ] tri ] bi
|
||||||
] with-create-doc
|
] with-create-doc
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
{ 1 1 } [
|
{ 1 1 } [
|
||||||
|
@ -113,7 +113,7 @@ IN: forestdb.lib
|
||||||
1 set-kv-n
|
1 set-kv-n
|
||||||
fdb-commit-normal
|
fdb-commit-normal
|
||||||
fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
|
fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
{ 6 5 } [
|
{ 6 5 } [
|
||||||
|
@ -122,7 +122,7 @@ IN: forestdb.lib
|
||||||
5 set-kv-nth
|
5 set-kv-nth
|
||||||
fdb-commit-normal
|
fdb-commit-normal
|
||||||
fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
|
fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
{ 5 5 } [
|
{ 5 5 } [
|
||||||
|
@ -130,7 +130,7 @@ IN: forestdb.lib
|
||||||
5 set-kv-n
|
5 set-kv-n
|
||||||
fdb-commit-normal
|
fdb-commit-normal
|
||||||
fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
|
fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
! Snapshots
|
! Snapshots
|
||||||
|
@ -143,7 +143,7 @@ IN: forestdb.lib
|
||||||
FDB_SNAPSHOT_INMEM [
|
FDB_SNAPSHOT_INMEM [
|
||||||
fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
|
fdb-get-kvs-info [ last_seqnum>> ] [ doc_count>> ] bi
|
||||||
] with-forestdb-snapshot
|
] with-forestdb-snapshot
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ IN: forestdb.lib
|
||||||
fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
|
fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
|
||||||
] with-fdb-normal-iterator
|
] with-fdb-normal-iterator
|
||||||
] { } make
|
] { } make
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
! All the keys
|
! All the keys
|
||||||
|
@ -280,7 +280,7 @@ IN: forestdb.lib
|
||||||
fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
|
fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
|
||||||
] with-fdb-normal-iterator
|
] with-fdb-normal-iterator
|
||||||
] { } make
|
] { } make
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
! Test that keys at extremes get returned
|
! Test that keys at extremes get returned
|
||||||
|
@ -297,7 +297,7 @@ IN: forestdb.lib
|
||||||
fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
|
fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
|
||||||
] with-fdb-normal-iterator
|
] with-fdb-normal-iterator
|
||||||
] { } make
|
] { } make
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -313,7 +313,7 @@ IN: forestdb.lib
|
||||||
fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
|
fdb_doc>doc [ seqnum>> ] [ key>> ] [ body>> ] tri 3array ,
|
||||||
] with-fdb-normal-iterator
|
] with-fdb-normal-iterator
|
||||||
] { } make
|
] { } make
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ IN: forestdb.lib
|
||||||
fdb_doc>doc
|
fdb_doc>doc
|
||||||
] with-fdb-byseq-map
|
] with-fdb-byseq-map
|
||||||
[ seqnum>> ] map
|
[ seqnum>> ] map
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
! XXX: Behavior changed here
|
! XXX: Behavior changed here
|
||||||
|
@ -345,7 +345,7 @@ IN: forestdb.lib
|
||||||
! fdb_doc>doc
|
! fdb_doc>doc
|
||||||
! ] with-fdb-byseq-map
|
! ] with-fdb-byseq-map
|
||||||
! [ [ seqnum>> ] [ deleted?>> ] bi 2array ] map
|
! [ [ seqnum>> ] [ deleted?>> ] bi 2array ] map
|
||||||
! ] with-forestdb-test-db
|
! ] with-forestdb-test-manual
|
||||||
! ] unit-test
|
! ] unit-test
|
||||||
|
|
||||||
! Test new behavior
|
! Test new behavior
|
||||||
|
@ -360,7 +360,7 @@ IN: forestdb.lib
|
||||||
fdb_doc>doc
|
fdb_doc>doc
|
||||||
] with-fdb-byseq-map
|
] with-fdb-byseq-map
|
||||||
[ [ seqnum>> ] [ deleted?>> ] bi 2array ] map
|
[ [ seqnum>> ] [ deleted?>> ] bi 2array ] map
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -382,5 +382,5 @@ IN: forestdb.lib
|
||||||
[ [ key>> ] [ keylen>> ] bi alien/length>string ] bi 2array ,
|
[ [ key>> ] [ keylen>> ] bi alien/length>string ] bi 2array ,
|
||||||
] with-fdb-byseq-each
|
] with-fdb-byseq-each
|
||||||
] { } make
|
] { } make
|
||||||
] with-forestdb-test-db
|
] with-forestdb-test-manual
|
||||||
] unit-test
|
] unit-test
|
|
@ -339,7 +339,7 @@ PRIVATE>
|
||||||
[ fdb_kvs_open fdb-check-error ] 3keep 2drop
|
[ fdb_kvs_open fdb-check-error ] 3keep 2drop
|
||||||
void* deref <fdb-kvs-handle> ;
|
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 ;
|
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 -- ) -- )
|
: 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 )
|
! : fdb-changes-since ( seqnum iterator_opt cb ctx -- seq )
|
||||||
! f 101 FDB_ITR_NONE fdb_changes_since ;
|
! 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-kvs-name-config ( name config quot -- )
|
||||||
: 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
|
_ _ fdb-kvs-open-config &dispose current-fdb-kvs-handle _ with-variable
|
||||||
] with-forestdb ; inline
|
] 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
|
! Do not try to commit here, as it will fail with FDB_RESULT_RONLY_VIOLATION
|
||||||
|
|
|
@ -1,24 +1,52 @@
|
||||||
! Copyright (C) 2014 Doug Coleman.
|
! Copyright (C) 2014 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: assocs continuations forestdb.lib fry io.directories
|
USING: accessors assocs continuations forestdb.ffi forestdb.lib
|
||||||
io.files.temp io.files.unique kernel math.parser math.ranges
|
fry io.directories io.files.temp io.files.unique
|
||||||
sequences ;
|
io.files.unique.private io.pathnames kernel locals math.parser
|
||||||
|
math.ranges namespaces sequences splitting ;
|
||||||
IN: forestdb.utils
|
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" [
|
"forestdb-test-manual" ".db" [
|
||||||
_ _ with-forestdb-kvs
|
_
|
||||||
|
"default" _ with-forestdb-path-config-kvs-name
|
||||||
] cleanup-unique-file
|
] cleanup-unique-file
|
||||||
] with-temp-directory ; inline
|
] 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" [
|
"forestdb-test-auto" { ".db.0" ".db.meta" } [
|
||||||
"default" _ with-forestdb-kvs
|
first ".0" ?tail drop
|
||||||
] cleanup-unique-file
|
_ "default" _ with-forestdb-path-config-kvs-name
|
||||||
|
] cleanup-unique-files
|
||||||
] with-temp-directory ; inline
|
] 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 )
|
: make-kv-nth ( n -- key val )
|
||||||
number>string [ "key" prepend ] [ "val" prepend ] bi ;
|
number>string [ "key" prepend ] [ "val" prepend ] bi ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue