Array tests now pass
[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
ffed8b01 15use_ok( 'DBM::Deep' );
16
eff6a245 17diag "This test can take up to a minute to run. Please be patient.";
18
fde3db1a 19my ($fh, $filename) = new_fh();
ffed8b01 20my $db = DBM::Deep->new(
2a81bf9e 21 file => $filename,
86867f3a 22 type => DBM::Deep->TYPE_HASH,
ffed8b01 23);
ffed8b01 24
68e37b51 25#$db->lock_exclusive;
26
2120a181 27$db->{foo} = {};
28my $foo = $db->{foo};
29
ffed8b01 30##
31# put/get many keys
32##
a4e2db58 33my $max_keys = 4000;
34
00d9bd0b 35warn localtime(time) . ": before put\n";
ffed8b01 36for ( 0 .. $max_keys ) {
2120a181 37 $foo->put( "hello $_" => "there " . $_ * 2 );
ffed8b01 38}
00d9bd0b 39warn localtime(time) . ": after put\n";
ffed8b01 40
30029562 41my $count = -1;
ffed8b01 42for ( 0 .. $max_keys ) {
30029562 43 $count = $_;
2120a181 44 unless ( $foo->get( "hello $_" ) eq "there " . $_ * 2 ) {
30029562 45 last;
46 };
ffed8b01 47}
30029562 48is( $count, $max_keys, "We read $count keys" );
00d9bd0b 49warn localtime(time) . ": after read\n";
bee3661a 50
2120a181 51my @keys = sort keys %$foo;
00d9bd0b 52warn localtime(time) . ": after keys\n";
86867f3a 53cmp_ok( scalar(@keys), '==', $max_keys + 1, "Number of keys is correct" );
54my @control = sort map { "hello $_" } 0 .. $max_keys;
55cmp_deeply( \@keys, \@control, "Correct keys are there" );
56
2120a181 57ok( !exists $foo->{does_not_exist}, "EXISTS works on large hashes for non-existent keys" );
58is( $foo->{does_not_exist}, undef, "autovivification works on large hashes" );
59ok( exists $foo->{does_not_exist}, "EXISTS works on large hashes for newly-existent keys" );
60cmp_ok( scalar(keys %$foo), '==', $max_keys + 2, "Number of keys after autovivify is correct" );
61
00d9bd0b 62warn localtime(time) . ": before clear\n";
bee3661a 63$db->clear;
00d9bd0b 64warn localtime(time) . ": after clear\n";
bee3661a 65cmp_ok( scalar(keys %$db), '==', 0, "Number of keys after clear() is correct" );
68e37b51 66
67#$db->unlock;