elasticsearch-transport 7.1.0 → 7.2.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.
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,12 @@ require 'logger'
4
4
  require 'ansi/code'
5
5
  require 'hashie/mash'
6
6
  require 'pry-nav'
7
+ if defined?(JRUBY_VERSION)
8
+ require 'elasticsearch/transport/transport/http/manticore'
9
+ else
10
+ require 'elasticsearch/transport/transport/http/curb'
11
+ require 'curb'
12
+ end
7
13
 
8
14
  # The hosts to use for creating a elasticsearch client.
9
15
  #
@@ -57,7 +57,7 @@ else
57
57
  should "perform request with headers" do
58
58
  @transport.connections.first.connection.expects(:put_data=).with('{"foo":"bar"}')
59
59
  @transport.connections.first.connection.expects(:http).with(:POST).returns(stub_everything)
60
- @transport.connections.first.connection.expects(:headers=).with({"Content-Type" => "application/x-ndjson"})
60
+ @transport.connections.first.connection.headers.expects(:merge!).with("Content-Type" => "application/x-ndjson")
61
61
 
62
62
  @transport.perform_request 'POST', '/', {}, {:foo => 'bar'}, {"Content-Type" => "application/x-ndjson"}
63
63
  end
@@ -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
 
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.2.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-06-26 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
@@ -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
@@ -408,6 +422,8 @@ 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