my ($tag, $md5, $orig_key) = @_;
#ACID - This is a read. Can find exact or HEAD
- my ($subloc, $offset, $size,$is_deleted) = $self->_find_in_buckets( $tag, $md5 );
- if ( $subloc && !$is_deleted ) {
+ my ($subloc, $offset, $size, $is_deleted) = $self->_find_in_buckets( $tag, $md5 );
+
+ if ( !$subloc ) {
+ #XXX Need to use real key
+# $self->add_bucket( $tag, $md5, $orig_key, undef, undef, $orig_key );
+# return;
+ }
+ elsif ( !$is_deleted ) {
return $self->read_from_loc( $subloc, $orig_key );
}
+
return;
}
# DBM::Deep Test
##
use strict;
-use Test::More tests => 32;
+use Test::More tests => 36;
use Test::Exception;
use t::common qw( new_fh );
ok( $db->exists("key1"), "exists() function works" );
ok( exists $db->{key2}, "exists() works against tied hash" );
+ok( !exists $db->{key4}, "exists() function works for keys that aren't there" );
+is( $db->{key4}, undef, "Autovivified key4" );
+TODO: {
+ local $TODO = "Autovivification isn't correct yet";
+ ok( exists $db->{key4}, "Autovivified key4 now exists" );
+}
+delete $db->{key4};
+ok( !exists $db->{key4}, "And key4 doesn't exists anymore" );
+
##
# count keys
##
use strict;
-use Test::More tests => 31;
+use Test::More tests => 37;
use Test::Exception;
use t::common qw( new_fh );
$db1->begin_work;
delete $db2->{other_x};
- is( $db2->{other_x}, undef, "DB2 deleted other_x in DB1's transaction, so it can't see it anymore" );
+ 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." );
delete $db1->{x};
- is( $db1->{x}, undef, "DB1 deleted X in a transaction, so it can't see it anymore" );
-
+ 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" );
+
$db1->rollback;
is( $db2->{other_x}, undef, "It's still deleted for DB2" );
$db1->begin_work;
delete $db1->{x};
- is( $db1->{x}, undef, "DB1 deleted X in a transaction, so it can't see it anymore" );
+ 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" );
$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" );
+
+$db1->{foo} = 'bar';
+is( $db1->{foo}, 'bar', "Set foo to bar in DB1" );
+is( $db2->{foo}, 'bar', "Set foo to bar in DB2" );
+
+TODO: {
+ local $TODO = 'Still need to work on clear()';
+
+$db1->begin_work;
+
+ %$db1 = (); # clear()
+ ok( !exists $db1->{foo}, "Cleared foo" );
+ is( $db2->{foo}, 'bar', "But in DB2, we can still see it" );
+
+$db1->rollback;
+
+is( $db1->{foo}, 'bar', "Rollback means 'foo' is still there" );
+is( $db2->{foo}, 'bar', "Rollback means 'foo' is still there" );
+}