elasticsearch-transport 7.7.0 → 7.9.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.
- checksums.yaml +4 -4
- data/Gemfile +16 -3
- data/README.md +4 -4
- data/Rakefile +16 -3
- data/elasticsearch-transport.gemspec +17 -4
- data/lib/elasticsearch-transport.rb +16 -3
- data/lib/elasticsearch/transport.rb +16 -3
- data/lib/elasticsearch/transport/client.rb +16 -3
- 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 +16 -3
- data/lib/elasticsearch/transport/transport/connections/connection.rb +19 -5
- 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 +16 -3
- 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/spec/elasticsearch/connections/collection_spec.rb +16 -3
- data/spec/elasticsearch/connections/selector_spec.rb +16 -3
- data/spec/elasticsearch/transport/base_spec.rb +16 -10
- data/spec/elasticsearch/transport/client_spec.rb +84 -7
- data/spec/elasticsearch/transport/sniffer_spec.rb +16 -16
- data/spec/spec_helper.rb +16 -3
- data/test/integration/transport_test.rb +16 -3
- data/test/profile/client_benchmark_test.rb +16 -3
- data/test/test_helper.rb +16 -3
- data/test/unit/connection_test.rb +16 -3
- data/test/unit/response_test.rb +17 -4
- data/test/unit/serializer_test.rb +16 -3
- data/test/unit/transport_base_test.rb +16 -3
- data/test/unit/transport_curb_test.rb +16 -3
- data/test/unit/transport_faraday_test.rb +16 -3
- data/test/unit/transport_manticore_test.rb +16 -3
- metadata +4 -4
@@ -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 'manticore'
|
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
|
module Elasticsearch
|
6
19
|
|
@@ -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
|
module Elasticsearch
|
6
19
|
module Transport
|
7
20
|
module Transport
|
8
|
-
|
9
21
|
# Wraps the response from Elasticsearch.
|
10
22
|
#
|
11
23
|
class Response
|
@@ -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
|
module Elasticsearch
|
6
19
|
module Transport
|
@@ -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
|
module Elasticsearch
|
6
19
|
module Transport
|
@@ -32,21 +45,21 @@ module Elasticsearch
|
|
32
45
|
#
|
33
46
|
def hosts
|
34
47
|
Timeout::timeout(timeout, SnifferTimeoutError) do
|
35
|
-
nodes =
|
36
|
-
reload_on_failure: false).body
|
48
|
+
nodes = perform_sniff_request.body
|
37
49
|
|
38
50
|
hosts = nodes['nodes'].map do |id, info|
|
39
|
-
|
40
|
-
|
51
|
+
next unless info[PROTOCOL]
|
52
|
+
host, port = parse_publish_address(info[PROTOCOL]['publish_address'])
|
41
53
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
54
|
+
{
|
55
|
+
id: id,
|
56
|
+
name: info['name'],
|
57
|
+
version: info['version'],
|
58
|
+
host: host,
|
59
|
+
port: port,
|
60
|
+
roles: info['roles'],
|
61
|
+
attributes: info['attributes']
|
62
|
+
}
|
50
63
|
end.compact
|
51
64
|
|
52
65
|
hosts.shuffle! if transport.options[:randomize_hosts]
|
@@ -56,6 +69,13 @@ module Elasticsearch
|
|
56
69
|
|
57
70
|
private
|
58
71
|
|
72
|
+
def perform_sniff_request
|
73
|
+
transport.perform_request(
|
74
|
+
'GET', '_nodes/http', {}, nil, nil,
|
75
|
+
reload_on_failure: false
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
59
79
|
def parse_publish_address(publish_address)
|
60
80
|
# publish_address is in the format hostname/ip:port
|
61
81
|
if publish_address =~ /\//
|
@@ -1,9 +1,22 @@
|
|
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
|
module Elasticsearch
|
6
19
|
module Transport
|
7
|
-
VERSION = "7.
|
20
|
+
VERSION = "7.9.0"
|
8
21
|
end
|
9
22
|
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 'spec_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 'spec_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 'spec_helper'
|
6
19
|
|
@@ -96,7 +109,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
96
109
|
end
|
97
110
|
|
98
111
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
99
|
-
|
100
112
|
before do
|
101
113
|
expect(client.transport).to receive(:get_connection).exactly(3).times.and_call_original
|
102
114
|
end
|
@@ -109,7 +121,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
109
121
|
end
|
110
122
|
|
111
123
|
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
112
|
-
|
113
124
|
before do
|
114
125
|
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
115
126
|
end
|
@@ -123,7 +134,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
123
134
|
end
|
124
135
|
|
125
136
|
context 'when the client has `retry_on_failure` set to true' do
|
126
|
-
|
127
137
|
let(:client) do
|
128
138
|
Elasticsearch::Transport::Client.new(arguments)
|
129
139
|
end
|
@@ -136,7 +146,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
136
146
|
end
|
137
147
|
|
138
148
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
139
|
-
|
140
149
|
before do
|
141
150
|
expect(client.transport).to receive(:get_connection).exactly(4).times.and_call_original
|
142
151
|
end
|
@@ -149,7 +158,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
149
158
|
end
|
150
159
|
|
151
160
|
context 'when `perform_request` is called with a `retry_on_failure` option value' do
|
152
|
-
|
153
161
|
before do
|
154
162
|
expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original
|
155
163
|
end
|
@@ -163,7 +171,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
163
171
|
end
|
164
172
|
|
165
173
|
context 'when the client has `retry_on_failure` set to false' do
|
166
|
-
|
167
174
|
let(:client) do
|
168
175
|
Elasticsearch::Transport::Client.new(arguments)
|
169
176
|
end
|
@@ -176,7 +183,6 @@ describe Elasticsearch::Transport::Transport::Base do
|
|
176
183
|
end
|
177
184
|
|
178
185
|
context 'when `perform_request` is called without a `retry_on_failure` option value' do
|
179
|
-
|
180
186
|
before do
|
181
187
|
expect(client.transport).to receive(:get_connection).once.and_call_original
|
182
188
|
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::Client do
|
8
|
-
|
9
21
|
let(:client) do
|
10
22
|
described_class.new.tap do |_client|
|
11
23
|
allow(_client).to receive(:__build_connections)
|
@@ -228,8 +240,7 @@ describe Elasticsearch::Transport::Client do
|
|
228
240
|
end
|
229
241
|
end
|
230
242
|
|
231
|
-
context 'when the adapter is
|
232
|
-
|
243
|
+
context 'when the adapter is patron' do
|
233
244
|
let(:adapter) do
|
234
245
|
client.transport.connections.all.first.connection.builder.adapter
|
235
246
|
end
|
@@ -243,8 +254,21 @@ describe Elasticsearch::Transport::Client do
|
|
243
254
|
end
|
244
255
|
end
|
245
256
|
|
246
|
-
context 'when the adapter is
|
257
|
+
context 'when the adapter is typhoeus' do
|
258
|
+
let(:adapter) do
|
259
|
+
client.transport.connections.all.first.connection.builder.adapter
|
260
|
+
end
|
261
|
+
|
262
|
+
let(:client) do
|
263
|
+
described_class.new(adapter: :typhoeus)
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'uses Faraday with the adapter' do
|
267
|
+
expect(adapter).to eq Faraday::Adapter::Typhoeus
|
268
|
+
end
|
269
|
+
end
|
247
270
|
|
271
|
+
context 'when the adapter is specified as a string key' do
|
248
272
|
let(:adapter) do
|
249
273
|
client.transport.connections.all.first.connection.builder.adapter
|
250
274
|
end
|
@@ -1134,6 +1158,32 @@ describe Elasticsearch::Transport::Client do
|
|
1134
1158
|
end
|
1135
1159
|
end
|
1136
1160
|
|
1161
|
+
context 'when Elasticsearch response includes a warning header' do
|
1162
|
+
let(:client) do
|
1163
|
+
Elasticsearch::Transport::Client.new(hosts: hosts)
|
1164
|
+
end
|
1165
|
+
|
1166
|
+
let(:warning) { 'Elasticsearch warning: "deprecation warning"' }
|
1167
|
+
|
1168
|
+
it 'prints a warning' do
|
1169
|
+
allow_any_instance_of(Elasticsearch::Transport::Transport::Response).to receive(:headers) do
|
1170
|
+
{ 'warning' => warning }
|
1171
|
+
end
|
1172
|
+
|
1173
|
+
begin
|
1174
|
+
stderr = $stderr
|
1175
|
+
fake_stderr = StringIO.new
|
1176
|
+
$stderr = fake_stderr
|
1177
|
+
|
1178
|
+
client.perform_request('GET', '/')
|
1179
|
+
fake_stderr.rewind
|
1180
|
+
expect(fake_stderr.string).to eq("warning: #{warning}\n")
|
1181
|
+
ensure
|
1182
|
+
$stderr = stderr
|
1183
|
+
end
|
1184
|
+
end
|
1185
|
+
end
|
1186
|
+
|
1137
1187
|
context 'when a header is set on an endpoint request' do
|
1138
1188
|
let(:client) { described_class.new(host: hosts) }
|
1139
1189
|
let(:headers) { { 'user-agent' => 'my ruby app' } }
|
@@ -1591,6 +1641,33 @@ describe Elasticsearch::Transport::Client do
|
|
1591
1641
|
expect(connections_after).to be >= (connections_before)
|
1592
1642
|
end
|
1593
1643
|
end
|
1644
|
+
|
1645
|
+
context 'when typhoeus is used as an adapter', unless: jruby? do
|
1646
|
+
before do
|
1647
|
+
require 'typhoeus'
|
1648
|
+
end
|
1649
|
+
|
1650
|
+
let(:options) do
|
1651
|
+
{ adapter: :typhoeus }
|
1652
|
+
end
|
1653
|
+
|
1654
|
+
let(:adapter) do
|
1655
|
+
client.transport.connections.first.connection.builder.adapter
|
1656
|
+
end
|
1657
|
+
|
1658
|
+
it 'uses the patron connection handler' do
|
1659
|
+
expect(adapter).to eq('Faraday::Adapter::Typhoeus')
|
1660
|
+
end
|
1661
|
+
|
1662
|
+
it 'keeps connections open' do
|
1663
|
+
response = client.perform_request('GET', '_nodes/stats/http')
|
1664
|
+
connections_before = response.body['nodes'].values.find { |n| n['name'] == node_names.first }['http']['total_opened']
|
1665
|
+
client.transport.reload_connections!
|
1666
|
+
response = client.perform_request('GET', '_nodes/stats/http')
|
1667
|
+
connections_after = response.body['nodes'].values.find { |n| n['name'] == node_names.first }['http']['total_opened']
|
1668
|
+
expect(connections_after).to be >= (connections_before)
|
1669
|
+
end
|
1670
|
+
end
|
1594
1671
|
end
|
1595
1672
|
end
|
1596
1673
|
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' } } } }
|