Final fixes before releasing last developer release
[dbsrgits/DBM-Deep.git] / t / 07_locking.t
CommitLineData
ffed8b01 1use strict;
0e3e3555 2use warnings FATAL => 'all';
3
4use Test::More;
2120a181 5use Test::Exception;
0e3e3555 6use t::common qw( new_dbm );
ffed8b01 7
bd773913 8use_ok( 'DBM::Deep' );
ffed8b01 9
0e3e3555 10my $dbm_factory = new_dbm( locking => 1 );
11while ( my $dbm_maker = $dbm_factory->() ) {
12 my $db = $dbm_maker->();
13
14 lives_ok {
15 $db->unlock;
16 } "Can call unlock on an unlocked DB.";
17
18 ##
19 # basic put/get
20 ##
21 $db->{key1} = "value1";
22 is( $db->{key1}, "value1", "key1 is set" );
23
24 $db->{key2} = [ 1 .. 3 ];
25 is( $db->{key2}[1], 2, "The value is set properly" );
26
27 ##
28 # explicit lock
29 ##
30 $db->lock_exclusive;
31 $db->{key1} = "value2";
32 $db->unlock();
33 is( $db->{key1}, "value2", "key1 is overridden" );
34}
35
36done_testing;