Commit | Line | Data |
9a63e1f2 |
1 | use strict; |
2 | use Test::More tests => 33; |
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, |
90a80a23 |
13 | num_txns => 2, |
9a63e1f2 |
14 | ); |
15 | |
16 | my $db2 = DBM::Deep->new( |
17 | file => $filename, |
18 | locking => 1, |
19 | autoflush => 1, |
90a80a23 |
20 | num_txns => 2, |
9a63e1f2 |
21 | ); |
22 | |
23 | $db1->{x} = { foo => 'y' }; |
24 | is( $db1->{x}{foo}, 'y', "Before transaction, DB1's X is Y" ); |
25 | is( $db2->{x}{foo}, 'y', "Before transaction, DB2's X is Y" ); |
26 | |
27 | $db1->begin_work; |
28 | |
29 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
30 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
31 | |
32 | cmp_bag( [ keys %{$db1->{x}} ], [qw( foo )], "DB1->X keys correct" ); |
33 | cmp_bag( [ keys %{$db2->{x}} ], [qw( foo )], "DB2->X keys correct" ); |
34 | |
35 | is( $db1->{x}{foo}, 'y', "After transaction, DB1's X is Y" ); |
36 | is( $db2->{x}{foo}, 'y', "After transaction, DB2's X is Y" ); |
37 | |
38 | $db1->{x} = { bar => 30 }; |
39 | ok( !exists $db1->{x}{foo}, "DB1: After reassignment of X, X->FOO is gone" ); |
40 | is( $db2->{x}{foo}, 'y', "DB2: After reassignment of DB1 X, X is Y" ); |
41 | |
42 | cmp_bag( [ keys %{$db1->{x}} ], [qw( bar )], "DB1->X keys correct" ); |
43 | cmp_bag( [ keys %{$db2->{x}} ], [qw( foo )], "DB2->X keys correct" ); |
44 | |
45 | $db1->rollback; |
46 | |
47 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
48 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
49 | |
50 | cmp_bag( [ keys %{$db1->{x}} ], [qw( foo )], "DB1->X keys correct" ); |
51 | cmp_bag( [ keys %{$db2->{x}} ], [qw( foo )], "DB2->X keys correct" ); |
52 | |
53 | is( $db1->{x}{foo}, 'y', "Before transaction, DB1's X is Y" ); |
54 | is( $db2->{x}{foo}, 'y', "Before transaction, DB2's X is Y" ); |
55 | |
56 | $db1->begin_work; |
57 | |
58 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
59 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
60 | |
61 | cmp_bag( [ keys %{$db1->{x}} ], [qw( foo )], "DB1->X keys correct" ); |
62 | cmp_bag( [ keys %{$db2->{x}} ], [qw( foo )], "DB2->X keys correct" ); |
63 | |
64 | is( $db1->{x}{foo}, 'y', "After transaction, DB1's X is Y" ); |
65 | is( $db2->{x}{foo}, 'y', "After transaction, DB2's X is Y" ); |
66 | |
67 | $db1->{x} = { bar => 30 }; |
68 | ok( !exists $db1->{x}{foo}, "DB1: After reassignment of X, X->FOO is gone" ); |
69 | is( $db2->{x}{foo}, 'y', "DB2: After reassignment of DB1 X, X is Y" ); |
70 | |
71 | cmp_bag( [ keys %{$db1->{x}} ], [qw( bar )], "DB1->X keys correct" ); |
72 | cmp_bag( [ keys %{$db2->{x}} ], [qw( foo )], "DB2->X keys correct" ); |
73 | |
74 | $db1->commit; |
75 | |
76 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
77 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
78 | |
79 | cmp_bag( [ keys %{$db1->{x}} ], [qw( bar )], "DB1->X keys correct" ); |
80 | cmp_bag( [ keys %{$db2->{x}} ], [qw( bar )], "DB2->X keys correct" ); |