2 use Test::More tests => 58;
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 $db2->{other_x} = 'bar';
62 is( $db2->{other_x}, 'bar', "DB2 set other_x within DB1's transaction, so DB2 can see it" );
63 is( $db1->{other_x}, 'foo', "Since other_x was modified after the transaction began, DB1 doesn't see the change." );
65 cmp_bag( [ keys %$db1 ], [qw( x other_x )], "DB1 keys correct" );
66 cmp_bag( [ keys %$db2 ], [qw( x other_x )], "DB2 keys correct" );
70 is( $db1->{x}, 'z', "After commit, DB1's X is Z" );
71 is( $db2->{x}, 'z', "After commit, DB2's X is Z" );
75 delete $db2->{other_x};
76 ok( !exists $db2->{other_x}, "DB2 deleted other_x in DB1's transaction, so it can't see it anymore" );
77 is( $db1->{other_x}, 'bar', "Since other_x was deleted after the transaction began, DB1 still sees it." );
79 cmp_bag( [ keys %$db1 ], [qw( x other_x )], "DB1 keys correct" );
80 cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
83 ok( !exists $db1->{x}, "DB1 deleted X in a transaction, so it can't see it anymore" );
84 is( $db2->{x}, 'z', "But, DB2 can still see it" );
87 local $TODO = "keys aren't working yet";
88 cmp_bag( [ keys %$db1 ], [qw( other_x )], "DB1 keys correct" );
90 cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
94 ok( !exists $db2->{other_x}, "It's still deleted for DB2" );
95 ok( !exists $db1->{other_x}, "And now DB1 sees the deletion" );
97 is( $db1->{x}, 'z', "The transaction was rolled back, so DB1 can see X now" );
98 is( $db2->{x}, 'z', "DB2 can still see it" );
100 cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
101 cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
106 ok( !exists $db1->{x}, "DB1 deleted X in a transaction, so it can't see it anymore" );
107 is( $db2->{x}, 'z', "But, DB2 can still see it" );
110 local $TODO = "keys aren't working yet";
111 cmp_bag( [ keys %$db1 ], [qw()], "DB1 keys correct" );
113 cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
117 ok( !exists $db1->{x}, "The transaction was committed, so DB1 still deleted X" );
118 ok( !exists $db2->{x}, "DB2 can now see the deletion of X" );
121 is( $db1->{foo}, 'bar', "Set foo to bar in DB1" );
122 is( $db2->{foo}, 'bar', "Set foo to bar in DB2" );
124 cmp_bag( [ keys %$db1 ], [qw( foo )], "DB1 keys correct" );
125 cmp_bag( [ keys %$db2 ], [qw( foo )], "DB2 keys correct" );
128 todo_skip 'Still need to work on clear()', 4;
132 %$db1 = (); # clear()
133 ok( !exists $db1->{foo}, "Cleared foo" );
134 is( $db2->{foo}, 'bar', "But in DB2, we can still see it" );
136 cmp_bag( [ keys %$db1 ], [qw()], "DB1 keys correct" );
137 cmp_bag( [ keys %$db2 ], [qw( foo )], "DB2 keys correct" );
141 is( $db1->{foo}, 'bar', "Rollback means 'foo' is still there" );
142 is( $db2->{foo}, 'bar', "Rollback means 'foo' is still there" );
144 cmp_bag( [ keys %$db1 ], [qw( foo )], "DB1 keys correct" );
145 cmp_bag( [ keys %$db2 ], [qw( foo )], "DB2 keys correct" );
150 is( $db1->{foo}, 'bar', 'After optimize, everything is ok' );
151 is( $db2->{foo}, 'bar', 'After optimize, everything is ok' );
153 cmp_bag( [ keys %$db1 ], [qw( foo )], "DB1 keys correct" );
154 cmp_bag( [ keys %$db2 ], [qw( foo )], "DB2 keys correct" );
158 cmp_ok( $db1->_fileobj->transaction_id, '==', 1, "Transaction ID has been reset after optimize" );
165 * Two transactions running at the same time
166 * Doing a clear on the head while a transaction is running
167 # More than just two keys
168 * Arrays (in particular, how is length handled?)