Commit | Line | Data |
2120a181 |
1 | use strict; |
0e3e3555 |
2 | use warnings FATAL => 'all'; |
3 | |
4 | use Test::More; |
2120a181 |
5 | use Test::Deep; |
0e3e3555 |
6 | use t::common qw( new_dbm ); |
2120a181 |
7 | |
8 | use_ok( 'DBM::Deep' ); |
9 | |
10 | # This testfile is in sections because the goal is to verify the behavior |
11 | # when a reindex occurs during an active transaction, both as a result of the |
12 | # transaction's actions as well as the result of the HEAD's actions. In order |
13 | # to keep this test quick, it's easier to restart and hit the known |
14 | # reindexing at 17 keys vs. attempting to hit the second-level reindex which |
15 | # can occur as early as 18 keys and as late as 4097 (256*16+1) keys. |
16 | |
17 | { |
0e3e3555 |
18 | my $dbm_factory = new_dbm( |
2120a181 |
19 | locking => 1, |
20 | autoflush => 1, |
21 | num_txns => 16, |
22 | ); |
0e3e3555 |
23 | while ( my $dbm_maker = $dbm_factory->() ) { |
24 | my $db1 = $dbm_maker->(); |
580e5ee2 |
25 | next unless $db1->supports( 'transactions' ); |
0e3e3555 |
26 | my $db2 = $dbm_maker->(); |
2120a181 |
27 | |
0e3e3555 |
28 | $db1->{x} = 'y'; |
29 | is( $db1->{x}, 'y', "Before transaction, DB1's X is Y" ); |
30 | is( $db2->{x}, 'y', "Before transaction, DB2's X is Y" ); |
2120a181 |
31 | |
0e3e3555 |
32 | $db1->begin_work; |
2120a181 |
33 | |
0e3e3555 |
34 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
35 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
2120a181 |
36 | |
0e3e3555 |
37 | # Add enough keys to force a reindex |
38 | $db1->{"K$_"} = "V$_" for 1 .. 16; |
2120a181 |
39 | |
0e3e3555 |
40 | cmp_bag( [ keys %$db1 ], ['x', (map { "K$_" } 1 .. 16)], "DB1 keys correct" ); |
41 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
2120a181 |
42 | |
0e3e3555 |
43 | $db1->rollback; |
2120a181 |
44 | |
0e3e3555 |
45 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
46 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
2120a181 |
47 | |
0e3e3555 |
48 | ok( !exists $db1->{"K$_"}, "DB1: Key K$_ doesn't exist" ) for 1 .. 16; |
49 | ok( !exists $db2->{"K$_"}, "DB2: Key K$_ doesn't exist" ) for 1 .. 16; |
50 | } |
2120a181 |
51 | } |
52 | |
53 | { |
0e3e3555 |
54 | my $dbm_factory = new_dbm( |
2120a181 |
55 | locking => 1, |
56 | autoflush => 1, |
57 | num_txns => 16, |
58 | ); |
0e3e3555 |
59 | while ( my $dbm_maker = $dbm_factory->() ) { |
60 | my $db1 = $dbm_maker->(); |
580e5ee2 |
61 | next unless $db1->supports( 'transactions' ); |
0e3e3555 |
62 | my $db2 = $dbm_maker->(); |
2120a181 |
63 | |
0e3e3555 |
64 | $db1->{x} = 'y'; |
65 | is( $db1->{x}, 'y', "Before transaction, DB1's X is Y" ); |
66 | is( $db2->{x}, 'y', "Before transaction, DB2's X is Y" ); |
2120a181 |
67 | |
0e3e3555 |
68 | $db1->begin_work; |
2120a181 |
69 | |
0e3e3555 |
70 | cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" ); |
71 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
2120a181 |
72 | |
0e3e3555 |
73 | # Add enough keys to force a reindex |
74 | $db1->{"K$_"} = "V$_" for 1 .. 16; |
2120a181 |
75 | |
0e3e3555 |
76 | cmp_bag( [ keys %$db1 ], ['x', (map { "K$_" } 1 .. 16)], "DB1 keys correct" ); |
77 | cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" ); |
2120a181 |
78 | |
0e3e3555 |
79 | $db1->commit; |
2120a181 |
80 | |
0e3e3555 |
81 | cmp_bag( [ keys %$db1 ], ['x', (map { "K$_" } 1 .. 16)], "DB1 keys correct" ); |
82 | cmp_bag( [ keys %$db2 ], ['x', (map { "K$_" } 1 .. 16)], "DB2 keys correct" ); |
2120a181 |
83 | |
0e3e3555 |
84 | ok( exists $db1->{"K$_"}, "DB1: Key K$_ doesn't exist" ) for 1 .. 16; |
85 | ok( exists $db2->{"K$_"}, "DB2: Key K$_ doesn't exist" ) for 1 .. 16; |
86 | } |
2120a181 |
87 | } |
0e3e3555 |
88 | |
89 | done_testing; |