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