Commit | Line | Data |
dec950d0 |
1 | use strict; |
2 | use Test::More tests => 51; |
3 | use Test::Deep; |
4 | use t::common qw( new_fh ); |
5 | |
6 | use_ok( 'DBM::Deep' ); |
7 | |
8 | my ($fh, $filename) = new_fh(); |
9 | my $db1 = DBM::Deep->new( |
10 | file => $filename, |
11 | locking => 1, |
12 | autoflush => 1, |
13 | ); |
14 | |
15 | my $db2 = DBM::Deep->new( |
16 | file => $filename, |
17 | locking => 1, |
18 | autoflush => 1, |
19 | ); |
20 | |
21 | my $db3 = DBM::Deep->new( |
22 | file => $filename, |
23 | locking => 1, |
24 | autoflush => 1, |
25 | ); |
26 | |
27 | $db1->{foo} = 'bar'; |
28 | is( $db1->{foo}, 'bar', "Before transaction, DB1's foo is bar" ); |
29 | is( $db2->{foo}, 'bar', "Before transaction, DB2's foo is bar" ); |
30 | is( $db3->{foo}, 'bar', "Before transaction, DB3's foo is bar" ); |
31 | |
32 | $db1->begin_work; |
33 | |
34 | is( $db1->{foo}, 'bar', "Before transaction work, DB1's foo is bar" ); |
35 | is( $db2->{foo}, 'bar', "Before transaction work, DB2's foo is bar" ); |
36 | is( $db3->{foo}, 'bar', "Before transaction work, DB3's foo is bar" ); |
37 | |
38 | $db1->{foo} = 'bar2'; |
39 | |
40 | is( $db1->{foo}, 'bar2', "After DB1 foo to bar2, DB1's foo is bar2" ); |
41 | is( $db2->{foo}, 'bar', "After DB1 foo to bar2, DB2's foo is bar" ); |
42 | is( $db3->{foo}, 'bar', "After DB1 foo to bar2, DB3's foo is bar" ); |
43 | |
44 | $db1->{bar} = 'foo'; |
45 | |
46 | ok( exists $db1->{bar}, "After DB1 set bar to foo, DB1's bar exists" ); |
47 | ok( !exists $db2->{bar}, "After DB1 set bar to foo, DB2's bar doesn't exist" ); |
48 | ok( !exists $db3->{bar}, "After DB1 set bar to foo, DB3's bar doesn't exist" ); |
49 | |
50 | $db2->begin_work; |
51 | |
41e27db3 |
52 | is( $db1->{foo}, 'bar2', "After DB2 transaction begin, DB1's foo is still bar2" ); |
53 | is( $db2->{foo}, 'bar', "After DB2 transaction begin, DB2's foo is still bar" ); |
54 | is( $db3->{foo}, 'bar', "After DB2 transaction begin, DB3's foo is still bar" ); |
505d0f47 |
55 | __END__ |
dec950d0 |
56 | ok( exists $db1->{bar}, "After DB2 transaction begin, DB1's bar exists" ); |
57 | ok( !exists $db2->{bar}, "After DB2 transaction begin, DB2's bar doesn't exist" ); |
58 | ok( !exists $db3->{bar}, "After DB2 transaction begin, DB3's bar doesn't exist" ); |
59 | |
60 | $db2->{foo} = 'bar333'; |
61 | |
62 | is( $db1->{foo}, 'bar2', "After DB2 foo to bar2, DB1's foo is bar2" ); |
63 | is( $db2->{foo}, 'bar333', "After DB2 foo to bar2, DB2's foo is bar333" ); |
64 | is( $db3->{foo}, 'bar', "After DB2 foo to bar2, DB3's foo is bar" ); |
65 | |
66 | $db2->{bar} = 'mybar'; |
67 | |
68 | ok( exists $db1->{bar}, "After DB2 set bar to mybar, DB1's bar exists" ); |
69 | ok( exists $db2->{bar}, "After DB2 set bar to mybar, DB2's bar exists" ); |
70 | ok( !exists $db3->{bar}, "After DB2 set bar to mybar, DB3's bar doesn't exist" ); |
71 | |
72 | is( $db1->{bar}, 'foo', "DB1's bar is still foo" ); |
73 | is( $db2->{bar}, 'mybar', "DB2's bar is now mybar" ); |
74 | |
75 | $db2->{mykey} = 'myval'; |
76 | |
77 | ok( !exists $db1->{mykey}, "After DB2 set mykey to myval, DB1's mykey doesn't exist" ); |
78 | ok( exists $db2->{mykey}, "After DB2 set mykey to myval, DB2's mykey exists" ); |
79 | ok( !exists $db3->{mykey}, "After DB2 set mykey to myval, DB3's mykey doesn't exist" ); |
80 | |
81 | cmp_bag( [ keys %$db1 ], [qw( foo bar )], "DB1 keys correct" ); |
82 | cmp_bag( [ keys %$db2 ], [qw( foo bar mykey )], "DB2 keys correct" ); |
83 | cmp_bag( [ keys %$db3 ], [qw( foo )], "DB3 keys correct" ); |
84 | |
85 | $db1->commit; |
86 | |
87 | is( $db1->{foo}, 'bar2', "After DB1 commit, DB1's foo is bar2" ); |
88 | is( $db2->{foo}, 'bar333', "After DB1 commit, DB2's foo is bar333" ); |
89 | is( $db3->{foo}, 'bar2', "After DB1 commit, DB3's foo is bar2" ); |
90 | |
91 | is( $db1->{bar}, 'foo', "DB1's bar is still foo" ); |
92 | is( $db2->{bar}, 'mybar', "DB2's bar is still mybar" ); |
93 | is( $db3->{bar}, 'foo', "DB3's bar is now foo" ); |
94 | |
95 | cmp_bag( [ keys %$db1 ], [qw( foo bar )], "DB1 keys correct" ); |
96 | cmp_bag( [ keys %$db2 ], [qw( foo bar mykey )], "DB2 keys correct" ); |
97 | cmp_bag( [ keys %$db3 ], [qw( foo bar )], "DB3 keys correct" ); |
98 | |
99 | $db2->commit; |
100 | |
101 | is( $db1->{foo}, 'bar333', "After DB2 commit, DB1's foo is bar333" ); |
102 | is( $db2->{foo}, 'bar333', "After DB2 commit, DB2's foo is bar333" ); |
103 | is( $db3->{foo}, 'bar333', "After DB2 commit, DB3's foo is bar333" ); |
104 | |
105 | is( $db1->{bar}, 'mybar', "DB1's bar is now mybar" ); |
106 | is( $db2->{bar}, 'mybar', "DB2's bar is still mybar" ); |
107 | is( $db3->{bar}, 'mybar', "DB3's bar is now mybar" ); |
108 | |
109 | cmp_bag( [ keys %$db1 ], [qw( foo bar mykey )], "DB1 keys correct" ); |
110 | cmp_bag( [ keys %$db2 ], [qw( foo bar mykey )], "DB2 keys correct" ); |
111 | cmp_bag( [ keys %$db3 ], [qw( foo bar mykey )], "DB3 keys correct" ); |