All tests pass except for the transaction tests under MySQL. InnoDB sucks
[dbsrgits/DBM-Deep.git] / t / 42_transaction_indexsector.t
CommitLineData
2120a181 1use strict;
0e3e3555 2use warnings FATAL => 'all';
3
4use Test::More;
2120a181 5use Test::Deep;
0e3e3555 6use t::common qw( new_dbm );
2120a181 7
8use_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
4f034d8f 17if ( $ENV{NO_TEST_TRANSACTIONS} ) {
18 done_testing;
19 exit;
20}
21
2120a181 22{
0e3e3555 23 my $dbm_factory = new_dbm(
2120a181 24 locking => 1,
25 autoflush => 1,
26 num_txns => 16,
27 );
0e3e3555 28 while ( my $dbm_maker = $dbm_factory->() ) {
29 my $db1 = $dbm_maker->();
30 my $db2 = $dbm_maker->();
2120a181 31
0e3e3555 32 $db1->{x} = 'y';
33 is( $db1->{x}, 'y', "Before transaction, DB1's X is Y" );
34 is( $db2->{x}, 'y', "Before transaction, DB2's X is Y" );
2120a181 35
0e3e3555 36 $db1->begin_work;
2120a181 37
0e3e3555 38 cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
39 cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
2120a181 40
0e3e3555 41 # Add enough keys to force a reindex
42 $db1->{"K$_"} = "V$_" for 1 .. 16;
2120a181 43
0e3e3555 44 cmp_bag( [ keys %$db1 ], ['x', (map { "K$_" } 1 .. 16)], "DB1 keys correct" );
45 cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
2120a181 46
0e3e3555 47 $db1->rollback;
2120a181 48
0e3e3555 49 cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
50 cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
2120a181 51
0e3e3555 52 ok( !exists $db1->{"K$_"}, "DB1: Key K$_ doesn't exist" ) for 1 .. 16;
53 ok( !exists $db2->{"K$_"}, "DB2: Key K$_ doesn't exist" ) for 1 .. 16;
54 }
2120a181 55}
56
57{
0e3e3555 58 my $dbm_factory = new_dbm(
2120a181 59 locking => 1,
60 autoflush => 1,
61 num_txns => 16,
62 );
0e3e3555 63 while ( my $dbm_maker = $dbm_factory->() ) {
64 my $db1 = $dbm_maker->();
65 my $db2 = $dbm_maker->();
2120a181 66
0e3e3555 67 $db1->{x} = 'y';
68 is( $db1->{x}, 'y', "Before transaction, DB1's X is Y" );
69 is( $db2->{x}, 'y', "Before transaction, DB2's X is Y" );
2120a181 70
0e3e3555 71 $db1->begin_work;
2120a181 72
0e3e3555 73 cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
74 cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
2120a181 75
0e3e3555 76 # Add enough keys to force a reindex
77 $db1->{"K$_"} = "V$_" for 1 .. 16;
2120a181 78
0e3e3555 79 cmp_bag( [ keys %$db1 ], ['x', (map { "K$_" } 1 .. 16)], "DB1 keys correct" );
80 cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
2120a181 81
0e3e3555 82 $db1->commit;
2120a181 83
0e3e3555 84 cmp_bag( [ keys %$db1 ], ['x', (map { "K$_" } 1 .. 16)], "DB1 keys correct" );
85 cmp_bag( [ keys %$db2 ], ['x', (map { "K$_" } 1 .. 16)], "DB2 keys correct" );
2120a181 86
0e3e3555 87 ok( exists $db1->{"K$_"}, "DB1: Key K$_ doesn't exist" ) for 1 .. 16;
88 ok( exists $db2->{"K$_"}, "DB2: Key K$_ doesn't exist" ) for 1 .. 16;
89 }
2120a181 90}
0e3e3555 91
92done_testing;