From: rkinyon Date: Sat, 22 Apr 2006 03:19:20 +0000 (+0000) Subject: More failing tests, particularly for keys() and transactions. X-Git-Tag: 0-99_01~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=42717e465f8d960a2a416cd681e1247f35f5e6f3;p=dbsrgits%2FDBM-Deep.git More failing tests, particularly for keys() and transactions. --- diff --git a/lib/DBM/Deep/Engine.pm b/lib/DBM/Deep/Engine.pm index 54609cb..e9d0711 100644 --- a/lib/DBM/Deep/Engine.pm +++ b/lib/DBM/Deep/Engine.pm @@ -884,8 +884,8 @@ sub traverse_index { } # index loop $obj->{return_next} = 1; - } # tag is an index - + } + # This is the bucket list else { my $keys = $tag->{content}; if ($force_return_next) { $obj->{return_next} = 1; } @@ -893,8 +893,14 @@ sub traverse_index { ## # Iterate through buckets, looking for a key match ## + my $transaction_id = $self->_fileobj->transaction_id; for (my $i = 0; $i < $self->{max_buckets}; $i++) { - my ($key, $subloc) = $self->_get_key_subloc( $keys, $i ); + my ($key, $subloc, $size, $trans_id, $is_deleted) = $self->_get_key_subloc( $keys, $i ); + + next if $is_deleted; +#XXX Need to find all the copies of this key to find out if $transaction_id has it +#XXX marked as deleted, in use, or what. + next if $trans_id && $trans_id != $transaction_id; # End of bucket list -- return to outer loop if (!$subloc) { @@ -928,7 +934,7 @@ sub traverse_index { } $obj->{return_next} = 1; - } # tag is a bucket list + } return; } diff --git a/lib/DBM/Deep/File.pm b/lib/DBM/Deep/File.pm index 52792c0..3fcf9d0 100644 --- a/lib/DBM/Deep/File.pm +++ b/lib/DBM/Deep/File.pm @@ -217,6 +217,10 @@ sub request_space { sub lock { my $self = shift; my ($obj, $type) = @_; + + #XXX This may not always be the correct thing to do + $obj = $self->{base_db_obj} unless defined $obj; + $type = LOCK_EX unless defined $type; if (!defined($self->{fh})) { return; } diff --git a/t/28_transactions.t b/t/28_transactions.t index 9af696e..747b57b 100644 --- a/t/28_transactions.t +++ b/t/28_transactions.t @@ -1,6 +1,6 @@ use strict; -use Test::More tests => 37; -use Test::Exception; +use Test::More tests => 56; +use Test::Deep; use t::common qw( new_fh ); use_ok( 'DBM::Deep' ); @@ -35,6 +35,12 @@ $db1->begin_work; is( $db2->{other_x}, 'foo', "DB2 set other_x within DB1's transaction, so DB2 can see it" ); is( $db1->{other_x}, undef, "Since other_x was added after the transaction began, DB1 doesn't see it." ); +TODO: { + local $TODO = "keys aren't working yet"; + cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); +} + cmp_bag( [ keys %$db2 ], [qw( x other_x )], "DB2 keys correct" ); + $db1->rollback; is( $db1->{x}, 'y', "After rollback, DB1's X is Y" ); @@ -52,6 +58,9 @@ $db1->begin_work; is( $db1->{x}, 'z', "Within DB1 transaction, DB1's X is Z" ); is( $db2->{x}, 'y', "Within DB1 transaction, DB2's X is still Y" ); + cmp_bag( [ keys %$db1 ], [qw( x other_x )], "DB1 keys correct" ); + cmp_bag( [ keys %$db2 ], [qw( x other_x )], "DB2 keys correct" ); + $db1->commit; is( $db1->{x}, 'z', "After commit, DB1's X is Z" ); @@ -63,35 +72,56 @@ $db1->begin_work; ok( !exists $db2->{other_x}, "DB2 deleted other_x in DB1's transaction, so it can't see it anymore" ); is( $db1->{other_x}, 'foo', "Since other_x was deleted after the transaction began, DB1 still sees it." ); + cmp_bag( [ keys %$db1 ], [qw( x other_x )], "DB1 keys correct" ); + cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); + delete $db1->{x}; ok( !exists $db1->{x}, "DB1 deleted X in a transaction, so it can't see it anymore" ); is( $db2->{x}, 'z', "But, DB2 can still see it" ); +TODO: { + local $TODO = "keys aren't working yet"; + cmp_bag( [ keys %$db1 ], [qw( other_x )], "DB1 keys correct" ); +} + cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); + $db1->rollback; -is( $db2->{other_x}, undef, "It's still deleted for DB2" ); -is( $db1->{other_x}, undef, "And now DB1 sees the deletion" ); +ok( !exists $db2->{other_x}, "It's still deleted for DB2" ); +ok( !exists $db1->{other_x}, "And now DB1 sees the deletion" ); is( $db1->{x}, 'z', "The transaction was rolled back, so DB1 can see X now" ); is( $db2->{x}, 'z', "DB2 can still see it" ); +cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); +cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); + $db1->begin_work; delete $db1->{x}; ok( !exists $db1->{x}, "DB1 deleted X in a transaction, so it can't see it anymore" ); is( $db2->{x}, 'z', "But, DB2 can still see it" ); +TODO: { + local $TODO = "keys aren't working yet"; + cmp_bag( [ keys %$db1 ], [qw()], "DB1 keys correct" ); +} + cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); + $db1->commit; -is( $db1->{x}, undef, "The transaction was committed, so DB1 still deleted X" ); -is( $db2->{x}, undef, "DB2 can now see the deletion of X" ); +ok( !exists $db1->{x}, "The transaction was committed, so DB1 still deleted X" ); +ok( !exists $db2->{x}, "DB2 can now see the deletion of X" ); $db1->{foo} = 'bar'; is( $db1->{foo}, 'bar', "Set foo to bar in DB1" ); is( $db2->{foo}, 'bar', "Set foo to bar in DB2" ); +cmp_bag( [ keys %$db1 ], [qw( foo )], "DB1 keys correct" ); +cmp_bag( [ keys %$db2 ], [qw( foo )], "DB2 keys correct" ); + TODO: { - local $TODO = 'Still need to work on clear()'; + todo_skip 'Still need to work on clear()', 4; $db1->begin_work; @@ -99,8 +129,36 @@ $db1->begin_work; ok( !exists $db1->{foo}, "Cleared foo" ); is( $db2->{foo}, 'bar', "But in DB2, we can still see it" ); + cmp_bag( [ keys %$db1 ], [qw()], "DB1 keys correct" ); + cmp_bag( [ keys %$db2 ], [qw( foo )], "DB2 keys correct" ); + $db1->rollback; is( $db1->{foo}, 'bar', "Rollback means 'foo' is still there" ); is( $db2->{foo}, 'bar', "Rollback means 'foo' is still there" ); + +cmp_bag( [ keys %$db1 ], [qw( foo )], "DB1 keys correct" ); +cmp_bag( [ keys %$db2 ], [qw( foo )], "DB2 keys correct" ); + } + +$db1->optimize; +is( $db1->{foo}, 'bar', 'After optimize, everything is ok' ); +is( $db2->{foo}, 'bar', 'After optimize, everything is ok' ); + +cmp_bag( [ keys %$db1 ], [qw( foo )], "DB1 keys correct" ); +cmp_bag( [ keys %$db2 ], [qw( foo )], "DB2 keys correct" ); + +$db1->begin_work; + + cmp_ok( $db1->_fileobj->transaction_id, '==', 1, "Transaction ID has been reset after optimize" ); + +$db1->rollback; + +__END__ + +Tests to add: +* Two transactions running at the same time +* Doing a clear on the head while a transaction is running +# More than just two keys +* Arrays (in particular, how is length handled?)