elasticsearch-transport 7.1.0 → 7.4.0

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -16
  3. data/{LICENSE.txt → LICENSE} +0 -0
  4. data/README.md +18 -19
  5. data/Rakefile +3 -16
  6. data/elasticsearch-transport.gemspec +5 -17
  7. data/lib/elasticsearch/transport/client.rb +26 -23
  8. data/lib/elasticsearch/transport/redacted.rb +3 -16
  9. data/lib/elasticsearch/transport/transport/base.rb +81 -26
  10. data/lib/elasticsearch/transport/transport/connections/collection.rb +3 -16
  11. data/lib/elasticsearch/transport/transport/connections/connection.rb +3 -16
  12. data/lib/elasticsearch/transport/transport/connections/selector.rb +20 -21
  13. data/lib/elasticsearch/transport/transport/errors.rb +3 -16
  14. data/lib/elasticsearch/transport/transport/http/curb.rb +28 -24
  15. data/lib/elasticsearch/transport/transport/http/faraday.rb +19 -18
  16. data/lib/elasticsearch/transport/transport/http/manticore.rb +27 -25
  17. data/lib/elasticsearch/transport/transport/loggable.rb +3 -16
  18. data/lib/elasticsearch/transport/transport/response.rb +3 -16
  19. data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +3 -16
  20. data/lib/elasticsearch/transport/transport/sniffer.rb +5 -17
  21. data/lib/elasticsearch/transport/version.rb +4 -17
  22. data/lib/elasticsearch/transport.rb +3 -16
  23. data/lib/elasticsearch-transport.rb +3 -16
  24. data/spec/elasticsearch/connections/collection_spec.rb +241 -0
  25. data/spec/elasticsearch/connections/selector_spec.rb +161 -0
  26. data/spec/elasticsearch/transport/base_spec.rb +183 -16
  27. data/spec/elasticsearch/transport/client_spec.rb +350 -19
  28. data/spec/elasticsearch/transport/sniffer_spec.rb +3 -16
  29. data/spec/spec_helper.rb +6 -0
  30. data/test/integration/transport_test.rb +3 -16
  31. data/test/profile/client_benchmark_test.rb +3 -16
  32. data/test/test_helper.rb +3 -16
  33. data/test/unit/connection_test.rb +3 -16
  34. data/test/unit/response_test.rb +3 -16
  35. data/test/unit/serializer_test.rb +3 -16
  36. data/test/unit/transport_base_test.rb +3 -16
  37. data/test/unit/transport_curb_test.rb +4 -17
  38. data/test/unit/transport_faraday_test.rb +3 -16
  39. data/test/unit/transport_manticore_test.rb +30 -27
  40. metadata +23 -9
  41. data/test/unit/connection_collection_test.rb +0 -147
  42. data/test/unit/connection_selector_test.rb +0 -81
@@ -1,19 +1,6 @@
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.
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
17
4
 
18
5
  require 'test_helper'
19
6
 
@@ -56,32 +43,42 @@ else
56
43
 
57
44
  should "set body for GET request" do
58
45
  @transport.connections.first.connection.expects(:get).
59
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}'}).returns(stub_everything)
46
+ with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
47
+ :headers => {"Content-Type" => "application/json",
48
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
60
49
  @transport.perform_request 'GET', '/', {}, '{"foo":"bar"}'
61
50
  end
62
51
 
63
52
  should "set body for PUT request" do
64
53
  @transport.connections.first.connection.expects(:put).
65
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}'}).returns(stub_everything)
54
+ with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
55
+ :headers => {"Content-Type" => "application/json",
56
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
66
57
  @transport.perform_request 'PUT', '/', {}, {:foo => 'bar'}
67
58
  end
68
59
 
69
60
  should "serialize the request body" do
70
61
  @transport.connections.first.connection.expects(:post).
71
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}'}).returns(stub_everything)
62
+ with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
63
+ :headers => {"Content-Type" => "application/json",
64
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
72
65
  @transport.perform_request 'POST', '/', {}, {'foo' => 'bar'}
73
66
  end
74
67
 
75
68
  should "set custom headers for PUT request" do
76
69
  @transport.connections.first.connection.expects(:put).
77
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}', :headers => {"Content-Type" => "application/x-ndjson"}})
70
+ with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
71
+ :headers => {"Content-Type" => "application/json",
72
+ "User-Agent" => @transport.send(:user_agent_header)}})
78
73
  .returns(stub_everything)
79
74
  @transport.perform_request 'PUT', '/', {}, '{"foo":"bar"}', {"Content-Type" => "application/x-ndjson"}
80
75
  end
81
76
 
82
77
  should "not serialize a String request body" do
83
78
  @transport.connections.first.connection.expects(:post).
84
- with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}'}).returns(stub_everything)
79
+ with('http://127.0.0.1:8080//', {:body => '{"foo":"bar"}',
80
+ :headers => {"Content-Type" => "application/json",
81
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
85
82
  @transport.serializer.expects(:dump).never
86
83
  @transport.perform_request 'POST', '/', {}, '{"foo":"bar"}'
87
84
  end
@@ -93,7 +90,8 @@ else
93
90
 
94
91
  transport = Manticore.new :hosts => [ { :host => 'localhost', :port => 8080 } ], :options => options
95
92
 
96
- transport.connections.first.connection.stub("http://localhost:8080//", :body => "\"\"", :headers => {"content-type" => "application/json"}, :code => 200 )
93
+ transport.connections.first.connection.stub("http://localhost:8080//", :body => "\"\"", :headers => {"Content-Type" => "application/x-ndjson",
94
+ "User-Agent" => @transport.send(:user_agent_header)}, :code => 200 )
97
95
 
98
96
  response = transport.perform_request 'GET', '/', {}
99
97
  assert_equal response.status, 200
@@ -113,11 +111,16 @@ else
113
111
  end
114
112
 
115
113
  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)
114
+ @transport.connections.first.connection.expects(:delete).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
115
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
116
+ @transport.connections.first.connection.expects(:head).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
117
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
118
+ @transport.connections.first.connection.expects(:get).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
119
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
120
+ @transport.connections.first.connection.expects(:put).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
121
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
122
+ @transport.connections.first.connection.expects(:post).with('http://127.0.0.1:8080//', { headers: {"Content-Type" => "application/json",
123
+ "User-Agent" => @transport.send(:user_agent_header)}}).returns(stub_everything)
121
124
 
122
125
  %w| HEAD GET PUT POST DELETE |.each { |method| @transport.perform_request method, '/' }
123
126
 
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.4.0
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: 2019-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: httpclient
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
195
209
  - !ruby/object:Gem::Dependency
196
210
  name: hashie
197
211
  requirement: !ruby/object:Gem::Requirement
@@ -342,11 +356,11 @@ executables: []
342
356
  extensions: []
343
357
  extra_rdoc_files:
344
358
  - README.md
345
- - LICENSE.txt
359
+ - LICENSE
346
360
  files:
347
361
  - ".gitignore"
348
362
  - Gemfile
349
- - LICENSE.txt
363
+ - LICENSE
350
364
  - README.md
351
365
  - Rakefile
352
366
  - elasticsearch-transport.gemspec
@@ -367,6 +381,8 @@ files:
367
381
  - lib/elasticsearch/transport/transport/serializer/multi_json.rb
368
382
  - lib/elasticsearch/transport/transport/sniffer.rb
369
383
  - lib/elasticsearch/transport/version.rb
384
+ - spec/elasticsearch/connections/collection_spec.rb
385
+ - spec/elasticsearch/connections/selector_spec.rb
370
386
  - spec/elasticsearch/transport/base_spec.rb
371
387
  - spec/elasticsearch/transport/client_spec.rb
372
388
  - spec/elasticsearch/transport/sniffer_spec.rb
@@ -374,8 +390,6 @@ files:
374
390
  - test/integration/transport_test.rb
375
391
  - test/profile/client_benchmark_test.rb
376
392
  - test/test_helper.rb
377
- - test/unit/connection_collection_test.rb
378
- - test/unit/connection_selector_test.rb
379
393
  - test/unit/connection_test.rb
380
394
  - test/unit/response_test.rb
381
395
  - test/unit/serializer_test.rb
@@ -403,11 +417,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
403
417
  - !ruby/object:Gem::Version
404
418
  version: '0'
405
419
  requirements: []
406
- rubygems_version: 3.0.3
420
+ rubygems_version: 3.0.6
407
421
  signing_key:
408
422
  specification_version: 4
409
423
  summary: Ruby client for Elasticsearch.
410
424
  test_files:
425
+ - spec/elasticsearch/connections/collection_spec.rb
426
+ - spec/elasticsearch/connections/selector_spec.rb
411
427
  - spec/elasticsearch/transport/base_spec.rb
412
428
  - spec/elasticsearch/transport/client_spec.rb
413
429
  - spec/elasticsearch/transport/sniffer_spec.rb
@@ -415,8 +431,6 @@ test_files:
415
431
  - test/integration/transport_test.rb
416
432
  - test/profile/client_benchmark_test.rb
417
433
  - test/test_helper.rb
418
- - test/unit/connection_collection_test.rb
419
- - test/unit/connection_selector_test.rb
420
434
  - test/unit/connection_test.rb
421
435
  - test/unit/response_test.rb
422
436
  - 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
@@ -1,81 +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::SelectorTest < Minitest::Test
21
- include Elasticsearch::Transport::Transport::Connections::Selector
22
-
23
- class DummyStrategySelector
24
- include Elasticsearch::Transport::Transport::Connections::Selector::Base
25
- end
26
-
27
- class BackupStrategySelector
28
- include Elasticsearch::Transport::Transport::Connections::Selector::Base
29
-
30
- def select(options={})
31
- connections.reject do |c|
32
- c.host[:attributes] && c.host[:attributes][:backup]
33
- end.send( defined?(RUBY_VERSION) && RUBY_VERSION > '1.9' ? :sample : :choice)
34
- end
35
- end
36
-
37
- context "Connection selector" do
38
-
39
- should "be initialized with connections" do
40
- assert_equal [1, 2], Random.new(:connections => [1, 2]).connections
41
- end
42
-
43
- should "have the abstract select method" do
44
- assert_raise(NoMethodError) { DummyStrategySelector.new.select }
45
- end
46
-
47
- context "in random strategy" do
48
- setup do
49
- @selector = Random.new :connections => ['A', 'B', 'C']
50
- end
51
-
52
- should "pick a connection" do
53
- assert_not_nil @selector.select
54
- end
55
- end
56
-
57
- context "in round-robin strategy" do
58
- setup do
59
- @selector = RoundRobin.new :connections => ['A', 'B', 'C']
60
- end
61
-
62
- should "rotate over connections" do
63
- assert_equal 'A', @selector.select
64
- assert_equal 'B', @selector.select
65
- assert_equal 'C', @selector.select
66
- assert_equal 'A', @selector.select
67
- end
68
- end
69
-
70
- context "with a custom strategy" do
71
-
72
- should "return proper connection" do
73
- selector = BackupStrategySelector.new :connections => [ stub(:host => { :hostname => 'host1' }),
74
- stub(:host => { :hostname => 'host2', :attributes => { :backup => true }}) ]
75
- 10.times { assert_equal 'host1', selector.select.host[:hostname] }
76
- end
77
-
78
- end
79
-
80
- end
81
- end