Commit | Line | Data |
2120a181 |
1 | use strict; |
45f047f8 |
2 | use Test::More tests => 41; |
2120a181 |
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, |
c57b19c6 |
13 | num_txns => 2, |
2120a181 |
14 | ); |
f1879fdc |
15 | seek $db1->_get_self->_engine->storage->{fh}, 0, 0; |
2120a181 |
16 | |
17 | my $db2 = DBM::Deep->new( |
18 | file => $filename, |
19 | locking => 1, |
20 | autoflush => 1, |
c57b19c6 |
21 | num_txns => 2, |
2120a181 |
22 | ); |
23 | |
45f047f8 |
24 | $db1->{x} = { xy => { foo => 'y' } }; |
25 | is( $db1->{x}{xy}{foo}, 'y', "Before transaction, DB1's X is Y" ); |
26 | is( $db2->{x}{xy}{foo}, 'y', "Before transaction, DB2's X is Y" ); |
2120a181 |
27 | |
28 | $db1->begin_work; |
29 | |
30 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
31 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
32 | |
45f047f8 |
33 | cmp_bag( [ keys %{$db1->{x}} ], [qw( xy )], "DB1->X keys correct" ); |
34 | cmp_bag( [ keys %{$db2->{x}} ], [qw( xy )], "DB2->X keys correct" ); |
2120a181 |
35 | |
45f047f8 |
36 | cmp_bag( [ keys %{$db1->{x}{xy}} ], [qw( foo )], "DB1->X->XY keys correct" ); |
37 | cmp_bag( [ keys %{$db2->{x}{xy}} ], [qw( foo )], "DB2->X->XY keys correct" ); |
2120a181 |
38 | |
45f047f8 |
39 | is( $db1->{x}{xy}{foo}, 'y', "After transaction, DB1's X is Y" ); |
40 | is( $db2->{x}{xy}{foo}, 'y', "After transaction, DB2's X is Y" ); |
2120a181 |
41 | |
45f047f8 |
42 | $db1->{x} = { yz => { bar => 30 } }; |
43 | ok( !exists $db1->{x}{xy}, "DB1: After reassignment of X, X->XY is gone" ); |
44 | is( $db2->{x}{xy}{foo}, 'y', "DB2: After reassignment of DB1 X, X is Y" ); |
45 | |
46 | cmp_bag( [ keys %{$db1->{x}} ], [qw( yz )], "DB1->X keys correct" ); |
47 | cmp_bag( [ keys %{$db2->{x}} ], [qw( xy )], "DB2->X keys correct" ); |
2120a181 |
48 | |
49 | $db1->rollback; |
9c87a079 |
50 | |
2120a181 |
51 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
52 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
53 | |
45f047f8 |
54 | cmp_bag( [ keys %{$db1->{x}} ], [qw( xy )], "DB1->X keys correct" ); |
55 | cmp_bag( [ keys %{$db2->{x}} ], [qw( xy )], "DB2->X keys correct" ); |
56 | |
57 | cmp_bag( [ keys %{$db1->{x}{xy}} ], [qw( foo )], "DB1->X->XY keys correct" ); |
58 | cmp_bag( [ keys %{$db2->{x}{xy}} ], [qw( foo )], "DB2->X->XY keys correct" ); |
2120a181 |
59 | |
45f047f8 |
60 | is( $db1->{x}{xy}{foo}, 'y', "Before transaction, DB1's X is Y" ); |
61 | is( $db2->{x}{xy}{foo}, 'y', "Before transaction, DB2's X is Y" ); |
2120a181 |
62 | |
63 | $db1->begin_work; |
64 | |
65 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
66 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
67 | |
45f047f8 |
68 | cmp_bag( [ keys %{$db1->{x}} ], [qw( xy )], "DB1->X keys correct" ); |
69 | cmp_bag( [ keys %{$db2->{x}} ], [qw( xy )], "DB2->X keys correct" ); |
70 | |
71 | cmp_bag( [ keys %{$db1->{x}{xy}} ], [qw( foo )], "DB1->X->XY keys correct" ); |
72 | cmp_bag( [ keys %{$db2->{x}{xy}} ], [qw( foo )], "DB2->X->XY keys correct" ); |
2120a181 |
73 | |
45f047f8 |
74 | is( $db1->{x}{xy}{foo}, 'y', "After transaction, DB1's X is Y" ); |
75 | is( $db2->{x}{xy}{foo}, 'y', "After transaction, DB2's X is Y" ); |
2120a181 |
76 | |
45f047f8 |
77 | $db1->{x} = { yz => { bar => 30 } }; |
78 | ok( !exists $db1->{x}{xy}, "DB1: After reassignment of X, X->XY is gone" ); |
79 | is( $db2->{x}{xy}{foo}, 'y', "DB2: After reassignment of DB1 X, X->YZ is Y" ); |
2120a181 |
80 | |
45f047f8 |
81 | cmp_bag( [ keys %{$db1->{x}} ], [qw( yz )], "DB1->X keys correct" ); |
82 | cmp_bag( [ keys %{$db2->{x}} ], [qw( xy )], "DB2->X keys correct" ); |
2120a181 |
83 | |
84 | $db1->commit; |
85 | |
86 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
87 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
88 | |
45f047f8 |
89 | cmp_bag( [ keys %{$db1->{x}} ], [qw( yz )], "DB1->X keys correct" ); |
90 | cmp_bag( [ keys %{$db2->{x}} ], [qw( yz )], "DB2->X keys correct" ); |
91 | |
92 | cmp_bag( [ keys %{$db1->{x}{yz}} ], [qw( bar )], "DB1->X->XY keys correct" ); |
93 | cmp_bag( [ keys %{$db2->{x}{yz}} ], [qw( bar )], "DB2->X->XY keys correct" ); |
94 | |
f1879fdc |
95 | $db1->_get_self->_engine->storage->close( $db1->_get_self ); |
96 | $db2->_get_self->_engine->storage->close( $db2->_get_self ); |