Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
535203b1 |
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 | |
86867f3a |
10 | use Test::Deep; |
fde3db1a |
11 | use t::common qw( new_fh ); |
ffed8b01 |
12 | |
9a63e1f2 |
13 | plan tests => 9; |
535203b1 |
14 | |
ffed8b01 |
15 | use_ok( 'DBM::Deep' ); |
16 | |
eff6a245 |
17 | diag "This test can take up to a minute to run. Please be patient."; |
18 | |
fde3db1a |
19 | my ($fh, $filename) = new_fh(); |
ffed8b01 |
20 | my $db = DBM::Deep->new( |
2a81bf9e |
21 | file => $filename, |
86867f3a |
22 | type => DBM::Deep->TYPE_HASH, |
ffed8b01 |
23 | ); |
ffed8b01 |
24 | |
9a63e1f2 |
25 | $db->{foo} = {}; |
26 | my $foo = $db->{foo}; |
27 | |
ffed8b01 |
28 | ## |
29 | # put/get many keys |
30 | ## |
a4e2db58 |
31 | my $max_keys = 4000; |
32 | |
ffed8b01 |
33 | for ( 0 .. $max_keys ) { |
9a63e1f2 |
34 | $foo->put( "hello $_" => "there " . $_ * 2 ); |
ffed8b01 |
35 | } |
36 | |
30029562 |
37 | my $count = -1; |
ffed8b01 |
38 | for ( 0 .. $max_keys ) { |
30029562 |
39 | $count = $_; |
9a63e1f2 |
40 | unless ( $foo->get( "hello $_" ) eq "there " . $_ * 2 ) { |
30029562 |
41 | last; |
42 | }; |
ffed8b01 |
43 | } |
30029562 |
44 | is( $count, $max_keys, "We read $count keys" ); |
bee3661a |
45 | |
9a63e1f2 |
46 | my @keys = sort keys %$foo; |
86867f3a |
47 | cmp_ok( scalar(@keys), '==', $max_keys + 1, "Number of keys is correct" ); |
48 | my @control = sort map { "hello $_" } 0 .. $max_keys; |
49 | cmp_deeply( \@keys, \@control, "Correct keys are there" ); |
50 | |
9a63e1f2 |
51 | ok( !exists $foo->{does_not_exist}, "EXISTS works on large hashes for non-existent keys" ); |
52 | is( $foo->{does_not_exist}, undef, "autovivification works on large hashes" ); |
53 | ok( exists $foo->{does_not_exist}, "EXISTS works on large hashes for newly-existent keys" ); |
54 | cmp_ok( scalar(keys %$foo), '==', $max_keys + 2, "Number of keys after autovivify is correct" ); |
55 | |
bee3661a |
56 | $db->clear; |
57 | cmp_ok( scalar(keys %$db), '==', 0, "Number of keys after clear() is correct" ); |