elasticsearch-transport 7.5.0 → 7.13.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +28 -11
- data/README.md +158 -58
- data/Rakefile +16 -3
- data/elasticsearch-transport.gemspec +57 -63
- data/lib/elasticsearch/transport/client.rb +150 -56
- data/lib/elasticsearch/transport/meta_header.rb +135 -0
- data/lib/elasticsearch/transport/redacted.rb +16 -3
- data/lib/elasticsearch/transport/transport/base.rb +32 -12
- data/lib/elasticsearch/transport/transport/connections/collection.rb +18 -8
- data/lib/elasticsearch/transport/transport/connections/connection.rb +23 -8
- data/lib/elasticsearch/transport/transport/connections/selector.rb +16 -3
- data/lib/elasticsearch/transport/transport/errors.rb +16 -3
- data/lib/elasticsearch/transport/transport/http/curb.rb +16 -3
- data/lib/elasticsearch/transport/transport/http/faraday.rb +27 -6
- data/lib/elasticsearch/transport/transport/http/manticore.rb +16 -3
- data/lib/elasticsearch/transport/transport/loggable.rb +16 -3
- data/lib/elasticsearch/transport/transport/response.rb +16 -4
- data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +16 -3
- data/lib/elasticsearch/transport/transport/sniffer.rb +35 -15
- data/lib/elasticsearch/transport/version.rb +17 -4
- data/lib/elasticsearch/transport.rb +16 -3
- data/lib/elasticsearch-transport.rb +16 -3
- data/spec/elasticsearch/connections/collection_spec.rb +28 -3
- data/spec/elasticsearch/connections/selector_spec.rb +16 -3
- data/spec/elasticsearch/transport/base_spec.rb +60 -38
- data/spec/elasticsearch/transport/client_spec.rb +628 -132
- data/spec/elasticsearch/transport/meta_header_spec.rb +265 -0
- data/spec/elasticsearch/transport/sniffer_spec.rb +16 -16
- data/spec/spec_helper.rb +19 -1
- data/test/integration/transport_test.rb +30 -4
- data/test/profile/client_benchmark_test.rb +16 -3
- data/test/test_helper.rb +16 -3
- data/test/unit/connection_test.rb +23 -5
- data/test/unit/response_test.rb +17 -4
- data/test/unit/serializer_test.rb +16 -3
- data/test/unit/transport_base_test.rb +17 -4
- data/test/unit/transport_curb_test.rb +16 -3
- data/test/unit/transport_faraday_test.rb +18 -5
- data/test/unit/transport_manticore_test.rb +29 -16
- metadata +70 -69
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
module Elasticsearch
|
6
19
|
module Transport
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
module Elasticsearch
|
6
19
|
module Transport
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
module Elasticsearch
|
6
19
|
module Transport
|
@@ -20,9 +33,17 @@ module Elasticsearch
|
|
20
33
|
# @return [Response]
|
21
34
|
# @see Transport::Base#perform_request
|
22
35
|
#
|
23
|
-
def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
|
36
|
+
def perform_request(method, path, params = {}, body = nil, headers = nil, opts = {})
|
24
37
|
super do |connection, url|
|
25
|
-
headers =
|
38
|
+
headers = if connection.connection.headers
|
39
|
+
if !headers.nil?
|
40
|
+
connection.connection.headers.merge(headers)
|
41
|
+
else
|
42
|
+
connection.connection.headers
|
43
|
+
end
|
44
|
+
else
|
45
|
+
headers
|
46
|
+
end
|
26
47
|
|
27
48
|
response = connection.connection.run_request(method.downcase.to_sym,
|
28
49
|
url,
|
@@ -48,7 +69,7 @@ module Elasticsearch
|
|
48
69
|
# @return [Array]
|
49
70
|
#
|
50
71
|
def host_unreachable_exceptions
|
51
|
-
[::Faraday::
|
72
|
+
[::Faraday::ConnectionFailed, ::Faraday::TimeoutError]
|
52
73
|
end
|
53
74
|
|
54
75
|
private
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
require 'manticore'
|
6
19
|
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
module Elasticsearch
|
6
19
|
|
@@ -1,11 +1,23 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
module Elasticsearch
|
6
19
|
module Transport
|
7
20
|
module Transport
|
8
|
-
|
9
21
|
# Wraps the response from Elasticsearch.
|
10
22
|
#
|
11
23
|
class Response
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
module Elasticsearch
|
6
19
|
module Transport
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
module Elasticsearch
|
6
19
|
module Transport
|
@@ -32,21 +45,21 @@ module Elasticsearch
|
|
32
45
|
#
|
33
46
|
def hosts
|
34
47
|
Timeout::timeout(timeout, SnifferTimeoutError) do
|
35
|
-
nodes =
|
36
|
-
reload_on_failure: false).body
|
48
|
+
nodes = perform_sniff_request.body
|
37
49
|
|
38
50
|
hosts = nodes['nodes'].map do |id, info|
|
39
|
-
|
40
|
-
|
51
|
+
next unless info[PROTOCOL]
|
52
|
+
host, port = parse_publish_address(info[PROTOCOL]['publish_address'])
|
41
53
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
54
|
+
{
|
55
|
+
id: id,
|
56
|
+
name: info['name'],
|
57
|
+
version: info['version'],
|
58
|
+
host: host,
|
59
|
+
port: port,
|
60
|
+
roles: info['roles'],
|
61
|
+
attributes: info['attributes']
|
62
|
+
}
|
50
63
|
end.compact
|
51
64
|
|
52
65
|
hosts.shuffle! if transport.options[:randomize_hosts]
|
@@ -56,6 +69,13 @@ module Elasticsearch
|
|
56
69
|
|
57
70
|
private
|
58
71
|
|
72
|
+
def perform_sniff_request
|
73
|
+
transport.perform_request(
|
74
|
+
'GET', '_nodes/http', {}, nil, nil,
|
75
|
+
reload_on_failure: false
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
59
79
|
def parse_publish_address(publish_address)
|
60
80
|
# publish_address is in the format hostname/ip:port
|
61
81
|
if publish_address =~ /\//
|
@@ -1,9 +1,22 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
module Elasticsearch
|
6
19
|
module Transport
|
7
|
-
VERSION =
|
20
|
+
VERSION = '7.13.3'.freeze
|
8
21
|
end
|
9
22
|
end
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
require "uri"
|
6
19
|
require "time"
|
@@ -1,5 +1,18 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
require 'elasticsearch/transport'
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
require 'spec_helper'
|
6
19
|
|
@@ -236,6 +249,18 @@ describe Elasticsearch::Transport::Transport::Connections::Collection do
|
|
236
249
|
collection.get_connection.host[:host]
|
237
250
|
end).to eq((0..9).to_a)
|
238
251
|
end
|
252
|
+
|
253
|
+
it 'always returns a connection' do
|
254
|
+
threads = 20.times.map do
|
255
|
+
Thread.new do
|
256
|
+
20.times.map do
|
257
|
+
collection.get_connection.dead!
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
expect(threads.flat_map(&:value).size).to eq(400)
|
263
|
+
end
|
239
264
|
end
|
240
265
|
end
|
241
266
|
end
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
require 'spec_helper'
|
6
19
|
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
4
17
|
|
5
18
|
require 'spec_helper'
|
6
19
|
|
@@ -33,10 +46,12 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
33
46
|
|
34
47
|
context 'when the user and password are provided as separate arguments' do
|
35
48
|
let(:arguments) do
|
36
|
-
{
|
49
|
+
{
|
50
|
+
hosts: 'fake',
|
37
51
|
logger: logger,
|
38
52
|
password: 'secret_password',
|
39
|
-
user: 'test'
|
53
|
+
user: 'test'
|
54
|
+
}
|
40
55
|
end
|
41
56
|
|
42
57
|
it_behaves_like 'a redacted string'
|
@@ -44,8 +59,10 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
44
59
|
|
45
60
|
context 'when the user and password are provided in the string URI' do
|
46
61
|
let(:arguments) do
|
47
|
-
{
|
48
|
-
|
62
|
+
{
|
63
|
+
hosts: 'https://test:secret_password@fake_local_elasticsearch',
|
64
|
+
logger: logger
|
65
|
+
}
|
49
66
|
end
|
50
67
|
|
51
68
|
it_behaves_like 'a redacted string'
|
@@ -53,8 +70,10 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
53
70
|
|
54
71
|
context 'when the user and password are provided in the URI object' do
|
55
72
|
let(:arguments) do
|
56
|
-
{
|
57
|
-
|
73
|
+
{
|
74
|
+
hosts: URI.parse('https://test:secret_password@fake_local_elasticsearch'),
|
75
|
+
logger: logger
|
76
|
+
}
|
58
77
|
end
|
59
78
|
|
60
79
|
it_behaves_like 'a redacted string'
|
@@ -62,41 +81,36 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
62
81
|
end
|
63
82
|
|
64
83
|
context 'when reload_on_failure is true and and hosts are unreachable' do
|
65
|
-
|
66
84
|
let(:client) do
|
67
85
|
Elasticsearch::Transport::Client.new(arguments)
|
68
86
|
end
|
69
87
|
|
70
88
|
let(:arguments) do
|
71
89
|
{
|
72
|
-
|
73
|
-
|
74
|
-
|
90
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
91
|
+
reload_on_failure: true,
|
92
|
+
sniffer_timeout: 5
|
75
93
|
}
|
76
94
|
end
|
77
95
|
|
78
96
|
it 'raises an exception' do
|
79
|
-
expect {
|
80
|
-
client.info
|
81
|
-
}.to raise_exception(Faraday::ConnectionFailed)
|
97
|
+
expect { client.info }.to raise_exception(Faraday::ConnectionFailed)
|
82
98
|
end
|
83
99
|
end
|
84
100
|
|
85
101
|
context 'when the client has `retry_on_failure` set to an integer' do
|
86
|
-
|
87
102
|
let(:client) do
|
88
103
|
Elasticsearch::Transport::Client.new(arguments)
|
89
104
|
end
|
90
105
|
|
91
106
|
let(:arguments) do
|
92
107
|
{
|
93
|
-
|
94
|
-
|
108
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
109
|
+
retry_on_failure: 2
|
95
110
|
}
|
96
111
|
end
|
97
112
|
|
98
113
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
99
|
-
|
100
114
|
before do
|
101
115
|
expect(client.transport).to receive(:get_connection).exactly(3).times.and_call_original
|
102
116
|
end
|
@@ -108,22 +122,39 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
108
122
|
end
|
109
123
|
end
|
110
124
|
|
111
|
-
context 'when `perform_request` is called with a `
|
125
|
+
context 'when `perform_request` is called with a `retry_on_status` option value' do
|
126
|
+
before do
|
127
|
+
expect(client.transport).to receive(:__raise_transport_error).exactly(6).times.and_call_original
|
128
|
+
end
|
112
129
|
|
130
|
+
let(:arguments) do
|
131
|
+
{
|
132
|
+
hosts: ['http://localhost:9250'],
|
133
|
+
retry_on_status: ['404']
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'retries on 404 status the specified number of max_retries' do
|
138
|
+
expect do
|
139
|
+
client.transport.perform_request('GET', 'myindex/mydoc/1?routing=FOOBARBAZ', {}, nil, nil, retry_on_failure: 5)
|
140
|
+
end.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
113
145
|
before do
|
114
146
|
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
115
147
|
end
|
116
148
|
|
117
149
|
it 'uses the option `retry_on_failure` value' do
|
118
|
-
expect
|
150
|
+
expect do
|
119
151
|
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
120
|
-
|
152
|
+
end.to raise_exception(Faraday::ConnectionFailed)
|
121
153
|
end
|
122
154
|
end
|
123
155
|
end
|
124
156
|
|
125
157
|
context 'when the client has `retry_on_failure` set to true' do
|
126
|
-
|
127
158
|
let(:client) do
|
128
159
|
Elasticsearch::Transport::Client.new(arguments)
|
129
160
|
end
|
@@ -136,7 +167,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
136
167
|
end
|
137
168
|
|
138
169
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
139
|
-
|
140
170
|
before do
|
141
171
|
expect(client.transport).to receive(:get_connection).exactly(4).times.and_call_original
|
142
172
|
end
|
@@ -149,7 +179,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
149
179
|
end
|
150
180
|
|
151
181
|
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
152
|
-
|
153
182
|
before do
|
154
183
|
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
155
184
|
end
|
@@ -163,7 +192,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
163
192
|
end
|
164
193
|
|
165
194
|
context 'when the client has `retry_on_failure` set to false' do
|
166
|
-
|
167
195
|
let(:client) do
|
168
196
|
Elasticsearch::Transport::Client.new(arguments)
|
169
197
|
end
|
@@ -176,7 +204,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
176
204
|
end
|
177
205
|
|
178
206
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
179
|
-
|
180
207
|
before do
|
181
208
|
expect(client.transport).to receive(:get_connection).once.and_call_original
|
182
209
|
end
|
@@ -203,40 +230,35 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
203
230
|
end
|
204
231
|
|
205
232
|
context 'when the client has no `retry_on_failure` set' do
|
206
|
-
|
207
233
|
let(:client) do
|
208
234
|
Elasticsearch::Transport::Client.new(arguments)
|
209
235
|
end
|
210
236
|
|
211
237
|
let(:arguments) do
|
212
|
-
{
|
213
|
-
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
214
|
-
}
|
238
|
+
{ hosts: ['http://unavailable:9200', 'http://unavailable:9201'] }
|
215
239
|
end
|
216
240
|
|
217
241
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
218
|
-
|
219
242
|
before do
|
220
243
|
expect(client.transport).to receive(:get_connection).exactly(1).times.and_call_original
|
221
244
|
end
|
222
245
|
|
223
246
|
it 'does not retry' do
|
224
|
-
expect
|
247
|
+
expect do
|
225
248
|
client.transport.perform_request('GET', '/info')
|
226
|
-
|
249
|
+
end.to raise_exception(Faraday::ConnectionFailed)
|
227
250
|
end
|
228
251
|
end
|
229
252
|
|
230
253
|
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
231
|
-
|
232
254
|
before do
|
233
255
|
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
234
256
|
end
|
235
257
|
|
236
258
|
it 'uses the option `retry_on_failure` value' do
|
237
|
-
expect
|
259
|
+
expect do
|
238
260
|
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
239
|
-
|
261
|
+
end.to raise_exception(Faraday::ConnectionFailed)
|
240
262
|
end
|
241
263
|
end
|
242
264
|
end
|