Commit | Line | Data |
2120a181 |
1 | use strict; |
350896ee |
2 | use Test::More; |
2120a181 |
3 | use Test::Deep; |
0e3e3555 |
4 | use t::common qw( new_dbm ); |
2120a181 |
5 | |
6 | use_ok( 'DBM::Deep' ); |
7 | |
0e3e3555 |
8 | my $dbm_factory = new_dbm( |
9 | locking => 1, |
2120a181 |
10 | autoflush => 1, |
c57b19c6 |
11 | num_txns => 2, |
2120a181 |
12 | ); |
0e3e3555 |
13 | while ( my $dbm_maker = $dbm_factory->() ) { |
14 | my $db1 = $dbm_maker->(); |
15 | my $db2 = $dbm_maker->(); |
2120a181 |
16 | |
0e3e3555 |
17 | $db1->{x} = { xy => { foo => 'y' } }; |
18 | is( $db1->{x}{xy}{foo}, 'y', "Before transaction, DB1's X is Y" ); |
19 | is( $db2->{x}{xy}{foo}, 'y', "Before transaction, DB2's X is Y" ); |
20 | |
21 | $db1->begin_work; |
22 | |
23 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
24 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
25 | |
26 | cmp_bag( [ keys %{$db1->{x}} ], [qw( xy )], "DB1->X keys correct" ); |
27 | cmp_bag( [ keys %{$db2->{x}} ], [qw( xy )], "DB2->X keys correct" ); |
2120a181 |
28 | |
0e3e3555 |
29 | cmp_bag( [ keys %{$db1->{x}{xy}} ], [qw( foo )], "DB1->X->XY keys correct" ); |
30 | cmp_bag( [ keys %{$db2->{x}{xy}} ], [qw( foo )], "DB2->X->XY keys correct" ); |
2120a181 |
31 | |
0e3e3555 |
32 | is( $db1->{x}{xy}{foo}, 'y', "After transaction, DB1's X is Y" ); |
33 | is( $db2->{x}{xy}{foo}, 'y', "After transaction, DB2's X is Y" ); |
34 | |
35 | $db1->{x} = { yz => { bar => 30 } }; |
36 | ok( !exists $db1->{x}{xy}, "DB1: After reassignment of X, X->XY is gone" ); |
37 | is( $db2->{x}{xy}{foo}, 'y', "DB2: After reassignment of DB1 X, X is Y" ); |
38 | |
39 | cmp_bag( [ keys %{$db1->{x}} ], [qw( yz )], "DB1->X keys correct" ); |
40 | cmp_bag( [ keys %{$db2->{x}} ], [qw( xy )], "DB2->X keys correct" ); |
41 | |
42 | $db1->rollback; |
2120a181 |
43 | |
44 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
45 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
46 | |
45f047f8 |
47 | cmp_bag( [ keys %{$db1->{x}} ], [qw( xy )], "DB1->X keys correct" ); |
48 | cmp_bag( [ keys %{$db2->{x}} ], [qw( xy )], "DB2->X keys correct" ); |
2120a181 |
49 | |
45f047f8 |
50 | cmp_bag( [ keys %{$db1->{x}{xy}} ], [qw( foo )], "DB1->X->XY keys correct" ); |
51 | cmp_bag( [ keys %{$db2->{x}{xy}} ], [qw( foo )], "DB2->X->XY keys correct" ); |
2120a181 |
52 | |
0e3e3555 |
53 | is( $db1->{x}{xy}{foo}, 'y', "Before transaction, DB1's X is Y" ); |
54 | is( $db2->{x}{xy}{foo}, 'y', "Before transaction, DB2's X is Y" ); |
2120a181 |
55 | |
0e3e3555 |
56 | $db1->begin_work; |
45f047f8 |
57 | |
0e3e3555 |
58 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
59 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
2120a181 |
60 | |
0e3e3555 |
61 | cmp_bag( [ keys %{$db1->{x}} ], [qw( xy )], "DB1->X keys correct" ); |
62 | cmp_bag( [ keys %{$db2->{x}} ], [qw( xy )], "DB2->X keys correct" ); |
9c87a079 |
63 | |
0e3e3555 |
64 | cmp_bag( [ keys %{$db1->{x}{xy}} ], [qw( foo )], "DB1->X->XY keys correct" ); |
65 | cmp_bag( [ keys %{$db2->{x}{xy}} ], [qw( foo )], "DB2->X->XY keys correct" ); |
2120a181 |
66 | |
0e3e3555 |
67 | is( $db1->{x}{xy}{foo}, 'y', "After transaction, DB1's X is Y" ); |
68 | is( $db2->{x}{xy}{foo}, 'y', "After transaction, DB2's X is Y" ); |
45f047f8 |
69 | |
0e3e3555 |
70 | $db1->{x} = { yz => { bar => 30 } }; |
71 | ok( !exists $db1->{x}{xy}, "DB1: After reassignment of X, X->XY is gone" ); |
72 | is( $db2->{x}{xy}{foo}, 'y', "DB2: After reassignment of DB1 X, X->YZ is Y" ); |
2120a181 |
73 | |
0e3e3555 |
74 | cmp_bag( [ keys %{$db1->{x}} ], [qw( yz )], "DB1->X keys correct" ); |
75 | cmp_bag( [ keys %{$db2->{x}} ], [qw( xy )], "DB2->X keys correct" ); |
2120a181 |
76 | |
0e3e3555 |
77 | $db1->commit; |
2120a181 |
78 | |
79 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
80 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
81 | |
45f047f8 |
82 | cmp_bag( [ keys %{$db1->{x}} ], [qw( yz )], "DB1->X keys correct" ); |
0e3e3555 |
83 | cmp_bag( [ keys %{$db2->{x}} ], [qw( yz )], "DB2->X keys correct" ); |
45f047f8 |
84 | |
0e3e3555 |
85 | cmp_bag( [ keys %{$db1->{x}{yz}} ], [qw( bar )], "DB1->X->XY keys correct" ); |
86 | cmp_bag( [ keys %{$db2->{x}{yz}} ], [qw( bar )], "DB2->X->XY keys correct" ); |
87 | } |
45f047f8 |
88 | |
0e3e3555 |
89 | done_testing; |