read_txn_slots has been moved into the FileHeader sector.
[dbsrgits/DBM-Deep.git] / t / 03_bighash.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
535203b1 5use Test::More;
6
7plan skip_all => "You must set \$ENV{LONG_TESTS} to run the long tests"
8 unless $ENV{LONG_TESTS};
9
86867f3a 10use Test::Deep;
fde3db1a 11use t::common qw( new_fh );
ffed8b01 12
2120a181 13plan tests => 9;
535203b1 14
40963fba 15my $locked = 0;
16
ffed8b01 17use_ok( 'DBM::Deep' );
18
eff6a245 19diag "This test can take up to a minute to run. Please be patient.";
20
fde3db1a 21my ($fh, $filename) = new_fh();
ffed8b01 22my $db = DBM::Deep->new(
2a81bf9e 23 file => $filename,
86867f3a 24 type => DBM::Deep->TYPE_HASH,
ffed8b01 25);
ffed8b01 26
40963fba 27$db->lock_exclusive if $locked;
68e37b51 28
2120a181 29$db->{foo} = {};
30my $foo = $db->{foo};
31
ffed8b01 32##
33# put/get many keys
34##
a4e2db58 35my $max_keys = 4000;
36
00d9bd0b 37warn localtime(time) . ": before put\n";
ffed8b01 38for ( 0 .. $max_keys ) {
2120a181 39 $foo->put( "hello $_" => "there " . $_ * 2 );
ffed8b01 40}
00d9bd0b 41warn localtime(time) . ": after put\n";
ffed8b01 42
30029562 43my $count = -1;
ffed8b01 44for ( 0 .. $max_keys ) {
30029562 45 $count = $_;
2120a181 46 unless ( $foo->get( "hello $_" ) eq "there " . $_ * 2 ) {
30029562 47 last;
48 };
ffed8b01 49}
30029562 50is( $count, $max_keys, "We read $count keys" );
00d9bd0b 51warn localtime(time) . ": after read\n";
bee3661a 52
2120a181 53my @keys = sort keys %$foo;
00d9bd0b 54warn localtime(time) . ": after keys\n";
86867f3a 55cmp_ok( scalar(@keys), '==', $max_keys + 1, "Number of keys is correct" );
56my @control = sort map { "hello $_" } 0 .. $max_keys;
57cmp_deeply( \@keys, \@control, "Correct keys are there" );
58
40963fba 59warn localtime(time) . ": before exists\n";
2120a181 60ok( !exists $foo->{does_not_exist}, "EXISTS works on large hashes for non-existent keys" );
61is( $foo->{does_not_exist}, undef, "autovivification works on large hashes" );
62ok( exists $foo->{does_not_exist}, "EXISTS works on large hashes for newly-existent keys" );
63cmp_ok( scalar(keys %$foo), '==', $max_keys + 2, "Number of keys after autovivify is correct" );
64
00d9bd0b 65warn localtime(time) . ": before clear\n";
bee3661a 66$db->clear;
00d9bd0b 67warn localtime(time) . ": after clear\n";
bee3661a 68cmp_ok( scalar(keys %$db), '==', 0, "Number of keys after clear() is correct" );
68e37b51 69
40963fba 70$db->unlock if $locked;