elasticsearch-transport 6.8.1 → 6.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +86 -32
  3. data/elasticsearch-transport.gemspec +44 -64
  4. data/lib/elasticsearch-transport.rb +4 -0
  5. data/lib/elasticsearch/transport.rb +4 -0
  6. data/lib/elasticsearch/transport/client.rb +51 -11
  7. data/lib/elasticsearch/transport/redacted.rb +4 -0
  8. data/lib/elasticsearch/transport/transport/base.rb +17 -7
  9. data/lib/elasticsearch/transport/transport/connections/collection.rb +4 -0
  10. data/lib/elasticsearch/transport/transport/connections/connection.rb +4 -0
  11. data/lib/elasticsearch/transport/transport/connections/selector.rb +4 -0
  12. data/lib/elasticsearch/transport/transport/errors.rb +4 -0
  13. data/lib/elasticsearch/transport/transport/http/curb.rb +6 -2
  14. data/lib/elasticsearch/transport/transport/http/faraday.rb +6 -2
  15. data/lib/elasticsearch/transport/transport/http/manticore.rb +5 -1
  16. data/lib/elasticsearch/transport/transport/response.rb +4 -0
  17. data/lib/elasticsearch/transport/transport/serializer/multi_json.rb +4 -0
  18. data/lib/elasticsearch/transport/transport/sniffer.rb +31 -3
  19. data/lib/elasticsearch/transport/version.rb +5 -1
  20. data/spec/elasticsearch/transport/base_spec.rb +184 -0
  21. data/spec/elasticsearch/transport/client_spec.rb +117 -21
  22. data/spec/elasticsearch/transport/sniffer_spec.rb +269 -0
  23. data/spec/spec_helper.rb +4 -0
  24. data/test/integration/transport_test.rb +4 -0
  25. data/test/profile/client_benchmark_test.rb +4 -0
  26. data/test/test_helper.rb +4 -0
  27. data/test/unit/connection_collection_test.rb +4 -0
  28. data/test/unit/connection_selector_test.rb +4 -0
  29. data/test/unit/connection_test.rb +4 -0
  30. data/test/unit/response_test.rb +5 -1
  31. data/test/unit/serializer_test.rb +4 -0
  32. data/test/unit/transport_base_test.rb +4 -0
  33. data/test/unit/transport_curb_test.rb +4 -0
  34. data/test/unit/transport_faraday_test.rb +4 -0
  35. data/test/unit/transport_manticore_test.rb +4 -0
  36. metadata +68 -64
  37. data/test/unit/sniffer_test.rb +0 -179
@@ -1,179 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Elasticsearch::Transport::Transport::SnifferTest < Test::Unit::TestCase
4
-
5
- class DummyTransport
6
- include Elasticsearch::Transport::Transport::Base
7
- def __build_connections; hosts; end
8
- end
9
-
10
- def __nodes_info(json)
11
- Elasticsearch::Transport::Transport::Response.new 200, MultiJson.load(json)
12
- end
13
-
14
- DEFAULT_NODES_INFO_RESPONSE = <<-JSON
15
- {
16
- "cluster_name" : "elasticsearch_test",
17
- "nodes" : {
18
- "N1" : {
19
- "name" : "Node 1",
20
- "transport_address" : "127.0.0.1:9300",
21
- "host" : "testhost1",
22
- "ip" : "127.0.0.1",
23
- "version" : "5.0.0",
24
- "roles": [
25
- "master",
26
- "data",
27
- "ingest"
28
- ],
29
- "attributes": {
30
- "testattr": "test"
31
- },
32
- "http": {
33
- "bound_address": [
34
- "[fe80::1]:9250",
35
- "[::1]:9250",
36
- "127.0.0.1:9250"
37
- ],
38
- "publish_address": "127.0.0.1:9250",
39
- "max_content_length_in_bytes": 104857600
40
- }
41
- }
42
- }
43
- }
44
- JSON
45
-
46
- context "Sniffer" do
47
- setup do
48
- @transport = DummyTransport.new
49
- @sniffer = Elasticsearch::Transport::Transport::Sniffer.new @transport
50
- end
51
-
52
- should "be initialized with a transport instance" do
53
- assert_equal @transport, @sniffer.transport
54
- end
55
-
56
- should "return an array of hosts as hashes" do
57
- @transport.expects(:perform_request).returns __nodes_info(DEFAULT_NODES_INFO_RESPONSE)
58
-
59
- hosts = @sniffer.hosts
60
-
61
- assert_equal 1, hosts.size
62
- assert_equal '127.0.0.1', hosts.first[:host]
63
- assert_equal '9250', hosts.first[:port]
64
- assert_equal 'Node 1', hosts.first[:name]
65
- end
66
-
67
- should "return an array of hosts as hostnames when a hostname is returned" do
68
- @transport.expects(:perform_request).returns __nodes_info <<-JSON
69
- {
70
- "nodes" : {
71
- "N1" : {
72
- "http": {
73
- "publish_address": "testhost1.com:9250"
74
- }
75
- }
76
- }
77
- }
78
- JSON
79
-
80
- hosts = @sniffer.hosts
81
-
82
- assert_equal 1, hosts.size
83
- assert_equal 'testhost1.com', hosts.first[:host]
84
- assert_equal '9250', hosts.first[:port]
85
- end
86
-
87
- should "return HTTP hosts for the HTTPS protocol in the transport" do
88
- @transport = DummyTransport.new :options => { :protocol => 'https' }
89
- @sniffer = Elasticsearch::Transport::Transport::Sniffer.new @transport
90
-
91
- @transport.expects(:perform_request).returns __nodes_info(DEFAULT_NODES_INFO_RESPONSE)
92
-
93
- assert_equal 1, @sniffer.hosts.size
94
- end
95
-
96
- should "skip hosts without a matching transport protocol" do
97
- @transport = DummyTransport.new
98
- @sniffer = Elasticsearch::Transport::Transport::Sniffer.new @transport
99
-
100
- @transport.expects(:perform_request).returns __nodes_info <<-JSON
101
- {
102
- "nodes" : {
103
- "N1" : {
104
- "foobar": {
105
- "publish_address": "foobar:1234"
106
- }
107
- }
108
- }
109
- }
110
- JSON
111
-
112
- assert_empty @sniffer.hosts
113
- end
114
-
115
- should "have configurable timeout" do
116
- @transport = DummyTransport.new :options => { :sniffer_timeout => 0.001 }
117
- @sniffer = Elasticsearch::Transport::Transport::Sniffer.new @transport
118
- assert_equal 0.001, @sniffer.timeout
119
- end
120
-
121
- should "have settable timeout" do
122
- @transport = DummyTransport.new
123
- @sniffer = Elasticsearch::Transport::Transport::Sniffer.new @transport
124
- assert_equal 1, @sniffer.timeout
125
-
126
- @sniffer.timeout = 2
127
- assert_equal 2, @sniffer.timeout
128
- end
129
-
130
- should "raise error on timeout" do
131
- @transport.expects(:perform_request).raises(Elasticsearch::Transport::Transport::SnifferTimeoutError)
132
-
133
- # TODO: Try to inject sleep into `perform_request` or make this test less ridiculous anyhow...
134
- assert_raise Elasticsearch::Transport::Transport::SnifferTimeoutError do
135
- @sniffer.hosts
136
- end
137
- end
138
-
139
- should "randomize hosts" do
140
- @transport = DummyTransport.new :options => { :randomize_hosts => true }
141
- @sniffer = Elasticsearch::Transport::Transport::Sniffer.new @transport
142
-
143
- @transport.expects(:perform_request).returns __nodes_info <<-JSON
144
- {
145
- "ok" : true,
146
- "cluster_name" : "elasticsearch_test",
147
- "nodes" : {
148
- "N1" : {
149
- "name" : "Node 1",
150
- "http_address" : "inet[/192.168.1.23:9200]"
151
- },
152
- "N2" : {
153
- "name" : "Node 2",
154
- "http_address" : "inet[/192.168.1.23:9201]"
155
- },
156
- "N3" : {
157
- "name" : "Node 3",
158
- "http_address" : "inet[/192.168.1.23:9202]"
159
- },
160
- "N4" : {
161
- "name" : "Node 4",
162
- "http_address" : "inet[/192.168.1.23:9203]"
163
- },
164
- "N5" : {
165
- "name" : "Node 5",
166
- "http_address" : "inet[/192.168.1.23:9204]"
167
- }
168
- }
169
- }
170
- JSON
171
-
172
- Array.any_instance.expects(:shuffle!)
173
-
174
- hosts = @sniffer.hosts
175
- end
176
-
177
- end
178
-
179
- end