File: 07_locking.t

package info (click to toggle)
libdbm-deep-perl 2.0008-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 884 kB
  • sloc: perl: 7,383; sql: 36
file content (36 lines) | stat: -rw-r--r-- 710 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use strict;
use warnings FATAL => 'all';

use Test::More;
use Test::Exception;
use t::common qw( new_dbm );

use_ok( 'DBM::Deep' );

my $dbm_factory = new_dbm( locking => 1 );
while ( my $dbm_maker = $dbm_factory->() ) {
    my $db = $dbm_maker->();

    lives_ok {
        $db->unlock;
    } "Can call unlock on an unlocked DB.";

    ##
    # basic put/get
    ##
    $db->{key1} = "value1";
    is( $db->{key1}, "value1", "key1 is set" );

    $db->{key2} = [ 1 .. 3 ];
    is( $db->{key2}[1], 2, "The value is set properly" );

    ##
    # explicit lock
    ##
    $db->lock_exclusive;
    $db->{key1} = "value2";
    $db->unlock();
    is( $db->{key1}, "value2", "key1 is overridden" );
}

done_testing;