elasticsearch-transport 7.5.0 → 7.17.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +26 -13
  3. data/README.md +159 -64
  4. data/Rakefile +25 -13
  5. data/elasticsearch-transport.gemspec +57 -63
  6. data/lib/elasticsearch/transport/client.rb +183 -58
  7. data/lib/elasticsearch/transport/meta_header.rb +135 -0
  8. data/lib/elasticsearch/transport/redacted.rb +16 -3
  9. data/lib/elasticsearch/transport/transport/base.rb +69 -30
  10. data/lib/elasticsearch/transport/transport/connections/collection.rb +18 -8
  11. data/lib/elasticsearch/transport/transport/connections/connection.rb +25 -9
  12. data/lib/elasticsearch/transport/transport/connections/selector.rb +16 -3
  13. data/lib/elasticsearch/transport/transport/errors.rb +17 -3
  14. data/lib/elasticsearch/transport/transport/http/curb.rb +60 -35
  15. data/lib/elasticsearch/transport/transport/http/faraday.rb +32 -9
  16. data/lib/elasticsearch/transport/transport/http/manticore.rb +51 -31
  17. data/lib/elasticsearch/transport/transport/loggable.rb +16 -3
  18. data/lib/elasticsearch/transport/transport/response.rb +16 -4
  19. data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +16 -3
  20. data/lib/elasticsearch/transport/transport/sniffer.rb +35 -15
  21. data/lib/elasticsearch/transport/version.rb +17 -4
  22. data/lib/elasticsearch/transport.rb +35 -33
  23. data/lib/elasticsearch-transport.rb +16 -3
  24. data/spec/elasticsearch/connections/collection_spec.rb +28 -3
  25. data/spec/elasticsearch/connections/selector_spec.rb +16 -3
  26. data/spec/elasticsearch/transport/base_spec.rb +104 -43
  27. data/spec/elasticsearch/transport/client_spec.rb +727 -163
  28. data/spec/elasticsearch/transport/http/curb_spec.rb +126 -0
  29. data/spec/elasticsearch/transport/http/faraday_spec.rb +141 -0
  30. data/spec/elasticsearch/transport/http/manticore_spec.rb +143 -0
  31. data/spec/elasticsearch/transport/meta_header_spec.rb +301 -0
  32. data/spec/elasticsearch/transport/sniffer_spec.rb +16 -16
  33. data/spec/spec_helper.rb +28 -6
  34. data/test/integration/jruby_test.rb +43 -0
  35. data/test/integration/transport_test.rb +46 -29
  36. data/test/profile/client_benchmark_test.rb +16 -3
  37. data/test/test_helper.rb +22 -25
  38. data/test/unit/connection_test.rb +23 -5
  39. data/test/unit/response_test.rb +18 -5
  40. data/test/unit/serializer_test.rb +16 -3
  41. data/test/unit/transport_base_test.rb +33 -11
  42. data/test/unit/transport_curb_test.rb +16 -4
  43. data/test/unit/transport_faraday_test.rb +18 -5
  44. data/test/unit/transport_manticore_test.rb +258 -158
  45. metadata +80 -71
data/test/test_helper.rb CHANGED
@@ -1,36 +1,36 @@
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
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 RUBY_1_8 and not ENV['BUNDLE_GEMFILE']
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 "/test|test_/" }
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'
@@ -106,8 +105,7 @@ module Elasticsearch
106
105
  extend Elasticsearch::Extensions::Test::StartupShutdown
107
106
 
108
107
  shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? && Elasticsearch::Extensions::Test::Cluster.running? }
109
- context "IntegrationTest" do; should "noop on Ruby 1.8" do; end; end if RUBY_1_8
110
- end if defined?(RUBY_VERSION) && RUBY_VERSION > '1.9'
108
+ end
111
109
  end
112
110
 
113
111
  module Test
@@ -116,7 +114,6 @@ module Elasticsearch
116
114
  extend Elasticsearch::Extensions::Test::Profiling
117
115
 
118
116
  shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? && Elasticsearch::Extensions::Test::Cluster.running? }
119
- context "IntegrationTest" do; should "noop on Ruby 1.8" do; end; end if RUBY_1_8
120
- end unless RUBY_1_8 || JRUBY
117
+ end unless JRUBY
121
118
  end
122
119
  end
@@ -1,6 +1,19 @@
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
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 /host: x/, c.to_s
50
- assert_match /alive/, c.to_s
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
@@ -1,6 +1,19 @@
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
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 unless RUBY_1_8
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 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
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 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
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 unless RUBY_1_8
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 unless RUBY_1_8
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 unless RUBY_1_8
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 /http:\/\/user:\*{1,15}@localhost\:9200/, message
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 unless RUBY_1_8
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 unless RUBY_1_8
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 unless RUBY_1_8
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 unless RUBY_1_8
534
+ end
513
535
 
514
536
  end
515
537
 
@@ -1,6 +1,19 @@
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
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']
@@ -1,6 +1,19 @@
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
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
 
@@ -136,7 +149,7 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Minitest::Test
136
149
 
137
150
  transport.connections.first.connection.expects(:run_request).
138
151
  with do |method, url, params, body|
139
- assert_match /\?format=yaml/, url
152
+ assert_match(/\?format=yaml/, url)
140
153
  true
141
154
  end.
142
155
  returns(stub_everything)
@@ -154,7 +167,7 @@ class Elasticsearch::Transport::Transport::HTTP::FaradayTest < Minitest::Test
154
167
 
155
168
  transport.connections.first.connection.expects(:run_request).
156
169
  with do |method, url, params, body|
157
- assert_match /\?format=json/, url
170
+ assert_match(/\?format=json/, url)
158
171
  true
159
172
  end.
160
173
  returns(stub_everything)