Converted to use the intermediate keyloc so that keys work under transactions
[dbsrgits/DBM-Deep.git] / t / 03_bighash.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
86867f3a 5use Test::More tests => 5;
6use Test::Deep;
fde3db1a 7use t::common qw( new_fh );
ffed8b01 8
9use_ok( 'DBM::Deep' );
10
fde3db1a 11my ($fh, $filename) = new_fh();
ffed8b01 12my $db = DBM::Deep->new(
2a81bf9e 13 file => $filename,
86867f3a 14 type => DBM::Deep->TYPE_HASH,
ffed8b01 15);
ffed8b01 16
17##
18# put/get many keys
19##
a4e2db58 20my $max_keys = 4000;
21
ffed8b01 22for ( 0 .. $max_keys ) {
23 $db->put( "hello $_" => "there " . $_ * 2 );
24}
25
30029562 26my $count = -1;
ffed8b01 27for ( 0 .. $max_keys ) {
30029562 28 $count = $_;
29 unless ( $db->get( "hello $_" ) eq "there " . $_ * 2 ) {
30 last;
31 };
ffed8b01 32}
30029562 33is( $count, $max_keys, "We read $count keys" );
bee3661a 34
86867f3a 35my @keys = sort keys %$db;
36cmp_ok( scalar(@keys), '==', $max_keys + 1, "Number of keys is correct" );
37my @control = sort map { "hello $_" } 0 .. $max_keys;
38cmp_deeply( \@keys, \@control, "Correct keys are there" );
39
bee3661a 40$db->clear;
41cmp_ok( scalar(keys %$db), '==', 0, "Number of keys after clear() is correct" );