blib/lib/Cassandra/Client/Policy/Throttle/Adaptive.pm

filter: Statementstmt 47.9% 23 / 48 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 63.6% 7 / 11 Podpod 0.0% 0 / 3 totaltotal 30.9% 30 / 97 CC 12 SCAR 28.7
CC
12
Cov
31%
count
42.0
_process_window
20.0
new
12.0
CRAP 17.6
« blib/lib/Cassandra/Client/AsyncAnyEvent.pm ↑ Summary blib/lib/Cassandra/Client/AsyncEV.pm »
1 package Cassandra::Client::Policy::Throttle::Adaptive;
2 2 our $AUTHORITY = 'cpan:TVDW';
3 2 $Cassandra::Client::Policy::Throttle::Adaptive::VERSION = '0.21';
4 2 ▶use parent 'Cassandra::Client::Policy::Throttle::Default';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Time::HiRes qw/CLOCK_MONOTONIC/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Ref::Util qw/is_blessed_ref/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Cassandra::Client::Error::ClientThrottlingError;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
13 0 my ($class, %args)= @_;
14 return bless {
15 ratio => $args{ratio} || 2,
16 0 ▶ time => $args{time} || 120,
Condition0%0/4
$args{'ratio'} || 2
l!l
00
$args{'time'} || 120
l!l
00
MC/DC0%0/1
$args{'ratio'} || 2
$args{'ratio'}
MC/DC0%0/1
$args{'time'} || 120
$args{'time'}
Truth table0%0/2
A
A= $args{'ratio'}
Aresult
11
00
Truth table0%0/2
A
A= $args{'time'}
Aresult
11
00
17  
18 window => [],
19 window_success => 0,
20 window_total => 0,
21 }, $class;
22 }
23  
24 0 ▶sub _process_window {
Subroutine _process_window: not called CC=4 SCAR=30.0
25 0 my ($self)= @_;
26 0 my $now= Time::HiRes::clock_gettime(CLOCK_MONOTONIC);
27 0 ▶ while (@{$self->{window}} && $self->{window}[0][0] < $now) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"window"};} and $self->{"window"}[0][0] < $now) 0 0 0
Condition0%0/3
@{$self->{"window"};} and $self->{"window"}[0][0] < $now
!ll&&!rl&&r
000
MC/DC0%0/2
@{$self->{"window"};} and $self->{"window"}[0][0] < $now
@{$self->{"window"};} $self->{"window"}[0][0] < $now
Truth table0%0/3
A and B
A= @{$self->{"window"};}B= $self->{"window"}[0][0] < $now
ABresult
0X0
100
111
28 0 my $entry= shift @{$self->{window}};
29 0 $self->{window_total}--;
30 0 ▶ $self->{window_success}-- if $entry->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $entry->[1] 0 0 0
31 }
32 0 return;
33 }
34  
35 0 ▶sub should_fail {
Subroutine should_fail: not called CC=2 SCAR=17.9
Pod undocumented
36 0 my ($self)= @_;
37 0 $self->_process_window;
38  
39 0 my $fail= ( rand() < (($self->{window_total} - ($self->{ratio} * $self->{window_success})) / ($self->{window_total} + 1)) );
40 0 ▶ return unless $fail;
Branch: 1 branch
BranchTrueFalseTotal
unless $fail 0 0 0
41  
42 0 $self->count(undef, 1);
43 0 return Cassandra::Client::Error::ClientThrottlingError->new;
44 }
45  
46 0 ▶sub count {
Subroutine count: not called CC=6 SCAR=37.4
Pod undocumented
47 0 my ($self, $error, $force_error)= @_;
48  
49 0 ▶ return if is_blessed_ref($error) && $error->isa('Cassandra::Client::Error::ClientThrottlingError');
Branch: 1 branch
BranchTrueFalseTotal
if is_blessed_ref($error) and $error->isa("Cassandra::Client::Error::ClientThrottlingError") 0 0 0
Condition0%0/3
is_blessed_ref($error) and $error->isa("Cassandra::Client::Error::ClientThrottlingError")
!ll&&!rl&&r
000
MC/DC0%0/2
is_blessed_ref($error) and $error->isa("Cassandra::Client::Error::ClientThrottlingError")
is_blessed_ref($error) $error->isa("Cassandra::Client::Error::ClientThrottlingError")
Truth table0%0/3
A and B
A= is_blessed_ref($error)B= $error->isa("Cassandra::Client::Error::ClientThrottlingError")
ABresult
0X0
100
111
50  
51 0 $self->{window_total}++;
52 0 ▶ my $success= !(is_blessed_ref($error) && $error->is_timeout) && !$force_error;
Condition0%0/6
is_blessed_ref($error) && $error->is_timeout || $force_error
l!l&&r!l&&!r
000
is_blessed_ref($error) and $error->is_timeout
!ll&&!rl&&r
000
MC/DC0%0/3
is_blessed_ref($error) && $error->is_timeout || $force_error
is_blessed_ref($error) $error->is_timeout $force_error
Truth table0%0/5
A and B || C
A= is_blessed_ref($error)B= $error->is_timeoutC= $force_error
ABCresult
11X1
0X11
1011
0X00
1000
53 0 push @{$self->{window}}, [ Time::HiRes::clock_gettime(CLOCK_MONOTONIC)+$self->{time}, $success ];
54 0 ▶ $self->{window_success}++ if $success;
Branch: 1 branch
BranchTrueFalseTotal
if $success 0 0 0
55 0 return;
56 }
57  
58 2 1;
59  
60 __END__
« blib/lib/Cassandra/Client/AsyncAnyEvent.pm ↑ Summary blib/lib/Cassandra/Client/AsyncEV.pm »