de35154a37f2482becf3170b5aa369c95d5c29ea
[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     locking => 1,
15 );
16
17 lives_ok {
18     $db->unlock;
19 } "Can call unlock on an unlocked DB.";
20
21 ##
22 # basic put/get
23 ##
24 $db->{key1} = "value1";
25 is( $db->{key1}, "value1", "key1 is set" );
26
27 $db->{key2} = [ 1 .. 3 ];
28 is( $db->{key2}[1], 2, "The value is set properly" );
29
30 ##
31 # explicit lock
32 ##
33 $db->lock_exclusive;
34 $db->{key1} = "value2";
35 $db->unlock();
36 is( $db->{key1}, "value2", "key1 is overridden" );