CHI/t/Driver/FastMmap.pm

filter: Statementstmt 56.3% 31 / 55 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 66.6% 10 / 15 Podpod 0.0% 0 / 5 totaltotal 48.2% 41 / 85 SCAR 17.9
CC
4
Cov
50%
test_fm_cache
12.0
new_cache_options
6.0
test_parameter_passthrough
2.0
CRAP 6.0
« CHI/Driver/FastMmap.pm ↑ Summary CHI/Driver/Memory.pm »
1 package CHI::t::Driver::FastMmap;
2 1 $CHI::t::Driver::FastMmap::VERSION = '0.59';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use CHI::Test;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use base qw(CHI::t::Driver);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 my $root_dir;
11  
12 sub required_modules {
13 1 ▶ return { 'Cache::FastMmap' => undef };
Subroutine required_modules: called CC=1 SCAR=0.0
Pod undocumented
14 }
15  
16 sub new_cache_options {
17 0 ▶ my $self = shift;
Subroutine new_cache_options: not called CC=2 SCAR=17.9
Pod undocumented
18  
19 0 ▶ $root_dir ||=
Condition0%0/3
$root_dir ||= tempdir("chi-driver-fastmmap-XXXX", "TMPDIR", 1, "CLEANUP", 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$root_dir ||= tempdir("chi-driver-fastmmap-XXXX", "TMPDIR", 1, "CLEANUP", 1)
$root_dir tempdir("chi-driver-fastmmap-XXXX", "TMPDIR", 1, "CLEANUP", 1)
Truth table0%0/3
A ||= B
A= $root_dirB= tempdir("chi-driver-fastmmap-XXXX", "TMPDIR", 1, "CLEANUP", 1)
ABresult
1X1
011
000
20 tempdir( "chi-driver-fastmmap-XXXX", TMPDIR => 1, CLEANUP => 1 );
21 0 return ( $self->SUPER::new_cache_options(), root_dir => $root_dir );
22 }
23  
24 sub test_fm_cache : Tests {
25 0 ▶ my ($self) = @_;
Subroutine test_fm_cache: not called CC=3 SCAR=24.8
Pod undocumented
26  
27 # Create brand new cache and check defaults
28 0 my $cache =
29 $self->new_cache( root_dir =>
30 tempdir( "chi-driver-fastmmap-XXXX", TMPDIR => 1, CLEANUP => 1 ) );
31  
32 0 my $fm_cache = $cache->fm_cache();
33 0 isa_ok( $fm_cache, 'Cache::FastMmap' );
34  
35 0 my %defaults = (
36 unlink_on_exit => 0,
37 empty_on_exit => 0,
38 raw_values => 1,
39 );
40 0 ▶ while ( my ( $key, $value ) = each(%defaults) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %defaults) 0 0 0
41 0 ▶ is( $fm_cache->{$key} || 0, $value, "$key = $value by default" );
Condition0%0/2
$fm_cache->{$key} || 0
l!l
00
MC/DC0%0/1
$fm_cache->{$key} || 0
$fm_cache->{$key}
Truth table0%0/2
A
A= $fm_cache->{$key}
Aresult
11
00
42 }
43 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 sub test_parameter_passthrough : Tests {
46 0 ▶ my ($self) = @_;
Subroutine test_parameter_passthrough: not called CC=1 SCAR=6.9
Pod undocumented
47  
48 0 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 0 589824,
53 'cache_size parameter is passed to Cache::FastMmap constructor' );
54  
55 0 $cache = $self->new_cache( page_size => 5000, num_pages => 11 );
56  
57 # Same here, it won't be equal to 5000 * 11
58 0 is( $cache->fm_cache()->{cache_size}, 45056,
59 'page_size and num_pages parameters are passed to Cache::FastMmap constructor'
60 );
61 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 sub test_value_too_large : Tests {
64 0 ▶ my ($self) = @_;
Subroutine test_value_too_large: not called CC=1 SCAR=6.9
Pod undocumented
65  
66 0 my $cache = $self->new_cache(
67 page_size => '4k',
68 num_pages => 11,
69 on_set_error => 'die'
70 );
71 0 my %values;
72 0 $values{small} = 'x' x 3 x 1024;
73 0 $values{large} = 'x' x 10 x 1024;
74 0 $cache->set( 'small', $values{small} );
75 0 is( $cache->get('small'), $values{small}, "got small" );
76 0 ▶ throws_ok { $cache->set( 'large', $values{large} ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
77 0 qr/error during cache set.*fastmmap set failed/;
78 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
79  
80 1 1;
« CHI/Driver/FastMmap.pm ↑ Summary CHI/Driver/Memory.pm »