elasticsearch-transport 6.8.2 → 7.0.0.pre
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/Gemfile +17 -0
- data/LICENSE.txt +199 -10
- data/README.md +32 -86
- data/Rakefile +23 -4
- data/elasticsearch-transport.gemspec +78 -44
- data/lib/elasticsearch-transport.rb +16 -3
- data/lib/elasticsearch/transport.rb +17 -3
- data/lib/elasticsearch/transport/client.rb +62 -85
- data/lib/elasticsearch/transport/redacted.rb +5 -9
- data/lib/elasticsearch/transport/transport/base.rb +63 -55
- data/lib/elasticsearch/transport/transport/connections/collection.rb +16 -3
- data/lib/elasticsearch/transport/transport/connections/connection.rb +16 -3
- 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 +18 -5
- data/lib/elasticsearch/transport/transport/http/faraday.rb +18 -5
- data/lib/elasticsearch/transport/transport/http/manticore.rb +17 -4
- data/lib/elasticsearch/transport/transport/loggable.rb +85 -0
- data/lib/elasticsearch/transport/transport/response.rb +16 -3
- data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +16 -3
- data/lib/elasticsearch/transport/transport/sniffer.rb +17 -5
- data/lib/elasticsearch/transport/version.rb +17 -4
- data/spec/elasticsearch/transport/base_spec.rb +8 -187
- data/spec/elasticsearch/transport/client_spec.rb +27 -123
- data/spec/elasticsearch/transport/sniffer_spec.rb +19 -0
- data/spec/spec_helper.rb +2 -4
- data/test/integration/transport_test.rb +18 -5
- data/test/profile/client_benchmark_test.rb +16 -3
- data/test/test_helper.rb +63 -14
- data/test/unit/connection_collection_test.rb +17 -4
- data/test/unit/connection_selector_test.rb +17 -4
- data/test/unit/connection_test.rb +17 -4
- data/test/unit/response_test.rb +18 -5
- data/test/unit/serializer_test.rb +17 -4
- data/test/unit/transport_base_test.rb +21 -8
- data/test/unit/transport_curb_test.rb +17 -4
- data/test/unit/transport_faraday_test.rb +17 -4
- data/test/unit/transport_manticore_test.rb +24 -6
- metadata +67 -76
@@ -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
|
@@ -32,8 +45,7 @@ module Elasticsearch
|
|
32
45
|
#
|
33
46
|
def hosts
|
34
47
|
Timeout::timeout(timeout, SnifferTimeoutError) do
|
35
|
-
nodes = transport.perform_request('GET', '_nodes/http'
|
36
|
-
reload_on_failure: false).body
|
48
|
+
nodes = transport.perform_request('GET', '_nodes/http').body
|
37
49
|
|
38
50
|
hosts = nodes['nodes'].map do |id, info|
|
39
51
|
if info[PROTOCOL]
|
@@ -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.0.0.pre"
|
8
21
|
end
|
9
22
|
end
|
@@ -1,7 +1,3 @@
|
|
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
1
|
# Licensed to Elasticsearch B.V. under one or more contributor
|
6
2
|
# license agreements. See the NOTICE file distributed with
|
7
3
|
# this work for additional information regarding copyright
|
@@ -22,8 +18,11 @@
|
|
22
18
|
require 'spec_helper'
|
23
19
|
|
24
20
|
describe Elasticsearch::Transport::Transport::Base do
|
21
|
+
|
25
22
|
context 'when a host is printed in a logged message' do
|
23
|
+
|
26
24
|
shared_examples_for 'a redacted string' do
|
25
|
+
|
27
26
|
let(:client) do
|
28
27
|
Elasticsearch::Transport::Client.new(arguments)
|
29
28
|
end
|
@@ -34,7 +33,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
34
33
|
|
35
34
|
it 'does not include the password in the logged string' do
|
36
35
|
expect(logger).not_to receive(:error).with(/secret_password/)
|
37
|
-
|
38
36
|
expect {
|
39
37
|
client.cluster.stats
|
40
38
|
}.to raise_exception(Faraday::ConnectionFailed)
|
@@ -49,6 +47,7 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
49
47
|
end
|
50
48
|
|
51
49
|
context 'when the user and password are provided as separate arguments' do
|
50
|
+
|
52
51
|
let(:arguments) do
|
53
52
|
{ hosts: 'fake',
|
54
53
|
logger: logger,
|
@@ -60,8 +59,9 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
60
59
|
end
|
61
60
|
|
62
61
|
context 'when the user and password are provided in the string URI' do
|
62
|
+
|
63
63
|
let(:arguments) do
|
64
|
-
{ hosts: '
|
64
|
+
{ hosts: 'http://test:secret_password@fake.com',
|
65
65
|
logger: logger }
|
66
66
|
end
|
67
67
|
|
@@ -69,192 +69,13 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
context 'when the user and password are provided in the URI object' do
|
72
|
+
|
72
73
|
let(:arguments) do
|
73
|
-
{ hosts: URI.parse('
|
74
|
+
{ hosts: URI.parse('http://test:secret_password@fake.com'),
|
74
75
|
logger: logger }
|
75
76
|
end
|
76
77
|
|
77
78
|
it_behaves_like 'a redacted string'
|
78
79
|
end
|
79
80
|
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
|
260
81
|
end
|
@@ -1,7 +1,3 @@
|
|
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
1
|
# Licensed to Elasticsearch B.V. under one or more contributor
|
6
2
|
# license agreements. See the NOTICE file distributed with
|
7
3
|
# this work for additional information regarding copyright
|
@@ -49,87 +45,31 @@ describe Elasticsearch::Transport::Client do
|
|
49
45
|
expect(client.transport.hosts[0][:host]).to eq('localhost')
|
50
46
|
end
|
51
47
|
|
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
|
59
|
-
|
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
|
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
48
|
describe 'adapter' do
|
49
|
+
|
96
50
|
context 'when no adapter is specified' do
|
51
|
+
|
97
52
|
let(:adapter) do
|
98
|
-
client.transport.connections.all.first.connection.builder.
|
53
|
+
client.transport.connections.all.first.connection.builder.handlers
|
99
54
|
end
|
100
55
|
|
101
56
|
it 'uses Faraday NetHttp' do
|
102
|
-
expect(adapter).to
|
57
|
+
expect(adapter).to include(Faraday::Adapter::NetHttp)
|
103
58
|
end
|
104
59
|
end
|
105
60
|
|
106
61
|
context 'when the adapter is specified' do
|
107
62
|
|
108
63
|
let(:adapter) do
|
109
|
-
client.transport.connections.all.first.connection.builder.
|
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
|
64
|
+
client.transport.connections.all.first.connection.builder.handlers
|
125
65
|
end
|
126
66
|
|
127
67
|
let(:client) do
|
128
|
-
described_class.new(
|
68
|
+
described_class.new(adapter: :typhoeus)
|
129
69
|
end
|
130
70
|
|
131
|
-
it 'uses Faraday
|
132
|
-
expect(adapter).to
|
71
|
+
it 'uses Faraday' do
|
72
|
+
expect(adapter).to include(Faraday::Adapter::Typhoeus)
|
133
73
|
end
|
134
74
|
end
|
135
75
|
|
@@ -141,11 +81,11 @@ describe Elasticsearch::Transport::Client do
|
|
141
81
|
end
|
142
82
|
|
143
83
|
let(:adapter) do
|
144
|
-
client.transport.connections.all.first.connection.builder.
|
84
|
+
client.transport.connections.all.first.connection.builder.handlers
|
145
85
|
end
|
146
86
|
|
147
87
|
it 'uses the detected adapter' do
|
148
|
-
expect(adapter).to
|
88
|
+
expect(adapter).to include(Faraday::Adapter::Patron)
|
149
89
|
end
|
150
90
|
end
|
151
91
|
|
@@ -153,21 +93,17 @@ describe Elasticsearch::Transport::Client do
|
|
153
93
|
|
154
94
|
let(:client) do
|
155
95
|
described_class.new do |faraday|
|
156
|
-
faraday.adapter :
|
96
|
+
faraday.adapter :typhoeus
|
157
97
|
faraday.response :logger
|
158
98
|
end
|
159
99
|
end
|
160
100
|
|
161
|
-
let(:adapter) do
|
162
|
-
client.transport.connections.all.first.connection.builder.adapter
|
163
|
-
end
|
164
|
-
|
165
101
|
let(:handlers) do
|
166
102
|
client.transport.connections.all.first.connection.builder.handlers
|
167
103
|
end
|
168
104
|
|
169
105
|
it 'sets the adapter' do
|
170
|
-
expect(
|
106
|
+
expect(handlers).to include(Faraday::Adapter::Typhoeus)
|
171
107
|
end
|
172
108
|
|
173
109
|
it 'sets the logger' do
|
@@ -675,43 +611,10 @@ describe Elasticsearch::Transport::Client do
|
|
675
611
|
expect(request).to be(true)
|
676
612
|
end
|
677
613
|
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
|
712
614
|
end
|
713
615
|
|
714
616
|
context 'when the client connects to Elasticsearch' do
|
617
|
+
|
715
618
|
let(:logger) do
|
716
619
|
Logger.new(STDERR).tap do |logger|
|
717
620
|
logger.formatter = proc do |severity, datetime, progname, msg|
|
@@ -727,7 +630,7 @@ describe Elasticsearch::Transport::Client do
|
|
727
630
|
end
|
728
631
|
|
729
632
|
let(:port) do
|
730
|
-
|
633
|
+
TEST_PORT
|
731
634
|
end
|
732
635
|
|
733
636
|
let(:transport_options) do
|
@@ -749,7 +652,7 @@ describe Elasticsearch::Transport::Client do
|
|
749
652
|
end
|
750
653
|
|
751
654
|
it 'connects to the cluster' do
|
752
|
-
expect(response.body['number_of_nodes']).to be
|
655
|
+
expect(response.body['number_of_nodes']).to be >= (1)
|
753
656
|
end
|
754
657
|
end
|
755
658
|
|
@@ -789,14 +692,15 @@ describe Elasticsearch::Transport::Client do
|
|
789
692
|
end
|
790
693
|
|
791
694
|
context 'when the Faraday adapter is set in the block' do
|
695
|
+
|
792
696
|
let(:client) do
|
793
697
|
Elasticsearch::Client.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
|
794
698
|
client.adapter(:net_http_persistent)
|
795
699
|
end
|
796
700
|
end
|
797
701
|
|
798
|
-
let(:
|
799
|
-
client.transport.connections.first.connection.builder.
|
702
|
+
let(:connection_handler) do
|
703
|
+
client.transport.connections.first.connection.builder.handlers.first
|
800
704
|
end
|
801
705
|
|
802
706
|
let(:response) do
|
@@ -804,7 +708,7 @@ describe Elasticsearch::Transport::Client do
|
|
804
708
|
end
|
805
709
|
|
806
710
|
it 'sets the adapter' do
|
807
|
-
expect(
|
711
|
+
expect(connection_handler.name).to eq('Faraday::Adapter::NetHttpPersistent')
|
808
712
|
end
|
809
713
|
|
810
714
|
it 'uses the adapter to connect' do
|
@@ -854,7 +758,7 @@ describe Elasticsearch::Transport::Client do
|
|
854
758
|
expect(client.perform_request('GET', '_nodes/_local'))
|
855
759
|
expect {
|
856
760
|
client.perform_request('GET', '_nodes/_local')
|
857
|
-
}.to raise_exception(Faraday::ConnectionFailed)
|
761
|
+
}.to raise_exception(Faraday::Error::ConnectionFailed)
|
858
762
|
end
|
859
763
|
end
|
860
764
|
|
@@ -877,7 +781,7 @@ describe Elasticsearch::Transport::Client do
|
|
877
781
|
it 'reloads the connections' do
|
878
782
|
expect(client.transport.connections.size).to eq(3)
|
879
783
|
expect(responses.all? { true }).to be(true)
|
880
|
-
expect(client.transport.connections.size).to
|
784
|
+
expect(client.transport.connections.size).to be >= (1)
|
881
785
|
end
|
882
786
|
end
|
883
787
|
|
@@ -888,7 +792,7 @@ describe Elasticsearch::Transport::Client do
|
|
888
792
|
end
|
889
793
|
|
890
794
|
let(:logger) do
|
891
|
-
double('logger', :fatal => false)
|
795
|
+
double('logger', :debug? => false, :warn? => true, :fatal? => false, :error? => false)
|
892
796
|
end
|
893
797
|
|
894
798
|
before do
|
@@ -910,7 +814,7 @@ describe Elasticsearch::Transport::Client do
|
|
910
814
|
before do
|
911
815
|
client.perform_request('DELETE', '_all')
|
912
816
|
client.perform_request('DELETE', 'myindex') rescue
|
913
|
-
|
817
|
+
client.perform_request('PUT', 'myindex', {}, { settings: { number_of_shards: 2, number_of_replicas: 0 } })
|
914
818
|
client.perform_request('PUT', 'myindex/mydoc/1', { routing: 'XYZ', timeout: '1s' }, { foo: 'bar' })
|
915
819
|
client.perform_request('GET', '_cluster/health?wait_for_status=green', {})
|
916
820
|
end
|
@@ -1003,12 +907,12 @@ describe Elasticsearch::Transport::Client do
|
|
1003
907
|
{ adapter: :patron }
|
1004
908
|
end
|
1005
909
|
|
1006
|
-
let(:
|
1007
|
-
client.transport.connections.first.connection.builder.
|
910
|
+
let(:connection_handler) do
|
911
|
+
client.transport.connections.first.connection.builder.handlers.first
|
1008
912
|
end
|
1009
913
|
|
1010
914
|
it 'uses the patron connection handler' do
|
1011
|
-
expect(
|
915
|
+
expect(connection_handler).to eq('Faraday::Adapter::Patron')
|
1012
916
|
end
|
1013
917
|
|
1014
918
|
it 'keeps connections open' do
|
@@ -1022,4 +926,4 @@ describe Elasticsearch::Transport::Client do
|
|
1022
926
|
end
|
1023
927
|
end
|
1024
928
|
end
|
1025
|
-
end
|
929
|
+
end
|