elasticsearch-transport 7.1.0 → 7.8.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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +12 -8
  3. data/{LICENSE.txt → LICENSE} +0 -0
  4. data/README.md +160 -72
  5. data/Rakefile +1 -1
  6. data/elasticsearch-transport.gemspec +42 -60
  7. data/lib/elasticsearch/transport/client.rb +70 -19
  8. data/lib/elasticsearch/transport/redacted.rb +1 -1
  9. data/lib/elasticsearch/transport/transport/base.rb +86 -12
  10. data/lib/elasticsearch/transport/transport/connections/collection.rb +1 -1
  11. data/lib/elasticsearch/transport/transport/connections/connection.rb +1 -1
  12. data/lib/elasticsearch/transport/transport/connections/selector.rb +18 -6
  13. data/lib/elasticsearch/transport/transport/errors.rb +1 -1
  14. data/lib/elasticsearch/transport/transport/http/curb.rb +26 -9
  15. data/lib/elasticsearch/transport/transport/http/faraday.rb +18 -4
  16. data/lib/elasticsearch/transport/transport/http/manticore.rb +25 -10
  17. data/lib/elasticsearch/transport/transport/loggable.rb +1 -1
  18. data/lib/elasticsearch/transport/transport/response.rb +1 -2
  19. data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +1 -1
  20. data/lib/elasticsearch/transport/transport/sniffer.rb +3 -2
  21. data/lib/elasticsearch/transport/version.rb +2 -2
  22. data/lib/elasticsearch/transport.rb +1 -1
  23. data/lib/elasticsearch-transport.rb +1 -1
  24. data/spec/elasticsearch/connections/collection_spec.rb +254 -0
  25. data/spec/elasticsearch/connections/selector_spec.rb +174 -0
  26. data/spec/elasticsearch/transport/base_spec.rb +177 -9
  27. data/spec/elasticsearch/transport/client_spec.rb +525 -29
  28. data/spec/elasticsearch/transport/sniffer_spec.rb +1 -1
  29. data/spec/spec_helper.rb +25 -1
  30. data/test/integration/transport_test.rb +1 -1
  31. data/test/profile/client_benchmark_test.rb +1 -1
  32. data/test/test_helper.rb +1 -1
  33. data/test/unit/connection_test.rb +1 -1
  34. data/test/unit/response_test.rb +2 -2
  35. data/test/unit/serializer_test.rb +1 -1
  36. data/test/unit/transport_base_test.rb +1 -1
  37. data/test/unit/transport_curb_test.rb +2 -2
  38. data/test/unit/transport_faraday_test.rb +1 -1
  39. data/test/unit/transport_manticore_test.rb +28 -12
  40. metadata +85 -61
  41. data/test/unit/connection_collection_test.rb +0 -147
  42. data/test/unit/connection_selector_test.rb +0 -81
@@ -1,147 +0,0 @@
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::Connections::CollectionTest < Minitest::Test
21
- include Elasticsearch::Transport::Transport::Connections
22
-
23
- context "Connection collection" do
24
-
25
- should "have empty array as default connections array" do
26
- assert_equal [], Collection.new.connections
27
- end
28
-
29
- should "have default selector class" do
30
- assert_not_nil Collection.new.selector
31
- end
32
-
33
- should "initialize a custom selector class" do
34
- c = Collection.new :selector_class => Selector::Random
35
- assert_instance_of Selector::Random, c.selector
36
- end
37
-
38
- should "take a custom selector instance" do
39
- c = Collection.new :selector => Selector::Random.new
40
- assert_instance_of Selector::Random, c.selector
41
- end
42
-
43
- should "get connection from selector" do
44
- c = Collection.new
45
- c.selector.expects(:select).returns('OK')
46
- assert_equal 'OK', c.get_connection
47
- end
48
-
49
- should "return an array of hosts" do
50
- c = Collection.new :connections => [ Connection.new(:host => 'foo'), Connection.new(:host => 'bar') ]
51
- assert_equal ['foo', 'bar'], c.hosts
52
- end
53
-
54
- should "be enumerable" do
55
- c = Collection.new :connections => [ Connection.new(:host => 'foo'), Connection.new(:host => 'bar') ]
56
-
57
- assert_equal ['FOO', 'BAR'], c.map { |i| i.host.upcase }
58
- assert_equal 'foo', c[0].host
59
- assert_equal 'bar', c[1].host
60
- assert_equal 2, c.size
61
- end
62
-
63
- should "add connections" do
64
- c = Collection.new :connections => [ Connection.new(:host => { :protocol => 'http', :host => 'foo', :port => 1}) ]
65
- assert_equal 1, c.size
66
-
67
- c.add([ Connection.new(:host => { :protocol => 'http', :host => 'bar', :port => 1 }),
68
- Connection.new(:host => { :protocol => 'http', :host => 'bam', :port => 1 }) ])
69
- assert_equal 3, c.size
70
- end
71
-
72
- should "add connection" do
73
- c = Collection.new :connections => [ Connection.new(:host => { :protocol => 'http', :host => 'foo', :port => 1}) ]
74
- assert_equal 1, c.size
75
-
76
- c.add(Connection.new(:host => { :protocol => 'http', :host => 'bar', :port => 1 }))
77
- assert_equal 2, c.size
78
- end
79
-
80
- should "remove connections" do
81
- c = Collection.new :connections => [
82
- Connection.new(:host => { :protocol => 'http', :host => 'foo', :port => 1 }),
83
- Connection.new(:host => { :protocol => 'http', :host => 'bar', :port => 1 })
84
- ]
85
- assert_equal 2, c.size
86
-
87
- c.remove([c.first])
88
- assert_equal 1, c.size
89
-
90
- c.remove(c)
91
- assert_equal 0, c.size
92
- end
93
-
94
- should "remove connection" do
95
- c = Collection.new :connections => [
96
- Connection.new(:host => { :protocol => 'http', :host => 'foo', :port => 1 }),
97
- Connection.new(:host => { :protocol => 'http', :host => 'bar', :port => 1 })
98
- ]
99
- assert_equal 2, c.size
100
-
101
- c.remove(c.first)
102
- assert_equal 1, c.size
103
- end
104
-
105
- context "with the dead pool" do
106
- setup do
107
- @collection = Collection.new :connections => [ Connection.new(:host => 'foo'), Connection.new(:host => 'bar') ]
108
- @collection[1].dead!
109
- end
110
-
111
- should "not iterate over dead connections" do
112
- assert_equal 1, @collection.size
113
- assert_equal ['FOO'], @collection.map { |c| c.host.upcase }
114
- assert_equal @collection.connections, @collection.alive
115
- end
116
-
117
- should "have dead connections collection" do
118
- assert_equal 1, @collection.dead.size
119
- assert_equal ['BAR'], @collection.dead.map { |c| c.host.upcase }
120
- end
121
-
122
- should "not return dead connections, when alive connections exist" do
123
- assert_equal 1, @collection.size
124
- @collection.all.size.times { refute @collection.get_connection.dead? }
125
- end
126
-
127
- should "resurrect dead connection with least failures when no alive is available" do
128
- c1 = Connection.new(:host => { :protocol => 'http', :host => 'foo', :port => 123 }).dead!.dead!
129
- c2 = Connection.new(:host => { :protocol => 'http', :host => 'bar', :port => 123 }).dead!
130
-
131
- @collection = Collection.new :connections => [ c1, c2 ]
132
-
133
- assert_equal 0, @collection.size
134
- assert_not_nil @collection.get_connection
135
- assert_equal 1, @collection.size
136
- assert_equal c2, @collection.first
137
- end
138
-
139
- should "return all connections" do
140
- assert_equal 2, @collection.all.size
141
- end
142
-
143
- end
144
-
145
- end
146
-
147
- end
@@ -1,81 +0,0 @@
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::Connections::SelectorTest < Minitest::Test
21
- include Elasticsearch::Transport::Transport::Connections::Selector
22
-
23
- class DummyStrategySelector
24
- include Elasticsearch::Transport::Transport::Connections::Selector::Base
25
- end
26
-
27
- class BackupStrategySelector
28
- include Elasticsearch::Transport::Transport::Connections::Selector::Base
29
-
30
- def select(options={})
31
- connections.reject do |c|
32
- c.host[:attributes] && c.host[:attributes][:backup]
33
- end.send( defined?(RUBY_VERSION) && RUBY_VERSION > '1.9' ? :sample : :choice)
34
- end
35
- end
36
-
37
- context "Connection selector" do
38
-
39
- should "be initialized with connections" do
40
- assert_equal [1, 2], Random.new(:connections => [1, 2]).connections
41
- end
42
-
43
- should "have the abstract select method" do
44
- assert_raise(NoMethodError) { DummyStrategySelector.new.select }
45
- end
46
-
47
- context "in random strategy" do
48
- setup do
49
- @selector = Random.new :connections => ['A', 'B', 'C']
50
- end
51
-
52
- should "pick a connection" do
53
- assert_not_nil @selector.select
54
- end
55
- end
56
-
57
- context "in round-robin strategy" do
58
- setup do
59
- @selector = RoundRobin.new :connections => ['A', 'B', 'C']
60
- end
61
-
62
- should "rotate over connections" do
63
- assert_equal 'A', @selector.select
64
- assert_equal 'B', @selector.select
65
- assert_equal 'C', @selector.select
66
- assert_equal 'A', @selector.select
67
- end
68
- end
69
-
70
- context "with a custom strategy" do
71
-
72
- should "return proper connection" do
73
- selector = BackupStrategySelector.new :connections => [ stub(:host => { :hostname => 'host1' }),
74
- stub(:host => { :hostname => 'host2', :attributes => { :backup => true }}) ]
75
- 10.times { assert_equal 'host1', selector.select.host[:hostname] }
76
- end
77
-
78
- end
79
-
80
- end
81
- end