elasticsearch-transport 7.13.3 → 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.
- checksums.yaml +4 -4
- data/Gemfile +4 -8
- data/README.md +3 -8
- data/Rakefile +9 -10
- data/elasticsearch-transport.gemspec +15 -15
- data/lib/elasticsearch/transport/client.rb +34 -3
- data/lib/elasticsearch/transport/transport/base.rb +41 -22
- data/lib/elasticsearch/transport/transport/connections/connection.rb +2 -1
- data/lib/elasticsearch/transport/transport/errors.rb +1 -0
- data/lib/elasticsearch/transport/transport/http/curb.rb +44 -32
- data/lib/elasticsearch/transport/transport/http/faraday.rb +5 -3
- data/lib/elasticsearch/transport/transport/http/manticore.rb +35 -28
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/lib/elasticsearch/transport.rb +19 -30
- data/spec/elasticsearch/transport/base_spec.rb +46 -7
- data/spec/elasticsearch/transport/client_spec.rb +129 -61
- data/spec/elasticsearch/transport/http/curb_spec.rb +126 -0
- data/spec/elasticsearch/transport/http/faraday_spec.rb +141 -0
- data/spec/elasticsearch/transport/http/manticore_spec.rb +143 -0
- data/spec/elasticsearch/transport/meta_header_spec.rb +64 -28
- data/spec/spec_helper.rb +9 -5
- data/test/integration/jruby_test.rb +43 -0
- data/test/integration/transport_test.rb +18 -27
- data/test/test_helper.rb +6 -22
- data/test/unit/response_test.rb +1 -1
- data/test/unit/transport_base_test.rb +16 -7
- data/test/unit/transport_curb_test.rb +0 -1
- data/test/unit/transport_manticore_test.rb +242 -155
- metadata +63 -55
@@ -29,6 +29,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
29
29
|
context "Transport" do
|
30
30
|
setup do
|
31
31
|
@host, @port = ELASTICSEARCH_HOSTS.first.split(':')
|
32
|
+
@hosts = { hosts: [ { host: @host, port: @port } ] }
|
32
33
|
begin; Object.send(:remove_const, :Patron); rescue NameError; end
|
33
34
|
end
|
34
35
|
|
@@ -36,11 +37,10 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
36
37
|
require 'typhoeus'
|
37
38
|
require 'typhoeus/adapters/faraday'
|
38
39
|
|
39
|
-
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
40
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
|
41
|
+
f.response :logger
|
42
|
+
f.adapter :typhoeus
|
43
|
+
end
|
44
44
|
|
45
45
|
client = Elasticsearch::Transport::Client.new transport: transport
|
46
46
|
client.perform_request 'GET', ''
|
@@ -49,8 +49,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
49
49
|
should "allow to customize the Faraday adapter to NetHttpPersistent" do
|
50
50
|
require 'net/http/persistent'
|
51
51
|
|
52
|
-
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new
|
53
|
-
:hosts => [ { host: @host, port: @port } ] do |f|
|
52
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
|
54
53
|
f.response :logger
|
55
54
|
f.adapter :net_http_persistent
|
56
55
|
end
|
@@ -60,13 +59,10 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
60
59
|
end
|
61
60
|
|
62
61
|
should "allow to define connection parameters and pass them" do
|
63
|
-
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
}
|
68
|
-
}
|
69
|
-
|
62
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(
|
63
|
+
hosts: [ { host: @host, port: @port } ],
|
64
|
+
options: { transport_options: { params: { :format => 'yaml' } } }
|
65
|
+
)
|
70
66
|
client = Elasticsearch::Transport::Client.new transport: transport
|
71
67
|
response = client.perform_request 'GET', ''
|
72
68
|
|
@@ -76,24 +72,20 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
76
72
|
should "use the Curb client" do
|
77
73
|
require 'curb'
|
78
74
|
require 'elasticsearch/transport/transport/http/curb'
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
curl.verbose = true
|
83
|
-
end
|
75
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Curb.new(@hosts) do |curl|
|
76
|
+
curl.verbose = true
|
77
|
+
end
|
84
78
|
|
85
79
|
client = Elasticsearch::Transport::Client.new transport: transport
|
86
80
|
client.perform_request 'GET', ''
|
87
|
-
end unless
|
81
|
+
end unless jruby?
|
88
82
|
|
89
83
|
should "deserialize JSON responses in the Curb client" do
|
90
84
|
require 'curb'
|
91
85
|
require 'elasticsearch/transport/transport/http/curb'
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
curl.verbose = true
|
96
|
-
end
|
86
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Curb.new(@hosts) do |curl|
|
87
|
+
curl.verbose = true
|
88
|
+
end
|
97
89
|
|
98
90
|
client = Elasticsearch::Transport::Client.new transport: transport
|
99
91
|
response = client.perform_request 'GET', ''
|
@@ -101,7 +93,6 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
101
93
|
assert_respond_to(response.body, :to_hash)
|
102
94
|
assert_not_nil response.body['name']
|
103
95
|
assert_equal 'application/json', response.headers['content-type']
|
104
|
-
end unless
|
96
|
+
end unless jruby?
|
105
97
|
end
|
106
|
-
|
107
98
|
end
|
data/test/test_helper.rb
CHANGED
@@ -20,30 +20,17 @@ ELASTICSEARCH_HOSTS = if hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOS
|
|
20
20
|
hosts.split(',').map do |host|
|
21
21
|
/(http\:\/\/)?(\S+)/.match(host)[2]
|
22
22
|
end
|
23
|
+
else
|
24
|
+
['localhost:9200']
|
23
25
|
end.freeze
|
24
26
|
|
25
27
|
TEST_HOST, TEST_PORT = ELASTICSEARCH_HOSTS.first.split(':') if ELASTICSEARCH_HOSTS
|
26
28
|
|
27
|
-
RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
|
28
29
|
JRUBY = defined?(JRUBY_VERSION)
|
29
30
|
|
30
|
-
if
|
31
|
-
require 'rubygems'
|
32
|
-
gem 'test-unit'
|
33
|
-
end
|
34
|
-
|
35
|
-
require 'rubygems' if RUBY_1_8
|
36
|
-
|
37
|
-
if ENV['COVERAGE'] && ENV['CI'].nil? && !RUBY_1_8
|
31
|
+
if ENV['COVERAGE']
|
38
32
|
require 'simplecov'
|
39
|
-
SimpleCov.start { add_filter
|
40
|
-
end
|
41
|
-
|
42
|
-
if ENV['CI'] && !RUBY_1_8
|
43
|
-
require 'simplecov'
|
44
|
-
require 'simplecov-rcov'
|
45
|
-
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
46
|
-
SimpleCov.start { add_filter "/test|test_" }
|
33
|
+
SimpleCov.start { add_filter %r{^/test/} }
|
47
34
|
end
|
48
35
|
|
49
36
|
# Register `at_exit` handler for integration tests shutdown.
|
@@ -52,7 +39,6 @@ if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
|
|
52
39
|
at_exit { Elasticsearch::Test::IntegrationTestCase.__run_at_exit_hooks }
|
53
40
|
end
|
54
41
|
|
55
|
-
require 'test/unit' if RUBY_1_8
|
56
42
|
require 'minitest/autorun'
|
57
43
|
require 'minitest/reporters'
|
58
44
|
require 'shoulda/context'
|
@@ -119,8 +105,7 @@ module Elasticsearch
|
|
119
105
|
extend Elasticsearch::Extensions::Test::StartupShutdown
|
120
106
|
|
121
107
|
shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? && Elasticsearch::Extensions::Test::Cluster.running? }
|
122
|
-
|
123
|
-
end if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
|
108
|
+
end
|
124
109
|
end
|
125
110
|
|
126
111
|
module Test
|
@@ -129,7 +114,6 @@ module Elasticsearch
|
|
129
114
|
extend Elasticsearch::Extensions::Test::Profiling
|
130
115
|
|
131
116
|
shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? && Elasticsearch::Extensions::Test::Cluster.running? }
|
132
|
-
|
133
|
-
end unless RUBY_1_8 || JRUBY
|
117
|
+
end unless JRUBY
|
134
118
|
end
|
135
119
|
end
|
data/test/unit/response_test.rb
CHANGED
@@ -263,6 +263,15 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
263
263
|
end
|
264
264
|
end
|
265
265
|
|
266
|
+
should 'raise TooManyRequestsError on 429' do
|
267
|
+
@transport.expects(:get_connection).returns(stub_everything :failures => 1)
|
268
|
+
assert_raise Elasticsearch::Transport::Transport::Errors::TooManyRequests do
|
269
|
+
@transport.perform_request 'GET', '/' do
|
270
|
+
Elasticsearch::Transport::Transport::Response.new 429, 'ERROR'
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
266
275
|
should "not raise an error when the :ignore argument has been passed" do
|
267
276
|
@transport.stubs(:get_connection).returns(stub_everything :failures => 1)
|
268
277
|
|
@@ -310,7 +319,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
310
319
|
@transport.perform_request('GET', '/', &@block)
|
311
320
|
assert_equal 2, @transport.counter
|
312
321
|
end
|
313
|
-
end
|
322
|
+
end
|
314
323
|
|
315
324
|
context "performing a request with retry on connection failures" do
|
316
325
|
setup do
|
@@ -344,7 +353,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
344
353
|
@transport.perform_request('GET', '/', &@block)
|
345
354
|
end
|
346
355
|
end
|
347
|
-
end
|
356
|
+
end
|
348
357
|
|
349
358
|
context "performing a request with retry on status" do
|
350
359
|
setup do
|
@@ -391,7 +400,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
391
400
|
@transport.perform_request('GET', '/', &@block)
|
392
401
|
end
|
393
402
|
end
|
394
|
-
end
|
403
|
+
end
|
395
404
|
|
396
405
|
context "logging" do
|
397
406
|
setup do
|
@@ -447,7 +456,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
447
456
|
assert_raise Elasticsearch::Transport::Transport::Errors::InternalServerError do
|
448
457
|
@transport.perform_request('POST', '_search', &@block)
|
449
458
|
end
|
450
|
-
end
|
459
|
+
end
|
451
460
|
|
452
461
|
should "not log a failed Elasticsearch request as fatal" do
|
453
462
|
@block = Proc.new { |c, u| puts "ERROR" }
|
@@ -458,7 +467,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
458
467
|
|
459
468
|
# No `BadRequest` error
|
460
469
|
@transport.perform_request('POST', '_search', :ignore => 500, &@block)
|
461
|
-
end
|
470
|
+
end
|
462
471
|
|
463
472
|
should "log and re-raise a Ruby exception" do
|
464
473
|
@block = Proc.new { |c, u| puts "ERROR" }
|
@@ -468,7 +477,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
468
477
|
@transport.logger.expects(:fatal)
|
469
478
|
|
470
479
|
assert_raise(Exception) { @transport.perform_request('POST', '_search', &@block) }
|
471
|
-
end
|
480
|
+
end
|
472
481
|
end
|
473
482
|
|
474
483
|
context "tracing" do
|
@@ -522,7 +531,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
522
531
|
assert_raise Elasticsearch::Transport::Transport::Errors::InternalServerError do
|
523
532
|
@transport.perform_request('POST', '_search', &@block)
|
524
533
|
end
|
525
|
-
end
|
534
|
+
end
|
526
535
|
|
527
536
|
end
|
528
537
|
|
@@ -84,7 +84,6 @@ else
|
|
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
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
|
-
|
88
87
|
response = @transport.perform_request 'GET', '/'
|
89
88
|
|
90
89
|
assert_equal 'application/json', response.headers['content-type']
|