Commit | Line | Data |
1cff45d7 |
1 | use strict; |
0e3e3555 |
2 | use warnings FATAL => 'all'; |
3 | |
4 | use Test::More; |
1cff45d7 |
5 | use Test::Exception; |
0e3e3555 |
6 | use t::common qw( new_dbm ); |
1cff45d7 |
7 | |
8 | use_ok( 'DBM::Deep' ); |
9 | |
0e3e3555 |
10 | my $dbm_factory = new_dbm( |
888453b9 |
11 | locking => 1, |
12 | autoflush => 1, |
13 | num_txns => 16, |
14 | ); |
0e3e3555 |
15 | while ( my $dbm_maker = $dbm_factory->() ) { |
16 | my $db1 = $dbm_maker->(); |
580e5ee2 |
17 | next unless $db1->supports( 'transactions' ); |
0e3e3555 |
18 | my $db2 = $dbm_maker->(); |
888453b9 |
19 | |
0e3e3555 |
20 | $db1->{foo} = 5; |
21 | $db1->{bar} = $db1->{foo}; |
45f047f8 |
22 | |
0e3e3555 |
23 | is( $db1->{foo}, 5, "Foo is still 5" ); |
24 | is( $db1->{bar}, 5, "Bar is now 5" ); |
1cff45d7 |
25 | |
0e3e3555 |
26 | $db1->{foo} = 6; |
1cff45d7 |
27 | |
0e3e3555 |
28 | is( $db1->{foo}, 6, "Foo is now 6" ); |
29 | is( $db1->{bar}, 5, "Bar is still 5" ); |
1cff45d7 |
30 | |
0e3e3555 |
31 | $db1->{foo} = [ 1 .. 3 ]; |
32 | $db1->{bar} = $db1->{foo}; |
1cff45d7 |
33 | |
0e3e3555 |
34 | is( $db1->{foo}[1], 2, "Foo[1] is still 2" ); |
35 | is( $db1->{bar}[1], 2, "Bar[1] is now 2" ); |
1cff45d7 |
36 | |
0e3e3555 |
37 | $db1->{foo}[3] = 42; |
1cff45d7 |
38 | |
0e3e3555 |
39 | is( $db1->{foo}[3], 42, "Foo[3] is now 42" ); |
40 | is( $db1->{bar}[3], 42, "Bar[3] is also 42" ); |
1cff45d7 |
41 | |
0e3e3555 |
42 | delete $db1->{foo}; |
43 | is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" ); |
1cff45d7 |
44 | |
0e3e3555 |
45 | $db1->{foo} = $db1->{bar}; |
46 | $db2->begin_work; |
888453b9 |
47 | |
0e3e3555 |
48 | delete $db2->{bar}; |
49 | delete $db2->{foo}; |
888453b9 |
50 | |
0e3e3555 |
51 | is( $db2->{bar}, undef, "It's deleted in the transaction" ); |
52 | is( $db1->{bar}[3], 42, "... but not in the main" ); |
888453b9 |
53 | |
0e3e3555 |
54 | $db2->rollback; |
888453b9 |
55 | |
0e3e3555 |
56 | # Why hasn't this failed!? Is it because stuff isn't getting deleted as |
57 | # expected? I need a test that walks the sectors |
58 | is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" ); |
59 | is( $db2->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" ); |
888453b9 |
60 | |
0e3e3555 |
61 | delete $db1->{foo}; |
888453b9 |
62 | |
0e3e3555 |
63 | is( $db1->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" ); |
64 | } |
888453b9 |
65 | |
0e3e3555 |
66 | done_testing; |
888453b9 |
67 | |
68 | __END__ |
888453b9 |
69 | $db2->begin_work; |
70 | |
888453b9 |
71 | delete $db2->{bar}; |
72 | |
888453b9 |
73 | $db2->commit; |
74 | |
0e3e3555 |
75 | ok( !exists $db1->{bar}, "After commit, bar is gone" ); |