elasticsearch-transport 7.1.0 → 7.13.3

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +13 -9
  3. data/{LICENSE.txt → LICENSE} +0 -0
  4. data/README.md +175 -76
  5. data/Rakefile +1 -1
  6. data/elasticsearch-transport.gemspec +42 -60
  7. data/lib/elasticsearch/transport/client.rb +154 -57
  8. data/lib/elasticsearch/transport/meta_header.rb +135 -0
  9. data/lib/elasticsearch/transport/redacted.rb +1 -1
  10. data/lib/elasticsearch/transport/transport/base.rb +93 -18
  11. data/lib/elasticsearch/transport/transport/connections/collection.rb +3 -6
  12. data/lib/elasticsearch/transport/transport/connections/connection.rb +8 -6
  13. data/lib/elasticsearch/transport/transport/connections/selector.rb +18 -6
  14. data/lib/elasticsearch/transport/transport/errors.rb +1 -1
  15. data/lib/elasticsearch/transport/transport/http/curb.rb +26 -9
  16. data/lib/elasticsearch/transport/transport/http/faraday.rb +27 -5
  17. data/lib/elasticsearch/transport/transport/http/manticore.rb +25 -10
  18. data/lib/elasticsearch/transport/transport/loggable.rb +1 -1
  19. data/lib/elasticsearch/transport/transport/response.rb +1 -2
  20. data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +1 -1
  21. data/lib/elasticsearch/transport/transport/sniffer.rb +20 -12
  22. data/lib/elasticsearch/transport/version.rb +2 -2
  23. data/lib/elasticsearch/transport.rb +1 -1
  24. data/lib/elasticsearch-transport.rb +1 -1
  25. data/spec/elasticsearch/connections/collection_spec.rb +266 -0
  26. data/spec/elasticsearch/connections/selector_spec.rb +174 -0
  27. data/spec/elasticsearch/transport/base_spec.rb +197 -13
  28. data/spec/elasticsearch/transport/client_spec.rb +945 -118
  29. data/spec/elasticsearch/transport/meta_header_spec.rb +265 -0
  30. data/spec/elasticsearch/transport/sniffer_spec.rb +1 -14
  31. data/spec/spec_helper.rb +25 -1
  32. data/test/integration/transport_test.rb +15 -2
  33. data/test/profile/client_benchmark_test.rb +1 -1
  34. data/test/test_helper.rb +1 -1
  35. data/test/unit/connection_test.rb +8 -3
  36. data/test/unit/response_test.rb +2 -2
  37. data/test/unit/serializer_test.rb +1 -1
  38. data/test/unit/transport_base_test.rb +2 -2
  39. data/test/unit/transport_curb_test.rb +2 -2
  40. data/test/unit/transport_faraday_test.rb +3 -3
  41. data/test/unit/transport_manticore_test.rb +30 -14
  42. metadata +87 -60
  43. data/test/unit/connection_collection_test.rb +0 -147
  44. data/test/unit/connection_selector_test.rb +0 -81
@@ -6,7 +6,7 @@
6
6
  # not use this file except in compliance with the License.
7
7
  # You may obtain a copy of the License at
8
8
  #
9
- # http://www.apache.org/licenses/LICENSE-2.0
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
10
  #
11
11
  # Unless required by applicable law or agreed to in writing,
12
12
  # software distributed under the License is distributed on an
@@ -56,32 +56,42 @@ else
56
56
 
57
57
  should "set body for GET request" do
58
58
  @transport.connections.first.connection.expects(:get).
59
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}'}).returns(stub_everything)
59
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
60
+ :headers => {"Content-Type" => "application/json",
61
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
60
62
  @transport.perform_request 'GET', '/', {}, '{"foo":"bar"}'
61
63
  end
62
64
 
63
65
  should "set body for PUT request" do
64
66
  @transport.connections.first.connection.expects(:put).
65
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}'}).returns(stub_everything)
67
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
68
+ :headers => {"Content-Type" => "application/json",
69
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
66
70
  @transport.perform_request 'PUT', '/', {}, {:foo => 'bar'}
67
71
  end
68
72
 
69
73
  should "serialize the request body" do
70
74
  @transport.connections.first.connection.expects(:post).
71
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}'}).returns(stub_everything)
75
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
76
+ :headers => {"Content-Type" => "application/json",
77
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
72
78
  @transport.perform_request 'POST', '/', {}, {'foo' => 'bar'}
73
79
  end
74
80
 
75
81
  should "set custom headers for PUT request" do
76
82
  @transport.connections.first.connection.expects(:put).
77
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}', :headers => {"Content-Type" => "application/x-ndjson"}})
83
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
84
+ :headers => {"Content-Type" => "application/json",
85
+ "User-Agent" => @transport.send(:user_agent_header)}})
78
86
  .returns(stub_everything)
79
87
  @transport.perform_request 'PUT', '/', {}, '{"foo":"bar"}', {"Content-Type" => "application/x-ndjson"}
80
88
  end
81
89
 
82
90
  should "not serialize a String request body" do
83
91
  @transport.connections.first.connection.expects(:post).
84
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}'}).returns(stub_everything)
92
+ with('http://127.0.0.1:8080/', {:body => '{"foo":"bar"}',
93
+ :headers => {"Content-Type" => "application/json",
94
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
85
95
  @transport.serializer.expects(:dump).never
86
96
  @transport.perform_request 'POST', '/', {}, '{"foo":"bar"}'
87
97
  end
@@ -93,7 +103,8 @@ else
93
103
 
94
104
  transport = Manticore.new :hosts => [ { :host => 'localhost', :port => 8080 } ], :options => options
95
105
 
96
- transport.connections.first.connection.stub("http://localhost:8080//", :body => "\"\"", :headers => {"content-type" => "application/json"}, :code => 200 )
106
+ transport.connections.first.connection.stub("http://localhost:8080/", :body => "\"\"", :headers => {"Content-Type" => "application/x-ndjson",
107
+ "User-Agent" => @transport.send(:user_agent_header)}, :code => 200 )
97
108
 
98
109
  response = transport.perform_request 'GET', '/', {}
99
110
  assert_equal response.status, 200
@@ -113,11 +124,16 @@ else
113
124
  end
114
125
 
115
126
  should "handle HTTP methods" do
116
- @transport.connections.first.connection.expects(:delete).with('http://127.0.0.1:8080//', {}).returns(stub_everything)
117
- @transport.connections.first.connection.expects(:head).with('http://127.0.0.1:8080//', {}).returns(stub_everything)
118
- @transport.connections.first.connection.expects(:get).with('http://127.0.0.1:8080//', {}).returns(stub_everything)
119
- @transport.connections.first.connection.expects(:put).with('http://127.0.0.1:8080//', {}).returns(stub_everything)
120
- @transport.connections.first.connection.expects(:post).with('http://127.0.0.1:8080//', {}).returns(stub_everything)
127
+ @transport.connections.first.connection.expects(:delete).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
128
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
129
+ @transport.connections.first.connection.expects(:head).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
130
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
131
+ @transport.connections.first.connection.expects(:get).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
132
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
133
+ @transport.connections.first.connection.expects(:put).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
134
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
135
+ @transport.connections.first.connection.expects(:post).with('http://127.0.0.1:8080/', { headers: {"Content-Type" => "application/json",
136
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
121
137
 
122
138
  %w| HEAD GET PUT POST DELETE |.each { |method| @transport.perform_request method, '/' }
123
139
 
@@ -129,8 +145,8 @@ else
129
145
  transport = Manticore.new :hosts => [ { :host => 'foobar', :port => 1234 } ], :options => options
130
146
  transport.connections.first.connection
131
147
  .expects(:get)
132
- .with do |host, options|
133
- assert_equal 'myapp-0.0', options[:headers]['User-Agent']
148
+ .with do |host, _options|
149
+ assert_equal 'myapp-0.0', _options[:headers]['User-Agent']
134
150
  true
135
151
  end
136
152
  .returns(stub_everything)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.0
4
+ version: 7.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-22 00:00:00.000000000 Z
11
+ date: 2021-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -28,18 +28,18 @@ dependencies:
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
42
+ name: cane
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,21 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '11.1'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '11.1'
69
- - !ruby/object:Gem::Dependency
70
- name: ansi
56
+ name: curb
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - ">="
@@ -81,7 +67,7 @@ dependencies:
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
- name: shoulda-context
70
+ name: elasticsearch-extensions
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - ">="
@@ -95,7 +81,7 @@ dependencies:
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
- name: mocha
84
+ name: minitest
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - ">="
@@ -109,7 +95,7 @@ dependencies:
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
- name: yard
98
+ name: minitest-reporters
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - ">="
@@ -123,21 +109,21 @@ dependencies:
123
109
  - !ruby/object:Gem::Version
124
110
  version: '0'
125
111
  - !ruby/object:Gem::Dependency
126
- name: pry
112
+ name: rake
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
- - - ">="
115
+ - - "~>"
130
116
  - !ruby/object:Gem::Version
131
- version: '0'
117
+ version: '13'
132
118
  type: :development
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
- - - ">="
122
+ - - "~>"
137
123
  - !ruby/object:Gem::Version
138
- version: '0'
124
+ version: '13'
139
125
  - !ruby/object:Gem::Dependency
140
- name: curb
126
+ name: require-prof
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
129
  - - ">="
@@ -151,7 +137,7 @@ dependencies:
151
137
  - !ruby/object:Gem::Version
152
138
  version: '0'
153
139
  - !ruby/object:Gem::Dependency
154
- name: patron
140
+ name: ruby-prof
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
143
  - - ">="
@@ -165,21 +151,27 @@ dependencies:
165
151
  - !ruby/object:Gem::Version
166
152
  version: '0'
167
153
  - !ruby/object:Gem::Dependency
168
- name: typhoeus
154
+ name: simplecov
169
155
  requirement: !ruby/object:Gem::Requirement
170
156
  requirements:
171
157
  - - "~>"
172
158
  - !ruby/object:Gem::Version
173
- version: '0.6'
159
+ version: '0.17'
160
+ - - "<"
161
+ - !ruby/object:Gem::Version
162
+ version: '0.18'
174
163
  type: :development
175
164
  prerelease: false
176
165
  version_requirements: !ruby/object:Gem::Requirement
177
166
  requirements:
178
167
  - - "~>"
179
168
  - !ruby/object:Gem::Version
180
- version: '0.6'
169
+ version: '0.17'
170
+ - - "<"
171
+ - !ruby/object:Gem::Version
172
+ version: '0.18'
181
173
  - !ruby/object:Gem::Dependency
182
- name: net-http-persistent
174
+ name: simplecov-rcov
183
175
  requirement: !ruby/object:Gem::Requirement
184
176
  requirements:
185
177
  - - ">="
@@ -193,7 +185,7 @@ dependencies:
193
185
  - !ruby/object:Gem::Version
194
186
  version: '0'
195
187
  - !ruby/object:Gem::Dependency
196
- name: hashie
188
+ name: ansi
197
189
  requirement: !ruby/object:Gem::Requirement
198
190
  requirements:
199
191
  - - ">="
@@ -207,7 +199,7 @@ dependencies:
207
199
  - !ruby/object:Gem::Version
208
200
  version: '0'
209
201
  - !ruby/object:Gem::Dependency
210
- name: minitest
202
+ name: hashie
211
203
  requirement: !ruby/object:Gem::Requirement
212
204
  requirements:
213
205
  - - ">="
@@ -221,7 +213,7 @@ dependencies:
221
213
  - !ruby/object:Gem::Version
222
214
  version: '0'
223
215
  - !ruby/object:Gem::Dependency
224
- name: minitest-reporters
216
+ name: httpclient
225
217
  requirement: !ruby/object:Gem::Requirement
226
218
  requirements:
227
219
  - - ">="
@@ -235,7 +227,7 @@ dependencies:
235
227
  - !ruby/object:Gem::Version
236
228
  version: '0'
237
229
  - !ruby/object:Gem::Dependency
238
- name: elasticsearch-extensions
230
+ name: mocha
239
231
  requirement: !ruby/object:Gem::Requirement
240
232
  requirements:
241
233
  - - ">="
@@ -249,7 +241,7 @@ dependencies:
249
241
  - !ruby/object:Gem::Version
250
242
  version: '0'
251
243
  - !ruby/object:Gem::Dependency
252
- name: ruby-prof
244
+ name: net-http-persistent
253
245
  requirement: !ruby/object:Gem::Requirement
254
246
  requirements:
255
247
  - - ">="
@@ -263,7 +255,7 @@ dependencies:
263
255
  - !ruby/object:Gem::Version
264
256
  version: '0'
265
257
  - !ruby/object:Gem::Dependency
266
- name: require-prof
258
+ name: patron
267
259
  requirement: !ruby/object:Gem::Requirement
268
260
  requirements:
269
261
  - - ">="
@@ -277,7 +269,7 @@ dependencies:
277
269
  - !ruby/object:Gem::Version
278
270
  version: '0'
279
271
  - !ruby/object:Gem::Dependency
280
- name: simplecov
272
+ name: pry
281
273
  requirement: !ruby/object:Gem::Requirement
282
274
  requirements:
283
275
  - - ">="
@@ -291,7 +283,7 @@ dependencies:
291
283
  - !ruby/object:Gem::Version
292
284
  version: '0'
293
285
  - !ruby/object:Gem::Dependency
294
- name: simplecov-rcov
286
+ name: shoulda-context
295
287
  requirement: !ruby/object:Gem::Requirement
296
288
  requirements:
297
289
  - - ">="
@@ -305,7 +297,35 @@ dependencies:
305
297
  - !ruby/object:Gem::Version
306
298
  version: '0'
307
299
  - !ruby/object:Gem::Dependency
308
- name: cane
300
+ name: test-unit
301
+ requirement: !ruby/object:Gem::Requirement
302
+ requirements:
303
+ - - "~>"
304
+ - !ruby/object:Gem::Version
305
+ version: '2'
306
+ type: :development
307
+ prerelease: false
308
+ version_requirements: !ruby/object:Gem::Requirement
309
+ requirements:
310
+ - - "~>"
311
+ - !ruby/object:Gem::Version
312
+ version: '2'
313
+ - !ruby/object:Gem::Dependency
314
+ name: typhoeus
315
+ requirement: !ruby/object:Gem::Requirement
316
+ requirements:
317
+ - - "~>"
318
+ - !ruby/object:Gem::Version
319
+ version: '1.4'
320
+ type: :development
321
+ prerelease: false
322
+ version_requirements: !ruby/object:Gem::Requirement
323
+ requirements:
324
+ - - "~>"
325
+ - !ruby/object:Gem::Version
326
+ version: '1.4'
327
+ - !ruby/object:Gem::Dependency
328
+ name: yard
309
329
  requirement: !ruby/object:Gem::Requirement
310
330
  requirements:
311
331
  - - ">="
@@ -319,19 +339,19 @@ dependencies:
319
339
  - !ruby/object:Gem::Version
320
340
  version: '0'
321
341
  - !ruby/object:Gem::Dependency
322
- name: test-unit
342
+ name: bundler
323
343
  requirement: !ruby/object:Gem::Requirement
324
344
  requirements:
325
- - - "~>"
345
+ - - ">="
326
346
  - !ruby/object:Gem::Version
327
- version: '2'
347
+ version: '0'
328
348
  type: :development
329
349
  prerelease: false
330
350
  version_requirements: !ruby/object:Gem::Requirement
331
351
  requirements:
332
- - - "~>"
352
+ - - ">="
333
353
  - !ruby/object:Gem::Version
334
- version: '2'
354
+ version: '0'
335
355
  description: 'Ruby client for Elasticsearch. See the `elasticsearch` gem for full
336
356
  integration.
337
357
 
@@ -342,17 +362,18 @@ executables: []
342
362
  extensions: []
343
363
  extra_rdoc_files:
344
364
  - README.md
345
- - LICENSE.txt
365
+ - LICENSE
346
366
  files:
347
367
  - ".gitignore"
348
368
  - Gemfile
349
- - LICENSE.txt
369
+ - LICENSE
350
370
  - README.md
351
371
  - Rakefile
352
372
  - elasticsearch-transport.gemspec
353
373
  - lib/elasticsearch-transport.rb
354
374
  - lib/elasticsearch/transport.rb
355
375
  - lib/elasticsearch/transport/client.rb
376
+ - lib/elasticsearch/transport/meta_header.rb
356
377
  - lib/elasticsearch/transport/redacted.rb
357
378
  - lib/elasticsearch/transport/transport/base.rb
358
379
  - lib/elasticsearch/transport/transport/connections/collection.rb
@@ -367,15 +388,16 @@ files:
367
388
  - lib/elasticsearch/transport/transport/serializer/multi_json.rb
368
389
  - lib/elasticsearch/transport/transport/sniffer.rb
369
390
  - lib/elasticsearch/transport/version.rb
391
+ - spec/elasticsearch/connections/collection_spec.rb
392
+ - spec/elasticsearch/connections/selector_spec.rb
370
393
  - spec/elasticsearch/transport/base_spec.rb
371
394
  - spec/elasticsearch/transport/client_spec.rb
395
+ - spec/elasticsearch/transport/meta_header_spec.rb
372
396
  - spec/elasticsearch/transport/sniffer_spec.rb
373
397
  - spec/spec_helper.rb
374
398
  - test/integration/transport_test.rb
375
399
  - test/profile/client_benchmark_test.rb
376
400
  - test/test_helper.rb
377
- - test/unit/connection_collection_test.rb
378
- - test/unit/connection_selector_test.rb
379
401
  - test/unit/connection_test.rb
380
402
  - test/unit/response_test.rb
381
403
  - test/unit/serializer_test.rb
@@ -383,10 +405,14 @@ files:
383
405
  - test/unit/transport_curb_test.rb
384
406
  - test/unit/transport_faraday_test.rb
385
407
  - test/unit/transport_manticore_test.rb
386
- homepage: https://github.com/elasticsearch/elasticsearch-ruby/tree/master/elasticsearch-transport
408
+ homepage: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/7.x/index.html
387
409
  licenses:
388
410
  - Apache-2.0
389
- metadata: {}
411
+ metadata:
412
+ homepage_uri: https://www.elastic.co/guide/en/elasticsearch/client/ruby-api/7.x/index.html
413
+ changelog_uri: https://github.com/elastic/elasticsearch-ruby/blob/7.x/CHANGELOG.md
414
+ source_code_uri: https://github.com/elastic/elasticsearch-ruby/tree/7.x/elasticsearch-transport
415
+ bug_tracker_uri: https://github.com/elastic/elasticsearch-ruby/issues
390
416
  post_install_message:
391
417
  rdoc_options:
392
418
  - "--charset=UTF-8"
@@ -396,27 +422,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
396
422
  requirements:
397
423
  - - ">="
398
424
  - !ruby/object:Gem::Version
399
- version: '1.9'
425
+ version: '2.4'
400
426
  required_rubygems_version: !ruby/object:Gem::Requirement
401
427
  requirements:
402
428
  - - ">="
403
429
  - !ruby/object:Gem::Version
404
430
  version: '0'
405
431
  requirements: []
406
- rubygems_version: 3.0.3
432
+ rubygems_version: 3.2.15
407
433
  signing_key:
408
434
  specification_version: 4
409
435
  summary: Ruby client for Elasticsearch.
410
436
  test_files:
437
+ - spec/elasticsearch/connections/collection_spec.rb
438
+ - spec/elasticsearch/connections/selector_spec.rb
411
439
  - spec/elasticsearch/transport/base_spec.rb
412
440
  - spec/elasticsearch/transport/client_spec.rb
441
+ - spec/elasticsearch/transport/meta_header_spec.rb
413
442
  - spec/elasticsearch/transport/sniffer_spec.rb
414
443
  - spec/spec_helper.rb
415
444
  - test/integration/transport_test.rb
416
445
  - test/profile/client_benchmark_test.rb
417
446
  - test/test_helper.rb
418
- - test/unit/connection_collection_test.rb
419
- - test/unit/connection_selector_test.rb
420
447
  - test/unit/connection_test.rb
421
448
  - test/unit/response_test.rb
422
449
  - test/unit/serializer_test.rb
@@ -1,147 +0,0 @@
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 'test_helper'
19
-
20
- class Elasticsearch::Transport::Transport::Connections::CollectionTest < Minitest::Test
21
- include Elasticsearch::Transport::Transport::Connections
22
-
23
- context "Connection collection" do
24
-
25
- should "have empty array as default connections array" do
26
- assert_equal [], Collection.new.connections
27
- end
28
-
29
- should "have default selector class" do
30
- assert_not_nil Collection.new.selector
31
- end
32
-
33
- should "initialize a custom selector class" do
34
- c = Collection.new :selector_class => Selector::Random
35
- assert_instance_of Selector::Random, c.selector
36
- end
37
-
38
- should "take a custom selector instance" do
39
- c = Collection.new :selector => Selector::Random.new
40
- assert_instance_of Selector::Random, c.selector
41
- end
42
-
43
- should "get connection from selector" do
44
- c = Collection.new
45
- c.selector.expects(:select).returns('OK')
46
- assert_equal 'OK', c.get_connection
47
- end
48
-
49
- should "return an array of hosts" do
50
- c = Collection.new :connections => [ Connection.new(:host => 'foo'), Connection.new(:host => 'bar') ]
51
- assert_equal ['foo', 'bar'], c.hosts
52
- end
53
-
54
- should "be enumerable" do
55
- c = Collection.new :connections => [ Connection.new(:host => 'foo'), Connection.new(:host => 'bar') ]
56
-
57
- assert_equal ['FOO', 'BAR'], c.map { |i| i.host.upcase }
58
- assert_equal 'foo', c[0].host
59
- assert_equal 'bar', c[1].host
60
- assert_equal 2, c.size
61
- end
62
-
63
- should "add connections" do
64
- c = Collection.new :connections => [ Connection.new(:host => { :protocol => 'http', :host => 'foo', :port => 1}) ]
65
- assert_equal 1, c.size
66
-
67
- c.add([ Connection.new(:host => { :protocol => 'http', :host => 'bar', :port => 1 }),
68
- Connection.new(:host => { :protocol => 'http', :host => 'bam', :port => 1 }) ])
69
- assert_equal 3, c.size
70
- end
71
-
72
- should "add connection" do
73
- c = Collection.new :connections => [ Connection.new(:host => { :protocol => 'http', :host => 'foo', :port => 1}) ]
74
- assert_equal 1, c.size
75
-
76
- c.add(Connection.new(:host => { :protocol => 'http', :host => 'bar', :port => 1 }))
77
- assert_equal 2, c.size
78
- end
79
-
80
- should "remove connections" do
81
- c = Collection.new :connections => [
82
- Connection.new(:host => { :protocol => 'http', :host => 'foo', :port => 1 }),
83
- Connection.new(:host => { :protocol => 'http', :host => 'bar', :port => 1 })
84
- ]
85
- assert_equal 2, c.size
86
-
87
- c.remove([c.first])
88
- assert_equal 1, c.size
89
-
90
- c.remove(c)
91
- assert_equal 0, c.size
92
- end
93
-
94
- should "remove connection" do
95
- c = Collection.new :connections => [
96
- Connection.new(:host => { :protocol => 'http', :host => 'foo', :port => 1 }),
97
- Connection.new(:host => { :protocol => 'http', :host => 'bar', :port => 1 })
98
- ]
99
- assert_equal 2, c.size
100
-
101
- c.remove(c.first)
102
- assert_equal 1, c.size
103
- end
104
-
105
- context "with the dead pool" do
106
- setup do
107
- @collection = Collection.new :connections => [ Connection.new(:host => 'foo'), Connection.new(:host => 'bar') ]
108
- @collection[1].dead!
109
- end
110
-
111
- should "not iterate over dead connections" do
112
- assert_equal 1, @collection.size
113
- assert_equal ['FOO'], @collection.map { |c| c.host.upcase }
114
- assert_equal @collection.connections, @collection.alive
115
- end
116
-
117
- should "have dead connections collection" do
118
- assert_equal 1, @collection.dead.size
119
- assert_equal ['BAR'], @collection.dead.map { |c| c.host.upcase }
120
- end
121
-
122
- should "not return dead connections, when alive connections exist" do
123
- assert_equal 1, @collection.size
124
- @collection.all.size.times { refute @collection.get_connection.dead? }
125
- end
126
-
127
- should "resurrect dead connection with least failures when no alive is available" do
128
- c1 = Connection.new(:host => { :protocol => 'http', :host => 'foo', :port => 123 }).dead!.dead!
129
- c2 = Connection.new(:host => { :protocol => 'http', :host => 'bar', :port => 123 }).dead!
130
-
131
- @collection = Collection.new :connections => [ c1, c2 ]
132
-
133
- assert_equal 0, @collection.size
134
- assert_not_nil @collection.get_connection
135
- assert_equal 1, @collection.size
136
- assert_equal c2, @collection.first
137
- end
138
-
139
- should "return all connections" do
140
- assert_equal 2, @collection.all.size
141
- end
142
-
143
- end
144
-
145
- end
146
-
147
- end