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.
@@ -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
- :hosts => [ { host: @host, port: @port } ] do |f|
41
- f.response :logger
42
- f.adapter :typhoeus
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
- :hosts => [ { host: @host, port: @port } ],
65
- :options => { :transport_options => {
66
- :params => { :format => 'yaml' }
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
- transport = Elasticsearch::Transport::Transport::HTTP::Curb.new \
81
- :hosts => [ { host: @host, port: @port } ] do |curl|
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 JRUBY
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
- transport = Elasticsearch::Transport::Transport::HTTP::Curb.new \
94
- :hosts => [ { host: @host, port: @port } ] do |curl|
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 JRUBY
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 RUBY_1_8 and not ENV['BUNDLE_GEMFILE']
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 "/test|test_/" }
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
- context "IntegrationTest" do; should "noop on Ruby 1.8" do; end; end if RUBY_1_8
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
- context "IntegrationTest" do; should "noop on Ruby 1.8" do; end; end if RUBY_1_8
133
- end unless RUBY_1_8 || JRUBY
117
+ end unless JRUBY
134
118
  end
135
119
  end
@@ -26,7 +26,7 @@ class Elasticsearch::Transport::Transport::ResponseTest < Minitest::Test
26
26
 
27
27
  response = Elasticsearch::Transport::Transport::Response.new 200, body
28
28
  assert_equal 'UTF-8', response.body.encoding.name
29
- end unless RUBY_1_8
29
+ end
30
30
 
31
31
  end
32
32
  end
@@ -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 unless RUBY_1_8
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 unless RUBY_1_8
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 unless RUBY_1_8
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 unless RUBY_1_8
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 unless RUBY_1_8
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 unless RUBY_1_8
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 unless RUBY_1_8
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']