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