line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::t::SetError; |
2
|
|
|
|
|
|
|
$CHI::t::SetError::VERSION = '0.61'; |
3
|
1
|
|
|
1
|
|
451
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
5
|
1
|
|
|
1
|
|
420
|
use CHI::Test; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
6
|
1
|
|
|
1
|
|
8
|
use CHI::Test::Util qw(activate_test_logger); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
7
|
1
|
|
|
1
|
|
6
|
use base qw(CHI::Test::Class); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1802
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub readonly_cache { |
10
|
5
|
|
|
5
|
0
|
13
|
my ($on_set_error) = @_; |
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
|
|
23
|
return CHI->new( |
13
|
|
|
|
|
|
|
driver => '+CHI::Test::Driver::Readonly', |
14
|
|
|
|
|
|
|
on_set_error => $on_set_error, |
15
|
|
|
|
|
|
|
global => 1 |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub test_set_errors : Tests { |
20
|
1
|
|
|
1
|
0
|
1508
|
my ( $key, $value ) = ( 'medium', 'medium' ); |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
5
|
my $error_pattern = |
23
|
|
|
|
|
|
|
qr/error during cache set for namespace='.*', key='medium', size=\d+.*: read-only cache/; |
24
|
1
|
|
|
|
|
5
|
my $log = activate_test_logger(); |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
3
|
my $cache; |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
5
|
$cache = readonly_cache('ignore'); |
29
|
1
|
|
|
1
|
|
13
|
lives_ok( sub { $cache->set( $key, $value ) }, "ignore - lives" ); |
|
1
|
|
|
|
|
50
|
|
30
|
1
|
|
|
|
|
639
|
ok( !defined( $cache->get($key) ), "ignore - miss" ); |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
353
|
$cache = readonly_cache('die'); |
33
|
1
|
|
|
1
|
|
38
|
throws_ok( sub { $cache->set( $key, $value ) }, |
34
|
1
|
|
|
|
|
11
|
$error_pattern, "die - dies" ); |
35
|
1
|
|
|
|
|
1125
|
ok( !defined( $cache->get($key) ), "die - miss" ); |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
324
|
$log->clear(); |
38
|
1
|
|
|
|
|
16
|
$cache = readonly_cache('log'); |
39
|
1
|
|
|
1
|
|
8
|
lives_ok( sub { $cache->set( $key, $value ) }, "log - lives" ); |
|
1
|
|
|
|
|
32
|
|
40
|
1
|
|
|
|
|
330
|
ok( !defined( $cache->get($key) ), "log - miss" ); |
41
|
1
|
|
|
|
|
339
|
$log->contains_ok(qr/cache get for .* key='medium', .*: MISS/); |
42
|
1
|
|
|
|
|
381
|
$log->contains_ok($error_pattern); |
43
|
1
|
|
|
|
|
400
|
$log->empty_ok(); |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
317
|
my ( $err_msg, $err_key ); |
46
|
|
|
|
|
|
|
$cache = readonly_cache( |
47
|
|
|
|
|
|
|
sub { |
48
|
1
|
|
|
1
|
|
4
|
( $err_msg, $err_key ) = @_; |
49
|
|
|
|
|
|
|
} |
50
|
1
|
|
|
|
|
8
|
); |
51
|
1
|
|
|
1
|
|
9
|
lives_ok( sub { $cache->set( $key, $value ) }, "custom - lives" ); |
|
1
|
|
|
|
|
32
|
|
52
|
1
|
|
|
|
|
333
|
ok( !defined( $cache->get($key) ), "custom - miss" ); |
53
|
1
|
|
|
|
|
321
|
like( $err_msg, $error_pattern, "custom - got msg" ); |
54
|
1
|
|
|
|
|
356
|
is( $err_key, $key, "custom - got key" ); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
throws_ok( |
57
|
1
|
|
|
1
|
|
34
|
sub { readonly_cache('bad') }, |
58
|
1
|
|
|
|
|
345
|
qr/Validation failed for|isa check for ".*" failed/, |
59
|
|
|
|
|
|
|
"bad - dies" |
60
|
|
|
|
|
|
|
); |
61
|
1
|
|
|
1
|
|
10
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |