File Coverage

blib/lib/OpenSearch/Client/CxnPool/Static.pm
Criterion Covered Total %
statement 24 24 100.0
branch 8 8 100.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 37 37 100.0


line stmt bran cond sub pod time code
1             # OpenSearch::Client is an unofficial client for OpenSearch.
2             # It is derived from Search::Elasticsearch version 7.714
3             # License details from the original work are contained in the
4             # NOTICE file distributed with this work.
5             #
6             #-----------------------------------------------------------------------
7             # OpenSearch::Client
8             #-----------------------------------------------------------------------
9             # Copyright 2026 Mark Dootson
10             #
11             # Licensed under the Apache License, Version 2.0 (the "License");
12             # you may not use this file except in compliance with the License.
13             # You may obtain a copy of the License at
14             #
15             # http://www.apache.org/licenses/LICENSE-2.0
16             #
17             # Unless required by applicable law or agreed to in writing, software
18             # distributed under the License is distributed on an "AS IS" BASIS,
19             # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20             # See the License for the specific language governing permissions and
21             # limitations under the License.
22              
23             package OpenSearch::Client::CxnPool::Static;
24             $OpenSearch::Client::CxnPool::Static::VERSION = '3.007002';
25 37     37   17035 use Moo;
  37         79  
  37         210  
26             with 'OpenSearch::Client::Role::CxnPool::Static',
27             'OpenSearch::Client::Role::Is_Sync';
28 37     37   12739 use OpenSearch::Client::Util qw(throw);
  37         73  
  37         316  
29 37     37   9735 use namespace::clean;
  37         108  
  37         211  
30              
31             #===================================
32             sub next_cxn {
33             #===================================
34 54     54 1 101 my ($self) = @_;
35              
36 54         106 my $cxns = $self->cxns;
37 54         81 my $total = @$cxns;
38              
39 54         74 my $now = time();
40 54         88 my @skipped;
41              
42 54         110 while ( $total-- ) {
43 63         173 my $cxn = $cxns->[ $self->next_cxn_num ];
44 63 100       192 return $cxn if $cxn->is_live;
45              
46 49 100       114 if ( $cxn->next_ping < $now ) {
47 40 100       92 return $cxn if $cxn->pings_ok;
48             }
49             else {
50 9         20 push @skipped, $cxn;
51             }
52             }
53              
54 12         22 for my $cxn (@skipped) {
55 7 100       16 return $cxn if $cxn->pings_ok;
56             }
57              
58 7         24 $_->force_ping for @$cxns;
59              
60 7         25 throw( "NoNodes", "No nodes are available: [" . $self->cxns_str . ']' );
61             }
62              
63             1;
64              
65             __END__