2 use Test::More tests => 56;
4 use t::common qw( new_fh );
8 my ($fh, $filename) = new_fh();
9 my $db1 = DBM::Deep->new(
15 my $db2 = DBM::Deep->new(
22 is( $db1->{x}, 'y', "Before transaction, DB1's X is Y" );
23 is( $db2->{x}, 'y', "Before transaction, DB2's X is Y" );
27 is( $db1->{x}, 'y', "DB1 transaction started, no actions - DB1's X is Y" );
28 is( $db2->{x}, 'y', "DB1 transaction started, no actions - DB2's X is Y" );
31 is( $db1->{x}, 'z', "Within DB1 transaction, DB1's X is Z" );
32 is( $db2->{x}, 'y', "Within DB1 transaction, DB2's X is still Y" );
34 $db2->{other_x} = 'foo';
35 is( $db2->{other_x}, 'foo', "DB2 set other_x within DB1's transaction, so DB2 can see it" );
36 is( $db1->{other_x}, undef, "Since other_x was added after the transaction began, DB1 doesn't see it." );
39 local $TODO = "keys aren't working yet";
40 cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
42 cmp_bag( [ keys %$db2 ], [qw( x other_x )], "DB2 keys correct" );
46 is( $db1->{x}, 'y', "After rollback, DB1's X is Y" );
47 is( $db2->{x}, 'y', "After rollback, DB2's X is Y" );
49 is( $db1->{other_x}, 'foo', "After DB1 transaction is over, DB1 can see other_x" );
50 is( $db2->{other_x}, 'foo', "After DB1 transaction is over, DB2 can still see other_x" );
54 is( $db1->{x}, 'y', "DB1 transaction started, no actions - DB1's X is Y" );
55 is( $db2->{x}, 'y', "DB1 transaction started, no actions - DB2's X is Y" );
58 is( $db1->{x}, 'z', "Within DB1 transaction, DB1's X is Z" );
59 is( $db2->{x}, 'y', "Within DB1 transaction, DB2's X is still Y" );
61 cmp_bag( [ keys %$db1 ], [qw( x other_x )], "DB1 keys correct" );
62 cmp_bag( [ keys %$db2 ], [qw( x other_x )], "DB2 keys correct" );
66 is( $db1->{x}, 'z', "After commit, DB1's X is Z" );
67 is( $db2->{x}, 'z', "After commit, DB2's X is Z" );
71 delete $db2->{other_x};
72 ok( !exists $db2->{other_x}, "DB2 deleted other_x in DB1's transaction, so it can't see it anymore" );
73 is( $db1->{other_x}, 'foo', "Since other_x was deleted after the transaction began, DB1 still sees it." );
75 cmp_bag( [ keys %$db1 ], [qw( x other_x )], "DB1 keys correct" );
76 cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
79 ok( !exists $db1->{x}, "DB1 deleted X in a transaction, so it can't see it anymore" );
80 is( $db2->{x}, 'z', "But, DB2 can still see it" );
83 local $TODO = "keys aren't working yet";
84 cmp_bag( [ keys %$db1 ], [qw( other_x )], "DB1 keys correct" );
86 cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
90 ok( !exists $db2->{other_x}, "It's still deleted for DB2" );
91 ok( !exists $db1->{other_x}, "And now DB1 sees the deletion" );
93 is( $db1->{x}, 'z', "The transaction was rolled back, so DB1 can see X now" );
94 is( $db2->{x}, 'z', "DB2 can still see it" );
96 cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
97 cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
102 ok( !exists $db1->{x}, "DB1 deleted X in a transaction, so it can't see it anymore" );
103 is( $db2->{x}, 'z', "But, DB2 can still see it" );
106 local $TODO = "keys aren't working yet";
107 cmp_bag( [ keys %$db1 ], [qw()], "DB1 keys correct" );
109 cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
113 ok( !exists $db1->{x}, "The transaction was committed, so DB1 still deleted X" );
114 ok( !exists $db2->{x}, "DB2 can now see the deletion of X" );
117 is( $db1->{foo}, 'bar', "Set foo to bar in DB1" );
118 is( $db2->{foo}, 'bar', "Set foo to bar in DB2" );
120 cmp_bag( [ keys %$db1 ], [qw( foo )], "DB1 keys correct" );
121 cmp_bag( [ keys %$db2 ], [qw( foo )], "DB2 keys correct" );
124 todo_skip 'Still need to work on clear()', 4;
128 %$db1 = (); # clear()
129 ok( !exists $db1->{foo}, "Cleared foo" );
130 is( $db2->{foo}, 'bar', "But in DB2, we can still see it" );
132 cmp_bag( [ keys %$db1 ], [qw()], "DB1 keys correct" );
133 cmp_bag( [ keys %$db2 ], [qw( foo )], "DB2 keys correct" );
137 is( $db1->{foo}, 'bar', "Rollback means 'foo' is still there" );
138 is( $db2->{foo}, 'bar', "Rollback means 'foo' is still there" );
140 cmp_bag( [ keys %$db1 ], [qw( foo )], "DB1 keys correct" );
141 cmp_bag( [ keys %$db2 ], [qw( foo )], "DB2 keys correct" );
146 is( $db1->{foo}, 'bar', 'After optimize, everything is ok' );
147 is( $db2->{foo}, 'bar', 'After optimize, everything is ok' );
149 cmp_bag( [ keys %$db1 ], [qw( foo )], "DB1 keys correct" );
150 cmp_bag( [ keys %$db2 ], [qw( foo )], "DB2 keys correct" );
154 cmp_ok( $db1->_fileobj->transaction_id, '==', 1, "Transaction ID has been reset after optimize" );
161 * Two transactions running at the same time
162 * Doing a clear on the head while a transaction is running
163 # More than just two keys
164 * Arrays (in particular, how is length handled?)