2 use Test::More tests => 37;
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." );
40 is( $db1->{x}, 'y', "After rollback, DB1's X is Y" );
41 is( $db2->{x}, 'y', "After rollback, DB2's X is Y" );
43 is( $db1->{other_x}, 'foo', "After DB1 transaction is over, DB1 can see other_x" );
44 is( $db2->{other_x}, 'foo', "After DB1 transaction is over, DB2 can still see other_x" );
48 is( $db1->{x}, 'y', "DB1 transaction started, no actions - DB1's X is Y" );
49 is( $db2->{x}, 'y', "DB1 transaction started, no actions - DB2's X is Y" );
52 is( $db1->{x}, 'z', "Within DB1 transaction, DB1's X is Z" );
53 is( $db2->{x}, 'y', "Within DB1 transaction, DB2's X is still Y" );
57 is( $db1->{x}, 'z', "After commit, DB1's X is Z" );
58 is( $db2->{x}, 'z', "After commit, DB2's X is Z" );
62 delete $db2->{other_x};
63 ok( !exists $db2->{other_x}, "DB2 deleted other_x in DB1's transaction, so it can't see it anymore" );
64 is( $db1->{other_x}, 'foo', "Since other_x was deleted after the transaction began, DB1 still sees it." );
67 ok( !exists $db1->{x}, "DB1 deleted X in a transaction, so it can't see it anymore" );
68 is( $db2->{x}, 'z', "But, DB2 can still see it" );
72 is( $db2->{other_x}, undef, "It's still deleted for DB2" );
73 is( $db1->{other_x}, undef, "And now DB1 sees the deletion" );
75 is( $db1->{x}, 'z', "The transaction was rolled back, so DB1 can see X now" );
76 is( $db2->{x}, 'z', "DB2 can still see it" );
81 ok( !exists $db1->{x}, "DB1 deleted X in a transaction, so it can't see it anymore" );
82 is( $db2->{x}, 'z', "But, DB2 can still see it" );
86 is( $db1->{x}, undef, "The transaction was committed, so DB1 still deleted X" );
87 is( $db2->{x}, undef, "DB2 can now see the deletion of X" );
90 is( $db1->{foo}, 'bar', "Set foo to bar in DB1" );
91 is( $db2->{foo}, 'bar', "Set foo to bar in DB2" );
94 local $TODO = 'Still need to work on clear()';
99 ok( !exists $db1->{foo}, "Cleared foo" );
100 is( $db2->{foo}, 'bar', "But in DB2, we can still see it" );
104 is( $db1->{foo}, 'bar', "Rollback means 'foo' is still there" );
105 is( $db2->{foo}, 'bar', "Rollback means 'foo' is still there" );