elasticsearch-transport 7.4.0 → 7.17.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +30 -13
- data/Gemfile-faraday1.gemfile +47 -0
- data/README.md +159 -64
- data/Rakefile +63 -13
- data/elasticsearch-transport.gemspec +55 -63
- data/lib/elasticsearch/transport/client.rb +184 -59
- data/lib/elasticsearch/transport/meta_header.rb +135 -0
- data/lib/elasticsearch/transport/redacted.rb +16 -3
- data/lib/elasticsearch/transport/transport/base.rb +69 -30
- data/lib/elasticsearch/transport/transport/connections/collection.rb +18 -8
- data/lib/elasticsearch/transport/transport/connections/connection.rb +25 -9
- data/lib/elasticsearch/transport/transport/connections/selector.rb +16 -3
- data/lib/elasticsearch/transport/transport/errors.rb +17 -3
- data/lib/elasticsearch/transport/transport/http/curb.rb +60 -35
- data/lib/elasticsearch/transport/transport/http/faraday.rb +32 -9
- data/lib/elasticsearch/transport/transport/http/manticore.rb +57 -32
- data/lib/elasticsearch/transport/transport/loggable.rb +16 -3
- data/lib/elasticsearch/transport/transport/response.rb +17 -5
- 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 +35 -33
- 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 +107 -49
- data/spec/elasticsearch/transport/client_spec.rb +734 -164
- data/spec/elasticsearch/transport/http/curb_spec.rb +126 -0
- data/spec/elasticsearch/transport/http/faraday_spec.rb +141 -0
- data/spec/elasticsearch/transport/http/manticore_spec.rb +161 -0
- data/spec/elasticsearch/transport/meta_header_spec.rb +301 -0
- data/spec/elasticsearch/transport/sniffer_spec.rb +16 -16
- data/spec/spec_helper.rb +32 -6
- data/test/integration/jruby_test.rb +43 -0
- data/test/integration/transport_test.rb +109 -46
- data/test/profile/client_benchmark_test.rb +16 -3
- data/test/test_helper.rb +26 -25
- data/test/unit/adapters_test.rb +88 -0
- data/test/unit/connection_test.rb +23 -5
- data/test/unit/response_test.rb +18 -5
- data/test/unit/serializer_test.rb +16 -3
- data/test/unit/transport_base_test.rb +33 -11
- data/test/unit/transport_curb_test.rb +16 -4
- data/test/unit/transport_faraday_test.rb +18 -5
- data/test/unit/transport_manticore_test.rb +258 -158
- metadata +64 -76
@@ -1,10 +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 'test_helper'
|
6
19
|
|
7
|
-
class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::IntegrationTestCase
|
20
|
+
class Elasticsearch::Transport::Transport::ClientIntegrationTest < Elasticsearch::Test::IntegrationTestCase
|
8
21
|
startup do
|
9
22
|
Elasticsearch::Extensions::Test::Cluster.start(number_of_nodes: 2) if ENV['SERVER'] and not Elasticsearch::Extensions::Test::Cluster.running?(number_of_nodes: 2)
|
10
23
|
end
|
@@ -16,66 +29,116 @@ class Elasticsearch::Transport::ClientIntegrationTest < Elasticsearch::Test::Int
|
|
16
29
|
context "Transport" do
|
17
30
|
setup do
|
18
31
|
@host, @port = ELASTICSEARCH_HOSTS.first.split(':')
|
19
|
-
|
32
|
+
@hosts = { hosts: [ { host: @host, port: @port } ] }
|
20
33
|
end
|
21
34
|
|
22
|
-
should "
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new \
|
27
|
-
:hosts => [ { host: @host, port: @port } ] do |f|
|
28
|
-
f.response :logger
|
29
|
-
f.adapter :typhoeus
|
30
|
-
end
|
35
|
+
should "use the default Faraday adapter" do
|
36
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
|
37
|
+
f.response :logger
|
38
|
+
end
|
31
39
|
|
32
40
|
client = Elasticsearch::Transport::Client.new transport: transport
|
41
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttp)
|
33
42
|
client.perform_request 'GET', ''
|
34
43
|
end
|
35
44
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
unless jruby?
|
46
|
+
should "allow to customize the Faraday adapter to Typhoeus" do
|
47
|
+
if is_faraday_v2?
|
48
|
+
require 'faraday/typhoeus'
|
49
|
+
else
|
50
|
+
require 'typhoeus'
|
51
|
+
end
|
43
52
|
|
44
|
-
|
45
|
-
|
53
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
|
54
|
+
f.response :logger
|
55
|
+
f.adapter :typhoeus
|
56
|
+
end
|
46
57
|
|
47
|
-
|
48
|
-
|
58
|
+
client = Elasticsearch::Transport::Client.new transport: transport
|
59
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Typhoeus)
|
60
|
+
client.perform_request 'GET', ''
|
61
|
+
end
|
49
62
|
|
50
|
-
|
51
|
-
|
52
|
-
|
63
|
+
should "use the Curb client" do
|
64
|
+
require 'curb'
|
65
|
+
require 'elasticsearch/transport/transport/http/curb'
|
66
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Curb.new(@hosts) do |curl|
|
67
|
+
curl.verbose = true
|
68
|
+
end
|
53
69
|
|
54
|
-
|
55
|
-
|
70
|
+
client = Elasticsearch::Transport::Client.new transport: transport
|
71
|
+
assert_equal(client.transport.class, Elasticsearch::Transport::Transport::HTTP::Curb)
|
72
|
+
client.perform_request 'GET', ''
|
73
|
+
end
|
74
|
+
|
75
|
+
should "deserialize JSON responses in the Curb client" do
|
76
|
+
require 'curb'
|
77
|
+
require 'elasticsearch/transport/transport/http/curb'
|
78
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Curb.new(@hosts) do |curl|
|
56
79
|
curl.verbose = true
|
57
80
|
end
|
58
81
|
|
59
|
-
|
60
|
-
|
61
|
-
end unless JRUBY
|
82
|
+
client = Elasticsearch::Transport::Client.new transport: transport
|
83
|
+
response = client.perform_request 'GET', ''
|
62
84
|
|
63
|
-
|
64
|
-
|
65
|
-
|
85
|
+
assert_respond_to(response.body, :to_hash)
|
86
|
+
assert_not_nil response.body['name']
|
87
|
+
assert_equal 'application/json', response.headers['content-type']
|
88
|
+
end
|
66
89
|
|
67
|
-
|
68
|
-
|
69
|
-
|
90
|
+
should 'allow to customize the Faraday adapter to Patron' do
|
91
|
+
if is_faraday_v2?
|
92
|
+
require 'faraday/patron'
|
93
|
+
else
|
94
|
+
require 'patron'
|
95
|
+
end
|
96
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
|
97
|
+
f.response :logger
|
98
|
+
f.adapter :patron
|
70
99
|
end
|
71
100
|
|
72
|
-
|
73
|
-
|
101
|
+
client = Elasticsearch::Transport::Client.new(transport: transport)
|
102
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Patron)
|
103
|
+
client.perform_request 'GET', ''
|
104
|
+
end
|
74
105
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
106
|
+
should "allow to customize the Faraday adapter to NetHttpPersistent" do
|
107
|
+
require 'faraday/net_http_persistent'
|
108
|
+
|
109
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
|
110
|
+
f.response :logger
|
111
|
+
f.adapter :net_http_persistent
|
112
|
+
end
|
80
113
|
|
114
|
+
client = Elasticsearch::Transport::Client.new transport: transport
|
115
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttpPersistent)
|
116
|
+
client.perform_request 'GET', ''
|
117
|
+
end
|
118
|
+
|
119
|
+
should 'allow to customize the Faraday adapter to HTTPClient' do
|
120
|
+
require 'faraday/httpclient'
|
121
|
+
|
122
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(@hosts) do |f|
|
123
|
+
f.response :logger
|
124
|
+
f.adapter :httpclient
|
125
|
+
end
|
126
|
+
|
127
|
+
client = Elasticsearch::Transport::Client.new(transport: transport)
|
128
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::HTTPClient)
|
129
|
+
client.perform_request 'GET', ''
|
130
|
+
end
|
131
|
+
|
132
|
+
should "allow to define connection parameters and pass them" do
|
133
|
+
transport = Elasticsearch::Transport::Transport::HTTP::Faraday.new(
|
134
|
+
hosts: [ { host: @host, port: @port } ],
|
135
|
+
options: { transport_options: { params: { :format => 'yaml' } } }
|
136
|
+
)
|
137
|
+
client = Elasticsearch::Transport::Client.new transport: transport
|
138
|
+
response = client.perform_request 'GET', ''
|
139
|
+
|
140
|
+
assert response.body.start_with?("---\n"), "Response body should be YAML: #{response.body.inspect}"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
81
144
|
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,36 +1,36 @@
|
|
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']
|
7
20
|
hosts.split(',').map do |host|
|
8
21
|
/(http\:\/\/)?(\S+)/.match(host)[2]
|
9
22
|
end
|
23
|
+
else
|
24
|
+
['localhost:9200']
|
10
25
|
end.freeze
|
11
26
|
|
12
27
|
TEST_HOST, TEST_PORT = ELASTICSEARCH_HOSTS.first.split(':') if ELASTICSEARCH_HOSTS
|
13
28
|
|
14
|
-
RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9'
|
15
29
|
JRUBY = defined?(JRUBY_VERSION)
|
16
30
|
|
17
|
-
if
|
18
|
-
require 'rubygems'
|
19
|
-
gem 'test-unit'
|
20
|
-
end
|
21
|
-
|
22
|
-
require 'rubygems' if RUBY_1_8
|
23
|
-
|
24
|
-
if ENV['COVERAGE'] && ENV['CI'].nil? && !RUBY_1_8
|
31
|
+
if ENV['COVERAGE']
|
25
32
|
require 'simplecov'
|
26
|
-
SimpleCov.start { add_filter
|
27
|
-
end
|
28
|
-
|
29
|
-
if ENV['CI'] && !RUBY_1_8
|
30
|
-
require 'simplecov'
|
31
|
-
require 'simplecov-rcov'
|
32
|
-
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
33
|
-
SimpleCov.start { add_filter "/test|test_" }
|
33
|
+
SimpleCov.start { add_filter %r{^/test/} }
|
34
34
|
end
|
35
35
|
|
36
36
|
# Register `at_exit` handler for integration tests shutdown.
|
@@ -39,7 +39,6 @@ if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
|
|
39
39
|
at_exit { Elasticsearch::Test::IntegrationTestCase.__run_at_exit_hooks }
|
40
40
|
end
|
41
41
|
|
42
|
-
require 'test/unit' if RUBY_1_8
|
43
42
|
require 'minitest/autorun'
|
44
43
|
require 'minitest/reporters'
|
45
44
|
require 'shoulda/context'
|
@@ -98,6 +97,10 @@ module Minitest
|
|
98
97
|
end
|
99
98
|
end
|
100
99
|
|
100
|
+
def is_faraday_v2?
|
101
|
+
Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
|
102
|
+
end
|
103
|
+
|
101
104
|
Minitest::Reporters.use! FixedMinitestSpecReporter.new
|
102
105
|
|
103
106
|
module Elasticsearch
|
@@ -106,8 +109,7 @@ module Elasticsearch
|
|
106
109
|
extend Elasticsearch::Extensions::Test::StartupShutdown
|
107
110
|
|
108
111
|
shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? && Elasticsearch::Extensions::Test::Cluster.running? }
|
109
|
-
|
110
|
-
end if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
|
112
|
+
end
|
111
113
|
end
|
112
114
|
|
113
115
|
module Test
|
@@ -116,7 +118,6 @@ module Elasticsearch
|
|
116
118
|
extend Elasticsearch::Extensions::Test::Profiling
|
117
119
|
|
118
120
|
shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? && Elasticsearch::Extensions::Test::Cluster.running? }
|
119
|
-
|
120
|
-
end unless RUBY_1_8 || JRUBY
|
121
|
+
end unless JRUBY
|
121
122
|
end
|
122
123
|
end
|
@@ -0,0 +1,88 @@
|
|
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 'test_helper'
|
19
|
+
|
20
|
+
class Elasticsearch::Transport::Transport::ClientAdaptersUnitTest < Minitest::Test
|
21
|
+
context 'Adapters' do
|
22
|
+
setup do
|
23
|
+
begin
|
24
|
+
Object.send(:remove_const, :Patron)
|
25
|
+
rescue NameError
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
should 'use the default Faraday adapter' do
|
30
|
+
fork do
|
31
|
+
client = Elasticsearch::Transport::Client.new
|
32
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttp)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
should 'use Patron Faraday adapter' do
|
37
|
+
fork do
|
38
|
+
if is_faraday_v2?
|
39
|
+
require 'faraday/patron'
|
40
|
+
else
|
41
|
+
require 'patron'
|
42
|
+
end
|
43
|
+
|
44
|
+
client = Elasticsearch::Transport::Client.new
|
45
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Patron)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
should 'use Typhoeus Faraday adapter' do
|
50
|
+
fork do
|
51
|
+
if is_faraday_v2?
|
52
|
+
require 'faraday/typhoeus'
|
53
|
+
else
|
54
|
+
require 'typhoeus'
|
55
|
+
end
|
56
|
+
|
57
|
+
client = Elasticsearch::Transport::Client.new
|
58
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Typhoeus)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
should 'use NetHttpPersistent Faraday adapter' do
|
63
|
+
fork do
|
64
|
+
if is_faraday_v2?
|
65
|
+
require 'faraday/net_http_persistent'
|
66
|
+
else
|
67
|
+
require 'net/http/persistent'
|
68
|
+
end
|
69
|
+
|
70
|
+
client = Elasticsearch::Transport::Client.new
|
71
|
+
assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttpPersistent)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
should 'use HTTPClient Faraday adapter' do
|
76
|
+
fork do
|
77
|
+
if is_faraday_v2?
|
78
|
+
require 'faraday/httpclient'
|
79
|
+
else
|
80
|
+
require 'httpclient'
|
81
|
+
end
|
82
|
+
|
83
|
+
client = Elasticsearch::Transport::Client.new
|
84
|
+
assert_equal(Faraday::Adapter::HTTPClient, client.transport.connections.first.connection.adapter)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end unless jruby?
|
88
|
+
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
|
|
@@ -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
|
|
@@ -13,7 +26,7 @@ class Elasticsearch::Transport::Transport::ResponseTest < Minitest::Test
|
|
13
26
|
|
14
27
|
response = Elasticsearch::Transport::Transport::Response.new 200, body
|
15
28
|
assert_equal 'UTF-8', response.body.encoding.name
|
16
|
-
end
|
29
|
+
end
|
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
|
|
@@ -250,6 +263,15 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
250
263
|
end
|
251
264
|
end
|
252
265
|
|
266
|
+
should 'raise TooManyRequestsError on 429' do
|
267
|
+
@transport.expects(:get_connection).returns(stub_everything :failures => 1)
|
268
|
+
assert_raise Elasticsearch::Transport::Transport::Errors::TooManyRequests do
|
269
|
+
@transport.perform_request 'GET', '/' do
|
270
|
+
Elasticsearch::Transport::Transport::Response.new 429, 'ERROR'
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
253
275
|
should "not raise an error when the :ignore argument has been passed" do
|
254
276
|
@transport.stubs(:get_connection).returns(stub_everything :failures => 1)
|
255
277
|
|
@@ -297,7 +319,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
297
319
|
@transport.perform_request('GET', '/', &@block)
|
298
320
|
assert_equal 2, @transport.counter
|
299
321
|
end
|
300
|
-
end
|
322
|
+
end
|
301
323
|
|
302
324
|
context "performing a request with retry on connection failures" do
|
303
325
|
setup do
|
@@ -331,7 +353,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
331
353
|
@transport.perform_request('GET', '/', &@block)
|
332
354
|
end
|
333
355
|
end
|
334
|
-
end
|
356
|
+
end
|
335
357
|
|
336
358
|
context "performing a request with retry on status" do
|
337
359
|
setup do
|
@@ -378,7 +400,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
378
400
|
@transport.perform_request('GET', '/', &@block)
|
379
401
|
end
|
380
402
|
end
|
381
|
-
end
|
403
|
+
end
|
382
404
|
|
383
405
|
context "logging" do
|
384
406
|
setup do
|
@@ -416,7 +438,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
416
438
|
@transport.stubs(:get_connection).returns(fake_connection)
|
417
439
|
|
418
440
|
@transport.logger.expects(:info).with do |message|
|
419
|
-
assert_match
|
441
|
+
assert_match(/http:\/\/user:\*{1,15}@localhost\:9200/, message)
|
420
442
|
true
|
421
443
|
end
|
422
444
|
|
@@ -434,7 +456,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
434
456
|
assert_raise Elasticsearch::Transport::Transport::Errors::InternalServerError do
|
435
457
|
@transport.perform_request('POST', '_search', &@block)
|
436
458
|
end
|
437
|
-
end
|
459
|
+
end
|
438
460
|
|
439
461
|
should "not log a failed Elasticsearch request as fatal" do
|
440
462
|
@block = Proc.new { |c, u| puts "ERROR" }
|
@@ -445,7 +467,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
445
467
|
|
446
468
|
# No `BadRequest` error
|
447
469
|
@transport.perform_request('POST', '_search', :ignore => 500, &@block)
|
448
|
-
end
|
470
|
+
end
|
449
471
|
|
450
472
|
should "log and re-raise a Ruby exception" do
|
451
473
|
@block = Proc.new { |c, u| puts "ERROR" }
|
@@ -455,7 +477,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
455
477
|
@transport.logger.expects(:fatal)
|
456
478
|
|
457
479
|
assert_raise(Exception) { @transport.perform_request('POST', '_search', &@block) }
|
458
|
-
end
|
480
|
+
end
|
459
481
|
end
|
460
482
|
|
461
483
|
context "tracing" do
|
@@ -509,7 +531,7 @@ class Elasticsearch::Transport::Transport::BaseTest < Minitest::Test
|
|
509
531
|
assert_raise Elasticsearch::Transport::Transport::Errors::InternalServerError do
|
510
532
|
@transport.perform_request('POST', '_search', &@block)
|
511
533
|
end
|
512
|
-
end
|
534
|
+
end
|
513
535
|
|
514
536
|
end
|
515
537
|
|
@@ -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
|
|
@@ -71,7 +84,6 @@ else
|
|
71
84
|
@transport.connections.first.connection.expects(:http).with(:GET).returns(stub_everything)
|
72
85
|
@transport.connections.first.connection.expects(:body_str).returns('{"foo":"bar"}')
|
73
86
|
@transport.connections.first.connection.expects(:header_str).returns('HTTP/1.1 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\nContent-Length: 311\r\n\r\n')
|
74
|
-
|
75
87
|
response = @transport.perform_request 'GET', '/'
|
76
88
|
|
77
89
|
assert_equal 'application/json', response.headers['content-type']
|