line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::t::Driver::FastMmap; |
2
|
|
|
|
|
|
|
$CHI::t::Driver::FastMmap::VERSION = '0.59'; |
3
|
1
|
|
|
1
|
|
550
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
523
|
use CHI::Test; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Encode; |
7
|
|
|
|
|
|
|
use File::Temp qw(tempdir); |
8
|
|
|
|
|
|
|
use base qw(CHI::t::Driver); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $root_dir; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub required_modules { |
13
|
|
|
|
|
|
|
return { 'Cache::FastMmap' => undef }; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new_cache_options { |
17
|
|
|
|
|
|
|
my $self = shift; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$root_dir ||= |
20
|
|
|
|
|
|
|
tempdir( "chi-driver-fastmmap-XXXX", TMPDIR => 1, CLEANUP => 1 ); |
21
|
|
|
|
|
|
|
return ( $self->SUPER::new_cache_options(), root_dir => $root_dir ); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub test_fm_cache : Tests { |
25
|
|
|
|
|
|
|
my ($self) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Create brand new cache and check defaults |
28
|
|
|
|
|
|
|
my $cache = |
29
|
|
|
|
|
|
|
$self->new_cache( root_dir => |
30
|
|
|
|
|
|
|
tempdir( "chi-driver-fastmmap-XXXX", TMPDIR => 1, CLEANUP => 1 ) ); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $fm_cache = $cache->fm_cache(); |
33
|
|
|
|
|
|
|
isa_ok( $fm_cache, 'Cache::FastMmap' ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my %defaults = ( |
36
|
|
|
|
|
|
|
unlink_on_exit => 0, |
37
|
|
|
|
|
|
|
empty_on_exit => 0, |
38
|
|
|
|
|
|
|
raw_values => 1, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
while ( my ( $key, $value ) = each(%defaults) ) { |
41
|
|
|
|
|
|
|
is( $fm_cache->{$key} || 0, $value, "$key = $value by default" ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub test_parameter_passthrough : Tests { |
46
|
|
|
|
|
|
|
my ($self) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $cache = $self->new_cache( cache_size => '500k' ); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# The number gets munged by FastMmap so it's not equal to 500 * 1024 |
51
|
|
|
|
|
|
|
is( $cache->fm_cache()->{cache_size}, |
52
|
|
|
|
|
|
|
589824, |
53
|
|
|
|
|
|
|
'cache_size parameter is passed to Cache::FastMmap constructor' ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$cache = $self->new_cache( page_size => 5000, num_pages => 11 ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Same here, it won't be equal to 5000 * 11 |
58
|
|
|
|
|
|
|
is( $cache->fm_cache()->{cache_size}, 45056, |
59
|
|
|
|
|
|
|
'page_size and num_pages parameters are passed to Cache::FastMmap constructor' |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub test_value_too_large : Tests { |
64
|
|
|
|
|
|
|
my ($self) = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $cache = $self->new_cache( |
67
|
|
|
|
|
|
|
page_size => '4k', |
68
|
|
|
|
|
|
|
num_pages => 11, |
69
|
|
|
|
|
|
|
on_set_error => 'die' |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
my %values; |
72
|
|
|
|
|
|
|
$values{small} = 'x' x 3 x 1024; |
73
|
|
|
|
|
|
|
$values{large} = 'x' x 10 x 1024; |
74
|
|
|
|
|
|
|
$cache->set( 'small', $values{small} ); |
75
|
|
|
|
|
|
|
is( $cache->get('small'), $values{small}, "got small" ); |
76
|
|
|
|
|
|
|
throws_ok { $cache->set( 'large', $values{large} ) } |
77
|
|
|
|
|
|
|
qr/error during cache set.*fastmmap set failed/; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |