elasticsearch-transport 7.1.0 → 7.13.3
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 +13 -9
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +175 -76
- data/Rakefile +1 -1
- data/elasticsearch-transport.gemspec +42 -60
- data/lib/elasticsearch/transport/client.rb +154 -57
- data/lib/elasticsearch/transport/meta_header.rb +135 -0
- data/lib/elasticsearch/transport/redacted.rb +1 -1
- data/lib/elasticsearch/transport/transport/base.rb +93 -18
- data/lib/elasticsearch/transport/transport/connections/collection.rb +3 -6
- data/lib/elasticsearch/transport/transport/connections/connection.rb +8 -6
- data/lib/elasticsearch/transport/transport/connections/selector.rb +18 -6
- data/lib/elasticsearch/transport/transport/errors.rb +1 -1
- data/lib/elasticsearch/transport/transport/http/curb.rb +26 -9
- data/lib/elasticsearch/transport/transport/http/faraday.rb +27 -5
- data/lib/elasticsearch/transport/transport/http/manticore.rb +25 -10
- data/lib/elasticsearch/transport/transport/loggable.rb +1 -1
- data/lib/elasticsearch/transport/transport/response.rb +1 -2
- data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +1 -1
- data/lib/elasticsearch/transport/transport/sniffer.rb +20 -12
- data/lib/elasticsearch/transport/version.rb +2 -2
- data/lib/elasticsearch/transport.rb +1 -1
- data/lib/elasticsearch-transport.rb +1 -1
- data/spec/elasticsearch/connections/collection_spec.rb +266 -0
- data/spec/elasticsearch/connections/selector_spec.rb +174 -0
- data/spec/elasticsearch/transport/base_spec.rb +197 -13
- data/spec/elasticsearch/transport/client_spec.rb +945 -118
- data/spec/elasticsearch/transport/meta_header_spec.rb +265 -0
- data/spec/elasticsearch/transport/sniffer_spec.rb +1 -14
- data/spec/spec_helper.rb +25 -1
- data/test/integration/transport_test.rb +15 -2
- data/test/profile/client_benchmark_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/connection_test.rb +8 -3
- data/test/unit/response_test.rb +2 -2
- data/test/unit/serializer_test.rb +1 -1
- data/test/unit/transport_base_test.rb +2 -2
- data/test/unit/transport_curb_test.rb +2 -2
- data/test/unit/transport_faraday_test.rb +3 -3
- data/test/unit/transport_manticore_test.rb +30 -14
- metadata +87 -60
- data/test/unit/connection_collection_test.rb +0 -147
- data/test/unit/connection_selector_test.rb +0 -81
@@ -0,0 +1,265 @@
|
|
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 'spec_helper'
|
19
|
+
|
20
|
+
describe Elasticsearch::Transport::Client do
|
21
|
+
context 'meta-header' do
|
22
|
+
let(:subject) { client.transport.connections.first.connection.headers }
|
23
|
+
let(:client) { described_class.new }
|
24
|
+
let(:regexp) { /^[a-z]{1,}=[a-z0-9.\-]{1,}(?:,[a-z]{1,}=[a-z0-9._\-]+)*$/ }
|
25
|
+
let(:adapter) { :net_http }
|
26
|
+
let(:adapter_code) { "nh=#{defined?(Net::HTTP::VERSION) ? Net::HTTP::VERSION : Net::HTTP::HTTPVersion}" }
|
27
|
+
let(:meta_header) do
|
28
|
+
if jruby?
|
29
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
|
30
|
+
else
|
31
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION},#{adapter_code}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'client_meta_version' do
|
36
|
+
let(:version) { ['7.1.0-alpha', '7.11.0.pre.1', '8.0.0-beta', '8.0.0.beta.2']}
|
37
|
+
|
38
|
+
it 'converts the version to X.X.Xp' do
|
39
|
+
expect(client.send(:client_meta_version, '7.0.0-alpha')).to eq('7.0.0p')
|
40
|
+
expect(client.send(:client_meta_version, '7.11.0.pre.1')).to eq('7.11.0p')
|
41
|
+
expect(client.send(:client_meta_version, '8.1.0-beta')).to eq('8.1.0p')
|
42
|
+
expect(client.send(:client_meta_version, '8.0.0.beta.2')).to eq('8.0.0p')
|
43
|
+
expect(client.send(:client_meta_version, '12.16.4.pre')).to eq('12.16.4p')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# We are testing this method in the previous block, so now using it inside the test to make the
|
48
|
+
# Elasticsearch version in the meta header string dynamic
|
49
|
+
def meta_version
|
50
|
+
client.send(:client_meta_version, Elasticsearch::VERSION)
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'single use of meta header' do
|
54
|
+
let(:client) do
|
55
|
+
described_class.new(adapter: adapter).tap do |klient|
|
56
|
+
allow(klient).to receive(:__build_connections)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'x-elastic-client-header value matches regexp' do
|
61
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
62
|
+
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when using user-agent headers' do
|
67
|
+
let(:client) do
|
68
|
+
transport_options = { headers: { user_agent: 'My Ruby App' } }
|
69
|
+
described_class.new(transport_options: transport_options, adapter: adapter).tap do |klient|
|
70
|
+
allow(klient).to receive(:__build_connections)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'is friendly to previously set headers' do
|
75
|
+
expect(subject).to include(user_agent: 'My Ruby App')
|
76
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
77
|
+
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when using API Key' do
|
82
|
+
let(:client) do
|
83
|
+
described_class.new(api_key: 'an_api_key', adapter: adapter)
|
84
|
+
end
|
85
|
+
|
86
|
+
let(:authorization_header) do
|
87
|
+
client.transport.connections.first.connection.headers['Authorization']
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'adds the ApiKey header to the connection' do
|
91
|
+
expect(authorization_header).to eq('ApiKey an_api_key')
|
92
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
93
|
+
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'adapters' do
|
98
|
+
let(:meta_header) do
|
99
|
+
if jruby?
|
100
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION},fd=#{Faraday::VERSION}"
|
101
|
+
else
|
102
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},fd=#{Faraday::VERSION}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
let(:client) { described_class.new(adapter: adapter) }
|
106
|
+
let(:headers) { client.transport.connections.first.connection.headers }
|
107
|
+
|
108
|
+
context 'using net/http/persistent' do
|
109
|
+
let(:adapter) { :net_http_persistent }
|
110
|
+
|
111
|
+
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
|
+
}
|
117
|
+
end unless jruby?
|
118
|
+
|
119
|
+
it 'sets adapter in the meta header' do
|
120
|
+
require 'net/http/persistent'
|
121
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
122
|
+
meta = "#{meta_header},np=#{Net::HTTP::Persistent::VERSION}"
|
123
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'using httpclient' do
|
128
|
+
let(:adapter) { :httpclient }
|
129
|
+
|
130
|
+
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
|
+
}
|
136
|
+
end unless jruby?
|
137
|
+
|
138
|
+
it 'sets adapter in the meta header' do
|
139
|
+
require 'httpclient'
|
140
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
141
|
+
meta = "#{meta_header},hc=#{HTTPClient::VERSION}"
|
142
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'using typhoeus' do
|
147
|
+
let(:adapter) { :typhoeus }
|
148
|
+
|
149
|
+
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
|
+
}
|
155
|
+
end unless jruby?
|
156
|
+
|
157
|
+
it 'sets adapter in the meta header' do
|
158
|
+
require 'typhoeus'
|
159
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
160
|
+
meta = "#{meta_header},ty=#{Typhoeus::VERSION}"
|
161
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
unless jruby?
|
166
|
+
let(:adapter) { :patron }
|
167
|
+
|
168
|
+
context 'using patron without requiring it' do
|
169
|
+
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
|
+
}
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'using patron' do
|
179
|
+
it 'sets adapter in the meta header' do
|
180
|
+
require 'patron'
|
181
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
182
|
+
meta = "#{meta_header},pt=#{Patron::VERSION}"
|
183
|
+
expect(headers).to include('x-elastic-client-meta' => meta)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'using other' do
|
189
|
+
let(:adapter) { :some_other_adapter }
|
190
|
+
|
191
|
+
it 'sets adapter in the meta header without requiring' do
|
192
|
+
Faraday::Adapter.register_middleware some_other_adapter: Faraday::Adapter::NetHttpPersistent
|
193
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
194
|
+
expect(headers).to include('x-elastic-client-meta' => meta_header)
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'sets adapter in the meta header' do
|
198
|
+
require 'net/http/persistent'
|
199
|
+
Faraday::Adapter.register_middleware some_other_adapter: Faraday::Adapter::NetHttpPersistent
|
200
|
+
expect(headers['x-elastic-client-meta']).to match(regexp)
|
201
|
+
expect(headers).to include('x-elastic-client-meta' => meta_header)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
if defined?(JRUBY_VERSION)
|
207
|
+
context 'when using manticore' do
|
208
|
+
let(:client) do
|
209
|
+
Elasticsearch::Client.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Manticore)
|
210
|
+
end
|
211
|
+
let(:subject) { client.transport.connections.first.connection.instance_variable_get("@options")[:headers]}
|
212
|
+
|
213
|
+
it 'sets manticore in the metaheader' do
|
214
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
215
|
+
expect(subject['x-elastic-client-meta']).to match(/mc=[0-9.]+/)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
else
|
219
|
+
context 'when using curb' do
|
220
|
+
let(:client) do
|
221
|
+
Elasticsearch::Client.new(transport_class: Elasticsearch::Transport::Transport::HTTP::Curb)
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'sets curb in the metaheader' do
|
225
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
226
|
+
expect(subject['x-elastic-client-meta']).to match(/cl=[0-9.]+/)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context 'when using custom transport implementation' do
|
232
|
+
class MyTransport
|
233
|
+
include Elasticsearch::Transport::Transport::Base
|
234
|
+
def initialize(args); end
|
235
|
+
end
|
236
|
+
let(:client) { Elasticsearch::Client.new(transport_class: MyTransport) }
|
237
|
+
let(:subject){ client.instance_variable_get("@arguments")[:transport_options][:headers] }
|
238
|
+
let(:meta_header) do
|
239
|
+
if jruby?
|
240
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION},jv=#{ENV_JAVA['java.version']},jr=#{JRUBY_VERSION}"
|
241
|
+
else
|
242
|
+
"es=#{meta_version},rb=#{RUBY_VERSION},t=#{Elasticsearch::Transport::VERSION}"
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'doesnae set any info about the implementation in the metaheader' do
|
247
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
248
|
+
expect(subject).to include('x-elastic-client-meta' => meta_header)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
context 'when using a different service version' do
|
253
|
+
before do
|
254
|
+
stub_const('Elastic::ELASTICSEARCH_SERVICE_VERSION', [:ent, '8.0.0'])
|
255
|
+
end
|
256
|
+
|
257
|
+
let(:client) { Elasticsearch::Client.new }
|
258
|
+
|
259
|
+
it 'sets the service version in the metaheader' do
|
260
|
+
expect(subject['x-elastic-client-meta']).to match(regexp)
|
261
|
+
expect(subject['x-elastic-client-meta']).to start_with('ent=8.0.0')
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -18,7 +18,6 @@
|
|
18
18
|
require 'spec_helper'
|
19
19
|
|
20
20
|
describe Elasticsearch::Transport::Transport::Sniffer do
|
21
|
-
|
22
21
|
let(:transport) do
|
23
22
|
double('transport').tap do |t|
|
24
23
|
allow(t).to receive(:perform_request).and_return(response)
|
@@ -45,7 +44,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
45
44
|
end
|
46
45
|
|
47
46
|
describe '#initialize' do
|
48
|
-
|
49
47
|
it 'has a transport instance' do
|
50
48
|
expect(sniffer.transport).to be(transport)
|
51
49
|
end
|
@@ -56,7 +54,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
56
54
|
end
|
57
55
|
|
58
56
|
describe '#timeout' do
|
59
|
-
|
60
57
|
let(:sniffer) do
|
61
58
|
described_class.new(double('transport', options: {}))
|
62
59
|
end
|
@@ -71,13 +68,11 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
71
68
|
end
|
72
69
|
|
73
70
|
describe '#hosts' do
|
74
|
-
|
75
71
|
let(:hosts) do
|
76
72
|
sniffer.hosts
|
77
73
|
end
|
78
74
|
|
79
75
|
context 'when the entire response is parsed' do
|
80
|
-
|
81
76
|
let(:raw_response) do
|
82
77
|
{
|
83
78
|
"cluster_name" => "elasticsearch_test",
|
@@ -142,7 +137,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
142
137
|
end
|
143
138
|
|
144
139
|
context 'when the transport protocol does not match' do
|
145
|
-
|
146
140
|
let(:raw_response) do
|
147
141
|
{ 'nodes' => { 'n1' => { 'foo' => { 'publish_address' => '127.0.0.1:9250' } } } }
|
148
142
|
end
|
@@ -153,7 +147,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
153
147
|
end
|
154
148
|
|
155
149
|
context 'when a list of nodes is returned' do
|
156
|
-
|
157
150
|
let(:raw_response) do
|
158
151
|
{ 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } },
|
159
152
|
'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } }
|
@@ -175,7 +168,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
175
168
|
end
|
176
169
|
|
177
170
|
context 'when the host and port are an ip address and port' do
|
178
|
-
|
179
171
|
it 'parses the response' do
|
180
172
|
expect(hosts.size).to eq(1)
|
181
173
|
end
|
@@ -190,7 +182,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
190
182
|
end
|
191
183
|
|
192
184
|
context 'when the host and port are a hostname and port' do
|
193
|
-
|
194
185
|
let(:publish_address) do
|
195
186
|
'testhost1.com:9250'
|
196
187
|
end
|
@@ -213,7 +204,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
213
204
|
end
|
214
205
|
|
215
206
|
context 'when the host and port are in the format: hostname/ip:port' do
|
216
|
-
|
217
207
|
let(:publish_address) do
|
218
208
|
'example.com/127.0.0.1:9250'
|
219
209
|
end
|
@@ -231,7 +221,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
231
221
|
end
|
232
222
|
|
233
223
|
context 'when the address is IPv6' do
|
234
|
-
|
235
224
|
let(:publish_address) do
|
236
225
|
'example.com/[::1]:9250'
|
237
226
|
end
|
@@ -251,7 +240,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
251
240
|
end
|
252
241
|
|
253
242
|
context 'when the address is IPv6' do
|
254
|
-
|
255
243
|
let(:publish_address) do
|
256
244
|
'[::1]:9250'
|
257
245
|
end
|
@@ -270,7 +258,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
270
258
|
end
|
271
259
|
|
272
260
|
context 'when the transport has :randomize_hosts option' do
|
273
|
-
|
274
261
|
let(:raw_response) do
|
275
262
|
{ 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } },
|
276
263
|
'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } }
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,33 @@
|
|
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
|
+
|
1
18
|
require 'elasticsearch'
|
2
19
|
require 'elasticsearch-transport'
|
3
20
|
require 'logger'
|
4
21
|
require 'ansi/code'
|
5
22
|
require 'hashie/mash'
|
6
|
-
|
23
|
+
if defined?(JRUBY_VERSION)
|
24
|
+
require 'elasticsearch/transport/transport/http/manticore'
|
25
|
+
require 'pry-nav'
|
26
|
+
else
|
27
|
+
require 'pry-byebug'
|
28
|
+
require 'elasticsearch/transport/transport/http/curb'
|
29
|
+
require 'curb'
|
30
|
+
end
|
7
31
|
|
8
32
|
# The hosts to use for creating a elasticsearch client.
|
9
33
|
#
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -32,7 +32,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
32
32
|
begin; Object.send(:remove_const, :Patron); rescue NameError; end
|
33
33
|
end
|
34
34
|
|
35
|
-
should "allow to customize the Faraday adapter" do
|
35
|
+
should "allow to customize the Faraday adapter to Typhoeus" do
|
36
36
|
require 'typhoeus'
|
37
37
|
require 'typhoeus/adapters/faraday'
|
38
38
|
|
@@ -42,6 +42,19 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
42
42
|
f.adapter :typhoeus
|
43
43
|
end
|
44
44
|
|
45
|
+
client = Elasticsearch::Transport::Client.new transport: transport
|
46
|
+
client.perform_request 'GET', ''
|
47
|
+
end unless jruby?
|
48
|
+
|
49
|
+
should "allow to customize the Faraday adapter to NetHttpPersistent" do
|
50
|
+
require 'net/http/persistent'
|
51
|
+
|
52
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
|
53
|
+
:hosts => [ { host: @host, port: @port } ] do |f|
|
54
|
+
f.response :logger
|
55
|
+
f.adapter :net_http_persistent
|
56
|
+
end
|
57
|
+
|
45
58
|
client = Elasticsearch::Transport::Client.new transport: transport
|
46
59
|
client.perform_request 'GET', ''
|
47
60
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
data/test/test_helper.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -57,10 +57,15 @@ class Elasticsearch::Transport::Transport::Connections::ConnectionTest < Minites
|
|
57
57
|
assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('_search', {:foo => 'bar'})
|
58
58
|
end
|
59
59
|
|
60
|
+
should "return right full url with path when path starts with /" do
|
61
|
+
c = Connection.new :host => { :protocol => 'http', :host => 'localhost', :port => '9200', :path => '/foo' }
|
62
|
+
assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('/_search', {:foo => 'bar'})
|
63
|
+
end
|
64
|
+
|
60
65
|
should "have a string representation" do
|
61
66
|
c = Connection.new :host => 'x'
|
62
|
-
assert_match
|
63
|
-
assert_match
|
67
|
+
assert_match(/host: x/, c.to_s)
|
68
|
+
assert_match(/alive/, c.to_s)
|
64
69
|
end
|
65
70
|
|
66
71
|
should "not be dead by default" do
|
data/test/unit/response_test.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -29,4 +29,4 @@ class Elasticsearch::Transport::Transport::ResponseTest < Minitest::Test
|
|
29
29
|
end unless RUBY_1_8
|
30
30
|
|
31
31
|
end
|
32
|
-
end
|
32
|
+
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -429,7 +429,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
429
429
|
@transport.stubs(:get_connection).returns(fake_connection)
|
430
430
|
|
431
431
|
@transport.logger.expects(:info).with do |message|
|
432
|
-
assert_match
|
432
|
+
assert_match(/http:\/\/user:\*{1,15}@localhost\:9200/, message)
|
433
433
|
true
|
434
434
|
end
|
435
435
|
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -57,7 +57,7 @@ else
|
|
57
57
|
should "perform request with headers" do
|
58
58
|
@transport.connections.first.connection.expects(:put_data=).with('{"foo":"bar"}')
|
59
59
|
@transport.connections.first.connection.expects(:http).with(:POST).returns(stub_everything)
|
60
|
-
@transport.connections.first.connection.expects(:
|
60
|
+
@transport.connections.first.connection.headers.expects(:merge!).with("Content-Type" => "application/x-ndjson")
|
61
61
|
|
62
62
|
@transport.perform_request 'POST', '/', {}, {:foo => 'bar'}, {"Content-Type" => "application/x-ndjson"}
|
63
63
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -149,7 +149,7 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Minitest::Test
|
|
149
149
|
|
150
150
|
transport.connections.first.connection.expects(:run_request).
|
151
151
|
with do |method, url, params, body|
|
152
|
-
assert_match
|
152
|
+
assert_match(/\?format=yaml/, url)
|
153
153
|
true
|
154
154
|
end.
|
155
155
|
returns(stub_everything)
|
@@ -167,7 +167,7 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Minitest::Test
|
|
167
167
|
|
168
168
|
transport.connections.first.connection.expects(:run_request).
|
169
169
|
with do |method, url, params, body|
|
170
|
-
assert_match
|
170
|
+
assert_match(/\?format=json/, url)
|
171
171
|
true
|
172
172
|
end.
|
173
173
|
returns(stub_everything)
|