elasticsearch-transport 7.9.0 → 7.17.10
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 +10 -10
- data/Gemfile-faraday1.gemfile +47 -0
- data/README.md +23 -17
- data/Rakefile +47 -10
- data/elasticsearch-transport.gemspec +16 -18
- data/lib/elasticsearch/transport/client.rb +133 -56
- data/lib/elasticsearch/transport/meta_header.rb +135 -0
- data/lib/elasticsearch/transport/transport/base.rb +41 -22
- data/lib/elasticsearch/transport/transport/connections/collection.rb +2 -5
- data/lib/elasticsearch/transport/transport/connections/connection.rb +6 -4
- data/lib/elasticsearch/transport/transport/errors.rb +1 -0
- data/lib/elasticsearch/transport/transport/http/curb.rb +44 -32
- data/lib/elasticsearch/transport/transport/http/faraday.rb +15 -5
- data/lib/elasticsearch/transport/transport/http/manticore.rb +41 -29
- data/lib/elasticsearch/transport/transport/response.rb +1 -1
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/lib/elasticsearch/transport.rb +19 -30
- data/spec/elasticsearch/connections/collection_spec.rb +12 -0
- data/spec/elasticsearch/transport/base_spec.rb +90 -33
- data/spec/elasticsearch/transport/client_spec.rb +569 -164
- data/spec/elasticsearch/transport/http/curb_spec.rb +126 -0
- data/spec/elasticsearch/transport/http/faraday_spec.rb +141 -0
- data/spec/elasticsearch/transport/http/manticore_spec.rb +161 -0
- data/spec/elasticsearch/transport/meta_header_spec.rb +301 -0
- data/spec/spec_helper.rb +13 -5
- data/test/integration/jruby_test.rb +43 -0
- data/test/integration/transport_test.rb +93 -43
- data/test/test_helper.rb +10 -22
- data/test/unit/adapters_test.rb +88 -0
- data/test/unit/connection_test.rb +7 -2
- data/test/unit/response_test.rb +1 -1
- data/test/unit/transport_base_test.rb +17 -8
- data/test/unit/transport_curb_test.rb +0 -1
- data/test/unit/transport_faraday_test.rb +2 -2
- data/test/unit/transport_manticore_test.rb +242 -155
- metadata +62 -84
|
@@ -0,0 +1,301 @@
|
|
|
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.
|
|
17
|
+
|
|
18
|
+
require 'spec_helper'
|
|
19
|
+
require 'elasticsearch'
|
|
20
|
+
|
|
21
|
+
describe Elasticsearch::Transport::Client do
|
|
22
|
+
context 'meta-header' do
|
|
23
|
+
let(:subject) { client.transport.connections.first.connection.headers }
|
|
24
|
+
let(:client) { described_class.new }
|
|
25
|
+
let(:regexp) { /^[a-z]{1,}=[a-z0-9.\-]{1,}(?:,[a-z]{1,}=[a-z0-9._\-]+)*$/ }
|
|
26
|
+
let(:adapter) { :net_http }
|
|
27
|
+
let(:adapter_code) { "nh=#{defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}" }
|
|
28
|
+
let(:meta_header) do
|
|
29
|
+
if jruby?
|
|
30
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
|
|
31
|
+
else
|
|
32
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'client_meta_version' do
|
|
37
|
+
let(:version) { ['7.1.0-alpha', '7.11.0.pre.1', '8.0.0-beta', '8.0.0.beta.2']}
|
|
38
|
+
|
|
39
|
+
it 'converts the version to X.X.Xp' do
|
|
40
|
+
expect(client.send(:client_meta_version, '7.0.0-alpha')).to eq('7.0.0p')
|
|
41
|
+
expect(client.send(:client_meta_version, '7.11.0.pre.1')).to eq('7.11.0p')
|
|
42
|
+
expect(client.send(:client_meta_version, '8.1.0-beta')).to eq('8.1.0p')
|
|
43
|
+
expect(client.send(:client_meta_version, '8.0.0.beta.2')).to eq('8.0.0p')
|
|
44
|
+
expect(client.send(:client_meta_version, '12.16.4.pre')).to eq('12.16.4p')
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# We are testing this method in the previous block, so now using it inside the test to make the
|
|
49
|
+
# Elasticsearch version in the meta header string dynamic
|
|
50
|
+
def meta_version
|
|
51
|
+
client.send(:client_meta_version, Elasticsearch::VERSION)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context 'single use of meta header' do
|
|
55
|
+
let(:client) do
|
|
56
|
+
described_class.new(adapter: adapter).tap do |klient|
|
|
57
|
+
allow(klient).to receive(:__build_connections)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'x-elastic-client-header value matches regexp' do
|
|
62
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
|
63
|
+
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
context 'when using user-agent headers' do
|
|
68
|
+
let(:client) do
|
|
69
|
+
transport_options = { headers: { user_agent: 'My Ruby App' } }
|
|
70
|
+
described_class.new(transport_options: transport_options, adapter: adapter).tap do |klient|
|
|
71
|
+
allow(klient).to receive(:__build_connections)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'is friendly to previously set headers' do
|
|
76
|
+
expect(subject).to include(user_agent: 'My Ruby App')
|
|
77
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
|
78
|
+
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context 'when using API Key' do
|
|
83
|
+
let(:client) do
|
|
84
|
+
described_class.new(api_key: 'an_api_key', adapter: adapter)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
let(:authorization_header) do
|
|
88
|
+
client.transport.connections.first.connection.headers['Authorization']
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'adds the ApiKey header to the connection' do
|
|
92
|
+
expect(authorization_header).to eq('ApiKey an_api_key')
|
|
93
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
|
94
|
+
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
context 'adapters' do
|
|
99
|
+
let(:meta_header) do
|
|
100
|
+
if jruby?
|
|
101
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION}"
|
|
102
|
+
else
|
|
103
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION}"
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
let(:client) { described_class.new(adapter: adapter) }
|
|
107
|
+
let(:headers) { client.transport.connections.first.connection.headers }
|
|
108
|
+
|
|
109
|
+
context 'using net/http/persistent' do
|
|
110
|
+
let(:adapter) { :net_http_persistent }
|
|
111
|
+
|
|
112
|
+
it 'sets adapter in the meta header version to 0 when not loaded' do
|
|
113
|
+
was_required = defined?(Net::HTTP::Persistent)
|
|
114
|
+
if was_required
|
|
115
|
+
@klass = Net::HTTP::Persistent.clone
|
|
116
|
+
Net::HTTP.send(:remove_const, :Persistent)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
|
120
|
+
meta = "#{meta_header},np=0"
|
|
121
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
|
122
|
+
|
|
123
|
+
Net::HTTP::Persistent = @klass if was_required
|
|
124
|
+
end unless jruby?
|
|
125
|
+
|
|
126
|
+
it 'sets adapter in the meta header' do
|
|
127
|
+
require 'net/http/persistent'
|
|
128
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
|
129
|
+
meta = "#{meta_header},np=#{Net::HTTP::Persistent::VERSION}"
|
|
130
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
context 'using httpclient' do
|
|
135
|
+
let(:adapter) { :httpclient }
|
|
136
|
+
|
|
137
|
+
it 'sets adapter in the meta header version to 0 when not loaded' do
|
|
138
|
+
was_required = defined?(HTTPClient)
|
|
139
|
+
if was_required
|
|
140
|
+
@klass = HTTPClient.clone
|
|
141
|
+
Object.send(:remove_const, :HTTPClient)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
|
145
|
+
meta = "#{meta_header},hc=0"
|
|
146
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
|
147
|
+
|
|
148
|
+
HTTPClient = @klass if was_required
|
|
149
|
+
end unless jruby?
|
|
150
|
+
|
|
151
|
+
it 'sets adapter in the meta header' do
|
|
152
|
+
require 'httpclient'
|
|
153
|
+
|
|
154
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
|
155
|
+
meta = "#{meta_header},hc=#{HTTPClient::VERSION}"
|
|
156
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
context 'using typhoeus' do
|
|
161
|
+
let(:adapter) { :typhoeus }
|
|
162
|
+
|
|
163
|
+
it 'sets adapter in the meta header version to 0 when not loaded' do
|
|
164
|
+
was_required = defined?(Typhoeus)
|
|
165
|
+
if was_required
|
|
166
|
+
@klass = Typhoeus.clone
|
|
167
|
+
Object.send(:remove_const, :Typhoeus)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
|
171
|
+
meta = "#{meta_header},ty=0"
|
|
172
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
|
173
|
+
|
|
174
|
+
Typhoeus = @klass if was_required
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it 'sets adapter in the meta header' do
|
|
178
|
+
require 'typhoeus'
|
|
179
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
|
180
|
+
meta = "#{meta_header},ty=#{Typhoeus::VERSION}"
|
|
181
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
|
182
|
+
end
|
|
183
|
+
end unless jruby?
|
|
184
|
+
|
|
185
|
+
unless jruby?
|
|
186
|
+
let(:adapter) { :patron }
|
|
187
|
+
|
|
188
|
+
context 'using patron without requiring it' do
|
|
189
|
+
it 'sets adapter in the meta header version to 0 when not loaded' do
|
|
190
|
+
was_required = defined?(Patron)
|
|
191
|
+
if was_required
|
|
192
|
+
@klass = Patron.clone
|
|
193
|
+
Object.send(:remove_const, :Patron)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
|
197
|
+
meta = "#{meta_header},pt=0"
|
|
198
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
|
199
|
+
|
|
200
|
+
Patron = @klass if was_required
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
context 'using patron' do
|
|
205
|
+
it 'sets adapter in the meta header' do
|
|
206
|
+
require 'patron'
|
|
207
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
|
208
|
+
meta = "#{meta_header},pt=#{Patron::VERSION}"
|
|
209
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
context 'using other' do
|
|
215
|
+
let(:adapter) { :some_other_adapter }
|
|
216
|
+
|
|
217
|
+
it 'sets adapter in the meta header without requiring' do
|
|
218
|
+
Faraday::Adapter.register_middleware some_other_adapter: Faraday::Adapter::NetHttpPersistent
|
|
219
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
|
220
|
+
expect(headers).to include('x-elastic-client-meta' => meta_header)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
it 'sets adapter in the meta header' do
|
|
224
|
+
require 'net/http/persistent'
|
|
225
|
+
Faraday::Adapter.register_middleware some_other_adapter: Faraday::Adapter::NetHttpPersistent
|
|
226
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
|
227
|
+
expect(headers).to include('x-elastic-client-meta' => meta_header)
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
if defined?(JRUBY_VERSION)
|
|
233
|
+
context 'when using manticore' do
|
|
234
|
+
let(:client) do
|
|
235
|
+
described_class.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Manticore).tap do |client|
|
|
236
|
+
client.instance_variable_set('@verified', true)
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
let(:subject) { client.transport.connections.first.connection.instance_variable_get("@options")[:headers]}
|
|
240
|
+
|
|
241
|
+
it 'sets manticore in the metaheader' do
|
|
242
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
|
243
|
+
expect(subject['x-elastic-client-meta']).to match(/mc=[0-9.]+/)
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
else
|
|
247
|
+
context 'when using curb' do
|
|
248
|
+
let(:client) do
|
|
249
|
+
described_class.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Curb).tap do |client|
|
|
250
|
+
client.instance_variable_set('@verified', true)
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
it 'sets curb in the metaheader' do
|
|
255
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
|
256
|
+
expect(subject['x-elastic-client-meta']).to match(/cl=[0-9.]+/)
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
context 'when using custom transport implementation' do
|
|
262
|
+
let(:transport_class) do
|
|
263
|
+
Class.new do
|
|
264
|
+
def initialize(args)
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
let(:client) { Elasticsearch::Transport::Client.new(transport_class: transport_class) }
|
|
269
|
+
let(:subject) { client.instance_variable_get('@arguments')[:transport_options][:headers] }
|
|
270
|
+
let(:meta_header) do
|
|
271
|
+
if jruby?
|
|
272
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
|
|
273
|
+
else
|
|
274
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION}"
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
it 'doesnae set any info about the implementation in the metaheader' do
|
|
279
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
|
280
|
+
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
context 'when using a different service version' do
|
|
285
|
+
before do
|
|
286
|
+
stub_const('Elastic::ELASTICSEARCH_SERVICE_VERSION', [:ent, '8.0.0'])
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
let(:client) do
|
|
290
|
+
described_class.new.tap do |client|
|
|
291
|
+
client.instance_variable_set('@verified', true)
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
it 'sets the service version in the metaheader' do
|
|
296
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
|
297
|
+
expect(subject['x-elastic-client-meta']).to start_with('ent=8.0.0')
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -14,8 +14,11 @@
|
|
|
14
14
|
# KIND, either express or implied. See the License for the
|
|
15
15
|
# specific language governing permissions and limitations
|
|
16
16
|
# under the License.
|
|
17
|
+
if ENV['COVERAGE'] && ENV['CI'].nil?
|
|
18
|
+
require 'simplecov'
|
|
19
|
+
SimpleCov.start { add_filter %r{^/test|spec/} }
|
|
20
|
+
end
|
|
17
21
|
|
|
18
|
-
require 'elasticsearch'
|
|
19
22
|
require 'elasticsearch-transport'
|
|
20
23
|
require 'logger'
|
|
21
24
|
require 'ansi/code'
|
|
@@ -32,10 +35,12 @@ end
|
|
|
32
35
|
# The hosts to use for creating a elasticsearch client.
|
|
33
36
|
#
|
|
34
37
|
# @since 7.0.0
|
|
35
|
-
ELASTICSEARCH_HOSTS = if hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOSTS']
|
|
38
|
+
ELASTICSEARCH_HOSTS = if (hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOSTS'])
|
|
36
39
|
hosts.split(',').map do |host|
|
|
37
40
|
/(http\:\/\/)?(\S+)/.match(host)[2]
|
|
38
41
|
end
|
|
42
|
+
else
|
|
43
|
+
['localhost:9200']
|
|
39
44
|
end.freeze
|
|
40
45
|
|
|
41
46
|
TEST_HOST, TEST_PORT = ELASTICSEARCH_HOSTS.first.split(':') if ELASTICSEARCH_HOSTS
|
|
@@ -55,7 +60,8 @@ end
|
|
|
55
60
|
#
|
|
56
61
|
# @since 7.0.0
|
|
57
62
|
def node_names
|
|
58
|
-
|
|
63
|
+
node_stats = default_client.perform_request('GET', '_nodes/stats').body
|
|
64
|
+
$node_names ||= node_stats['nodes'].collect do |name, stats|
|
|
59
65
|
stats['name']
|
|
60
66
|
end
|
|
61
67
|
end
|
|
@@ -69,10 +75,12 @@ def default_client
|
|
|
69
75
|
$client ||= Elasticsearch::Client.new(hosts: ELASTICSEARCH_HOSTS)
|
|
70
76
|
end
|
|
71
77
|
|
|
72
|
-
|
|
78
|
+
def is_faraday_v2?
|
|
79
|
+
Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
|
|
80
|
+
end
|
|
73
81
|
|
|
82
|
+
module Config
|
|
74
83
|
def self.included(context)
|
|
75
|
-
|
|
76
84
|
# Get the hosts to use to connect an elasticsearch client.
|
|
77
85
|
#
|
|
78
86
|
# @since 7.0.0
|
|
@@ -0,0 +1,43 @@
|
|
|
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.
|
|
17
|
+
require 'test_helper'
|
|
18
|
+
|
|
19
|
+
if JRUBY
|
|
20
|
+
require 'elasticsearch/transport/transport/http/manticore'
|
|
21
|
+
|
|
22
|
+
class Elasticsearch::Transport::ClientManticoreIntegrationTest < Elasticsearch::Test::IntegrationTestCase
|
|
23
|
+
context "Transport" do
|
|
24
|
+
setup do
|
|
25
|
+
@host, @port = ELASTICSEARCH_HOSTS.first.split(':')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
shutdown do
|
|
29
|
+
begin; Object.send(:remove_const, :Manticore); rescue NameError; end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
should 'allow to customize the Faraday adapter to Manticore' do
|
|
33
|
+
client = Elasticsearch::Transport::Client.new(
|
|
34
|
+
transport_class: Elasticsearch::Transport::Transport::HTTP::Manticore,
|
|
35
|
+
trace: true,
|
|
36
|
+
hosts: [ { host: @host, port: @port } ]
|
|
37
|
+
)
|
|
38
|
+
response = client.perform_request 'GET', ''
|
|
39
|
+
assert_respond_to(response.body, :to_hash)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
require 'test_helper'
|
|
19
19
|
|
|
20
|
-
class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::IntegrationTestCase
|
|
20
|
+
class Elasticsearch::Transport::Transport::ClientIntegrationTest < Elasticsearch::Test::IntegrationTestCase
|
|
21
21
|
startup do
|
|
22
22
|
Elasticsearch::Extensions::Test::Cluster.start(number_of_nodes: 2) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?(number_of_nodes: 2)
|
|
23
23
|
end
|
|
@@ -29,66 +29,116 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
|
29
29
|
context "Transport" do
|
|
30
30
|
setup do
|
|
31
31
|
@host, @port = ELASTICSEARCH_HOSTS.first.split(':')
|
|
32
|
-
|
|
32
|
+
@hosts = { hosts: [ { host: @host, port: @port } ] }
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
should "
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
|
|
40
|
-
:hosts => [ { host: @host, port: @port } ] do |f|
|
|
41
|
-
f.response :logger
|
|
42
|
-
f.adapter :typhoeus
|
|
43
|
-
end
|
|
35
|
+
should "use the default Faraday adapter" do
|
|
36
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
|
|
37
|
+
f.response :logger
|
|
38
|
+
end
|
|
44
39
|
|
|
45
40
|
client = Elasticsearch::Transport::Client.new transport: transport
|
|
41
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttp)
|
|
46
42
|
client.perform_request 'GET', ''
|
|
47
43
|
end
|
|
48
44
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
unless jruby?
|
|
46
|
+
should "allow to customize the Faraday adapter to Typhoeus" do
|
|
47
|
+
if is_faraday_v2?
|
|
48
|
+
require 'faraday/typhoeus'
|
|
49
|
+
else
|
|
50
|
+
require 'typhoeus'
|
|
51
|
+
end
|
|
56
52
|
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
|
|
54
|
+
f.response :logger
|
|
55
|
+
f.adapter :typhoeus
|
|
56
|
+
end
|
|
59
57
|
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
client = Elasticsearch::Transport::Client.new transport: transport
|
|
59
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Typhoeus)
|
|
60
|
+
client.perform_request 'GET', ''
|
|
61
|
+
end
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
should "use the Curb client" do
|
|
64
|
+
require 'curb'
|
|
65
|
+
require 'elasticsearch/transport/transport/http/curb'
|
|
66
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Curb.new(@hosts) do |curl|
|
|
67
|
+
curl.verbose = true
|
|
68
|
+
end
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
client = Elasticsearch::Transport::Client.new transport: transport
|
|
71
|
+
assert_equal(client.transport.class, Elasticsearch::Transport::Transport::HTTP::Curb)
|
|
72
|
+
client.perform_request 'GET', ''
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
should "deserialize JSON responses in the Curb client" do
|
|
76
|
+
require 'curb'
|
|
77
|
+
require 'elasticsearch/transport/transport/http/curb'
|
|
78
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Curb.new(@hosts) do |curl|
|
|
69
79
|
curl.verbose = true
|
|
70
80
|
end
|
|
71
81
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
end unless JRUBY
|
|
82
|
+
client = Elasticsearch::Transport::Client.new transport: transport
|
|
83
|
+
response = client.perform_request 'GET', ''
|
|
75
84
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
assert_respond_to(response.body, :to_hash)
|
|
86
|
+
assert_not_nil response.body['name']
|
|
87
|
+
assert_equal 'application/json', response.headers['content-type']
|
|
88
|
+
end
|
|
79
89
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
should 'allow to customize the Faraday adapter to Patron' do
|
|
91
|
+
if is_faraday_v2?
|
|
92
|
+
require 'faraday/patron'
|
|
93
|
+
else
|
|
94
|
+
require 'patron'
|
|
95
|
+
end
|
|
96
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
|
|
97
|
+
f.response :logger
|
|
98
|
+
f.adapter :patron
|
|
83
99
|
end
|
|
84
100
|
|
|
85
|
-
|
|
86
|
-
|
|
101
|
+
client = Elasticsearch::Transport::Client.new(transport: transport)
|
|
102
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Patron)
|
|
103
|
+
client.perform_request 'GET', ''
|
|
104
|
+
end
|
|
87
105
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
106
|
+
should "allow to customize the Faraday adapter to NetHttpPersistent" do
|
|
107
|
+
require 'faraday/net_http_persistent'
|
|
108
|
+
|
|
109
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
|
|
110
|
+
f.response :logger
|
|
111
|
+
f.adapter :net_http_persistent
|
|
112
|
+
end
|
|
93
113
|
|
|
114
|
+
client = Elasticsearch::Transport::Client.new transport: transport
|
|
115
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttpPersistent)
|
|
116
|
+
client.perform_request 'GET', ''
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
should 'allow to customize the Faraday adapter to HTTPClient' do
|
|
120
|
+
require 'faraday/httpclient'
|
|
121
|
+
|
|
122
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
|
|
123
|
+
f.response :logger
|
|
124
|
+
f.adapter :httpclient
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
client = Elasticsearch::Transport::Client.new(transport: transport)
|
|
128
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::HTTPClient)
|
|
129
|
+
client.perform_request 'GET', ''
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
should "allow to define connection parameters and pass them" do
|
|
133
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(
|
|
134
|
+
hosts: [ { host: @host, port: @port } ],
|
|
135
|
+
options: { transport_options: { params: { :format => 'yaml' } } }
|
|
136
|
+
)
|
|
137
|
+
client = Elasticsearch::Transport::Client.new transport: transport
|
|
138
|
+
response = client.perform_request 'GET', ''
|
|
139
|
+
|
|
140
|
+
assert response.body.start_with?("---\n"), "Response body should be YAML: #{response.body.inspect}"
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
94
144
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -20,30 +20,17 @@ ELASTICSEARCH_HOSTS = if hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOS
|
|
|
20
20
|
hosts.split(',').map do |host|
|
|
21
21
|
/(http\:\/\/)?(\S+)/.match(host)[2]
|
|
22
22
|
end
|
|
23
|
+
else
|
|
24
|
+
['localhost:9200']
|
|
23
25
|
end.freeze
|
|
24
26
|
|
|
25
27
|
TEST_HOST, TEST_PORT = ELASTICSEARCH_HOSTS.first.split(':') if ELASTICSEARCH_HOSTS
|
|
26
28
|
|
|
27
|
-
RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
|
|
28
29
|
JRUBY = defined?(JRUBY_VERSION)
|
|
29
30
|
|
|
30
|
-
if
|
|
31
|
-
require 'rubygems'
|
|
32
|
-
gem 'test-unit'
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
require 'rubygems' if RUBY_1_8
|
|
36
|
-
|
|
37
|
-
if ENV['COVERAGE'] && ENV['CI'].nil? && !RUBY_1_8
|
|
31
|
+
if ENV['COVERAGE']
|
|
38
32
|
require 'simplecov'
|
|
39
|
-
SimpleCov.start { add_filter
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
if ENV['CI'] && !RUBY_1_8
|
|
43
|
-
require 'simplecov'
|
|
44
|
-
require 'simplecov-rcov'
|
|
45
|
-
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
|
46
|
-
SimpleCov.start { add_filter "/test|test_" }
|
|
33
|
+
SimpleCov.start { add_filter %r{^/test/} }
|
|
47
34
|
end
|
|
48
35
|
|
|
49
36
|
# Register `at_exit` handler for integration tests shutdown.
|
|
@@ -52,7 +39,6 @@ if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
|
|
|
52
39
|
at_exit { Elasticsearch::Test::IntegrationTestCase.__run_at_exit_hooks }
|
|
53
40
|
end
|
|
54
41
|
|
|
55
|
-
require 'test/unit' if RUBY_1_8
|
|
56
42
|
require 'minitest/autorun'
|
|
57
43
|
require 'minitest/reporters'
|
|
58
44
|
require 'shoulda/context'
|
|
@@ -111,6 +97,10 @@ module Minitest
|
|
|
111
97
|
end
|
|
112
98
|
end
|
|
113
99
|
|
|
100
|
+
def is_faraday_v2?
|
|
101
|
+
Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
|
|
102
|
+
end
|
|
103
|
+
|
|
114
104
|
Minitest::Reporters.use! FixedMinitestSpecReporter.new
|
|
115
105
|
|
|
116
106
|
module Elasticsearch
|
|
@@ -119,8 +109,7 @@ module Elasticsearch
|
|
|
119
109
|
extend Elasticsearch::Extensions::Test::StartupShutdown
|
|
120
110
|
|
|
121
111
|
shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? && Elasticsearch::Extensions::Test::Cluster.running? }
|
|
122
|
-
|
|
123
|
-
end if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
|
|
112
|
+
end
|
|
124
113
|
end
|
|
125
114
|
|
|
126
115
|
module Test
|
|
@@ -129,7 +118,6 @@ module Elasticsearch
|
|
|
129
118
|
extend Elasticsearch::Extensions::Test::Profiling
|
|
130
119
|
|
|
131
120
|
shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? && Elasticsearch::Extensions::Test::Cluster.running? }
|
|
132
|
-
|
|
133
|
-
end unless RUBY_1_8 || JRUBY
|
|
121
|
+
end unless JRUBY
|
|
134
122
|
end
|
|
135
123
|
end
|