elasticsearch-transport 7.5.0 → 7.17.7

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +26 -13
  3. data/README.md +159 -64
  4. data/Rakefile +25 -13
  5. data/elasticsearch-transport.gemspec +57 -63
  6. data/lib/elasticsearch/transport/client.rb +183 -58
  7. data/lib/elasticsearch/transport/meta_header.rb +135 -0
  8. data/lib/elasticsearch/transport/redacted.rb +16 -3
  9. data/lib/elasticsearch/transport/transport/base.rb +69 -30
  10. data/lib/elasticsearch/transport/transport/connections/collection.rb +18 -8
  11. data/lib/elasticsearch/transport/transport/connections/connection.rb +25 -9
  12. data/lib/elasticsearch/transport/transport/connections/selector.rb +16 -3
  13. data/lib/elasticsearch/transport/transport/errors.rb +17 -3
  14. data/lib/elasticsearch/transport/transport/http/curb.rb +60 -35
  15. data/lib/elasticsearch/transport/transport/http/faraday.rb +32 -9
  16. data/lib/elasticsearch/transport/transport/http/manticore.rb +51 -31
  17. data/lib/elasticsearch/transport/transport/loggable.rb +16 -3
  18. data/lib/elasticsearch/transport/transport/response.rb +16 -4
  19. data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +16 -3
  20. data/lib/elasticsearch/transport/transport/sniffer.rb +35 -15
  21. data/lib/elasticsearch/transport/version.rb +17 -4
  22. data/lib/elasticsearch/transport.rb +35 -33
  23. data/lib/elasticsearch-transport.rb +16 -3
  24. data/spec/elasticsearch/connections/collection_spec.rb +28 -3
  25. data/spec/elasticsearch/connections/selector_spec.rb +16 -3
  26. data/spec/elasticsearch/transport/base_spec.rb +104 -43
  27. data/spec/elasticsearch/transport/client_spec.rb +727 -163
  28. data/spec/elasticsearch/transport/http/curb_spec.rb +126 -0
  29. data/spec/elasticsearch/transport/http/faraday_spec.rb +141 -0
  30. data/spec/elasticsearch/transport/http/manticore_spec.rb +143 -0
  31. data/spec/elasticsearch/transport/meta_header_spec.rb +301 -0
  32. data/spec/elasticsearch/transport/sniffer_spec.rb +16 -16
  33. data/spec/spec_helper.rb +28 -6
  34. data/test/integration/jruby_test.rb +43 -0
  35. data/test/integration/transport_test.rb +46 -29
  36. data/test/profile/client_benchmark_test.rb +16 -3
  37. data/test/test_helper.rb +22 -25
  38. data/test/unit/connection_test.rb +23 -5
  39. data/test/unit/response_test.rb +18 -5
  40. data/test/unit/serializer_test.rb +16 -3
  41. data/test/unit/transport_base_test.rb +33 -11
  42. data/test/unit/transport_curb_test.rb +16 -4
  43. data/test/unit/transport_faraday_test.rb +18 -5
  44. data/test/unit/transport_manticore_test.rb +258 -158
  45. metadata +80 -71
@@ -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 unless jruby?
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
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
@@ -1,11 +1,23 @@
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
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
 
7
20
  describe Elasticsearch::Transport::Transport::Sniffer do
8
-
9
21
  let(:transport) do
10
22
  double('transport').tap do |t|
11
23
  allow(t).to receive(:perform_request).and_return(response)
@@ -32,7 +44,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
32
44
  end
33
45
 
34
46
  describe '#initialize' do
35
-
36
47
  it 'has a transport instance' do
37
48
  expect(sniffer.transport).to be(transport)
38
49
  end
@@ -43,7 +54,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
43
54
  end
44
55
 
45
56
  describe '#timeout' do
46
-
47
57
  let(:sniffer) do
48
58
  described_class.new(double('transport', options: {}))
49
59
  end
@@ -58,13 +68,11 @@ describe Elasticsearch::Transport::Transport::Sniffer do
58
68
  end
59
69
 
60
70
  describe '#hosts' do
61
-
62
71
  let(:hosts) do
63
72
  sniffer.hosts
64
73
  end
65
74
 
66
75
  context 'when the entire response is parsed' do
67
-
68
76
  let(:raw_response) do
69
77
  {
70
78
  "cluster_name" => "elasticsearch_test",
@@ -129,7 +137,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
129
137
  end
130
138
 
131
139
  context 'when the transport protocol does not match' do
132
-
133
140
  let(:raw_response) do
134
141
  { 'nodes' => { 'n1' => { 'foo' => { 'publish_address' => '127.0.0.1:9250' } } } }
135
142
  end
@@ -140,7 +147,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
140
147
  end
141
148
 
142
149
  context 'when a list of nodes is returned' do
143
-
144
150
  let(:raw_response) do
145
151
  { 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } },
146
152
  'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } }
@@ -162,7 +168,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
162
168
  end
163
169
 
164
170
  context 'when the host and port are an ip address and port' do
165
-
166
171
  it 'parses the response' do
167
172
  expect(hosts.size).to eq(1)
168
173
  end
@@ -177,7 +182,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
177
182
  end
178
183
 
179
184
  context 'when the host and port are a hostname and port' do
180
-
181
185
  let(:publish_address) do
182
186
  'testhost1.com:9250'
183
187
  end
@@ -200,7 +204,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
200
204
  end
201
205
 
202
206
  context 'when the host and port are in the format: hostname/ip:port' do
203
-
204
207
  let(:publish_address) do
205
208
  'example.com/127.0.0.1:9250'
206
209
  end
@@ -218,7 +221,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
218
221
  end
219
222
 
220
223
  context 'when the address is IPv6' do
221
-
222
224
  let(:publish_address) do
223
225
  'example.com/[::1]:9250'
224
226
  end
@@ -238,7 +240,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
238
240
  end
239
241
 
240
242
  context 'when the address is IPv6' do
241
-
242
243
  let(:publish_address) do
243
244
  '[::1]:9250'
244
245
  end
@@ -257,7 +258,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
257
258
  end
258
259
 
259
260
  context 'when the transport has :randomize_hosts option' do
260
-
261
261
  let(:raw_response) do
262
262
  { 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } },
263
263
  'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } }
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,33 @@
1
- require 'elasticsearch'
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
+ if ENV['COVERAGE'] && ENV['CI'].nil?
18
+ require 'simplecov'
19
+ SimpleCov.start { add_filter %r{^/test|spec/} }
20
+ end
21
+
2
22
  require 'elasticsearch-transport'
3
23
  require 'logger'
4
24
  require 'ansi/code'
5
25
  require 'hashie/mash'
6
- require 'pry-nav'
7
26
  if defined?(JRUBY_VERSION)
8
27
  require 'elasticsearch/transport/transport/http/manticore'
28
+ require 'pry-nav'
9
29
  else
30
+ require 'pry-byebug'
10
31
  require 'elasticsearch/transport/transport/http/curb'
11
32
  require 'curb'
12
33
  end
@@ -14,10 +35,12 @@ end
14
35
  # The hosts to use for creating a elasticsearch client.
15
36
  #
16
37
  # @since 7.0.0
17
- ELASTICSEARCH_HOSTS = if hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOSTS']
38
+ ELASTICSEARCH_HOSTS = if (hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOSTS'])
18
39
  hosts.split(',').map do |host|
19
40
  /(http\:\/\/)?(\S+)/.match(host)[2]
20
41
  end
42
+ else
43
+ ['localhost:9200']
21
44
  end.freeze
22
45
 
23
46
  TEST_HOST, TEST_PORT = ELASTICSEARCH_HOSTS.first.split(':') if ELASTICSEARCH_HOSTS
@@ -37,7 +60,8 @@ end
37
60
  #
38
61
  # @since 7.0.0
39
62
  def node_names
40
- $node_names ||= default_client.nodes.stats['nodes'].collect do |name, stats|
63
+ node_stats = default_client.perform_request('GET', '_nodes/stats').body
64
+ $node_names ||= node_stats['nodes'].collect do |name, stats|
41
65
  stats['name']
42
66
  end
43
67
  end
@@ -52,9 +76,7 @@ def default_client
52
76
  end
53
77
 
54
78
  module Config
55
-
56
79
  def self.included(context)
57
-
58
80
  # Get the hosts to use to connect an elasticsearch client.
59
81
  #
60
82
  # @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
@@ -1,6 +1,19 @@
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
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 'test_helper'
6
19
 
@@ -16,31 +29,40 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
16
29
  context "Transport" do
17
30
  setup do
18
31
  @host, @port = ELASTICSEARCH_HOSTS.first.split(':')
32
+ @hosts = { hosts: [ { host: @host, port: @port } ] }
19
33
  begin; Object.send(:remove_const, :Patron); rescue NameError; end
20
34
  end
21
35
 
22
- should "allow to customize the Faraday adapter" do
36
+ should "allow to customize the Faraday adapter to Typhoeus" do
23
37
  require 'typhoeus'
24
38
  require 'typhoeus/adapters/faraday'
25
39
 
26
- transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
27
- :hosts => [ { host: @host, port: @port } ] do |f|
28
- f.response :logger
29
- f.adapter :typhoeus
30
- end
40
+ transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
41
+ f.response :logger
42
+ f.adapter :typhoeus
43
+ end
44
+
45
+ client = Elasticsearch::Transport::Client.new transport: transport
46
+ client.perform_request 'GET', ''
47
+ end unless jruby?
48
+
49
+ should "allow to customize the Faraday adapter to NetHttpPersistent" do
50
+ require 'net/http/persistent'
51
+
52
+ transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
53
+ f.response :logger
54
+ f.adapter :net_http_persistent
55
+ end
31
56
 
32
57
  client = Elasticsearch::Transport::Client.new transport: transport
33
58
  client.perform_request 'GET', ''
34
59
  end
35
60
 
36
61
  should "allow to define connection parameters and pass them" do
37
- transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
38
- :hosts => [ { host: @host, port: @port } ],
39
- :options => { :transport_options => {
40
- :params => { :format => 'yaml' }
41
- }
42
- }
43
-
62
+ transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(
63
+ hosts: [ { host: @host, port: @port } ],
64
+ options: { transport_options: { params: { :format => 'yaml' } } }
65
+ )
44
66
  client = Elasticsearch::Transport::Client.new transport: transport
45
67
  response = client.perform_request 'GET', ''
46
68
 
@@ -50,24 +72,20 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
50
72
  should "use the Curb client" do
51
73
  require 'curb'
52
74
  require 'elasticsearch/transport/transport/http/curb'
53
-
54
- transport = Elasticsearch::Transport::Transport::HTTP::Curb.new \
55
- :hosts => [ { host: @host, port: @port } ] do |curl|
56
- curl.verbose = true
57
- end
75
+ transport = Elasticsearch::Transport::Transport::HTTP::Curb.new(@hosts) do |curl|
76
+ curl.verbose = true
77
+ end
58
78
 
59
79
  client = Elasticsearch::Transport::Client.new transport: transport
60
80
  client.perform_request 'GET', ''
61
- end unless JRUBY
81
+ end unless jruby?
62
82
 
63
83
  should "deserialize JSON responses in the Curb client" do
64
84
  require 'curb'
65
85
  require 'elasticsearch/transport/transport/http/curb'
66
-
67
- transport = Elasticsearch::Transport::Transport::HTTP::Curb.new \
68
- :hosts => [ { host: @host, port: @port } ] do |curl|
69
- curl.verbose = true
70
- end
86
+ transport = Elasticsearch::Transport::Transport::HTTP::Curb.new(@hosts) do |curl|
87
+ curl.verbose = true
88
+ end
71
89
 
72
90
  client = Elasticsearch::Transport::Client.new transport: transport
73
91
  response = client.perform_request 'GET', ''
@@ -75,7 +93,6 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
75
93
  assert_respond_to(response.body, :to_hash)
76
94
  assert_not_nil response.body['name']
77
95
  assert_equal 'application/json', response.headers['content-type']
78
- end unless JRUBY
96
+ end unless jruby?
79
97
  end
80
-
81
98
  end
@@ -1,6 +1,19 @@
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
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 'test_helper'
6
19