CxnPool/Async/Static.pm

filter: Statementstmt 95.4% 42 / 44 Branchbran 66.6% 8 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 87.1% 61 / 70 CC 9 SCAR 18.1
CC
9
Cov
88%
__ANON__
9.9
__ANON__
2.0
next_cxn
1.0
CRAP 6.1
« CxnPool/Async/Sniff.pm ↑ Summary Async/Util.pm »
1 # Licensed to Elasticsearch B.V under one or more agreements.
2 # Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3 # See the LICENSE file in the project root for more information
4  
5 package Search::Elasticsearch::CxnPool::Async::Static;
6 32 $Search::Elasticsearch::CxnPool::Async::Static::VERSION = '7.30_1'; # TRIAL
7  
8 32 $Search::Elasticsearch::CxnPool::Async::Static::VERSION = '7.301';
9 32 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 32 with 'Search::Elasticsearch::Role::CxnPool::Static',
11 'Search::Elasticsearch::Role::Is_Async';
12  
13 32 ▶use Search::Elasticsearch::Util qw(new_error);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 32 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 32 ▶use Promises qw(deferred);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 32 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 #===================================
19 sub next_cxn {
20 #===================================
21 11 ▶ my ($self) = @_;
Subroutine next_cxn: called CC=1 SCAR=0.1
Pod documented
22  
23 11 my $cxns = $self->cxns;
24 11 my $now = time();
25 11 my $deferred = deferred;
26  
27 11 my ( %seen, @skipped, $weak_find_cxn );
28  
29 my $find_cxn = sub {
30 31 ▶ my $total = @$cxns;
Subroutine __ANON__: called CC=9 SCAR=23.0
31 31 my $found;
32  
33 31 ▶ if ( $total > keys %seen ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($total > keys %seen) 20 11 31
34  
35 # we haven't seen all cxns yet
36 20 ▶ while ( $total-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($total--) 20 0 20
37 20 my $cxn = $cxns->[ $self->next_cxn_num ];
38 20 ▶ next if $seen{$cxn}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$cxn}++ 0 20 20
39  
40 20 ▶ return $deferred->resolve($cxn)
Branch: 1 branch
BranchTrueFalseTotal
if $cxn->is_live 0 20 20
41 if $cxn->is_live;
42  
43 20 ▶ if ( $cxn->next_ping <= time() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cxn->next_ping <= time) 20 0 20
44 20 $found = $cxn;
45 20 last;
46 }
47  
48 0 push @skipped, $cxn;
49 }
50 }
51  
52 31 ▶ if ( $found ||= shift @skipped ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found ||= shift @skipped) 20 11 31
Condition66%2/3
$found ||= shift @skipped
l!l&&r!l&&!r
20011
MC/DC50%1/2
$found ||= shift @skipped
$found shift @skipped
Truth table66%2/3
A ||= B
A= $foundB= shift @skipped
ABresult
1X1
011
000
53 return $found->pings_ok->then(
54 0 ▶ sub { $deferred->resolve($found) }, # success
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 20 $weak_find_cxn # resolve
56 );
57 }
58  
59 11 $_->force_ping for @$cxns;
60  
61 11 return $deferred->reject(
62 new_error(
63 "NoNodes", "No nodes are available: [" . $self->cxns_str . ']'
64 )
65 );
66  
67 11 };
68 11 weaken( $weak_find_cxn = $find_cxn );
69  
70 11 $find_cxn->();
71 11 $deferred->promise;
72 }
73  
74 32 1;
75  
76 # ABSTRACT: An async CxnPool for connecting to a remote cluster with a static list of nodes.
77  
78 __END__
« CxnPool/Async/Sniff.pm ↑ Summary Async/Util.pm »