line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::t::GetError; |
2
|
|
|
|
|
|
|
$CHI::t::GetError::VERSION = '0.59'; |
3
|
1
|
|
|
1
|
|
346
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
315
|
use CHI::Test; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use CHI::Test::Util qw(activate_test_logger); |
7
|
|
|
|
|
|
|
use base qw(CHI::Test::Class); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub writeonly_cache { |
10
|
|
|
|
|
|
|
my ($on_get_error) = @_; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
return CHI->new( |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# leave as driver_class rather than driver to test back compat |
15
|
|
|
|
|
|
|
driver_class => 'CHI::Test::Driver::Writeonly', |
16
|
|
|
|
|
|
|
on_get_error => $on_get_error, |
17
|
|
|
|
|
|
|
global => 1, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub test_get_errors : Tests { |
22
|
|
|
|
|
|
|
my ( $key, $value ) = ( 'medium', 'medium' ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $error_pattern = |
25
|
|
|
|
|
|
|
qr/error during cache get for namespace='.*', key='medium'.*: write-only cache/; |
26
|
|
|
|
|
|
|
my $log = activate_test_logger(); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $cache; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$cache = writeonly_cache('ignore'); |
31
|
|
|
|
|
|
|
$cache->set( $key, $value ); |
32
|
|
|
|
|
|
|
ok( !defined( $cache->get($key) ), "ignore - miss" ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$cache = writeonly_cache('die'); |
35
|
|
|
|
|
|
|
$cache->set( $key, $value ); |
36
|
|
|
|
|
|
|
throws_ok( sub { $cache->get($key) }, $error_pattern, "die - dies" ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$log->clear(); |
39
|
|
|
|
|
|
|
$cache = writeonly_cache('log'); |
40
|
|
|
|
|
|
|
$cache->set( $key, $value ); |
41
|
|
|
|
|
|
|
ok( !defined( $cache->get($key) ), "log - miss" ); |
42
|
|
|
|
|
|
|
$log->contains_ok(qr/cache set for .* key='medium'/); |
43
|
|
|
|
|
|
|
$log->contains_ok($error_pattern); |
44
|
|
|
|
|
|
|
$log->empty_ok(); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my ( $err_msg, $err_key ); |
47
|
|
|
|
|
|
|
$cache = writeonly_cache( |
48
|
|
|
|
|
|
|
sub { |
49
|
|
|
|
|
|
|
( $err_msg, $err_key ) = @_; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
$cache->set( $key, $value ); |
53
|
|
|
|
|
|
|
ok( !defined( $cache->get($key) ), "custom - miss" ); |
54
|
|
|
|
|
|
|
like( $err_msg, $error_pattern, "custom - got msg" ); |
55
|
|
|
|
|
|
|
is( $err_key, $key, "custom - got key" ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
throws_ok( |
58
|
|
|
|
|
|
|
sub { writeonly_cache('bad') }, |
59
|
|
|
|
|
|
|
qr/Validation failed for|isa check for .* failed/, |
60
|
|
|
|
|
|
|
"bad - dies" |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |