elastic-transport 8.1.0 → 8.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,8 +18,9 @@
18
18
  require 'test_helper'
19
19
 
20
20
  class Elastic::Transport::ClientIntegrationTest < Minitest::Test
21
- context 'Transport' do
21
+ context "Transport" do
22
22
  setup do
23
+ begin; Object.send(:remove_const, :Patron); rescue NameError; end
23
24
  uri = URI(HOST)
24
25
  @host = {
25
26
  host: uri.host,
@@ -29,108 +30,32 @@ class Elastic::Transport::ClientIntegrationTest < Minitest::Test
29
30
  }
30
31
  end
31
32
 
32
- should 'use the default Faraday adapter' do
33
- transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
34
- f.response :logger
35
- end
36
-
37
- client = Elastic::Transport::Client.new(transport: transport)
38
- assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttp)
39
- client.perform_request 'GET', ''
40
- end
41
-
42
- unless jruby?
43
- should 'allow to customize the Faraday adapter to Typhoeus' do
44
- if is_faraday_v2?
45
- require 'faraday/typhoeus'
46
- else
47
- require 'typhoeus'
48
- end
49
-
50
- transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
51
- f.response :logger
52
- f.adapter :typhoeus
53
- end
54
-
55
- client = Elastic::Transport::Client.new(transport: transport)
56
- assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Typhoeus)
57
- client.perform_request 'GET', ''
58
- end
59
-
60
- should 'use the Curb client' do
61
- require 'curb'
62
- require 'elastic/transport/transport/http/curb'
63
-
64
- transport = Elastic::Transport::Transport::HTTP::Curb.new(hosts: [@host]) do |curl|
65
- curl.verbose = true
66
- end
67
-
68
- client = Elastic::Transport::Client.new(transport: transport)
69
- assert_equal(client.transport.class, Elastic::Transport::Transport::HTTP::Curb)
70
- client.perform_request 'GET', ''
71
- end
72
-
73
- should 'deserialize JSON responses in the Curb client' do
74
- require 'curb'
75
- require 'elastic/transport/transport/http/curb'
76
-
77
- transport = Elastic::Transport::Transport::HTTP::Curb.new(hosts: [@host]) do |curl|
78
- curl.verbose = true
79
- end
80
-
81
- client = Elastic::Transport::Client.new(transport: transport)
82
- response = client.perform_request 'GET', ''
83
-
84
- assert_respond_to(response.body, :to_hash)
85
- assert_not_nil response.body['name']
86
- assert_equal 'application/json', response.headers['content-type']
87
- assert_equal 'Elasticsearch', response.headers['x-elastic-product']
88
- end
89
-
90
- should 'allow to customize the Faraday adapter to Patron' do
91
- if is_faraday_v2?
92
- require 'faraday/patron'
93
- else
94
- require 'patron'
95
- end
96
- transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
97
- f.response :logger
98
- f.adapter :patron
99
- end
100
-
101
- client = Elastic::Transport::Client.new(transport: transport)
102
- assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Patron)
103
- client.perform_request 'GET', ''
104
- end
105
- end
106
-
107
- should 'allow to customize the Faraday adapter to NetHttpPersistent' do
108
- require 'faraday/net_http_persistent'
33
+ should "allow to customize the Faraday adapter to Typhoeus" do
34
+ require 'typhoeus'
35
+ require 'typhoeus/adapters/faraday'
109
36
 
110
37
  transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
111
38
  f.response :logger
112
- f.adapter :net_http_persistent
39
+ f.adapter :typhoeus
113
40
  end
114
41
 
115
42
  client = Elastic::Transport::Client.new(transport: transport)
116
- assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttpPersistent)
117
43
  client.perform_request 'GET', ''
118
- end
44
+ end unless jruby?
119
45
 
120
- should 'allow to customize the Faraday adapter to HTTPClient' do
121
- require 'faraday/httpclient'
46
+ should "allow to customize the Faraday adapter to NetHttpPersistent" do
47
+ require 'net/http/persistent'
122
48
 
123
49
  transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
124
50
  f.response :logger
125
- f.adapter :httpclient
51
+ f.adapter :net_http_persistent
126
52
  end
127
53
 
128
54
  client = Elastic::Transport::Client.new(transport: transport)
129
- assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::HTTPClient)
130
55
  client.perform_request 'GET', ''
131
56
  end
132
57
 
133
- should 'allow to define connection parameters and pass them' do
58
+ should "allow to define connection parameters and pass them" do
134
59
  transport = Elastic::Transport::Transport::HTTP::Faraday.new(
135
60
  hosts: [@host],
136
61
  options: { transport_options: { params: { format: 'yaml' } } }
@@ -138,7 +63,36 @@ class Elastic::Transport::ClientIntegrationTest < Minitest::Test
138
63
 
139
64
  client = Elastic::Transport::Client.new transport: transport
140
65
  response = client.perform_request 'GET', ''
66
+
141
67
  assert response.body.start_with?("---\n"), "Response body should be YAML: #{response.body.inspect}"
142
68
  end
69
+
70
+ should "use the Curb client" do
71
+ require 'curb'
72
+ require 'elastic/transport/transport/http/curb'
73
+
74
+ transport = Elastic::Transport::Transport::HTTP::Curb.new(hosts: [@host]) do |curl|
75
+ curl.verbose = true
76
+ end
77
+
78
+ client = Elastic::Transport::Client.new(transport: transport)
79
+ client.perform_request 'GET', ''
80
+ end unless JRUBY
81
+
82
+ should "deserialize JSON responses in the Curb client" do
83
+ require 'curb'
84
+ require 'elastic/transport/transport/http/curb'
85
+
86
+ transport = Elastic::Transport::Transport::HTTP::Curb.new(hosts: [@host]) do |curl|
87
+ curl.verbose = true
88
+ end
89
+
90
+ client = Elastic::Transport::Client.new(transport: transport)
91
+ response = client.perform_request 'GET', ''
92
+
93
+ assert_respond_to(response.body, :to_hash)
94
+ assert_not_nil response.body['name']
95
+ assert_equal 'application/json', response.headers['content-type']
96
+ end unless jruby?
143
97
  end
144
98
  end
data/test/test_helper.rb CHANGED
@@ -14,7 +14,6 @@
14
14
  # KIND, either express or implied. See the License for the
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
- require 'uri'
18
17
 
19
18
  password = ENV['ELASTIC_PASSWORD'] || 'changeme'
20
19
  host = ENV['TEST_ES_SERVER'] || 'http://localhost:9200'
@@ -30,16 +29,17 @@ if ENV['COVERAGE']
30
29
  SimpleCov.start { add_filter %r{^/test/} }
31
30
  end
32
31
 
33
- require 'ansi/code'
34
32
  require 'minitest/autorun'
35
33
  require 'minitest/reporters'
36
- require 'mocha/minitest'
37
34
  require 'shoulda/context'
35
+ require 'mocha/minitest'
36
+ require 'ansi/code'
38
37
 
38
+ require 'require-prof' if ENV["REQUIRE_PROF"]
39
39
  require 'elastic-transport'
40
- require 'hashie'
41
40
  require 'logger'
42
- require 'require-prof' if ENV["REQUIRE_PROF"]
41
+
42
+ require 'hashie'
43
43
 
44
44
  RequireProf.print_timing_infos if ENV["REQUIRE_PROF"]
45
45
 
@@ -80,8 +80,4 @@ module Minitest
80
80
  end
81
81
  end
82
82
 
83
- def is_faraday_v2?
84
- Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
85
- end
86
-
87
83
  Minitest::Reporters.use! FixedMinitestSpecReporter.new
@@ -255,10 +255,9 @@ class Elastic::Transport::Transport::BaseTest < Minitest::Test
255
255
  should "raise an error on connection failure" do
256
256
  @transport.expects(:get_connection).returns(stub_everything :failures => 1)
257
257
 
258
- # `block.expects(:call).raises(::Errno::ECONNREFUSED)` fails on Ruby 1.8
259
- block = lambda { |a,b| raise ::Errno::ECONNREFUSED }
258
+ block = lambda { |a,b| raise Elastic::Transport::Transport::Error }
260
259
 
261
- assert_raise ::Errno::ECONNREFUSED do
260
+ assert_raise Elastic::Transport::Transport::Error do
262
261
  @transport.perform_request 'GET', '/', &block
263
262
  end
264
263
  end
@@ -291,11 +290,11 @@ class Elastic::Transport::Transport::BaseTest < Minitest::Test
291
290
  c = stub_everything :failures => 1
292
291
  @transport.expects(:get_connection).returns(c)
293
292
 
294
- block = lambda { |a,b| raise ::Errno::ECONNREFUSED }
293
+ block = lambda { |a, b| raise Errno::ECONNREFUSED }
295
294
 
296
295
  c.expects(:dead!)
297
296
 
298
- assert_raise( ::Errno::ECONNREFUSED ) { @transport.perform_request 'GET', '/', &block }
297
+ assert_raise( Elastic::Transport::Transport::Error ) { @transport.perform_request 'GET', '/', &block }
299
298
  end
300
299
  end
301
300
 
@@ -311,7 +310,7 @@ class Elastic::Transport::Transport::BaseTest < Minitest::Test
311
310
 
312
311
  should "reload connections when host is unreachable" do
313
312
  @block.expects(:call).times(2).
314
- raises(Errno::ECONNREFUSED).
313
+ raises(Errno::ECONNREFUSED).
315
314
  then.returns(stub_everything :failures => 1)
316
315
 
317
316
  @transport.expects(:reload_connections!).returns([])
@@ -343,13 +342,13 @@ class Elastic::Transport::Transport::BaseTest < Minitest::Test
343
342
 
344
343
  should "raise an error after max tries" do
345
344
  @block.expects(:call).times(4).
346
- raises(Errno::ECONNREFUSED).
345
+ raises(Errno::ECONNREFUSED).
347
346
  then.raises(Errno::ECONNREFUSED).
348
347
  then.raises(Errno::ECONNREFUSED).
349
348
  then.raises(Errno::ECONNREFUSED).
350
349
  then.returns(stub_everything :failures => 1)
351
350
 
352
- assert_raise Errno::ECONNREFUSED do
351
+ assert_raise Elastic::Transport::Transport::Error do
353
352
  @transport.perform_request('GET', '/', &@block)
354
353
  end
355
354
  end
@@ -83,10 +83,11 @@ else
83
83
  should "set application/json response header" do
84
84
  @transport.connections.first.connection.expects(:http).with(:GET).returns(stub_everything)
85
85
  @transport.connections.first.connection.expects(:body_str).returns('{"foo":"bar"}')
86
- @transport.connections.first.connection.expects(:header_str).returns("HTTP/1.1 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\nContent-Length: 311\r\n\r\n")
86
+ @transport.connections.first.connection.expects(:header_str).returns('HTTP/1.1 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\nContent-Length: 311\r\n\r\n')
87
87
 
88
88
  response = @transport.perform_request 'GET', '/'
89
- assert_equal 'application/json; charset=UTF-8', response.headers['content-type']
89
+
90
+ assert_equal 'application/json', response.headers['content-type']
90
91
  end
91
92
 
92
93
  should "handle HTTP methods" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.0
4
+ version: 8.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
@@ -10,30 +10,44 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-09-01 00:00:00.000000000 Z
13
+ date: 2023-07-05 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: multi_json
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
15
29
  - !ruby/object:Gem::Dependency
16
30
  name: faraday
17
31
  requirement: !ruby/object:Gem::Requirement
18
32
  requirements:
19
- - - "<"
33
+ - - "~>"
20
34
  - !ruby/object:Gem::Version
21
- version: '3'
35
+ version: '1'
22
36
  type: :runtime
23
37
  prerelease: false
24
38
  version_requirements: !ruby/object:Gem::Requirement
25
39
  requirements:
26
- - - "<"
40
+ - - "~>"
27
41
  - !ruby/object:Gem::Version
28
- version: '3'
42
+ version: '1'
29
43
  - !ruby/object:Gem::Dependency
30
- name: multi_json
44
+ name: bundler
31
45
  requirement: !ruby/object:Gem::Requirement
32
46
  requirements:
33
47
  - - ">="
34
48
  - !ruby/object:Gem::Version
35
49
  version: '0'
36
- type: :runtime
50
+ type: :development
37
51
  prerelease: false
38
52
  version_requirements: !ruby/object:Gem::Requirement
39
53
  requirements:
@@ -41,7 +55,7 @@ dependencies:
41
55
  - !ruby/object:Gem::Version
42
56
  version: '0'
43
57
  - !ruby/object:Gem::Dependency
44
- name: curb
58
+ name: cane
45
59
  requirement: !ruby/object:Gem::Requirement
46
60
  requirements:
47
61
  - - ">="
@@ -55,7 +69,7 @@ dependencies:
55
69
  - !ruby/object:Gem::Version
56
70
  version: '0'
57
71
  - !ruby/object:Gem::Dependency
58
- name: bundler
72
+ name: curb
59
73
  requirement: !ruby/object:Gem::Requirement
60
74
  requirements:
61
75
  - - ">="
@@ -69,7 +83,7 @@ dependencies:
69
83
  - !ruby/object:Gem::Version
70
84
  version: '0'
71
85
  - !ruby/object:Gem::Dependency
72
- name: cane
86
+ name: hashie
73
87
  requirement: !ruby/object:Gem::Requirement
74
88
  requirements:
75
89
  - - ">="
@@ -83,7 +97,7 @@ dependencies:
83
97
  - !ruby/object:Gem::Version
84
98
  version: '0'
85
99
  - !ruby/object:Gem::Dependency
86
- name: hashie
100
+ name: httpclient
87
101
  requirement: !ruby/object:Gem::Requirement
88
102
  requirements:
89
103
  - - ">="
@@ -138,6 +152,34 @@ dependencies:
138
152
  - - ">="
139
153
  - !ruby/object:Gem::Version
140
154
  version: '0'
155
+ - !ruby/object:Gem::Dependency
156
+ name: net-http-persistent
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ type: :development
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ - !ruby/object:Gem::Dependency
170
+ name: patron
171
+ requirement: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ type: :development
177
+ prerelease: false
178
+ version_requirements: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
141
183
  - !ruby/object:Gem::Dependency
142
184
  name: pry
143
185
  requirement: !ruby/object:Gem::Requirement
@@ -236,6 +278,20 @@ dependencies:
236
278
  - - "~>"
237
279
  - !ruby/object:Gem::Version
238
280
  version: '2'
281
+ - !ruby/object:Gem::Dependency
282
+ name: typhoeus
283
+ requirement: !ruby/object:Gem::Requirement
284
+ requirements:
285
+ - - "~>"
286
+ - !ruby/object:Gem::Version
287
+ version: '1.4'
288
+ type: :development
289
+ prerelease: false
290
+ version_requirements: !ruby/object:Gem::Requirement
291
+ requirements:
292
+ - - "~>"
293
+ - !ruby/object:Gem::Version
294
+ version: '1.4'
239
295
  - !ruby/object:Gem::Dependency
240
296
  name: yard
241
297
  requirement: !ruby/object:Gem::Requirement
@@ -255,7 +311,7 @@ description: 'Low level Ruby client for Elastic. See the `elasticsearch` or `ela
255
311
 
256
312
  '
257
313
  email:
258
- - support@elastic.co
314
+ - clients-team@elastic.co
259
315
  executables: []
260
316
  extensions: []
261
317
  extra_rdoc_files:
@@ -269,7 +325,6 @@ files:
269
325
  - ".gitignore"
270
326
  - CHANGELOG.md
271
327
  - Gemfile
272
- - Gemfile-faraday1.gemfile
273
328
  - LICENSE
274
329
  - README.md
275
330
  - Rakefile
@@ -306,7 +361,6 @@ files:
306
361
  - test/integration/transport_test.rb
307
362
  - test/profile/client_benchmark_test.rb
308
363
  - test/test_helper.rb
309
- - test/unit/adapters_test.rb
310
364
  - test/unit/connection_test.rb
311
365
  - test/unit/response_test.rb
312
366
  - test/unit/serializer_test.rb
@@ -338,7 +392,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
338
392
  - !ruby/object:Gem::Version
339
393
  version: '0'
340
394
  requirements: []
341
- rubygems_version: 3.3.7
395
+ rubygems_version: 3.4.13
342
396
  signing_key:
343
397
  specification_version: 4
344
398
  summary: Low level Ruby client for Elastic services.
@@ -357,7 +411,6 @@ test_files:
357
411
  - test/integration/transport_test.rb
358
412
  - test/profile/client_benchmark_test.rb
359
413
  - test/test_helper.rb
360
- - test/unit/adapters_test.rb
361
414
  - test/unit/connection_test.rb
362
415
  - test/unit/response_test.rb
363
416
  - test/unit/serializer_test.rb
@@ -1,39 +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
- source 'https://rubygems.org'
19
-
20
- # Usage:
21
- #
22
- # $ BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle install
23
- # $ BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle exec rake test:faraday1:unit
24
-
25
- gem 'faraday', '~> 1'
26
- gemspec path: './'
27
-
28
- group :development, :test do
29
- gem 'httpclient'
30
- gem 'net-http-persistent'
31
- gem 'patron' unless defined? JRUBY_VERSION
32
- gem 'rspec'
33
- gem 'typhoeus'
34
- if defined?(JRUBY_VERSION)
35
- gem 'pry-nav'
36
- else
37
- gem 'pry-byebug'
38
- end
39
- end
@@ -1,88 +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 Elastic::Transport::ClientAdaptersUnitTest < Minitest::Test
21
- context 'Adapters' do
22
- setup do
23
- begin
24
- Object.send(:remove_const, :Patron)
25
- rescue NameError
26
- end
27
- end
28
-
29
- should 'use the default Faraday adapter' do
30
- fork do
31
- client = Elastic::Transport::Client.new
32
- assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttp)
33
- end
34
- end
35
-
36
- should 'use Patron Faraday adapter' do
37
- fork do
38
- if is_faraday_v2?
39
- require 'faraday/patron'
40
- else
41
- require 'patron'
42
- end
43
-
44
- client = Elastic::Transport::Client.new
45
- assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Patron)
46
- end
47
- end
48
-
49
- should 'use Typhoeus Faraday adapter' do
50
- fork do
51
- if is_faraday_v2?
52
- require 'faraday/typhoeus'
53
- else
54
- require 'typhoeus'
55
- end
56
-
57
- client = Elastic::Transport::Client.new
58
- assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Typhoeus)
59
- end
60
- end
61
-
62
- should 'use NetHttpPersistent Faraday adapter' do
63
- fork do
64
- if is_faraday_v2?
65
- require 'faraday/net_http_persistent'
66
- else
67
- require 'net/http/persistent'
68
- end
69
-
70
- client = Elastic::Transport::Client.new
71
- assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttpPersistent)
72
- end
73
- end
74
-
75
- should 'use HTTPClient Faraday adapter' do
76
- fork do
77
- if is_faraday_v2?
78
- require 'faraday/httpclient'
79
- else
80
- require 'httpclient'
81
- end
82
-
83
- client = Elastic::Transport::Client.new
84
- assert_equal(Faraday::Adapter::HTTPClient, client.transport.connections.first.connection.adapter)
85
- end
86
- end
87
- end unless jruby?
88
- end