elasticsearch-transport 6.8.1 → 6.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +86 -32
- data/elasticsearch-transport.gemspec +44 -64
- data/lib/elasticsearch-transport.rb +4 -0
- data/lib/elasticsearch/transport.rb +4 -0
- data/lib/elasticsearch/transport/client.rb +51 -11
- data/lib/elasticsearch/transport/redacted.rb +4 -0
- data/lib/elasticsearch/transport/transport/base.rb +17 -7
- data/lib/elasticsearch/transport/transport/connections/collection.rb +4 -0
- data/lib/elasticsearch/transport/transport/connections/connection.rb +4 -0
- data/lib/elasticsearch/transport/transport/connections/selector.rb +4 -0
- data/lib/elasticsearch/transport/transport/errors.rb +4 -0
- data/lib/elasticsearch/transport/transport/http/curb.rb +6 -2
- data/lib/elasticsearch/transport/transport/http/faraday.rb +6 -2
- data/lib/elasticsearch/transport/transport/http/manticore.rb +5 -1
- data/lib/elasticsearch/transport/transport/response.rb +4 -0
- data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +4 -0
- data/lib/elasticsearch/transport/transport/sniffer.rb +31 -3
- data/lib/elasticsearch/transport/version.rb +5 -1
- data/spec/elasticsearch/transport/base_spec.rb +184 -0
- data/spec/elasticsearch/transport/client_spec.rb +117 -21
- data/spec/elasticsearch/transport/sniffer_spec.rb +269 -0
- data/spec/spec_helper.rb +4 -0
- data/test/integration/transport_test.rb +4 -0
- data/test/profile/client_benchmark_test.rb +4 -0
- data/test/test_helper.rb +4 -0
- data/test/unit/connection_collection_test.rb +4 -0
- data/test/unit/connection_selector_test.rb +4 -0
- data/test/unit/connection_test.rb +4 -0
- data/test/unit/response_test.rb +5 -1
- data/test/unit/serializer_test.rb +4 -0
- data/test/unit/transport_base_test.rb +4 -0
- data/test/unit/transport_curb_test.rb +4 -0
- data/test/unit/transport_faraday_test.rb +4 -0
- data/test/unit/transport_manticore_test.rb +4 -0
- metadata +68 -64
- data/test/unit/sniffer_test.rb +0 -179
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
7
|
module Transport
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
7
|
module Transport
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
7
|
module Transport
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
7
|
module Transport
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
7
|
module Transport
|
@@ -15,8 +19,8 @@ module Elasticsearch
|
|
15
19
|
# @return [Response]
|
16
20
|
# @see Transport::Base#perform_request
|
17
21
|
#
|
18
|
-
def perform_request(method, path, params={}, body=nil, headers=nil)
|
19
|
-
super do |connection,url|
|
22
|
+
def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
|
23
|
+
super do |connection, url|
|
20
24
|
connection.connection.url = url
|
21
25
|
|
22
26
|
case method
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
7
|
module Transport
|
@@ -16,7 +20,7 @@ module Elasticsearch
|
|
16
20
|
# @return [Response]
|
17
21
|
# @see Transport::Base#perform_request
|
18
22
|
#
|
19
|
-
def perform_request(method, path, params={}, body=nil, headers=nil)
|
23
|
+
def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
|
20
24
|
super do |connection, url|
|
21
25
|
headers = headers || connection.connection.headers
|
22
26
|
|
@@ -43,7 +47,7 @@ module Elasticsearch
|
|
43
47
|
# @return [Array]
|
44
48
|
#
|
45
49
|
def host_unreachable_exceptions
|
46
|
-
[::Faraday::
|
50
|
+
[::Faraday::ConnectionFailed, ::Faraday::TimeoutError]
|
47
51
|
end
|
48
52
|
end
|
49
53
|
end
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
require 'manticore'
|
2
6
|
|
3
7
|
module Elasticsearch
|
@@ -63,7 +67,7 @@ module Elasticsearch
|
|
63
67
|
# @return [Response]
|
64
68
|
# @see Transport::Base#perform_request
|
65
69
|
#
|
66
|
-
def perform_request(method, path, params={}, body=nil, headers=nil)
|
70
|
+
def perform_request(method, path, params={}, body=nil, headers=nil, opts={})
|
67
71
|
super do |connection, url|
|
68
72
|
params[:body] = __convert_to_json(body) if body
|
69
73
|
params[:headers] = headers if headers
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
7
|
module Transport
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
7
|
module Transport
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
7
|
module Transport
|
@@ -28,11 +32,12 @@ module Elasticsearch
|
|
28
32
|
#
|
29
33
|
def hosts
|
30
34
|
Timeout::timeout(timeout, SnifferTimeoutError) do
|
31
|
-
nodes = transport.perform_request('GET', '_nodes/http'
|
35
|
+
nodes = transport.perform_request('GET', '_nodes/http', {}, nil, nil,
|
36
|
+
reload_on_failure: false).body
|
32
37
|
|
33
|
-
hosts = nodes['nodes'].map do |id,info|
|
38
|
+
hosts = nodes['nodes'].map do |id, info|
|
34
39
|
if info[PROTOCOL]
|
35
|
-
host, port = info[PROTOCOL]['publish_address']
|
40
|
+
host, port = parse_publish_address(info[PROTOCOL]['publish_address'])
|
36
41
|
|
37
42
|
{ :id => id,
|
38
43
|
:name => info['name'],
|
@@ -48,6 +53,29 @@ module Elasticsearch
|
|
48
53
|
hosts
|
49
54
|
end
|
50
55
|
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def parse_publish_address(publish_address)
|
60
|
+
# publish_address is in the format hostname/ip:port
|
61
|
+
if publish_address =~ /\//
|
62
|
+
parts = publish_address.partition('/')
|
63
|
+
[ parts[0], parse_address_port(parts[2])[1] ]
|
64
|
+
else
|
65
|
+
parse_address_port(publish_address)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def parse_address_port(publish_address)
|
70
|
+
# address is ipv6
|
71
|
+
if publish_address =~ /[\[\]]/
|
72
|
+
if parts = publish_address.match(/\A\[(.+)\](?::(\d+))?\z/)
|
73
|
+
[ parts[1], parts[2] ]
|
74
|
+
end
|
75
|
+
else
|
76
|
+
publish_address.split(':')
|
77
|
+
end
|
78
|
+
end
|
51
79
|
end
|
52
80
|
end
|
53
81
|
end
|
@@ -1,5 +1,9 @@
|
|
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
|
+
|
1
5
|
module Elasticsearch
|
2
6
|
module Transport
|
3
|
-
VERSION = '6.8.
|
7
|
+
VERSION = '6.8.2'
|
4
8
|
end
|
5
9
|
end
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
6
|
# license agreements. See the NOTICE file distributed with
|
3
7
|
# this work for additional information regarding copyright
|
@@ -73,4 +77,184 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
73
77
|
it_behaves_like 'a redacted string'
|
74
78
|
end
|
75
79
|
end
|
80
|
+
|
81
|
+
context 'when reload_on_failure is true and and hosts are unreachable' do
|
82
|
+
|
83
|
+
let(:client) do
|
84
|
+
Elasticsearch::Transport::Client.new(arguments)
|
85
|
+
end
|
86
|
+
|
87
|
+
let(:arguments) do
|
88
|
+
{
|
89
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
90
|
+
reload_on_failure: true,
|
91
|
+
sniffer_timeout: 5
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'raises an exception' do
|
96
|
+
expect {
|
97
|
+
client.info
|
98
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'when the client has `retry_on_failure` set to an integer' do
|
103
|
+
|
104
|
+
let(:client) do
|
105
|
+
Elasticsearch::Transport::Client.new(arguments)
|
106
|
+
end
|
107
|
+
|
108
|
+
let(:arguments) do
|
109
|
+
{
|
110
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
111
|
+
retry_on_failure: 2
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
116
|
+
|
117
|
+
before do
|
118
|
+
expect(client.transport).to receive(:get_connection).exactly(3).times.and_call_original
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'uses the client `retry_on_failure` value' do
|
122
|
+
expect {
|
123
|
+
client.transport.perform_request('GET', '/info')
|
124
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
129
|
+
|
130
|
+
before do
|
131
|
+
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'uses the option `retry_on_failure` value' do
|
135
|
+
expect {
|
136
|
+
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
137
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'when the client has `retry_on_failure` set to true' do
|
143
|
+
|
144
|
+
let(:client) do
|
145
|
+
Elasticsearch::Transport::Client.new(arguments)
|
146
|
+
end
|
147
|
+
|
148
|
+
let(:arguments) do
|
149
|
+
{
|
150
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
151
|
+
retry_on_failure: true
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
156
|
+
|
157
|
+
before do
|
158
|
+
expect(client.transport).to receive(:get_connection).exactly(4).times.and_call_original
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'uses the default `MAX_RETRIES` value' do
|
162
|
+
expect {
|
163
|
+
client.transport.perform_request('GET', '/info')
|
164
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
169
|
+
|
170
|
+
before do
|
171
|
+
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'uses the option `retry_on_failure` value' do
|
175
|
+
expect {
|
176
|
+
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
177
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'when the client has `retry_on_failure` set to false' do
|
183
|
+
|
184
|
+
let(:client) do
|
185
|
+
Elasticsearch::Transport::Client.new(arguments)
|
186
|
+
end
|
187
|
+
|
188
|
+
let(:arguments) do
|
189
|
+
{
|
190
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
191
|
+
retry_on_failure: false
|
192
|
+
}
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
196
|
+
|
197
|
+
before do
|
198
|
+
expect(client.transport).to receive(:get_connection).once.and_call_original
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'does not retry' do
|
202
|
+
expect {
|
203
|
+
client.transport.perform_request('GET', '/info')
|
204
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
209
|
+
|
210
|
+
before do
|
211
|
+
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'uses the option `retry_on_failure` value' do
|
215
|
+
expect {
|
216
|
+
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
217
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'when the client has no `retry_on_failure` set' do
|
223
|
+
|
224
|
+
let(:client) do
|
225
|
+
Elasticsearch::Transport::Client.new(arguments)
|
226
|
+
end
|
227
|
+
|
228
|
+
let(:arguments) do
|
229
|
+
{
|
230
|
+
hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
|
231
|
+
}
|
232
|
+
end
|
233
|
+
|
234
|
+
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
235
|
+
|
236
|
+
before do
|
237
|
+
expect(client.transport).to receive(:get_connection).exactly(1).times.and_call_original
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'does not retry' do
|
241
|
+
expect {
|
242
|
+
client.transport.perform_request('GET', '/info')
|
243
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
248
|
+
|
249
|
+
before do
|
250
|
+
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'uses the option `retry_on_failure` value' do
|
254
|
+
expect {
|
255
|
+
client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5)
|
256
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
76
260
|
end
|
@@ -1,3 +1,7 @@
|
|
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
|
+
|
1
5
|
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
6
|
# license agreements. See the NOTICE file distributed with
|
3
7
|
# this work for additional information regarding copyright
|
@@ -45,31 +49,87 @@ describe Elasticsearch::Transport::Client do
|
|
45
49
|
expect(client.transport.hosts[0][:host]).to eq('localhost')
|
46
50
|
end
|
47
51
|
|
48
|
-
|
52
|
+
context 'when an encoded api_key is provided' do
|
53
|
+
let(:client) do
|
54
|
+
described_class.new(api_key: 'an_api_key')
|
55
|
+
end
|
56
|
+
let(:authorization_header) do
|
57
|
+
client.transport.connections.first.connection.headers['Authorization']
|
58
|
+
end
|
49
59
|
|
50
|
-
|
60
|
+
it 'Adds the ApiKey header to the connection' do
|
61
|
+
expect(authorization_header).to eq('ApiKey an_api_key')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when an un-encoded api_key is provided' do
|
66
|
+
let(:client) do
|
67
|
+
described_class.new(api_key: { id: 'my_id', api_key: 'my_api_key' })
|
68
|
+
end
|
69
|
+
let(:authorization_header) do
|
70
|
+
client.transport.connections.first.connection.headers['Authorization']
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'Adds the ApiKey header to the connection' do
|
74
|
+
expect(authorization_header).to eq("ApiKey #{Base64.strict_encode64('my_id:my_api_key')}")
|
75
|
+
end
|
76
|
+
end
|
51
77
|
|
78
|
+
context 'when basic auth and api_key are provided' do
|
79
|
+
let(:client) do
|
80
|
+
described_class.new(
|
81
|
+
api_key: { id: 'my_id', api_key: 'my_api_key' },
|
82
|
+
host: 'http://elastic:password@localhost:9200'
|
83
|
+
)
|
84
|
+
end
|
85
|
+
let(:authorization_header) do
|
86
|
+
client.transport.connections.first.connection.headers['Authorization']
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'removes basic auth credentials' do
|
90
|
+
expect(authorization_header).not_to match(/^Basic/)
|
91
|
+
expect(authorization_header).to match(/^ApiKey/)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'adapter' do
|
96
|
+
context 'when no adapter is specified' do
|
52
97
|
let(:adapter) do
|
53
|
-
client.transport.connections.all.first.connection.builder.
|
98
|
+
client.transport.connections.all.first.connection.builder.adapter
|
54
99
|
end
|
55
100
|
|
56
101
|
it 'uses Faraday NetHttp' do
|
57
|
-
expect(adapter).to
|
102
|
+
expect(adapter).to eq Faraday::Adapter::NetHttp
|
58
103
|
end
|
59
104
|
end
|
60
105
|
|
61
106
|
context 'when the adapter is specified' do
|
62
107
|
|
63
108
|
let(:adapter) do
|
64
|
-
client.transport.connections.all.first.connection.builder.
|
109
|
+
client.transport.connections.all.first.connection.builder.adapter
|
110
|
+
end
|
111
|
+
|
112
|
+
let(:client) do
|
113
|
+
described_class.new(adapter: :patron)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'uses Faraday with the adapter' do
|
117
|
+
expect(adapter).to eq Faraday::Adapter::Patron
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when the adapter is specified as a string key' do
|
122
|
+
|
123
|
+
let(:adapter) do
|
124
|
+
client.transport.connections.all.first.connection.builder.adapter
|
65
125
|
end
|
66
126
|
|
67
127
|
let(:client) do
|
68
|
-
described_class.new(adapter
|
128
|
+
described_class.new('adapter' => :patron)
|
69
129
|
end
|
70
130
|
|
71
|
-
it 'uses Faraday' do
|
72
|
-
expect(adapter).to
|
131
|
+
it 'uses Faraday with the adapter' do
|
132
|
+
expect(adapter).to eq Faraday::Adapter::Patron
|
73
133
|
end
|
74
134
|
end
|
75
135
|
|
@@ -81,11 +141,11 @@ describe Elasticsearch::Transport::Client do
|
|
81
141
|
end
|
82
142
|
|
83
143
|
let(:adapter) do
|
84
|
-
client.transport.connections.all.first.connection.builder.
|
144
|
+
client.transport.connections.all.first.connection.builder.adapter
|
85
145
|
end
|
86
146
|
|
87
147
|
it 'uses the detected adapter' do
|
88
|
-
expect(adapter).to
|
148
|
+
expect(adapter).to eq Faraday::Adapter::Patron
|
89
149
|
end
|
90
150
|
end
|
91
151
|
|
@@ -93,17 +153,21 @@ describe Elasticsearch::Transport::Client do
|
|
93
153
|
|
94
154
|
let(:client) do
|
95
155
|
described_class.new do |faraday|
|
96
|
-
faraday.adapter :
|
156
|
+
faraday.adapter :patron
|
97
157
|
faraday.response :logger
|
98
158
|
end
|
99
159
|
end
|
100
160
|
|
161
|
+
let(:adapter) do
|
162
|
+
client.transport.connections.all.first.connection.builder.adapter
|
163
|
+
end
|
164
|
+
|
101
165
|
let(:handlers) do
|
102
166
|
client.transport.connections.all.first.connection.builder.handlers
|
103
167
|
end
|
104
168
|
|
105
169
|
it 'sets the adapter' do
|
106
|
-
expect(
|
170
|
+
expect(adapter).to eq Faraday::Adapter::Patron
|
107
171
|
end
|
108
172
|
|
109
173
|
it 'sets the logger' do
|
@@ -611,10 +675,43 @@ describe Elasticsearch::Transport::Client do
|
|
611
675
|
expect(request).to be(true)
|
612
676
|
end
|
613
677
|
end
|
678
|
+
|
679
|
+
context 'when x-opaque-id is set' do
|
680
|
+
let(:client) { described_class.new(host: hosts) }
|
681
|
+
|
682
|
+
it 'uses x-opaque-id on a request' do
|
683
|
+
expect(client.perform_request('GET', '/', { opaque_id: '12345' }).headers['x-opaque-id']).to eq('12345')
|
684
|
+
end
|
685
|
+
end
|
686
|
+
|
687
|
+
context 'when an x-opaque-id prefix is set on initialization' do
|
688
|
+
let(:prefix) { 'elastic_cloud' }
|
689
|
+
let(:client) do
|
690
|
+
described_class.new(host: hosts, opaque_id_prefix: prefix)
|
691
|
+
end
|
692
|
+
|
693
|
+
it 'uses x-opaque-id on a request' do
|
694
|
+
expect(client.perform_request('GET', '/', { opaque_id: '12345' }).headers['x-opaque-id']).to eq("#{prefix}12345")
|
695
|
+
end
|
696
|
+
|
697
|
+
context 'when using an API call' do
|
698
|
+
let(:client) { described_class.new(host: hosts) }
|
699
|
+
|
700
|
+
it 'doesnae raise an ArgumentError' do
|
701
|
+
expect { client.search(opaque_id: 'no_error') }.not_to raise_error
|
702
|
+
end
|
703
|
+
|
704
|
+
it 'uses X-Opaque-Id in the header' do
|
705
|
+
allow(client).to receive(:perform_request) { OpenStruct.new(body: '') }
|
706
|
+
expect { client.search(opaque_id: 'opaque_id') }.not_to raise_error
|
707
|
+
expect(client).to have_received(:perform_request)
|
708
|
+
.with('GET', '_search', { opaque_id: 'opaque_id' }, nil)
|
709
|
+
end
|
710
|
+
end
|
711
|
+
end
|
614
712
|
end
|
615
713
|
|
616
714
|
context 'when the client connects to Elasticsearch' do
|
617
|
-
|
618
715
|
let(:logger) do
|
619
716
|
Logger.new(STDERR).tap do |logger|
|
620
717
|
logger.formatter = proc do |severity, datetime, progname, msg|
|
@@ -692,15 +789,14 @@ describe Elasticsearch::Transport::Client do
|
|
692
789
|
end
|
693
790
|
|
694
791
|
context 'when the Faraday adapter is set in the block' do
|
695
|
-
|
696
792
|
let(:client) do
|
697
793
|
Elasticsearch::Client.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
|
698
794
|
client.adapter(:net_http_persistent)
|
699
795
|
end
|
700
796
|
end
|
701
797
|
|
702
|
-
let(:
|
703
|
-
client.transport.connections.first.connection.builder.
|
798
|
+
let(:handler_name) do
|
799
|
+
client.transport.connections.first.connection.builder.adapter.name
|
704
800
|
end
|
705
801
|
|
706
802
|
let(:response) do
|
@@ -708,7 +804,7 @@ describe Elasticsearch::Transport::Client do
|
|
708
804
|
end
|
709
805
|
|
710
806
|
it 'sets the adapter' do
|
711
|
-
expect(
|
807
|
+
expect(handler_name).to eq('Faraday::Adapter::NetHttpPersistent')
|
712
808
|
end
|
713
809
|
|
714
810
|
it 'uses the adapter to connect' do
|
@@ -758,7 +854,7 @@ describe Elasticsearch::Transport::Client do
|
|
758
854
|
expect(client.perform_request('GET', '_nodes/_local'))
|
759
855
|
expect {
|
760
856
|
client.perform_request('GET', '_nodes/_local')
|
761
|
-
}.to raise_exception(Faraday::
|
857
|
+
}.to raise_exception(Faraday::ConnectionFailed)
|
762
858
|
end
|
763
859
|
end
|
764
860
|
|
@@ -907,12 +1003,12 @@ describe Elasticsearch::Transport::Client do
|
|
907
1003
|
{ adapter: :patron }
|
908
1004
|
end
|
909
1005
|
|
910
|
-
let(:
|
911
|
-
client.transport.connections.first.connection.builder.
|
1006
|
+
let(:adapter) do
|
1007
|
+
client.transport.connections.first.connection.builder.adapter
|
912
1008
|
end
|
913
1009
|
|
914
1010
|
it 'uses the patron connection handler' do
|
915
|
-
expect(
|
1011
|
+
expect(adapter).to eq('Faraday::Adapter::Patron')
|
916
1012
|
end
|
917
1013
|
|
918
1014
|
it 'keeps connections open' do
|