elasticsearch-transport 5.0.5 → 6.8.2
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 +5 -5
- data/Gemfile +5 -0
- data/README.md +88 -34
- data/Rakefile +14 -17
- data/elasticsearch-transport.gemspec +44 -63
- data/lib/elasticsearch/transport/client.rb +120 -61
- data/lib/elasticsearch/transport/redacted.rb +79 -0
- data/lib/elasticsearch/transport/transport/base.rb +28 -14
- data/lib/elasticsearch/transport/transport/connections/collection.rb +4 -0
- data/lib/elasticsearch/transport/transport/connections/connection.rb +5 -1
- data/lib/elasticsearch/transport/transport/connections/selector.rb +4 -0
- data/lib/elasticsearch/transport/transport/errors.rb +4 -0
- data/lib/elasticsearch/transport/transport/http/curb.rb +7 -2
- data/lib/elasticsearch/transport/transport/http/faraday.rb +11 -8
- data/lib/elasticsearch/transport/transport/http/manticore.rb +6 -1
- data/lib/elasticsearch/transport/transport/response.rb +4 -0
- data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +4 -0
- data/lib/elasticsearch/transport/transport/sniffer.rb +31 -3
- data/lib/elasticsearch/transport/version.rb +5 -1
- data/lib/elasticsearch/transport.rb +5 -0
- data/lib/elasticsearch-transport.rb +4 -0
- data/spec/elasticsearch/transport/base_spec.rb +260 -0
- data/spec/elasticsearch/transport/client_spec.rb +1025 -0
- data/spec/elasticsearch/transport/sniffer_spec.rb +269 -0
- data/spec/spec_helper.rb +65 -0
- data/test/integration/transport_test.rb +9 -5
- data/test/profile/client_benchmark_test.rb +23 -25
- data/test/test_helper.rb +10 -0
- data/test/unit/connection_collection_test.rb +4 -0
- data/test/unit/connection_selector_test.rb +4 -0
- data/test/unit/connection_test.rb +4 -0
- data/test/unit/response_test.rb +5 -1
- data/test/unit/serializer_test.rb +4 -0
- data/test/unit/transport_base_test.rb +21 -1
- data/test/unit/transport_curb_test.rb +12 -0
- data/test/unit/transport_faraday_test.rb +16 -0
- data/test/unit/transport_manticore_test.rb +11 -0
- metadata +82 -84
- data/test/integration/client_test.rb +0 -237
- data/test/unit/client_test.rb +0 -366
- data/test/unit/sniffer_test.rb +0 -179
@@ -0,0 +1,269 @@
|
|
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::Transport::Sniffer do
|
21
|
+
|
22
|
+
let(:transport) do
|
23
|
+
double('transport').tap do |t|
|
24
|
+
allow(t).to receive(:perform_request).and_return(response)
|
25
|
+
allow(t).to receive(:options).and_return(sniffer_timeout: 2)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:sniffer) do
|
30
|
+
described_class.new(transport)
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:response) do
|
34
|
+
double('response').tap do |r|
|
35
|
+
allow(r).to receive(:body).and_return(raw_response)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:raw_response) do
|
40
|
+
{ 'nodes' => { 'n1' => { 'http' => { 'publish_address' => publish_address } } } }
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:publish_address) do
|
44
|
+
'127.0.0.1:9250'
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#initialize' do
|
48
|
+
|
49
|
+
it 'has a transport instance' do
|
50
|
+
expect(sniffer.transport).to be(transport)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'inherits the sniffer timeout from the transport object' do
|
54
|
+
expect(sniffer.timeout).to eq(2)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#timeout' do
|
59
|
+
|
60
|
+
let(:sniffer) do
|
61
|
+
described_class.new(double('transport', options: {}))
|
62
|
+
end
|
63
|
+
|
64
|
+
before do
|
65
|
+
sniffer.timeout = 3
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'allows the timeout to be configured' do
|
69
|
+
expect(sniffer.timeout).to eq(3)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#hosts' do
|
74
|
+
|
75
|
+
let(:hosts) do
|
76
|
+
sniffer.hosts
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when the entire response is parsed' do
|
80
|
+
|
81
|
+
let(:raw_response) do
|
82
|
+
{
|
83
|
+
"cluster_name" => "elasticsearch_test",
|
84
|
+
"nodes" => {
|
85
|
+
"N1" => {
|
86
|
+
"name" => "Node 1",
|
87
|
+
"transport_address" => "127.0.0.1:9300",
|
88
|
+
"host" => "testhost1",
|
89
|
+
"ip" => "127.0.0.1",
|
90
|
+
"version" => "7.0.0",
|
91
|
+
"roles" => [
|
92
|
+
"master",
|
93
|
+
"data",
|
94
|
+
"ingest"
|
95
|
+
],
|
96
|
+
"attributes" => {
|
97
|
+
"testattr" => "test"
|
98
|
+
},
|
99
|
+
"http" => {
|
100
|
+
"bound_address" => [
|
101
|
+
"[fe80::1]:9250",
|
102
|
+
"[::1]:9250",
|
103
|
+
"127.0.0.1:9250"
|
104
|
+
],
|
105
|
+
"publish_address" => "127.0.0.1:9250",
|
106
|
+
"max_content_length_in_bytes" => 104857600
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'parses the id' do
|
114
|
+
expect(sniffer.hosts[0][:id]).to eq('N1')
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'parses the name' do
|
118
|
+
expect(sniffer.hosts[0][:name]).to eq('Node 1')
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'parses the version' do
|
122
|
+
expect(sniffer.hosts[0][:version]).to eq('7.0.0')
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'parses the host' do
|
126
|
+
expect(sniffer.hosts[0][:host]).to eq('127.0.0.1')
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'parses the port' do
|
130
|
+
expect(sniffer.hosts[0][:port]).to eq('9250')
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'parses the roles' do
|
134
|
+
expect(sniffer.hosts[0][:roles]).to eq(['master',
|
135
|
+
'data',
|
136
|
+
'ingest'])
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'parses the attributes' do
|
140
|
+
expect(sniffer.hosts[0][:attributes]).to eq('testattr' => 'test')
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'when the transport protocol does not match' do
|
145
|
+
|
146
|
+
let(:raw_response) do
|
147
|
+
{ 'nodes' => { 'n1' => { 'foo' => { 'publish_address' => '127.0.0.1:9250' } } } }
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'does not parse the addresses' do
|
151
|
+
expect(hosts).to eq([])
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when a list of nodes is returned' do
|
156
|
+
|
157
|
+
let(:raw_response) do
|
158
|
+
{ 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } },
|
159
|
+
'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } }
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'parses the response' do
|
163
|
+
expect(hosts.size).to eq(2)
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'correctly parses the hosts' do
|
167
|
+
expect(hosts[0][:host]).to eq('127.0.0.1')
|
168
|
+
expect(hosts[1][:host]).to eq('127.0.0.1')
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'correctly parses the ports' do
|
172
|
+
expect(hosts[0][:port]).to eq('9250')
|
173
|
+
expect(hosts[1][:port]).to eq('9251')
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'when the host and port are an ip address and port' do
|
178
|
+
|
179
|
+
it 'parses the response' do
|
180
|
+
expect(hosts.size).to eq(1)
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'correctly parses the host' do
|
184
|
+
expect(hosts[0][:host]).to eq('127.0.0.1')
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'correctly parses the port' do
|
188
|
+
expect(hosts[0][:port]).to eq('9250')
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'when the host and port are a hostname and port' do
|
193
|
+
|
194
|
+
let(:publish_address) do
|
195
|
+
'testhost1.com:9250'
|
196
|
+
end
|
197
|
+
|
198
|
+
let(:hosts) do
|
199
|
+
sniffer.hosts
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'parses the response' do
|
203
|
+
expect(hosts.size).to eq(1)
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'correctly parses the host' do
|
207
|
+
expect(hosts[0][:host]).to eq('testhost1.com')
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'correctly parses the port' do
|
211
|
+
expect(hosts[0][:port]).to eq('9250')
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context 'when the host and port are in the format: hostname/ip:port' do
|
216
|
+
|
217
|
+
let(:publish_address) do
|
218
|
+
'example.com/127.0.0.1:9250'
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'parses the response' do
|
222
|
+
expect(hosts.size).to eq(1)
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'uses the hostname' do
|
226
|
+
expect(hosts[0][:host]).to eq('example.com')
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'correctly parses the port' do
|
230
|
+
expect(hosts[0][:port]).to eq('9250')
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context 'when the address is IPv6' do
|
235
|
+
|
236
|
+
let(:publish_address) do
|
237
|
+
'[::1]:9250'
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'parses the response' do
|
241
|
+
expect(hosts.size).to eq(1)
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'correctly parses the host' do
|
245
|
+
expect(hosts[0][:host]).to eq('::1')
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'correctly parses the port' do
|
249
|
+
expect(hosts[0][:port]).to eq('9250')
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
context 'when the transport has :randomize_hosts option' do
|
254
|
+
|
255
|
+
let(:raw_response) do
|
256
|
+
{ 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } },
|
257
|
+
'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } }
|
258
|
+
end
|
259
|
+
|
260
|
+
before do
|
261
|
+
allow(transport).to receive(:options).and_return(randomize_hosts: true)
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'shuffles the list' do
|
265
|
+
expect(hosts.size).to eq(2)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V under one or more agreements.
|
2
|
+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
3
|
+
# See the LICENSE file in the project root for more information
|
4
|
+
|
5
|
+
require 'elasticsearch'
|
6
|
+
require 'elasticsearch-transport'
|
7
|
+
require 'logger'
|
8
|
+
require 'ansi/code'
|
9
|
+
require 'hashie/mash'
|
10
|
+
require 'pry-nav'
|
11
|
+
|
12
|
+
# The hosts to use for creating a elasticsearch client.
|
13
|
+
#
|
14
|
+
# @since 7.0.0
|
15
|
+
ELASTICSEARCH_HOSTS = if hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOSTS']
|
16
|
+
hosts.split(',').map do |host|
|
17
|
+
/(http\:\/\/)?(\S+)/.match(host)[2]
|
18
|
+
end
|
19
|
+
end.freeze
|
20
|
+
|
21
|
+
# Are we testing on JRuby?
|
22
|
+
#
|
23
|
+
# @return [ true, false ] Whether JRuby is being used.
|
24
|
+
#
|
25
|
+
# @since 7.0.0
|
26
|
+
def jruby?
|
27
|
+
RUBY_PLATFORM =~ /\bjava\b/
|
28
|
+
end
|
29
|
+
|
30
|
+
# The names of the connected nodes.
|
31
|
+
#
|
32
|
+
# @return [ Array<String> ] The node names.
|
33
|
+
#
|
34
|
+
# @since 7.0.0
|
35
|
+
def node_names
|
36
|
+
$node_names ||= default_client.nodes.stats['nodes'].collect do |name, stats|
|
37
|
+
stats['name']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# The default client.
|
42
|
+
#
|
43
|
+
# @return [ Elasticsearch::Client ] The default client.
|
44
|
+
#
|
45
|
+
# @since 7.0.0
|
46
|
+
def default_client
|
47
|
+
$client ||= Elasticsearch::Client.new(hosts: ELASTICSEARCH_HOSTS)
|
48
|
+
end
|
49
|
+
|
50
|
+
module Config
|
51
|
+
|
52
|
+
def self.included(context)
|
53
|
+
|
54
|
+
# Get the hosts to use to connect an elasticsearch client.
|
55
|
+
#
|
56
|
+
# @since 7.0.0
|
57
|
+
context.let(:hosts) { ELASTICSEARCH_HOSTS }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
RSpec.configure do |config|
|
62
|
+
config.include(Config)
|
63
|
+
config.formatter = 'documentation'
|
64
|
+
config.color = true
|
65
|
+
end
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V under one or more agreements.
|
2
|
+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
3
|
+
# See the LICENSE file in the project root for more information
|
4
|
+
|
1
5
|
require 'test_helper'
|
2
6
|
|
3
7
|
class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::IntegrationTestCase
|
@@ -11,7 +15,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
11
15
|
|
12
16
|
context "Transport" do
|
13
17
|
setup do
|
14
|
-
@port = (
|
18
|
+
@host, @port = ELASTICSEARCH_HOSTS.first.split(':')
|
15
19
|
begin; Object.send(:remove_const, :Patron); rescue NameError; end
|
16
20
|
end
|
17
21
|
|
@@ -20,7 +24,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
20
24
|
require 'typhoeus/adapters/faraday'
|
21
25
|
|
22
26
|
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
|
23
|
-
:hosts => [ { :host
|
27
|
+
:hosts => [ { host: @host, port: @port } ] do |f|
|
24
28
|
f.response :logger
|
25
29
|
f.adapter :typhoeus
|
26
30
|
end
|
@@ -31,7 +35,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
31
35
|
|
32
36
|
should "allow to define connection parameters and pass them" do
|
33
37
|
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
|
34
|
-
:hosts => [ { :host
|
38
|
+
:hosts => [ { host: @host, port: @port } ],
|
35
39
|
:options => { :transport_options => {
|
36
40
|
:params => { :format => 'yaml' }
|
37
41
|
}
|
@@ -48,7 +52,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
48
52
|
require 'elasticsearch/transport/transport/http/curb'
|
49
53
|
|
50
54
|
transport = Elasticsearch::Transport::Transport::HTTP::Curb.new \
|
51
|
-
:hosts => [ { :host
|
55
|
+
:hosts => [ { host: @host, port: @port } ] do |curl|
|
52
56
|
curl.verbose = true
|
53
57
|
end
|
54
58
|
|
@@ -61,7 +65,7 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
61
65
|
require 'elasticsearch/transport/transport/http/curb'
|
62
66
|
|
63
67
|
transport = Elasticsearch::Transport::Transport::HTTP::Curb.new \
|
64
|
-
:hosts => [ { :host
|
68
|
+
:hosts => [ { host: @host, port: @port } ] do |curl|
|
65
69
|
curl.verbose = true
|
66
70
|
end
|
67
71
|
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V under one or more agreements.
|
2
|
+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
3
|
+
# See the LICENSE file in the project root for more information
|
4
|
+
|
1
5
|
require 'test_helper'
|
2
6
|
|
3
7
|
class Elasticsearch::Transport::ClientProfilingTest < Elasticsearch::Test::ProfilingTest
|
@@ -9,15 +13,15 @@ class Elasticsearch::Transport::ClientProfilingTest < Elasticsearch::Test::Profi
|
|
9
13
|
setup do
|
10
14
|
@port = (ENV['TEST_CLUSTER_PORT'] || 9250).to_i
|
11
15
|
client = Elasticsearch::Client.new host: "localhost:#{@port}", adapter: ::Faraday.default_adapter
|
12
|
-
client.perform_request 'DELETE', '
|
13
|
-
client.perform_request '
|
14
|
-
100.times do client.perform_request 'POST', '
|
15
|
-
client.perform_request 'POST', '
|
16
|
+
client.perform_request 'DELETE', 'ruby_test_benchmark' rescue nil
|
17
|
+
client.perform_request 'PUT', 'ruby_test_benchmark', {}, {settings: {index: {number_of_shards: 1, number_of_replicas: 0}}}
|
18
|
+
100.times do client.perform_request 'POST', 'ruby_test_benchmark_search/test', {}, {foo: 'bar'}; end
|
19
|
+
client.perform_request 'POST', 'ruby_test_benchmark_search/_refresh'
|
16
20
|
end
|
17
21
|
teardown do
|
18
22
|
client = Elasticsearch::Client.new host: "localhost:#{@port}"
|
19
|
-
client.perform_request 'DELETE', '
|
20
|
-
client.perform_request 'DELETE', '
|
23
|
+
client.perform_request 'DELETE', 'ruby_test_benchmark' rescue nil
|
24
|
+
client.perform_request 'DELETE', 'ruby_test_benchmark_search' rescue nil
|
21
25
|
end
|
22
26
|
|
23
27
|
context "with a single-node cluster and the default adapter" do
|
@@ -30,11 +34,11 @@ class Elasticsearch::Transport::ClientProfilingTest < Elasticsearch::Test::Profi
|
|
30
34
|
end
|
31
35
|
|
32
36
|
measure "index a document" do
|
33
|
-
@client.perform_request 'POST', '
|
37
|
+
@client.perform_request 'POST', 'ruby_test_benchmark/test', {}, {foo: 'bar'}
|
34
38
|
end
|
35
39
|
|
36
40
|
measure "search" do
|
37
|
-
@client.perform_request '
|
41
|
+
@client.perform_request 'GET', 'ruby_test_benchmark_search/test/_search', {}, {query: {match: {foo: 'bar'}}}
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
@@ -48,11 +52,11 @@ class Elasticsearch::Transport::ClientProfilingTest < Elasticsearch::Test::Profi
|
|
48
52
|
end
|
49
53
|
|
50
54
|
measure "index a document"do
|
51
|
-
@client.perform_request 'POST', '
|
55
|
+
@client.perform_request 'POST', 'ruby_test_benchmark/test', {}, {foo: 'bar'}
|
52
56
|
end
|
53
57
|
|
54
58
|
measure "search" do
|
55
|
-
@client.perform_request '
|
59
|
+
@client.perform_request 'GET', 'ruby_test_benchmark_search/test/_search', {}, {query: {match: {foo: 'bar'}}}
|
56
60
|
end
|
57
61
|
end
|
58
62
|
|
@@ -69,25 +73,19 @@ class Elasticsearch::Transport::ClientProfilingTest < Elasticsearch::Test::Profi
|
|
69
73
|
end
|
70
74
|
|
71
75
|
measure "index a document" do
|
72
|
-
@client.perform_request 'POST', '
|
76
|
+
@client.perform_request 'POST', 'ruby_test_benchmark/test', {}, {foo: 'bar'}
|
73
77
|
end
|
74
78
|
|
75
79
|
measure "search" do
|
76
|
-
@client.perform_request '
|
80
|
+
@client.perform_request 'GET', 'ruby_test_benchmark_search/test/_search', {}, {query: {match: {foo: 'bar'}}}
|
77
81
|
end
|
78
82
|
end
|
79
83
|
|
80
84
|
context "with a single-node cluster and the Typhoeus client" do
|
81
|
-
require 'typhoeus'
|
82
|
-
require 'typhoeus/adapters/faraday'
|
83
|
-
|
84
85
|
setup do
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
@client = Elasticsearch::Client.new transport: transport
|
86
|
+
require 'typhoeus'
|
87
|
+
require 'typhoeus/adapters/faraday'
|
88
|
+
@client = Elasticsearch::Client.new host: "localhost:#{@port}", adapter: :typhoeus
|
91
89
|
end
|
92
90
|
|
93
91
|
measure "get the cluster info", count: 1_000 do
|
@@ -95,11 +93,11 @@ class Elasticsearch::Transport::ClientProfilingTest < Elasticsearch::Test::Profi
|
|
95
93
|
end
|
96
94
|
|
97
95
|
measure "index a document" do
|
98
|
-
@client.perform_request 'POST', '
|
96
|
+
@client.perform_request 'POST', 'ruby_test_benchmark/test', {}, {foo: 'bar'}
|
99
97
|
end
|
100
98
|
|
101
99
|
measure "search" do
|
102
|
-
@client.perform_request '
|
100
|
+
@client.perform_request 'GET', 'ruby_test_benchmark_search/test/_search', {}, {query: {match: {foo: 'bar'}}}
|
103
101
|
end
|
104
102
|
end
|
105
103
|
|
@@ -114,11 +112,11 @@ class Elasticsearch::Transport::ClientProfilingTest < Elasticsearch::Test::Profi
|
|
114
112
|
end
|
115
113
|
|
116
114
|
measure "index a document" do
|
117
|
-
@client.perform_request 'POST', '
|
115
|
+
@client.perform_request 'POST', 'ruby_test_benchmark/test', {}, {foo: 'bar'}
|
118
116
|
end
|
119
117
|
|
120
118
|
measure "search" do
|
121
|
-
@client.perform_request '
|
119
|
+
@client.perform_request 'GET', 'ruby_test_benchmark_search/test/_search', {}, {query: {match: {foo: 'bar'}}}
|
122
120
|
end
|
123
121
|
end
|
124
122
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,16 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V under one or more agreements.
|
2
|
+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
3
|
+
# See the LICENSE file in the project root for more information
|
4
|
+
|
1
5
|
RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
|
2
6
|
JRUBY = defined?(JRUBY_VERSION)
|
3
7
|
|
8
|
+
ELASTICSEARCH_HOSTS = if hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOSTS']
|
9
|
+
hosts.split(',').map do |host|
|
10
|
+
/(http\:\/\/)?(\S+)/.match(host)[2]
|
11
|
+
end
|
12
|
+
end.freeze
|
13
|
+
|
4
14
|
if RUBY_1_8 and not ENV['BUNDLE_GEMFILE']
|
5
15
|
require 'rubygems'
|
6
16
|
gem 'test-unit'
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V under one or more agreements.
|
2
|
+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
3
|
+
# See the LICENSE file in the project root for more information
|
4
|
+
|
1
5
|
require 'test_helper'
|
2
6
|
|
3
7
|
class Elasticsearch::Transport::Transport::Connections::CollectionTest < Test::Unit::TestCase
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V under one or more agreements.
|
2
|
+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
3
|
+
# See the LICENSE file in the project root for more information
|
4
|
+
|
1
5
|
require 'test_helper'
|
2
6
|
|
3
7
|
class Elasticsearch::Transport::Transport::Connections::SelectorTest < Test::Unit::TestCase
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V under one or more agreements.
|
2
|
+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
3
|
+
# See the LICENSE file in the project root for more information
|
4
|
+
|
1
5
|
require 'test_helper'
|
2
6
|
|
3
7
|
class Elasticsearch::Transport::Transport::Connections::ConnectionTest < Test::Unit::TestCase
|
data/test/unit/response_test.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V under one or more agreements.
|
2
|
+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
3
|
+
# See the LICENSE file in the project root for more information
|
4
|
+
|
1
5
|
require 'test_helper'
|
2
6
|
|
3
7
|
class Elasticsearch::Transport::Transport::ResponseTest < Test::Unit::TestCase
|
@@ -12,4 +16,4 @@ class Elasticsearch::Transport::Transport::ResponseTest < Test::Unit::TestCase
|
|
12
16
|
end unless RUBY_1_8
|
13
17
|
|
14
18
|
end
|
15
|
-
end
|
19
|
+
end
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V under one or more agreements.
|
2
|
+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
3
|
+
# See the LICENSE file in the project root for more information
|
4
|
+
|
1
5
|
require 'test_helper'
|
2
6
|
|
3
7
|
class Elasticsearch::Transport::Transport::SerializerTest < Test::Unit::TestCase
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V under one or more agreements.
|
2
|
+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
3
|
+
# See the LICENSE file in the project root for more information
|
4
|
+
|
1
5
|
require 'test_helper'
|
2
6
|
|
3
7
|
class Elasticsearch::Transport::Transport::BaseTest < Test::Unit::TestCase
|
@@ -353,7 +357,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Test::Unit::TestCase
|
|
353
357
|
never
|
354
358
|
|
355
359
|
assert_raise Elasticsearch::Transport::Transport::Errors::BadRequest do
|
356
|
-
@transport.perform_request('GET', '/', &@block)
|
360
|
+
@transport.perform_request('GET', '/', {}, nil, &@block)
|
357
361
|
end
|
358
362
|
end
|
359
363
|
|
@@ -555,6 +559,22 @@ class Elasticsearch::Transport::Transport::BaseTest < Test::Unit::TestCase
|
|
555
559
|
assert_equal 1, @transport.connections.size
|
556
560
|
assert_equal 1, @transport.connections.all.size
|
557
561
|
end
|
562
|
+
|
563
|
+
should "not duplicate connections" do
|
564
|
+
@transport.__rebuild_connections :hosts => [ { :host => 'node1', :port => 1 },
|
565
|
+
{ :host => 'node2', :port => 2 } ],
|
566
|
+
:options => { :http => {} }
|
567
|
+
assert_equal 2, @transport.connections.size
|
568
|
+
|
569
|
+
@transport.connections[0].dead!
|
570
|
+
|
571
|
+
@transport.__rebuild_connections :hosts => [ { :host => 'node1', :port => 1 },
|
572
|
+
{ :host => 'node2', :port => 2 } ],
|
573
|
+
:options => { :http => {} }
|
574
|
+
|
575
|
+
assert_equal 2, @transport.connections.all.size
|
576
|
+
assert_equal 1, @transport.connections.size
|
577
|
+
end
|
558
578
|
end
|
559
579
|
|
560
580
|
context "rebuilding connections" do
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V under one or more agreements.
|
2
|
+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
3
|
+
# See the LICENSE file in the project root for more information
|
4
|
+
|
1
5
|
require 'test_helper'
|
2
6
|
|
3
7
|
if JRUBY
|
@@ -37,6 +41,14 @@ else
|
|
37
41
|
@transport.perform_request 'GET', '/', {}, '{"foo":"bar"}'
|
38
42
|
end
|
39
43
|
|
44
|
+
should "perform request with headers" do
|
45
|
+
@transport.connections.first.connection.expects(:put_data=).with('{"foo":"bar"}')
|
46
|
+
@transport.connections.first.connection.expects(:http).with(:POST).returns(stub_everything)
|
47
|
+
@transport.connections.first.connection.expects(:headers=).with({"Content-Type" => "application/x-ndjson"})
|
48
|
+
|
49
|
+
@transport.perform_request 'POST', '/', {}, {:foo => 'bar'}, {"Content-Type" => "application/x-ndjson"}
|
50
|
+
end
|
51
|
+
|
40
52
|
should "set body for PUT request" do
|
41
53
|
@transport.connections.first.connection.expects(:put_data=)
|
42
54
|
@transport.connections.first.connection.expects(:http).with(:PUT).returns(stub_everything)
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V under one or more agreements.
|
2
|
+
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
|
3
|
+
# See the LICENSE file in the project root for more information
|
4
|
+
|
1
5
|
require 'test_helper'
|
2
6
|
|
3
7
|
class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Test::Unit::TestCase
|
@@ -42,6 +46,18 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Test::Unit::TestC
|
|
42
46
|
@transport.perform_request 'POST', '/', {}, {:foo => 'bar'}
|
43
47
|
end
|
44
48
|
|
49
|
+
should "properly prepare the request with custom headers" do
|
50
|
+
@transport.connections.first.connection.expects(:run_request).with do |method, url, body, headers|
|
51
|
+
assert_equal :post, method
|
52
|
+
assert_equal '{"foo":"bar"}', body
|
53
|
+
assert_nil headers['Accept']
|
54
|
+
assert_equal "application/x-ndjson", headers['Content-Type']
|
55
|
+
true
|
56
|
+
end.returns(stub_everything)
|
57
|
+
|
58
|
+
@transport.perform_request 'POST', '/', {}, {:foo => 'bar'}, {"Content-Type" => "application/x-ndjson"}
|
59
|
+
end
|
60
|
+
|
45
61
|
should "properly pass the Content-Type header option" do
|
46
62
|
transport = Faraday.new :hosts => [ { :host => 'foobar', :port => 1234 } ], :options => { :transport_options => { :headers => { 'Content-Type' => 'foo/bar' } } }
|
47
63
|
|