opensearch-transport 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +3 -0
  3. data/.gitignore +17 -0
  4. data/Gemfile +47 -0
  5. data/LICENSE +202 -0
  6. data/README.md +551 -0
  7. data/Rakefile +89 -0
  8. data/lib/opensearch/transport/client.rb +354 -0
  9. data/lib/opensearch/transport/redacted.rb +84 -0
  10. data/lib/opensearch/transport/transport/base.rb +450 -0
  11. data/lib/opensearch/transport/transport/connections/collection.rb +136 -0
  12. data/lib/opensearch/transport/transport/connections/connection.rb +169 -0
  13. data/lib/opensearch/transport/transport/connections/selector.rb +101 -0
  14. data/lib/opensearch/transport/transport/errors.rb +100 -0
  15. data/lib/opensearch/transport/transport/http/curb.rb +140 -0
  16. data/lib/opensearch/transport/transport/http/faraday.rb +101 -0
  17. data/lib/opensearch/transport/transport/http/manticore.rb +188 -0
  18. data/lib/opensearch/transport/transport/loggable.rb +94 -0
  19. data/lib/opensearch/transport/transport/response.rb +46 -0
  20. data/lib/opensearch/transport/transport/serializer/multi_json.rb +62 -0
  21. data/lib/opensearch/transport/transport/sniffer.rb +111 -0
  22. data/lib/opensearch/transport/version.rb +31 -0
  23. data/lib/opensearch/transport.rb +46 -0
  24. data/lib/opensearch-transport.rb +27 -0
  25. data/opensearch-transport.gemspec +92 -0
  26. data/spec/opensearch/connections/collection_spec.rb +275 -0
  27. data/spec/opensearch/connections/selector_spec.rb +183 -0
  28. data/spec/opensearch/transport/base_spec.rb +313 -0
  29. data/spec/opensearch/transport/client_spec.rb +1818 -0
  30. data/spec/opensearch/transport/sniffer_spec.rb +284 -0
  31. data/spec/spec_helper.rb +99 -0
  32. data/test/integration/transport_test.rb +108 -0
  33. data/test/profile/client_benchmark_test.rb +141 -0
  34. data/test/test_helper.rb +97 -0
  35. data/test/unit/connection_test.rb +145 -0
  36. data/test/unit/response_test.rb +41 -0
  37. data/test/unit/serializer_test.rb +42 -0
  38. data/test/unit/transport_base_test.rb +673 -0
  39. data/test/unit/transport_curb_test.rb +143 -0
  40. data/test/unit/transport_faraday_test.rb +237 -0
  41. data/test/unit/transport_manticore_test.rb +191 -0
  42. data.tar.gz.sig +1 -0
  43. metadata +456 -0
  44. metadata.gz.sig +1 -0
@@ -0,0 +1,284 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # The OpenSearch Contributors require contributions made to
4
+ # this file be licensed under the Apache-2.0 license or a
5
+ # compatible open source license.
6
+ #
7
+ # Modifications Copyright OpenSearch Contributors. See
8
+ # GitHub history for details.
9
+ #
10
+ # Licensed to Elasticsearch B.V. under one or more contributor
11
+ # license agreements. See the NOTICE file distributed with
12
+ # this work for additional information regarding copyright
13
+ # ownership. Elasticsearch B.V. licenses this file to you under
14
+ # the Apache License, Version 2.0 (the "License"); you may
15
+ # not use this file except in compliance with the License.
16
+ # You may obtain a copy of the License at
17
+ #
18
+ # http://www.apache.org/licenses/LICENSE-2.0
19
+ #
20
+ # Unless required by applicable law or agreed to in writing,
21
+ # software distributed under the License is distributed on an
22
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
+ # KIND, either express or implied. See the License for the
24
+ # specific language governing permissions and limitations
25
+ # under the License.
26
+
27
+ require 'spec_helper'
28
+
29
+ describe OpenSearch::Transport::Transport::Sniffer do
30
+ let(:transport) do
31
+ double('transport').tap do |t|
32
+ allow(t).to receive(:perform_request).and_return(response)
33
+ allow(t).to receive(:options).and_return(sniffer_timeout: 2)
34
+ end
35
+ end
36
+
37
+ let(:sniffer) do
38
+ described_class.new(transport)
39
+ end
40
+
41
+ let(:response) do
42
+ double('response').tap do |r|
43
+ allow(r).to receive(:body).and_return(raw_response)
44
+ end
45
+ end
46
+
47
+ let(:raw_response) do
48
+ { 'nodes' => { 'n1' => { 'http' => { 'publish_address' => publish_address } } } }
49
+ end
50
+
51
+ let(:publish_address) do
52
+ '127.0.0.1:9250'
53
+ end
54
+
55
+ describe '#initialize' do
56
+ it 'has a transport instance' do
57
+ expect(sniffer.transport).to be(transport)
58
+ end
59
+
60
+ it 'inherits the sniffer timeout from the transport object' do
61
+ expect(sniffer.timeout).to eq(2)
62
+ end
63
+ end
64
+
65
+ describe '#timeout' do
66
+ let(:sniffer) do
67
+ described_class.new(double('transport', options: {}))
68
+ end
69
+
70
+ before do
71
+ sniffer.timeout = 3
72
+ end
73
+
74
+ it 'allows the timeout to be configured' do
75
+ expect(sniffer.timeout).to eq(3)
76
+ end
77
+ end
78
+
79
+ describe '#hosts' do
80
+ let(:hosts) do
81
+ sniffer.hosts
82
+ end
83
+
84
+ context 'when the entire response is parsed' do
85
+ let(:raw_response) do
86
+ {
87
+ "cluster_name" => "opensearch_test",
88
+ "nodes" => {
89
+ "N1" => {
90
+ "name" => "Node 1",
91
+ "transport_address" => "127.0.0.1:9300",
92
+ "host" => "testhost1",
93
+ "ip" => "127.0.0.1",
94
+ "version" => "7.0.0",
95
+ "roles" => [
96
+ "master",
97
+ "data",
98
+ "ingest"
99
+ ],
100
+ "attributes" => {
101
+ "testattr" => "test"
102
+ },
103
+ "http" => {
104
+ "bound_address" => [
105
+ "[fe80::1]:9250",
106
+ "[::1]:9250",
107
+ "127.0.0.1:9250"
108
+ ],
109
+ "publish_address" => "127.0.0.1:9250",
110
+ "max_content_length_in_bytes" => 104857600
111
+ }
112
+ }
113
+ }
114
+ }
115
+ end
116
+
117
+ it 'parses the id' do
118
+ expect(sniffer.hosts[0][:id]).to eq('N1')
119
+ end
120
+
121
+ it 'parses the name' do
122
+ expect(sniffer.hosts[0][:name]).to eq('Node 1')
123
+ end
124
+
125
+ it 'parses the version' do
126
+ expect(sniffer.hosts[0][:version]).to eq('7.0.0')
127
+ end
128
+
129
+ it 'parses the host' do
130
+ expect(sniffer.hosts[0][:host]).to eq('127.0.0.1')
131
+ end
132
+
133
+ it 'parses the port' do
134
+ expect(sniffer.hosts[0][:port]).to eq('9250')
135
+ end
136
+
137
+ it 'parses the roles' do
138
+ expect(sniffer.hosts[0][:roles]).to eq(['master',
139
+ 'data',
140
+ 'ingest'])
141
+ end
142
+
143
+ it 'parses the attributes' do
144
+ expect(sniffer.hosts[0][:attributes]).to eq('testattr' => 'test')
145
+ end
146
+ end
147
+
148
+ context 'when the transport protocol does not match' do
149
+ let(:raw_response) do
150
+ { 'nodes' => { 'n1' => { 'foo' => { 'publish_address' => '127.0.0.1:9250' } } } }
151
+ end
152
+
153
+ it 'does not parse the addresses' do
154
+ expect(hosts).to eq([])
155
+ end
156
+ end
157
+
158
+ context 'when a list of nodes is returned' do
159
+ let(:raw_response) do
160
+ { 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } },
161
+ 'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } }
162
+ end
163
+
164
+ it 'parses the response' do
165
+ expect(hosts.size).to eq(2)
166
+ end
167
+
168
+ it 'correctly parses the hosts' do
169
+ expect(hosts[0][:host]).to eq('127.0.0.1')
170
+ expect(hosts[1][:host]).to eq('127.0.0.1')
171
+ end
172
+
173
+ it 'correctly parses the ports' do
174
+ expect(hosts[0][:port]).to eq('9250')
175
+ expect(hosts[1][:port]).to eq('9251')
176
+ end
177
+ end
178
+
179
+ context 'when the host and port are an ip address and port' do
180
+ it 'parses the response' do
181
+ expect(hosts.size).to eq(1)
182
+ end
183
+
184
+ it 'correctly parses the host' do
185
+ expect(hosts[0][:host]).to eq('127.0.0.1')
186
+ end
187
+
188
+ it 'correctly parses the port' do
189
+ expect(hosts[0][:port]).to eq('9250')
190
+ end
191
+ end
192
+
193
+ context 'when the host and port are a hostname and port' do
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
+ let(:publish_address) do
217
+ 'example.com/127.0.0.1:9250'
218
+ end
219
+
220
+ it 'parses the response' do
221
+ expect(hosts.size).to eq(1)
222
+ end
223
+
224
+ it 'uses the hostname' do
225
+ expect(hosts[0][:host]).to eq('example.com')
226
+ end
227
+
228
+ it 'correctly parses the port' do
229
+ expect(hosts[0][:port]).to eq('9250')
230
+ end
231
+
232
+ context 'when the address is IPv6' do
233
+ let(:publish_address) do
234
+ 'example.com/[::1]:9250'
235
+ end
236
+
237
+ it 'parses the response' do
238
+ expect(hosts.size).to eq(1)
239
+ end
240
+
241
+ it 'uses the hostname' do
242
+ expect(hosts[0][:host]).to eq('example.com')
243
+ end
244
+
245
+ it 'correctly parses the port' do
246
+ expect(hosts[0][:port]).to eq('9250')
247
+ end
248
+ end
249
+ end
250
+
251
+ context 'when the address is IPv6' do
252
+ let(:publish_address) do
253
+ '[::1]:9250'
254
+ end
255
+
256
+ it 'parses the response' do
257
+ expect(hosts.size).to eq(1)
258
+ end
259
+
260
+ it 'correctly parses the host' do
261
+ expect(hosts[0][:host]).to eq('::1')
262
+ end
263
+
264
+ it 'correctly parses the port' do
265
+ expect(hosts[0][:port]).to eq('9250')
266
+ end
267
+ end
268
+
269
+ context 'when the transport has :randomize_hosts option' do
270
+ let(:raw_response) do
271
+ { 'nodes' => { 'n1' => { 'http' => { 'publish_address' => '127.0.0.1:9250' } },
272
+ 'n2' => { 'http' => { 'publish_address' => '127.0.0.1:9251' } } } }
273
+ end
274
+
275
+ before do
276
+ allow(transport).to receive(:options).and_return(randomize_hosts: true)
277
+ end
278
+
279
+ it 'shuffles the list' do
280
+ expect(hosts.size).to eq(2)
281
+ end
282
+ end
283
+ end
284
+ end
@@ -0,0 +1,99 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # The OpenSearch Contributors require contributions made to
4
+ # this file be licensed under the Apache-2.0 license or a
5
+ # compatible open source license.
6
+ #
7
+ # Modifications Copyright OpenSearch Contributors. See
8
+ # GitHub history for details.
9
+ #
10
+ # Licensed to Elasticsearch B.V. under one or more contributor
11
+ # license agreements. See the NOTICE file distributed with
12
+ # this work for additional information regarding copyright
13
+ # ownership. Elasticsearch B.V. licenses this file to you under
14
+ # the Apache License, Version 2.0 (the "License"); you may
15
+ # not use this file except in compliance with the License.
16
+ # You may obtain a copy of the License at
17
+ #
18
+ # http://www.apache.org/licenses/LICENSE-2.0
19
+ #
20
+ # Unless required by applicable law or agreed to in writing,
21
+ # software distributed under the License is distributed on an
22
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
+ # KIND, either express or implied. See the License for the
24
+ # specific language governing permissions and limitations
25
+ # under the License.
26
+ if ENV['COVERAGE'] && ENV['CI'].nil?
27
+ require 'simplecov'
28
+ SimpleCov.start { add_filter %r{^/test|spec/} }
29
+ end
30
+
31
+ require 'opensearch-transport'
32
+ require 'logger'
33
+ require 'ansi/code'
34
+ require 'hashie/mash'
35
+ if defined?(JRUBY_VERSION)
36
+ require 'opensearch/transport/transport/http/manticore'
37
+ require 'pry-nav'
38
+ else
39
+ require 'pry-byebug'
40
+ require 'opensearch/transport/transport/http/curb'
41
+ require 'curb'
42
+ end
43
+
44
+ # The hosts to use for creating a opensearch client.
45
+ #
46
+ # @since 7.0.0
47
+ OPENSEARCH_HOSTS = if (hosts = ENV['TEST_OPENSEARCH_SERVER'] || ENV['OPENSEARCH_HOSTS'])
48
+ hosts.split(',').map do |host|
49
+ /(http\:\/\/)?(\S+)/.match(host)[2]
50
+ end
51
+ else
52
+ ['localhost:9200']
53
+ end.freeze
54
+
55
+ TEST_HOST, TEST_PORT = OPENSEARCH_HOSTS.first.split(':') if OPENSEARCH_HOSTS
56
+
57
+ # Are we testing on JRuby?
58
+ #
59
+ # @return [ true, false ] Whether JRuby is being used.
60
+ #
61
+ # @since 7.0.0
62
+ def jruby?
63
+ RUBY_PLATFORM =~ /\bjava\b/
64
+ end
65
+
66
+ # The names of the connected nodes.
67
+ #
68
+ # @return [ Array<String> ] The node names.
69
+ #
70
+ # @since 7.0.0
71
+ def node_names
72
+ node_stats = default_client.perform_request('GET', '_nodes/stats').body
73
+ $node_names ||= node_stats['nodes'].collect do |name, stats|
74
+ stats['name']
75
+ end
76
+ end
77
+
78
+ # The default client.
79
+ #
80
+ # @return [ OpenSearch::Client ] The default client.
81
+ #
82
+ def default_client
83
+ $client ||= OpenSearch::Client.new(hosts: OPENSEARCH_HOSTS)
84
+ end
85
+
86
+ module Config
87
+ def self.included(context)
88
+ # Get the hosts to use to connect an opensearch client.
89
+ #
90
+ # @since 7.0.0
91
+ context.let(:hosts) { OPENSEARCH_HOSTS }
92
+ end
93
+ end
94
+
95
+ RSpec.configure do |config|
96
+ config.include(Config)
97
+ config.formatter = 'documentation'
98
+ config.color = true
99
+ end
@@ -0,0 +1,108 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # The OpenSearch Contributors require contributions made to
4
+ # this file be licensed under the Apache-2.0 license or a
5
+ # compatible open source license.
6
+ #
7
+ # Modifications Copyright OpenSearch Contributors. See
8
+ # GitHub history for details.
9
+ #
10
+ # Licensed to Elasticsearch B.V. under one or more contributor
11
+ # license agreements. See the NOTICE file distributed with
12
+ # this work for additional information regarding copyright
13
+ # ownership. Elasticsearch B.V. licenses this file to you under
14
+ # the Apache License, Version 2.0 (the "License"); you may
15
+ # not use this file except in compliance with the License.
16
+ # You may obtain a copy of the License at
17
+ #
18
+ # http://www.apache.org/licenses/LICENSE-2.0
19
+ #
20
+ # Unless required by applicable law or agreed to in writing,
21
+ # software distributed under the License is distributed on an
22
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
+ # KIND, either express or implied. See the License for the
24
+ # specific language governing permissions and limitations
25
+ # under the License.
26
+
27
+ require 'test_helper'
28
+
29
+ class OpenSearch::Transport::ClientIntegrationTest < Minitest::Test
30
+ context "Transport" do
31
+ setup do
32
+ @host, @port = OPENSEARCH_HOSTS.first.split(':')
33
+ begin; Object.send(:remove_const, :Patron); rescue NameError; end
34
+ end
35
+
36
+ should "allow to customize the Faraday adapter to Typhoeus" do
37
+ require 'typhoeus'
38
+ require 'typhoeus/adapters/faraday'
39
+
40
+ transport = OpenSearch::Transport::Transport::HTTP::Faraday.new \
41
+ :hosts => [ { host: @host, port: @port } ] do |f|
42
+ f.response :logger
43
+ f.adapter :typhoeus
44
+ end
45
+
46
+ client = OpenSearch::Transport::Client.new transport: transport
47
+ client.perform_request 'GET', ''
48
+ end unless jruby?
49
+
50
+ should "allow to customize the Faraday adapter to NetHttpPersistent" do
51
+ require 'net/http/persistent'
52
+
53
+ transport = OpenSearch::Transport::Transport::HTTP::Faraday.new \
54
+ :hosts => [ { host: @host, port: @port } ] do |f|
55
+ f.response :logger
56
+ f.adapter :net_http_persistent
57
+ end
58
+
59
+ client = OpenSearch::Transport::Client.new transport: transport
60
+ client.perform_request 'GET', ''
61
+ end
62
+
63
+ should "allow to define connection parameters and pass them" do
64
+ transport = OpenSearch::Transport::Transport::HTTP::Faraday.new \
65
+ :hosts => [ { host: @host, port: @port } ],
66
+ :options => { :transport_options => {
67
+ :params => { :format => 'yaml' }
68
+ }
69
+ }
70
+
71
+ client = OpenSearch::Transport::Client.new transport: transport
72
+ response = client.perform_request 'GET', ''
73
+
74
+ assert response.body.start_with?("---\n"), "Response body should be YAML: #{response.body.inspect}"
75
+ end
76
+
77
+ should "use the Curb client" do
78
+ require 'curb'
79
+ require 'opensearch/transport/transport/http/curb'
80
+
81
+ transport = OpenSearch::Transport::Transport::HTTP::Curb.new \
82
+ :hosts => [ { host: @host, port: @port } ] do |curl|
83
+ curl.verbose = true
84
+ end
85
+
86
+ client = OpenSearch::Transport::Client.new transport: transport
87
+ client.perform_request 'GET', ''
88
+ end unless JRUBY
89
+
90
+ should "deserialize JSON responses in the Curb client" do
91
+ require 'curb'
92
+ require 'opensearch/transport/transport/http/curb'
93
+
94
+ transport = OpenSearch::Transport::Transport::HTTP::Curb.new \
95
+ :hosts => [ { host: @host, port: @port } ] do |curl|
96
+ curl.verbose = true
97
+ end
98
+
99
+ client = OpenSearch::Transport::Client.new transport: transport
100
+ response = client.perform_request 'GET', ''
101
+
102
+ assert_respond_to(response.body, :to_hash)
103
+ assert_not_nil response.body['name']
104
+ assert_equal 'application/json', response.headers['content-type']
105
+ end unless JRUBY
106
+ end
107
+
108
+ end
@@ -0,0 +1,141 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # The OpenSearch Contributors require contributions made to
4
+ # this file be licensed under the Apache-2.0 license or a
5
+ # compatible open source license.
6
+ #
7
+ # Modifications Copyright OpenSearch Contributors. See
8
+ # GitHub history for details.
9
+ #
10
+ # Licensed to Elasticsearch B.V. under one or more contributor
11
+ # license agreements. See the NOTICE file distributed with
12
+ # this work for additional information regarding copyright
13
+ # ownership. Elasticsearch B.V. licenses this file to you under
14
+ # the Apache License, Version 2.0 (the "License"); you may
15
+ # not use this file except in compliance with the License.
16
+ # You may obtain a copy of the License at
17
+ #
18
+ # http://www.apache.org/licenses/LICENSE-2.0
19
+ #
20
+ # Unless required by applicable law or agreed to in writing,
21
+ # software distributed under the License is distributed on an
22
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
+ # KIND, either express or implied. See the License for the
24
+ # specific language governing permissions and limitations
25
+ # under the License.
26
+
27
+ require 'test_helper'
28
+
29
+ class OpenSearch::Transport::ClientProfilingTest < OpenSearch::Test::ProfilingTest
30
+ context "OpenSearch client benchmark" do
31
+ setup do
32
+ @port = (ENV['TEST_CLUSTER_PORT'] || 9250).to_i
33
+ client = OpenSearch::Client.new host: "localhost:#{@port}", adapter: ::Faraday.default_adapter
34
+ client.perform_request 'DELETE', 'ruby_test_benchmark' rescue nil
35
+ client.perform_request 'PUT', 'ruby_test_benchmark', {}, {settings: {index: {number_of_shards: 1, number_of_replicas: 0}}}
36
+ 100.times do client.perform_request 'POST', 'ruby_test_benchmark_search/test', {}, {foo: 'bar'}; end
37
+ client.perform_request 'POST', 'ruby_test_benchmark_search/_refresh'
38
+ end
39
+ teardown do
40
+ client = OpenSearch::Client.new host: "localhost:#{@port}"
41
+ client.perform_request 'DELETE', 'ruby_test_benchmark' rescue nil
42
+ client.perform_request 'DELETE', 'ruby_test_benchmark_search' rescue nil
43
+ end
44
+
45
+ context "with a single-node cluster and the default adapter" do
46
+ setup do
47
+ @client = OpenSearch::Client.new hosts: "localhost:#{@port}", adapter: ::Faraday.default_adapter
48
+ end
49
+
50
+ measure "get the cluster info", count: 1_000 do
51
+ @client.perform_request 'GET', ''
52
+ end
53
+
54
+ measure "index a document" do
55
+ @client.perform_request 'POST', 'ruby_test_benchmark/test', {}, {foo: 'bar'}
56
+ end
57
+
58
+ measure "search" do
59
+ @client.perform_request 'GET', 'ruby_test_benchmark_search/test/_search', {}, {query: {match: {foo: 'bar'}}}
60
+ end
61
+ end
62
+
63
+ context "with a two-node cluster and the default adapter" do
64
+ setup do
65
+ @client = OpenSearch::Client.new hosts: ["localhost:#{@port}", "localhost:#{@port+1}"], adapter: ::Faraday.default_adapter
66
+ end
67
+
68
+ measure "get the cluster info", count: 1_000 do
69
+ @client.perform_request 'GET', ''
70
+ end
71
+
72
+ measure "index a document"do
73
+ @client.perform_request 'POST', 'ruby_test_benchmark/test', {}, {foo: 'bar'}
74
+ end
75
+
76
+ measure "search" do
77
+ @client.perform_request 'GET', 'ruby_test_benchmark_search/test/_search', {}, {query: {match: {foo: 'bar'}}}
78
+ end
79
+ end
80
+
81
+ context "with a single-node cluster and the Curb client" do
82
+ setup do
83
+ require 'curb'
84
+ require 'opensearch/transport/transport/http/curb'
85
+ @client = OpenSearch::Client.new host: "localhost:#{@port}",
86
+ transport_class: OpenSearch::Transport::Transport::HTTP::Curb
87
+ end
88
+
89
+ measure "get the cluster info", count: 1_000 do
90
+ @client.perform_request 'GET', ''
91
+ end
92
+
93
+ measure "index a document" do
94
+ @client.perform_request 'POST', 'ruby_test_benchmark/test', {}, {foo: 'bar'}
95
+ end
96
+
97
+ measure "search" do
98
+ @client.perform_request 'GET', 'ruby_test_benchmark_search/test/_search', {}, {query: {match: {foo: 'bar'}}}
99
+ end
100
+ end
101
+
102
+ context "with a single-node cluster and the Typhoeus client" do
103
+ setup do
104
+ require 'typhoeus'
105
+ require 'typhoeus/adapters/faraday'
106
+ @client = OpenSearch::Client.new host: "localhost:#{@port}", adapter: :typhoeus
107
+ end
108
+
109
+ measure "get the cluster info", count: 1_000 do
110
+ @client.perform_request 'GET', ''
111
+ end
112
+
113
+ measure "index a document" do
114
+ @client.perform_request 'POST', 'ruby_test_benchmark/test', {}, {foo: 'bar'}
115
+ end
116
+
117
+ measure "search" do
118
+ @client.perform_request 'GET', 'ruby_test_benchmark_search/test/_search', {}, {query: {match: {foo: 'bar'}}}
119
+ end
120
+ end
121
+
122
+ context "with a single-node cluster and the Patron adapter" do
123
+ setup do
124
+ require 'patron'
125
+ @client = OpenSearch::Client.new host: "localhost:#{@port}", adapter: :patron
126
+ end
127
+
128
+ measure "get the cluster info", count: 1_000 do
129
+ @client.perform_request 'GET', ''
130
+ end
131
+
132
+ measure "index a document" do
133
+ @client.perform_request 'POST', 'ruby_test_benchmark/test', {}, {foo: 'bar'}
134
+ end
135
+
136
+ measure "search" do
137
+ @client.perform_request 'GET', 'ruby_test_benchmark_search/test/_search', {}, {query: {match: {foo: 'bar'}}}
138
+ end
139
+ end
140
+ end
141
+ end