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