elasticsearch-transport 7.13.3 → 7.15.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.
@@ -24,10 +24,6 @@ describe Elasticsearch::Transport::Client do
24
24
  end
25
25
  end
26
26
 
27
- it 'is aliased as Elasticsearch::Client' do
28
- expect(Elasticsearch::Client.new).to be_a(described_class)
29
- end
30
-
31
27
  it 'has a default transport' do
32
28
  expect(client.transport).to be_a(Elasticsearch::Transport::Client::DEFAULT_TRANSPORT_CLASS)
33
29
  end
@@ -231,13 +227,14 @@ describe Elasticsearch::Transport::Client do
231
227
 
232
228
  describe 'adapter' do
233
229
  context 'when no adapter is specified' do
234
- let(:adapter) do
235
- client.transport.connections.all.first.connection.builder.adapter
236
- end
230
+ fork do
231
+ let(:client) { described_class.new }
232
+ let(:adapter) { client.transport.connections.all.first.connection.builder.adapter }
237
233
 
238
- it 'uses Faraday NetHttp' do
239
- expect(adapter).to eq Faraday::Adapter::NetHttp
240
- end
234
+ it 'uses Faraday NetHttp' do
235
+ expect(adapter).to eq Faraday::Adapter::NetHttp
236
+ end
237
+ end unless jruby?
241
238
  end
242
239
 
243
240
  context 'when the adapter is patron' do
@@ -1416,14 +1413,14 @@ describe Elasticsearch::Transport::Client do
1416
1413
  let(:client) { described_class.new(host: hosts) }
1417
1414
 
1418
1415
  it 'doesnae raise an ArgumentError' do
1419
- expect { client.search(opaque_id: 'no_error') }.not_to raise_error
1416
+ expect { client.perform_request('GET', '_search', opaque_id: 'no_error') }.not_to raise_error
1420
1417
  end
1421
1418
 
1422
1419
  it 'uses X-Opaque-Id in the header' do
1423
1420
  allow(client).to receive(:perform_request) { OpenStruct.new(body: '') }
1424
- expect { client.search(opaque_id: 'opaque_id') }.not_to raise_error
1421
+ expect { client.perform_request('GET', '_search', {}, nil, opaque_id: 'opaque_id') }.not_to raise_error
1425
1422
  expect(client).to have_received(:perform_request)
1426
- .with('GET', '_search', { opaque_id: 'opaque_id' }, nil, {})
1423
+ .with('GET', '_search', {}, nil, { opaque_id: 'opaque_id' })
1427
1424
  end
1428
1425
  end
1429
1426
  end
@@ -1500,7 +1497,7 @@ describe Elasticsearch::Transport::Client do
1500
1497
 
1501
1498
  it 'performs the request with the header' do
1502
1499
  allow(client).to receive(:perform_request) { OpenStruct.new(body: '') }
1503
- expect { client.search(headers: headers) }.not_to raise_error
1500
+ expect { client.perform_request('GET', '_search', {}, nil, headers) }.not_to raise_error
1504
1501
  expect(client).to have_received(:perform_request)
1505
1502
  .with('GET', '_search', {}, nil, headers)
1506
1503
  end
@@ -1514,7 +1511,7 @@ describe Elasticsearch::Transport::Client do
1514
1511
  )
1515
1512
  end
1516
1513
  let(:instance_headers) { { set_in_instantiation: 'header value' } }
1517
- let(:param_headers) {{'user-agent' => 'My Ruby Tests', 'set-on-method-call' => 'header value'}}
1514
+ let(:param_headers) { {'user-agent' => 'My Ruby Tests', 'set-on-method-call' => 'header value'} }
1518
1515
 
1519
1516
  it 'performs the request with the header' do
1520
1517
  expected_headers = client.transport.connections.connections.first.connection.headers.merge(param_headers)
@@ -1523,7 +1520,7 @@ describe Elasticsearch::Transport::Client do
1523
1520
  .to receive(:run_request)
1524
1521
  .with(:get, "http://#{hosts[0]}/_search", nil, expected_headers) { OpenStruct.new(body: '')}
1525
1522
 
1526
- client.search(headers: param_headers)
1523
+ client.perform_request('GET', '_search', {}, nil, param_headers)
1527
1524
  end
1528
1525
  end
1529
1526
  end
@@ -1560,7 +1557,6 @@ describe Elasticsearch::Transport::Client do
1560
1557
  end
1561
1558
 
1562
1559
  context 'when a request is made' do
1563
-
1564
1560
  let!(:response) do
1565
1561
  client.perform_request('GET', '_cluster/health')
1566
1562
  end
@@ -1571,9 +1567,7 @@ describe Elasticsearch::Transport::Client do
1571
1567
  end
1572
1568
 
1573
1569
  describe '#initialize' do
1574
-
1575
1570
  context 'when options are specified' do
1576
-
1577
1571
  let(:transport_options) do
1578
1572
  { headers: { accept: 'application/yaml', content_type: 'application/yaml' } }
1579
1573
  end
@@ -1589,9 +1583,8 @@ describe Elasticsearch::Transport::Client do
1589
1583
  end
1590
1584
 
1591
1585
  context 'when a block is provided' do
1592
-
1593
1586
  let(:client) do
1594
- Elasticsearch::Client.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
1587
+ described_class.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
1595
1588
  client.headers['Accept'] = 'application/yaml'
1596
1589
  end
1597
1590
  end
@@ -1607,7 +1600,7 @@ describe Elasticsearch::Transport::Client do
1607
1600
 
1608
1601
  context 'when the Faraday adapter is set in the block' do
1609
1602
  let(:client) do
1610
- Elasticsearch::Client.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
1603
+ described_class.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
1611
1604
  client.adapter(:net_http_persistent)
1612
1605
  end
1613
1606
  end
@@ -1821,11 +1814,12 @@ describe Elasticsearch::Transport::Client do
1821
1814
  end
1822
1815
 
1823
1816
  context 'when using Curb as the transport', unless: jruby? do
1824
-
1825
1817
  let(:client) do
1826
- described_class.new(hosts: ELASTICSEARCH_HOSTS,
1827
- compression: true,
1828
- transport_class: Elasticsearch::Transport::Transport::HTTP::Curb)
1818
+ described_class.new(
1819
+ hosts: ELASTICSEARCH_HOSTS,
1820
+ compression: true,
1821
+ transport_class: Elasticsearch::Transport::Transport::HTTP::Curb
1822
+ )
1829
1823
  end
1830
1824
 
1831
1825
  it 'compresses the request and decompresses the response' do
@@ -1842,7 +1836,6 @@ describe Elasticsearch::Transport::Client do
1842
1836
  end
1843
1837
 
1844
1838
  context 'when using Manticore as the transport', if: jruby? do
1845
-
1846
1839
  let(:client) do
1847
1840
  described_class.new(hosts: ELASTICSEARCH_HOSTS,
1848
1841
  compression: true,
@@ -1856,9 +1849,7 @@ describe Elasticsearch::Transport::Client do
1856
1849
  end
1857
1850
 
1858
1851
  describe '#perform_request' do
1859
-
1860
1852
  context 'when a request is made' do
1861
-
1862
1853
  before do
1863
1854
  client.perform_request('DELETE', '_all')
1864
1855
  client.perform_request('DELETE', 'myindex') rescue
@@ -1881,7 +1872,6 @@ describe Elasticsearch::Transport::Client do
1881
1872
  end
1882
1873
 
1883
1874
  context 'when an invalid url is specified' do
1884
-
1885
1875
  it 'raises an exception' do
1886
1876
  expect {
1887
1877
  client.perform_request('GET', 'myindex/mydoc/1?routing=FOOBARBAZ')
@@ -1890,7 +1880,6 @@ describe Elasticsearch::Transport::Client do
1890
1880
  end
1891
1881
 
1892
1882
  context 'when the \'ignore\' parameter is specified' do
1893
-
1894
1883
  let(:response) do
1895
1884
  client.perform_request('PUT', '_foobar', ignore: 400)
1896
1885
  end
@@ -1927,7 +1916,7 @@ describe Elasticsearch::Transport::Client do
1927
1916
  end
1928
1917
 
1929
1918
  let(:node_names) do
1930
- client.nodes.stats['nodes'].collect do |name, stats|
1919
+ client.perform_request('GET', '_nodes/stats').body('nodes').collect do |name, stats|
1931
1920
  stats['name']
1932
1921
  end
1933
1922
  end
@@ -1946,7 +1935,6 @@ describe Elasticsearch::Transport::Client do
1946
1935
  end
1947
1936
 
1948
1937
  context 'when patron is used as an adapter', unless: jruby? do
1949
-
1950
1938
  before do
1951
1939
  require 'patron'
1952
1940
  end
@@ -16,6 +16,7 @@
16
16
  # under the License.
17
17
 
18
18
  require 'spec_helper'
19
+ require 'elasticsearch'
19
20
 
20
21
  describe Elasticsearch::Transport::Client do
21
22
  context 'meta-header' do
@@ -109,11 +110,17 @@ describe Elasticsearch::Transport::Client do
109
110
  let(:adapter) { :net_http_persistent }
110
111
 
111
112
  it 'sets adapter in the meta header version to 0 when not loaded' do
112
- fork {
113
- expect(headers['x-elastic-client-meta']).to match(regexp)
114
- meta = "#{meta_header},np=0"
115
- expect(headers).to include('x-elastic-client-meta' => meta)
116
- }
113
+ was_required = defined?(Net::HTTP::Persistent)
114
+ if was_required
115
+ @klass = Net::HTTP::Persistent.clone
116
+ Net::HTTP.send(:remove_const, :Persistent)
117
+ end
118
+
119
+ expect(headers['x-elastic-client-meta']).to match(regexp)
120
+ meta = "#{meta_header},np=0"
121
+ expect(headers).to include('x-elastic-client-meta' => meta)
122
+
123
+ Net::HTTP::Persistent = @klass if was_required
117
124
  end unless jruby?
118
125
 
119
126
  it 'sets adapter in the meta header' do
@@ -128,15 +135,22 @@ describe Elasticsearch::Transport::Client do
128
135
  let(:adapter) { :httpclient }
129
136
 
130
137
  it 'sets adapter in the meta header version to 0 when not loaded' do
131
- fork {
132
- expect(headers['x-elastic-client-meta']).to match(regexp)
133
- meta = "#{meta_header},hc=0"
134
- expect(headers).to include('x-elastic-client-meta' => meta)
135
- }
138
+ was_required = defined?(HTTPClient)
139
+ if was_required
140
+ @klass = HTTPClient.clone
141
+ Object.send(:remove_const, :HTTPClient)
142
+ end
143
+
144
+ expect(headers['x-elastic-client-meta']).to match(regexp)
145
+ meta = "#{meta_header},hc=0"
146
+ expect(headers).to include('x-elastic-client-meta' => meta)
147
+
148
+ HTTPClient = @klass if was_required
136
149
  end unless jruby?
137
150
 
138
151
  it 'sets adapter in the meta header' do
139
152
  require 'httpclient'
153
+
140
154
  expect(headers['x-elastic-client-meta']).to match(regexp)
141
155
  meta = "#{meta_header},hc=#{HTTPClient::VERSION}"
142
156
  expect(headers).to include('x-elastic-client-meta' => meta)
@@ -147,11 +161,17 @@ describe Elasticsearch::Transport::Client do
147
161
  let(:adapter) { :typhoeus }
148
162
 
149
163
  it 'sets adapter in the meta header version to 0 when not loaded' do
150
- fork {
151
- expect(headers['x-elastic-client-meta']).to match(regexp)
152
- meta = "#{meta_header},ty=0"
153
- expect(headers).to include('x-elastic-client-meta' => meta)
154
- }
164
+ was_required = defined?(Typhoeus)
165
+ if was_required
166
+ @klass = Typhoeus.clone
167
+ Object.send(:remove_const, :Typhoeus)
168
+ end
169
+
170
+ expect(headers['x-elastic-client-meta']).to match(regexp)
171
+ meta = "#{meta_header},ty=0"
172
+ expect(headers).to include('x-elastic-client-meta' => meta)
173
+
174
+ Typhoeus = @klass if was_required
155
175
  end unless jruby?
156
176
 
157
177
  it 'sets adapter in the meta header' do
@@ -167,11 +187,17 @@ describe Elasticsearch::Transport::Client do
167
187
 
168
188
  context 'using patron without requiring it' do
169
189
  it 'sets adapter in the meta header version to 0 when not loaded' do
170
- fork {
171
- expect(headers['x-elastic-client-meta']).to match(regexp)
172
- meta = "#{meta_header},pt=0"
173
- expect(headers).to include('x-elastic-client-meta' => meta)
174
- }
190
+ was_required = defined?(Patron)
191
+ if was_required
192
+ @klass = Patron.clone
193
+ Object.send(:remove_const, :Patron)
194
+ end
195
+
196
+ expect(headers['x-elastic-client-meta']).to match(regexp)
197
+ meta = "#{meta_header},pt=0"
198
+ expect(headers).to include('x-elastic-client-meta' => meta)
199
+
200
+ Patron = @klass if was_required
175
201
  end
176
202
  end
177
203
 
@@ -206,7 +232,9 @@ describe Elasticsearch::Transport::Client do
206
232
  if defined?(JRUBY_VERSION)
207
233
  context 'when using manticore' do
208
234
  let(:client) do
209
- Elasticsearch::Client.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Manticore)
235
+ described_class.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Manticore).tap do |client|
236
+ client.instance_variable_set('@verified', true)
237
+ end
210
238
  end
211
239
  let(:subject) { client.transport.connections.first.connection.instance_variable_get("@options")[:headers]}
212
240
 
@@ -218,7 +246,9 @@ describe Elasticsearch::Transport::Client do
218
246
  else
219
247
  context 'when using curb' do
220
248
  let(:client) do
221
- Elasticsearch::Client.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Curb)
249
+ described_class.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Curb).tap do |client|
250
+ client.instance_variable_set('@verified', true)
251
+ end
222
252
  end
223
253
 
224
254
  it 'sets curb in the metaheader' do
@@ -229,12 +259,14 @@ describe Elasticsearch::Transport::Client do
229
259
  end
230
260
 
231
261
  context 'when using custom transport implementation' do
232
- class MyTransport
233
- include Elasticsearch::Transport::Transport::Base
234
- def initialize(args); end
262
+ let(:transport_class) do
263
+ Class.new do
264
+ def initialize(args)
265
+ end
266
+ end
235
267
  end
236
- let(:client) { Elasticsearch::Client.new(transport_class: MyTransport) }
237
- let(:subject){ client.instance_variable_get("@arguments")[:transport_options][:headers] }
268
+ let(:client) { Elasticsearch::Transport::Client.new(transport_class: transport_class) }
269
+ let(:subject) { client.instance_variable_get('@arguments')[:transport_options][:headers] }
238
270
  let(:meta_header) do
239
271
  if jruby?
240
272
  "es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
@@ -254,7 +286,11 @@ describe Elasticsearch::Transport::Client do
254
286
  stub_const('Elastic::ELASTICSEARCH_SERVICE_VERSION', [:ent, '8.0.0'])
255
287
  end
256
288
 
257
- let(:client) { Elasticsearch::Client.new }
289
+ let(:client) do
290
+ described_class.new.tap do |client|
291
+ client.instance_variable_set('@verified', true)
292
+ end
293
+ end
258
294
 
259
295
  it 'sets the service version in the metaheader' do
260
296
  expect(subject['x-elastic-client-meta']).to match(regexp)
data/spec/spec_helper.rb CHANGED
@@ -14,8 +14,11 @@
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
+ if ENV['COVERAGE'] && ENV['CI'].nil?
18
+ require 'simplecov'
19
+ SimpleCov.start { add_filter %r{^/test|spec/} }
20
+ end
17
21
 
18
- require 'elasticsearch'
19
22
  require 'elasticsearch-transport'
20
23
  require 'logger'
21
24
  require 'ansi/code'
@@ -32,10 +35,12 @@ end
32
35
  # The hosts to use for creating a elasticsearch client.
33
36
  #
34
37
  # @since 7.0.0
35
- ELASTICSEARCH_HOSTS = if hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOSTS']
38
+ ELASTICSEARCH_HOSTS = if (hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOSTS'])
36
39
  hosts.split(',').map do |host|
37
40
  /(http\:\/\/)?(\S+)/.match(host)[2]
38
41
  end
42
+ else
43
+ ['localhost:9200']
39
44
  end.freeze
40
45
 
41
46
  TEST_HOST, TEST_PORT = ELASTICSEARCH_HOSTS.first.split(':') if ELASTICSEARCH_HOSTS
@@ -55,7 +60,8 @@ end
55
60
  #
56
61
  # @since 7.0.0
57
62
  def node_names
58
- $node_names ||= default_client.nodes.stats['nodes'].collect do |name, stats|
63
+ node_stats = default_client.perform_request('GET', '_nodes/stats').body
64
+ $node_names ||= node_stats['nodes'].collect do |name, stats|
59
65
  stats['name']
60
66
  end
61
67
  end
@@ -70,9 +76,7 @@ def default_client
70
76
  end
71
77
 
72
78
  module Config
73
-
74
79
  def self.included(context)
75
-
76
80
  # Get the hosts to use to connect an elasticsearch client.
77
81
  #
78
82
  # @since 7.0.0
@@ -0,0 +1,43 @@
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
+ require 'test_helper'
18
+
19
+ if JRUBY
20
+ require 'elasticsearch/transport/transport/http/manticore'
21
+
22
+ class Elasticsearch::Transport::ClientManticoreIntegrationTest < Elasticsearch::Test::IntegrationTestCase
23
+ context "Transport" do
24
+ setup do
25
+ @host, @port = ELASTICSEARCH_HOSTS.first.split(':')
26
+ end
27
+
28
+ shutdown do
29
+ begin; Object.send(:remove_const, :Manticore); rescue NameError; end
30
+ end
31
+
32
+ should 'allow to customize the Faraday adapter to Manticore' do
33
+ client = Elasticsearch::Transport::Client.new(
34
+ transport_class: Elasticsearch::Transport::Transport::HTTP::Manticore,
35
+ trace: true,
36
+ hosts: [ { host: @host, port: @port } ]
37
+ )
38
+ response = client.perform_request 'GET', ''
39
+ assert_respond_to(response.body, :to_hash)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -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