Elasticsearch/CxnPool/Sniff.pm

filter: Statementstmt 100% 39 / 39 Branchbran 100% 16 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 66.6% 2 / 3 totaltotal 98.4% 63 / 64 CC 11 SCAR 16.6
CC
11
Cov
100%
sniff
8.0
next_cxn
4.0
BEGIN
1.0
CRAP 5.2
« Elasticsearch.pm ↑ Summary Elasticsearch/Role/CxnPool/Static/NoPing.pm »
1 package Search::Elasticsearch::CxnPool::Sniff;
2 11 $Search::Elasticsearch::CxnPool::Sniff::VERSION = '6.80';
3 11 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 with 'Search::Elasticsearch::Role::CxnPool::Sniff',
5 'Search::Elasticsearch::Role::Is_Sync';
6  
7 11 ▶use Search::Elasticsearch::Util qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #===================================
11 sub next_cxn {
12 #===================================
13 50 ▶ my ($self) = @_;
Subroutine next_cxn: called CC=4 SCAR=13.9
Pod documented
14  
15 50 ▶ $self->sniff if $self->next_sniff <= time();
Branch: 1 branch
BranchTrueFalseTotal
if $self->next_sniff <= time 29 21 50
16  
17 50 my $cxns = $self->cxns;
18 50 my $total = @$cxns;
19  
20 50 ▶ while ( 0 < $total-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 < $total--) 49 5 54
21 49 my $cxn = $cxns->[ $self->next_cxn_num ];
22 49 ▶ return $cxn if $cxn->is_live;
Branch: 1 branch
BranchTrueFalseTotal
if $cxn->is_live 45 4 49
23 }
24  
25 5 throw( "NoNodes",
26 "No nodes are available: [" . $self->cxns_seeds_str . ']' );
27 }
28  
29 #===================================
30 sub sniff {
31 #===================================
32 29 ▶ my $self = shift;
Subroutine sniff: called CC=8 SCAR=20.8
Pod documented
33  
34 29 my $cxns = $self->cxns;
35 29 my $total = @$cxns;
36 29 my @skipped;
37  
38 29 ▶ while ( 0 < $total-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 < $total--) 19 16 35
39 19 my $cxn = $cxns->[ $self->next_cxn_num ];
40 19 ▶ if ( $cxn->is_dead ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cxn->is_dead) { } 5 14 19
41 5 push @skipped, $cxn;
42 }
43 else {
44 14 ▶ $self->sniff_cxn($cxn) and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->sniff_cxn($cxn) and return 13 1 14
45 1 $cxn->mark_dead;
46 }
47 }
48  
49 16 for my $cxn (@skipped) {
50 4 ▶ $self->sniff_cxn($cxn) and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->sniff_cxn($cxn) and return 1 3 4
51 }
52  
53 15 $self->logger->info("No live nodes available. Trying seed nodes.");
54 15 for my $seed ( @{ $self->seed_nodes } ) {
55 20 my $cxn = $self->cxn_factory->new_cxn($seed);
56 20 ▶ $self->sniff_cxn($cxn) and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->sniff_cxn($cxn) and return 10 10 20
57 }
58  
59 }
60  
61 #===================================
62 sub sniff_cxn {
63 #===================================
64 38 ▶ my ( $self, $cxn ) = @_;
Subroutine sniff_cxn: called CC=1 SCAR=0.0
Pod undocumented
65 38 return $self->parse_sniff( $cxn->sniff );
66 }
67  
68 11 1;
69  
70 # ABSTRACT: A CxnPool for connecting to a local cluster with a dynamic node list
71  
72 __END__
« Elasticsearch.pm ↑ Summary Elasticsearch/Role/CxnPool/Static/NoPing.pm »