Added files and deps for SQL backend. THIS STILL NEEDS LOTS OF WORK AND WILL LIKELY...
[dbsrgits/DBM-Deep.git] / t / 41_transaction_multilevel.t
CommitLineData
2120a181 1use strict;
45f047f8 2use Test::More tests => 41;
2120a181 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,
c57b19c6 13 num_txns => 2,
2120a181 14);
f1879fdc 15seek $db1->_get_self->_engine->storage->{fh}, 0, 0;
2120a181 16
17my $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' } };
25is( $db1->{x}{xy}{foo}, 'y', "Before transaction, DB1's X is Y" );
26is( $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 51cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
52cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
53
45f047f8 54cmp_bag( [ keys %{$db1->{x}} ], [qw( xy )], "DB1->X keys correct" );
55cmp_bag( [ keys %{$db2->{x}} ], [qw( xy )], "DB2->X keys correct" );
56
57cmp_bag( [ keys %{$db1->{x}{xy}} ], [qw( foo )], "DB1->X->XY keys correct" );
58cmp_bag( [ keys %{$db2->{x}{xy}} ], [qw( foo )], "DB2->X->XY keys correct" );
2120a181 59
45f047f8 60is( $db1->{x}{xy}{foo}, 'y', "Before transaction, DB1's X is Y" );
61is( $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
86cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
87cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
88
45f047f8 89cmp_bag( [ keys %{$db1->{x}} ], [qw( yz )], "DB1->X keys correct" );
90cmp_bag( [ keys %{$db2->{x}} ], [qw( yz )], "DB2->X keys correct" );
91
92cmp_bag( [ keys %{$db1->{x}{yz}} ], [qw( bar )], "DB1->X->XY keys correct" );
93cmp_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 );