Commit | Line | Data |
ffed8b01 |
1 | use strict; |
0e3e3555 |
2 | use warnings FATAL => 'all'; |
3 | |
535203b1 |
4 | use Test::More; |
5 | |
6 | plan skip_all => "You must set \$ENV{LONG_TESTS} to run the long tests" |
7 | unless $ENV{LONG_TESTS}; |
8 | |
86867f3a |
9 | use Test::Deep; |
0e3e3555 |
10 | use t::common qw( new_dbm ); |
535203b1 |
11 | |
ffed8b01 |
12 | use_ok( 'DBM::Deep' ); |
13 | |
0e3e3555 |
14 | diag "This test can take up to several minutes to run. Please be patient."; |
15 | |
16 | my $dbm_factory = new_dbm( type => DBM::Deep->TYPE_HASH ); |
17 | while ( my $dbm_maker = $dbm_factory->() ) { |
18 | my $db = $dbm_maker->(); |
19 | |
20 | $db->{foo} = {}; |
21 | my $foo = $db->{foo}; |
22 | |
23 | ## |
24 | # put/get many keys |
25 | ## |
26 | my $max_keys = 4000; |
27 | |
28 | for ( 0 .. $max_keys ) { |
29 | $foo->put( "hello $_" => "there " . $_ * 2 ); |
30 | } |
31 | |
32 | my $count = -1; |
33 | for ( 0 .. $max_keys ) { |
34 | $count = $_; |
35 | unless ( $foo->get( "hello $_" ) eq "there " . $_ * 2 ) { |
36 | last; |
37 | }; |
38 | } |
39 | is( $count, $max_keys, "We read $count keys" ); |
40 | |
41 | my @keys = sort keys %$foo; |
42 | cmp_ok( scalar(@keys), '==', $max_keys + 1, "Number of keys is correct" ); |
43 | my @control = sort map { "hello $_" } 0 .. $max_keys; |
44 | cmp_deeply( \@keys, \@control, "Correct keys are there" ); |
45 | |
46 | ok( !exists $foo->{does_not_exist}, "EXISTS works on large hashes for non-existent keys" ); |
47 | is( $foo->{does_not_exist}, undef, "autovivification works on large hashes" ); |
48 | ok( exists $foo->{does_not_exist}, "EXISTS works on large hashes for newly-existent keys" ); |
49 | cmp_ok( scalar(keys %$foo), '==', $max_keys + 2, "Number of keys after autovivify is correct" ); |
50 | |
51 | $db->clear; |
52 | cmp_ok( scalar(keys %$db), '==', 0, "Number of keys after clear() is correct" ); |
ffed8b01 |
53 | } |
2120a181 |
54 | |
0e3e3555 |
55 | done_testing; |