elasticsearch-transport 7.5.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 +28 -11
- data/README.md +158 -58
- data/Rakefile +16 -3
- data/elasticsearch-transport.gemspec +57 -63
- data/lib/elasticsearch/transport/client.rb +150 -56
- data/lib/elasticsearch/transport/meta_header.rb +135 -0
- data/lib/elasticsearch/transport/redacted.rb +16 -3
- data/lib/elasticsearch/transport/transport/base.rb +32 -12
- data/lib/elasticsearch/transport/transport/connections/collection.rb +18 -8
- data/lib/elasticsearch/transport/transport/connections/connection.rb +23 -8
- data/lib/elasticsearch/transport/transport/connections/selector.rb +16 -3
- data/lib/elasticsearch/transport/transport/errors.rb +16 -3
- data/lib/elasticsearch/transport/transport/http/curb.rb +16 -3
- data/lib/elasticsearch/transport/transport/http/faraday.rb +27 -6
- data/lib/elasticsearch/transport/transport/http/manticore.rb +16 -3
- data/lib/elasticsearch/transport/transport/loggable.rb +16 -3
- data/lib/elasticsearch/transport/transport/response.rb +16 -4
- data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +16 -3
- data/lib/elasticsearch/transport/transport/sniffer.rb +35 -15
- data/lib/elasticsearch/transport/version.rb +17 -4
- data/lib/elasticsearch/transport.rb +16 -3
- data/lib/elasticsearch-transport.rb +16 -3
- data/spec/elasticsearch/connections/collection_spec.rb +28 -3
- data/spec/elasticsearch/connections/selector_spec.rb +16 -3
- data/spec/elasticsearch/transport/base_spec.rb +60 -38
- data/spec/elasticsearch/transport/client_spec.rb +628 -132
- data/spec/elasticsearch/transport/meta_header_spec.rb +265 -0
- data/spec/elasticsearch/transport/sniffer_spec.rb +16 -16
- data/spec/spec_helper.rb +19 -1
- data/test/integration/transport_test.rb +30 -4
- data/test/profile/client_benchmark_test.rb +16 -3
- data/test/test_helper.rb +16 -3
- data/test/unit/connection_test.rb +23 -5
- data/test/unit/response_test.rb +17 -4
- data/test/unit/serializer_test.rb +16 -3
- data/test/unit/transport_base_test.rb +17 -4
- data/test/unit/transport_curb_test.rb +16 -3
- data/test/unit/transport_faraday_test.rb +18 -5
- data/test/unit/transport_manticore_test.rb +29 -16
- metadata +70 -69
@@ -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
|
@@ -1,11 +1,23 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
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.
|
4
17
|
|
5
18
|
require 'spec_helper'
|
6
19
|
|
7
20
|
describe Elasticsearch::Transport::Transport::Sniffer do
|
8
|
-
|
9
21
|
let(:transport) do
|
10
22
|
double('transport').tap do |t|
|
11
23
|
allow(t).to receive(:perform_request).and_return(response)
|
@@ -32,7 +44,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
32
44
|
end
|
33
45
|
|
34
46
|
describe '#initialize' do
|
35
|
-
|
36
47
|
it 'has a transport instance' do
|
37
48
|
expect(sniffer.transport).to be(transport)
|
38
49
|
end
|
@@ -43,7 +54,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
43
54
|
end
|
44
55
|
|
45
56
|
describe '#timeout' do
|
46
|
-
|
47
57
|
let(:sniffer) do
|
48
58
|
described_class.new(double('transport', options: {}))
|
49
59
|
end
|
@@ -58,13 +68,11 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
58
68
|
end
|
59
69
|
|
60
70
|
describe '#hosts' do
|
61
|
-
|
62
71
|
let(:hosts) do
|
63
72
|
sniffer.hosts
|
64
73
|
end
|
65
74
|
|
66
75
|
context 'when the entire response is parsed' do
|
67
|
-
|
68
76
|
let(:raw_response) do
|
69
77
|
{
|
70
78
|
"cluster_name" => "elasticsearch_test",
|
@@ -129,7 +137,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
129
137
|
end
|
130
138
|
|
131
139
|
context 'when the transport protocol does not match' do
|
132
|
-
|
133
140
|
let(:raw_response) do
|
134
141
|
{ 'nodes' => { 'n1' => { 'foo' => { 'publish_address' => '127.0.0.1:9250' } } } }
|
135
142
|
end
|
@@ -140,7 +147,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
140
147
|
end
|
141
148
|
|
142
149
|
context 'when a list of nodes is returned' do
|
143
|
-
|
144
150
|
let(:raw_response) do
|
145
151
|
{ 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } },
|
146
152
|
'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } }
|
@@ -162,7 +168,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
162
168
|
end
|
163
169
|
|
164
170
|
context 'when the host and port are an ip address and port' do
|
165
|
-
|
166
171
|
it 'parses the response' do
|
167
172
|
expect(hosts.size).to eq(1)
|
168
173
|
end
|
@@ -177,7 +182,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
177
182
|
end
|
178
183
|
|
179
184
|
context 'when the host and port are a hostname and port' do
|
180
|
-
|
181
185
|
let(:publish_address) do
|
182
186
|
'testhost1.com:9250'
|
183
187
|
end
|
@@ -200,7 +204,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
200
204
|
end
|
201
205
|
|
202
206
|
context 'when the host and port are in the format: hostname/ip:port' do
|
203
|
-
|
204
207
|
let(:publish_address) do
|
205
208
|
'example.com/127.0.0.1:9250'
|
206
209
|
end
|
@@ -218,7 +221,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
218
221
|
end
|
219
222
|
|
220
223
|
context 'when the address is IPv6' do
|
221
|
-
|
222
224
|
let(:publish_address) do
|
223
225
|
'example.com/[::1]:9250'
|
224
226
|
end
|
@@ -238,7 +240,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
238
240
|
end
|
239
241
|
|
240
242
|
context 'when the address is IPv6' do
|
241
|
-
|
242
243
|
let(:publish_address) do
|
243
244
|
'[::1]:9250'
|
244
245
|
end
|
@@ -257,7 +258,6 @@ describe Elasticsearch::Transport::Transport::Sniffer do
|
|
257
258
|
end
|
258
259
|
|
259
260
|
context 'when the transport has :randomize_hosts option' do
|
260
|
-
|
261
261
|
let(:raw_response) do
|
262
262
|
{ 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } },
|
263
263
|
'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } }
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,30 @@
|
|
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
|
-
require 'pry-nav'
|
7
23
|
if defined?(JRUBY_VERSION)
|
8
24
|
require 'elasticsearch/transport/transport/http/manticore'
|
25
|
+
require 'pry-nav'
|
9
26
|
else
|
27
|
+
require 'pry-byebug'
|
10
28
|
require 'elasticsearch/transport/transport/http/curb'
|
11
29
|
require 'curb'
|
12
30
|
end
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
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.
|
4
17
|
|
5
18
|
require 'test_helper'
|
6
19
|
|
@@ -19,7 +32,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
19
32
|
begin; Object.send(:remove_const, :Patron); rescue NameError; end
|
20
33
|
end
|
21
34
|
|
22
|
-
should "allow to customize the Faraday adapter" do
|
35
|
+
should "allow to customize the Faraday adapter to Typhoeus" do
|
23
36
|
require 'typhoeus'
|
24
37
|
require 'typhoeus/adapters/faraday'
|
25
38
|
|
@@ -29,6 +42,19 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
29
42
|
f.adapter :typhoeus
|
30
43
|
end
|
31
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
|
+
|
32
58
|
client = Elasticsearch::Transport::Client.new transport: transport
|
33
59
|
client.perform_request 'GET', ''
|
34
60
|
end
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
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.
|
4
17
|
|
5
18
|
require 'test_helper'
|
6
19
|
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
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.
|
4
17
|
|
5
18
|
|
6
19
|
ELASTICSEARCH_HOSTS = if hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOSTS']
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
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.
|
4
17
|
|
5
18
|
require 'test_helper'
|
6
19
|
|
@@ -44,10 +57,15 @@ class Elasticsearch::Transport::Transport::Connections::ConnectionTest < Minites
|
|
44
57
|
assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('_search', {:foo => 'bar'})
|
45
58
|
end
|
46
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
|
+
|
47
65
|
should "have a string representation" do
|
48
66
|
c = Connection.new :host => 'x'
|
49
|
-
assert_match
|
50
|
-
assert_match
|
67
|
+
assert_match(/host: x/, c.to_s)
|
68
|
+
assert_match(/alive/, c.to_s)
|
51
69
|
end
|
52
70
|
|
53
71
|
should "not be dead by default" do
|
data/test/unit/response_test.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
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.
|
4
17
|
|
5
18
|
require 'test_helper'
|
6
19
|
|
@@ -16,4 +29,4 @@ class Elasticsearch::Transport::Transport::ResponseTest < Minitest::Test
|
|
16
29
|
end unless RUBY_1_8
|
17
30
|
|
18
31
|
end
|
19
|
-
end
|
32
|
+
end
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
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.
|
4
17
|
|
5
18
|
require 'test_helper'
|
6
19
|
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
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.
|
4
17
|
|
5
18
|
require 'test_helper'
|
6
19
|
|
@@ -416,7 +429,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
416
429
|
@transport.stubs(:get_connection).returns(fake_connection)
|
417
430
|
|
418
431
|
@transport.logger.expects(:info).with do |message|
|
419
|
-
assert_match
|
432
|
+
assert_match(/http:\/\/user:\*{1,15}@localhost\:9200/, message)
|
420
433
|
true
|
421
434
|
end
|
422
435
|
|
@@ -1,6 +1,19 @@
|
|
1
|
-
# Licensed to Elasticsearch B.V under one or more
|
2
|
-
#
|
3
|
-
#
|
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.
|
4
17
|
|
5
18
|
require 'test_helper'
|
6
19
|
|