elasticsearch-transport 7.13.1 → 7.14.1.pre
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 +11 -11
- data/lib/elasticsearch/transport.rb +18 -30
- data/lib/elasticsearch/transport/client.rb +1 -2
- data/lib/elasticsearch/transport/transport/errors.rb +1 -0
- data/lib/elasticsearch/transport/transport/http/curb.rb +39 -29
- data/lib/elasticsearch/transport/transport/http/faraday.rb +6 -5
- data/lib/elasticsearch/transport/transport/http/manticore.rb +3 -3
- data/lib/elasticsearch/transport/version.rb +1 -1
- data/spec/elasticsearch/transport/base_spec.rb +46 -7
- data/spec/elasticsearch/transport/client_spec.rb +21 -33
- data/spec/elasticsearch/transport/meta_header_spec.rb +64 -28
- data/spec/spec_helper.rb +9 -5
- 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 +224 -155
- metadata +53 -53
@@ -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
|
-
|
235
|
-
client.
|
236
|
-
|
230
|
+
fork do
|
231
|
+
let(:client) { described_class.new }
|
232
|
+
let(:adapter) { client.transport.connections.all.first.connection.builder.adapter }
|
237
233
|
|
238
|
-
|
239
|
-
|
240
|
-
|
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.
|
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.
|
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' }
|
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.
|
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.
|
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
|
-
|
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
|
-
|
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(
|
1827
|
-
|
1828
|
-
|
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.
|
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
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
233
|
-
|
234
|
-
|
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:
|
237
|
-
let(:subject){ client.instance_variable_get(
|
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)
|
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
|
-
|
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
|
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