r14214@rob-kinyons-computer (orig r8081): rkinyon | 2006-11-17 20:51:21 -0500
[dbsrgits/DBM-Deep.git] / t / 07_locking.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
9a63e1f2 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(
2a81bf9e 13 file => $filename,
2ccea4dc 14 locking => 1,
ffed8b01 15);
ffed8b01 16
9a63e1f2 17lives_ok {
18 $db->unlock;
19} "Can call unlock on an unlocked DB.";
20
ffed8b01 21##
22# basic put/get
23##
24$db->{key1} = "value1";
bd773913 25is( $db->{key1}, "value1", "key1 is set" );
ffed8b01 26
25369e06 27$db->{key2} = [ 1 .. 3 ];
28is( $db->{key2}[1], 2 );
29
ffed8b01 30##
31# explicit lock
32##
bd773913 33$db->lock( DBM::Deep->LOCK_EX );
ffed8b01 34$db->{key1} = "value2";
35$db->unlock();
bd773913 36is( $db->{key1}, "value2", "key1 is overridden" );