Merged with master and am ready to merge back
[dbsrgits/DBM-Deep.git] / t / 42_transaction_indexsector.t
index 99433cb..39274fc 100644 (file)
@@ -1,7 +1,9 @@
 use strict;
-use Test::More tests => 81;
+use warnings FATAL => 'all';
+
+use Test::More;
 use Test::Deep;
-use t::common qw( new_fh );
+use t::common qw( new_dbm );
 
 use_ok( 'DBM::Deep' );
 
@@ -13,81 +15,75 @@ use_ok( 'DBM::Deep' );
 # can occur as early as 18 keys and as late as 4097 (256*16+1) keys.
 
 {
-    my ($fh, $filename) = new_fh();
-    my $db1 = DBM::Deep->new(
-        file => $filename,
-        locking => 1,
-        autoflush => 1,
-        num_txns  => 16,
-    );
-
-    my $db2 = DBM::Deep->new(
-        file => $filename,
+    my $dbm_factory = new_dbm(
         locking => 1,
         autoflush => 1,
         num_txns  => 16,
     );
+    while ( my $dbm_maker = $dbm_factory->() ) {
+        my $db1 = $dbm_maker->();
+        next unless $db1->supports( 'transactions' );
+        my $db2 = $dbm_maker->();
 
-    $db1->{x} = 'y';
-    is( $db1->{x}, 'y', "Before transaction, DB1's X is Y" );
-    is( $db2->{x}, 'y', "Before transaction, DB2's X is Y" );
+        $db1->{x} = 'y';
+        is( $db1->{x}, 'y', "Before transaction, DB1's X is Y" );
+        is( $db2->{x}, 'y', "Before transaction, DB2's X is Y" );
 
-    $db1->begin_work;
+        $db1->begin_work;
 
-        cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
-        cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
+            cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
+            cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
 
-        # Add enough keys to force a reindex
-        $db1->{"K$_"} = "V$_" for 1 .. 16;
+            # Add enough keys to force a reindex
+            $db1->{"K$_"} = "V$_" for 1 .. 16;
 
-        cmp_bag( [ keys %$db1 ], ['x', (map { "K$_" } 1 .. 16)], "DB1 keys correct" );
-        cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
+            cmp_bag( [ keys %$db1 ], ['x', (map { "K$_" } 1 .. 16)], "DB1 keys correct" );
+            cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
 
-    $db1->rollback;
+        $db1->rollback;
 
-    cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
-    cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
+        cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
+        cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
 
-    ok( !exists $db1->{"K$_"}, "DB1: Key K$_ doesn't exist" ) for 1 .. 16;
-    ok( !exists $db2->{"K$_"}, "DB2: Key K$_ doesn't exist" ) for 1 .. 16;
+        ok( !exists $db1->{"K$_"}, "DB1: Key K$_ doesn't exist" ) for 1 .. 16;
+        ok( !exists $db2->{"K$_"}, "DB2: Key K$_ doesn't exist" ) for 1 .. 16;
+    }
 }
 
 {
-    my ($fh, $filename) = new_fh();
-    my $db1 = DBM::Deep->new(
-        file => $filename,
+    my $dbm_factory = new_dbm(
         locking => 1,
         autoflush => 1,
         num_txns  => 16,
     );
+    while ( my $dbm_maker = $dbm_factory->() ) {
+        my $db1 = $dbm_maker->();
+        next unless $db1->supports( 'transactions' );
+        my $db2 = $dbm_maker->();
 
-    my $db2 = DBM::Deep->new(
-        file => $filename,
-        locking => 1,
-        autoflush => 1,
-        num_txns  => 16,
-    );
+        $db1->{x} = 'y';
+        is( $db1->{x}, 'y', "Before transaction, DB1's X is Y" );
+        is( $db2->{x}, 'y', "Before transaction, DB2's X is Y" );
 
-    $db1->{x} = 'y';
-    is( $db1->{x}, 'y', "Before transaction, DB1's X is Y" );
-    is( $db2->{x}, 'y', "Before transaction, DB2's X is Y" );
+        $db1->begin_work;
 
-    $db1->begin_work;
+            cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
+            cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
 
-        cmp_bag( [ keys %$db1 ], [qw( x )], "DB1 keys correct" );
-        cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
+            # Add enough keys to force a reindex
+            $db1->{"K$_"} = "V$_" for 1 .. 16;
 
-        # Add enough keys to force a reindex
-        $db1->{"K$_"} = "V$_" for 1 .. 16;
+            cmp_bag( [ keys %$db1 ], ['x', (map { "K$_" } 1 .. 16)], "DB1 keys correct" );
+            cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
 
-        cmp_bag( [ keys %$db1 ], ['x', (map { "K$_" } 1 .. 16)], "DB1 keys correct" );
-        cmp_bag( [ keys %$db2 ], [qw( x )], "DB2 keys correct" );
-
-    $db1->commit;
+        $db1->commit;
 
-    cmp_bag( [ keys %$db1 ], ['x', (map { "K$_" } 1 .. 16)], "DB1 keys correct" );
-    cmp_bag( [ keys %$db2 ], ['x', (map { "K$_" } 1 .. 16)], "DB2 keys correct" );
+        cmp_bag( [ keys %$db1 ], ['x', (map { "K$_" } 1 .. 16)], "DB1 keys correct" );
+        cmp_bag( [ keys %$db2 ], ['x', (map { "K$_" } 1 .. 16)], "DB2 keys correct" );
 
-    ok( exists $db1->{"K$_"}, "DB1: Key K$_ doesn't exist" ) for 1 .. 16;
-    ok( exists $db2->{"K$_"}, "DB2: Key K$_ doesn't exist" ) for 1 .. 16;
+        ok( exists $db1->{"K$_"}, "DB1: Key K$_ doesn't exist" ) for 1 .. 16;
+        ok( exists $db2->{"K$_"}, "DB2: Key K$_ doesn't exist" ) for 1 .. 16;
+    }
 }
+
+done_testing;