Flushing problems fixed
[dbsrgits/DBM-Deep.git] / t / 07_locking.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
2120a181 5use Test::More tests => 5;
6use Test::Exception;
fde3db1a 7use t::common qw( new_fh );
ffed8b01 8
bd773913 9use_ok( 'DBM::Deep' );
ffed8b01 10
fde3db1a 11my ($fh, $filename) = new_fh();
bd773913 12my $db = DBM::Deep->new(
45f047f8 13 file => $filename,
14 fh => $fh,
15 locking => 1,
ffed8b01 16);
ffed8b01 17
2120a181 18lives_ok {
19 $db->unlock;
20} "Can call unlock on an unlocked DB.";
21
ffed8b01 22##
23# basic put/get
24##
25$db->{key1} = "value1";
bd773913 26is( $db->{key1}, "value1", "key1 is set" );
ffed8b01 27
25369e06 28$db->{key2} = [ 1 .. 3 ];
29is( $db->{key2}[1], 2 );
30
ffed8b01 31##
32# explicit lock
33##
5c0756fc 34$db->lock_exclusive;
ffed8b01 35$db->{key1} = "value2";
36$db->unlock();
bd773913 37is( $db->{key1}, "value2", "key1 is overridden" );