elastic-transport 8.0.1 → 8.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51e53310c92bb9b3e3cb43d0ffb2587e980218f6a4de9052f21fa1dee645b319
4
- data.tar.gz: 960f931aff3f04f14d93c45d585b37e1bc23fcf6273d731c7c3ec3d7a217bea3
3
+ metadata.gz: 8b066c34f0b23cddd1cb3da7667df6889e749f93241838edbf7ce82aa45a08b5
4
+ data.tar.gz: 054ac019e3aa6b50526694696af8bbcd51be8a3c79ff8165486011581d0615f3
5
5
  SHA512:
6
- metadata.gz: 77748ed0f93bbf3c065331bb4d6bc2b76b5ee254a1412728b68feb4c7679277a3eafb39bfd3267a67374cc410b2f9277ceea42e899869624134af5cf7f8429e2
7
- data.tar.gz: 645430db2265232b924d2c85877cde70d7e54d8c4ad5f2a0b98003419c61db42ffe0f1629a964436ca4fcbfb1bca5fe29b97f8991784170af6f8219ee83eaed4
6
+ metadata.gz: 279d92ef2d6df1909d7d6b537ba9283c24d2791dc9c85c3e05330bd65b580356511c8412a987ee788eeee8ac0a0600624d0b4a42eddf386d988f879299947dc4
7
+ data.tar.gz: 1e9266023daa113c11df4a1913d27b68aa81034d951487ccd5ed08a73011827d4ecdb409eaafbc360785286b52bbe00299447ac7820def9741817f9ca66b794b
@@ -7,14 +7,16 @@ on:
7
7
  branches:
8
8
  - main
9
9
  jobs:
10
- test-ruby:
10
+ test:
11
+ name: 'Main tests'
11
12
  env:
12
13
  TEST_ES_SERVER: http://localhost:9250
13
14
  PORT: 9250
14
15
  strategy:
15
16
  fail-fast: false
16
17
  matrix:
17
- ruby: [ '2.6', '2.7', '3.0', '3.1', 'jruby-9.3' ]
18
+ ruby: [ '2.7', '3.0', '3.1', 'jruby-9.3' ]
19
+ es_version: ['8.2-SNAPSHOT', '8.3-SNAPSHOT', '8.4-SNAPSHOT']
18
20
  runs-on: ubuntu-latest
19
21
  steps:
20
22
  - uses: actions/checkout@v2
@@ -26,7 +28,8 @@ jobs:
26
28
  sudo sysctl -w vm.max_map_count=262144
27
29
  - uses: elastic/elastic-github-actions/elasticsearch@master
28
30
  with:
29
- stack-version: 8.0.0-SNAPSHOT
31
+ stack-version: ${{ matrix.es_version }}
32
+ security-enabled: false
30
33
  - uses: ruby/setup-ruby@v1
31
34
  with:
32
35
  ruby-version: ${{ matrix.ruby }}
@@ -42,4 +45,42 @@ jobs:
42
45
  run: bundle exec rake test:spec
43
46
  - name: integration tests
44
47
  run: bundle exec rake test:integration
45
-
48
+ test-faraday1:
49
+ name: 'Test Faraday 1'
50
+ env:
51
+ TEST_ES_SERVER: http://localhost:9250
52
+ PORT: 9250
53
+ strategy:
54
+ fail-fast: false
55
+ matrix:
56
+ ruby: [ '2.7', '3.0', '3.1', 'jruby-9.3' ]
57
+ es_version: ['8.3.0-SNAPSHOT']
58
+ runs-on: ubuntu-latest
59
+ steps:
60
+ - uses: actions/checkout@v2
61
+ - name: Increase system limits
62
+ run: |
63
+ sudo swapoff -a
64
+ sudo sysctl -w vm.swappiness=1
65
+ sudo sysctl -w fs.file-max=262144
66
+ sudo sysctl -w vm.max_map_count=262144
67
+ - uses: elastic/elastic-github-actions/elasticsearch@master
68
+ with:
69
+ stack-version: ${{ matrix.es_version }}
70
+ security-enabled: false
71
+ - uses: ruby/setup-ruby@v1
72
+ with:
73
+ ruby-version: ${{ matrix.ruby }}
74
+ - name: Build and test with Rake
75
+ run: |
76
+ sudo apt-get update
77
+ sudo apt-get install libcurl4-openssl-dev
78
+ ruby -v
79
+ gem install bundler
80
+ BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle install
81
+ - name: faraday1 unit tests
82
+ run: BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle exec rake test:faraday1:unit
83
+ - name: specs
84
+ run: BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle exec rake test:faraday1:spec
85
+ - name: integration tests
86
+ run: BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle exec rake test:faraday1:integration
data/.gitignore CHANGED
@@ -5,7 +5,7 @@
5
5
  .bundle
6
6
  .config
7
7
  .yardoc
8
- Gemfile.lock
8
+ Gemfile*.lock
9
9
  InstalledFiles
10
10
  _yardoc
11
11
  coverage
data/CHANGELOG.md CHANGED
@@ -1,3 +1,30 @@
1
+ ## 8.1.0.pre1
2
+
3
+ Adds support for Faraday version 2. From [Faraday's Upgrading guide](https://github.com/lostisland/faraday/blob/main/UPGRADING.md#faraday-20), the main change is the adapters have moved:
4
+
5
+ > With this release, we've officially moved all adapters, except for the net_http one, out of Faraday. What that means, is that they won't be available out-of-the-box anymore, and you'll instead need to add them to your Gemfile.
6
+ > If you just use the default net_http adapter, then you don't need to do anything!
7
+ > Otherwise, add the corresponding adapter gem to your Gemfile (e.g. faraday-net_http_persistent). Then, simply require them after you require faraday.
8
+
9
+ We're now supporting Faraday v2 and Faraday v1. The adapters were removed as development dependency in the gemspec and added to the Gemfile. A new file `Gemfile-faraday1.gemfile` was added to run tests with version `1.x` of Faraday too.
10
+
11
+ These are the gems required for the different adapters with Faraday 2, instead of the libraries on which they were based:
12
+ ```
13
+ # HTTPCLient
14
+ 'faraday-httpclient'
15
+
16
+ # NetHTTPPersistent
17
+ 'faraday-net_http_persistent'
18
+
19
+ # Patron
20
+ 'faraday-patron'
21
+
22
+ # Typhoeus
23
+ 'faraday-typhoeus'
24
+ ```
25
+
26
+ If you're using Faraday 1, you shouldn't have to change anything, but please [submit an issue](https://github.com/elastic/elastic-transport-ruby/issues) if you encounter any issues.
27
+
1
28
  ## 8.0.1
2
29
 
3
30
  - Minor code cleanup
data/Gemfile CHANGED
@@ -20,15 +20,11 @@ source 'https://rubygems.org'
20
20
  # Specify your gem's dependencies in elasticsearch-transport.gemspec
21
21
  gemspec
22
22
 
23
- if File.exist? File.expand_path('../elasticsearch-api/elasticsearch-api.gemspec', __dir__)
24
- gem 'elasticsearch-api', path: File.expand_path('../elasticsearch-api', __dir__), require: false
25
- end
26
-
27
- if File.exist? File.expand_path('../elasticsearch/elasticsearch.gemspec', __dir__)
28
- gem 'elasticsearch', path: File.expand_path('../elasticsearch', __dir__), require: false
29
- end
30
-
31
23
  group :development, :test do
24
+ gem 'faraday-httpclient'
25
+ gem 'faraday-net_http_persistent'
26
+ gem 'faraday-patron' unless defined? JRUBY_VERSION
27
+ gem 'faraday-typhoeus'
32
28
  gem 'rspec'
33
29
  if defined?(JRUBY_VERSION)
34
30
  gem 'pry-nav'
@@ -0,0 +1,39 @@
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
+ source 'https://rubygems.org'
19
+
20
+ # Usage:
21
+ #
22
+ # $ BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle install
23
+ # $ BUNDLE_GEMFILE=./Gemfile-faraday1.gemfile bundle exec rake test:faraday1:unit
24
+
25
+ gem 'faraday', '~> 1'
26
+ gemspec path: './'
27
+
28
+ group :development, :test do
29
+ gem 'httpclient'
30
+ gem 'net-http-persistent'
31
+ gem 'patron' unless defined? JRUBY_VERSION
32
+ gem 'rspec'
33
+ gem 'typhoeus'
34
+ if defined?(JRUBY_VERSION)
35
+ gem 'pry-nav'
36
+ else
37
+ gem 'pry-byebug'
38
+ end
39
+ end
data/Rakefile CHANGED
@@ -18,13 +18,22 @@
18
18
  require 'bundler/gem_tasks'
19
19
  require 'mkmf'
20
20
 
21
- desc "Run unit tests"
21
+ desc 'Run unit tests'
22
22
  task default: 'test:unit'
23
23
  task test: 'test:unit'
24
24
 
25
25
  # ----- Test tasks ------------------------------------------------------------
26
26
  require 'rake/testtask'
27
27
  require 'rspec/core/rake_task'
28
+ FARADAY1_GEMFILE = 'Gemfile-faraday1.gemfile'.freeze
29
+ GEMFILES = ['Gemfile', FARADAY1_GEMFILE].freeze
30
+
31
+ task :install do
32
+ GEMFILES.each do |gemfile|
33
+ gemfile = File.expand_path("../#{gemfile}", __FILE__)
34
+ sh "bundle install --gemfile #{gemfile}"
35
+ end
36
+ end
28
37
 
29
38
  namespace :test do
30
39
  RSpec::Core::RakeTask.new(:spec)
@@ -46,6 +55,7 @@ namespace :test do
46
55
  desc 'Run all tests'
47
56
  task :all do
48
57
  Rake::Task['test:unit'].invoke
58
+ Rake::Task['test:spec'].invoke
49
59
  Rake::Task['test:integration'].invoke
50
60
  end
51
61
 
@@ -53,6 +63,34 @@ namespace :test do
53
63
  test.libs << 'lib' << 'test'
54
64
  test.test_files = FileList['test/profile/**/*_test.rb']
55
65
  end
66
+
67
+ namespace :faraday1 do
68
+ desc 'Faraday 1: Run RSpec with dependency on Faraday 1'
69
+ task :spec do
70
+ sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} bundle exec rspec"
71
+ end
72
+
73
+ desc 'Faraday 1: Run unit tests with dependency on Faraday 1'
74
+ task :unit do
75
+ Dir.glob('./test/unit/**/**.rb').each do |test|
76
+ sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} ruby -Ilib:test #{test}"
77
+ end
78
+ end
79
+
80
+ desc 'Faraday 1: Run integration tests with dependency on Faraday 1'
81
+ task :integration do
82
+ Dir.glob('./test/integration/**/**.rb').each do |test|
83
+ sh "BUNDLE_GEMFILE=#{FARADAY1_GEMFILE} ruby -Ilib:test #{test}"
84
+ end
85
+ end
86
+
87
+ desc 'Faraday 1: Run all tests'
88
+ task :all do
89
+ Rake::Task['test:faraday1:unit'].invoke
90
+ Rake::Task['test:faraday1:spec'].invoke
91
+ Rake::Task['test:faraday1:integration'].invoke
92
+ end
93
+ end
56
94
  end
57
95
 
58
96
  namespace :docker do
@@ -44,20 +44,18 @@ Gem::Specification.new do |s|
44
44
 
45
45
  s.required_ruby_version = '>= 2.5'
46
46
 
47
+ s.add_dependency 'faraday'
47
48
  s.add_dependency 'multi_json'
48
- s.add_dependency 'faraday', '~> 1'
49
49
 
50
+ # Faraday Adapters
51
+ s.add_development_dependency 'manticore' if defined? JRUBY_VERSION
52
+ s.add_development_dependency 'curb' unless defined? JRUBY_VERSION
50
53
  s.add_development_dependency 'bundler'
51
54
  s.add_development_dependency 'cane'
52
- s.add_development_dependency 'curb' unless defined? JRUBY_VERSION
53
55
  s.add_development_dependency 'hashie'
54
- s.add_development_dependency 'httpclient'
55
- s.add_development_dependency 'manticore' if defined? JRUBY_VERSION
56
56
  s.add_development_dependency 'minitest'
57
57
  s.add_development_dependency 'minitest-reporters'
58
58
  s.add_development_dependency 'mocha'
59
- s.add_development_dependency 'net-http-persistent'
60
- s.add_development_dependency 'patron' unless defined? JRUBY_VERSION
61
59
  s.add_development_dependency 'pry'
62
60
  s.add_development_dependency 'rake', '~> 13'
63
61
  s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
@@ -65,7 +63,6 @@ Gem::Specification.new do |s|
65
63
  s.add_development_dependency 'shoulda-context'
66
64
  s.add_development_dependency 'simplecov'
67
65
  s.add_development_dependency 'test-unit', '~> 2'
68
- s.add_development_dependency 'typhoeus', '~> 1.4'
69
66
  s.add_development_dependency 'yard'
70
67
 
71
68
  s.description = <<-DESC.gsub(/^ /, '')
@@ -103,31 +103,31 @@ module Elastic
103
103
  adapter_version = case @arguments[:adapter]
104
104
  when :patron
105
105
  version = Patron::VERSION if defined?(::Patron::VERSION)
106
- {pt: version}
106
+ { pt: version }
107
107
  when :net_http
108
108
  version = if defined?(Net::HTTP::VERSION)
109
109
  Net::HTTP::VERSION
110
110
  elsif defined?(Net::HTTP::HTTPVersion)
111
111
  Net::HTTP::HTTPVersion
112
112
  end
113
- {nh: version}
113
+ { nh: version }
114
114
  when :typhoeus
115
115
  version = Typhoeus::VERSION if defined?(::Typhoeus::VERSION)
116
- {ty: version}
116
+ { ty: version }
117
117
  when :httpclient
118
118
  version = HTTPClient::VERSION if defined?(HTTPClient::VERSION)
119
- {hc: version}
119
+ { hc: version }
120
120
  when :net_http_persistent
121
121
  version = Net::HTTP::Persistent::VERSION if defined?(Net::HTTP::Persistent::VERSION)
122
- {np: version}
122
+ { np: version }
123
123
  else
124
124
  {}
125
125
  end
126
- {fd: Faraday::VERSION}.merge(adapter_version)
126
+ { fd: Faraday::VERSION }.merge(adapter_version)
127
127
  elsif defined?(Transport::HTTP::Curb) && @transport_class == Transport::HTTP::Curb
128
- {cl: Curl::CURB_VERSION}
128
+ { cl: Curl::CURB_VERSION }
129
129
  elsif defined?(Transport::HTTP::Manticore) && @transport_class == Transport::HTTP::Manticore
130
- {mc: Manticore::VERSION}
130
+ { mc: Manticore::VERSION }
131
131
  end
132
132
  end
133
133
  end
@@ -37,31 +37,34 @@ module Elastic
37
37
  body, headers = compress_request(body, headers)
38
38
 
39
39
  case method
40
- when 'HEAD'
41
- connection.connection.set :nobody, true
42
- when 'GET', 'POST', 'PUT', 'DELETE'
43
- connection.connection.set :nobody, false
44
- connection.connection.put_data = body if body
40
+ when 'HEAD'
41
+ connection.connection.set :nobody, true
42
+ when 'GET', 'POST', 'PUT', 'DELETE'
43
+ connection.connection.set :nobody, false
44
+ connection.connection.put_data = body if body
45
45
 
46
- if headers
47
- if connection.connection.headers
48
- connection.connection.headers.merge!(headers)
49
- else
50
- connection.connection.headers = headers
51
- end
46
+ if headers
47
+ if connection.connection.headers
48
+ connection.connection.headers.merge!(headers)
49
+ else
50
+ connection.connection.headers = headers
52
51
  end
52
+ end
53
53
 
54
- else raise ArgumentError, "Unsupported HTTP method: #{method}"
54
+ else raise ArgumentError, "Unsupported HTTP method: #{method}"
55
55
  end
56
56
 
57
57
  connection.connection.http(method.to_sym)
58
+ header_string = connection.connection.header_str.to_s
58
59
 
59
- response_headers = {}
60
- response_headers['content-type'] = 'application/json' if connection.connection.header_str =~ /\/json/
60
+ _response_status, *response_headers = header_string.split(/[\r\n]+/).map(&:strip)
61
+ response_headers = Hash[response_headers.flat_map { |s| s.scan(/^(\S+): (.+)/) }].transform_keys(&:downcase)
61
62
 
62
- Response.new connection.connection.response_code,
63
- decompress_response(connection.connection.body_str),
64
- response_headers
63
+ Response.new(
64
+ connection.connection.response_code,
65
+ decompress_response(connection.connection.body_str),
66
+ response_headers
67
+ )
65
68
  end
66
69
  end
67
70
 
@@ -73,7 +76,7 @@ module Elastic
73
76
  client = ::Curl::Easy.new
74
77
 
75
78
  apply_headers(client, options)
76
- client.url = __full_url(host)
79
+ client.url = __full_url(host)
77
80
 
78
81
  if host[:user]
79
82
  client.http_auth_types = host[:auth_type] || :basic
@@ -105,13 +108,13 @@ module Elastic
105
108
 
106
109
  def user_agent_header(client)
107
110
  @user_agent ||= begin
108
- meta = ["RUBY_VERSION: #{RUBY_VERSION}"]
109
- if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
110
- meta << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
111
- end
112
- meta << "Curb #{Curl::CURB_VERSION}"
113
- "elastic-transport-ruby/#{VERSION} (#{meta.join('; ')})"
114
- end
111
+ meta = ["RUBY_VERSION: #{RUBY_VERSION}"]
112
+ if RbConfig::CONFIG && RbConfig::CONFIG['host_os']
113
+ meta << "#{RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase} #{RbConfig::CONFIG['target_cpu']}"
114
+ end
115
+ meta << "Curb #{Curl::CURB_VERSION}"
116
+ "elastic-transport-ruby/#{VERSION} (#{meta.join('; ')})"
117
+ end
115
118
  end
116
119
  end
117
120
  end
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Elastic
19
19
  module Transport
20
- VERSION = '8.0.1'.freeze
20
+ VERSION = '8.1.0.pre1'.freeze
21
21
  end
22
22
  end
@@ -105,7 +105,8 @@ describe Elastic::Transport::Transport::Base do
105
105
  let(:arguments) do
106
106
  {
107
107
  hosts: ['http://unavailable:9200', 'http://unavailable:9201'],
108
- retry_on_failure: 2
108
+ retry_on_failure: 2,
109
+ adapter: :net_http
109
110
  }
110
111
  end
111
112
 
@@ -129,7 +130,8 @@ describe Elastic::Transport::Transport::Base do
129
130
  let(:arguments) do
130
131
  {
131
132
  hosts: ELASTICSEARCH_HOSTS,
132
- retry_on_status: ['404']
133
+ retry_on_status: ['404'],
134
+ adapter: :net_http
133
135
  }
134
136
  end
135
137
 
@@ -191,8 +191,8 @@ describe Elastic::Transport::Client do
191
191
  it 'uses Faraday NetHttp' do
192
192
  expect(adapter).to eq Faraday::Adapter::NetHttp
193
193
  end
194
- end unless jruby?
195
- end
194
+ end
195
+ end unless jruby?
196
196
 
197
197
  context 'when the adapter is patron' do
198
198
  let(:adapter) do
@@ -204,9 +204,10 @@ describe Elastic::Transport::Client do
204
204
  end
205
205
 
206
206
  it 'uses Faraday with the adapter' do
207
+ require 'faraday/patron'
207
208
  expect(adapter).to eq Faraday::Adapter::Patron
208
209
  end
209
- end
210
+ end unless jruby?
210
211
 
211
212
  context 'when the adapter is typhoeus' do
212
213
  let(:adapter) do
@@ -214,6 +215,8 @@ describe Elastic::Transport::Client do
214
215
  end
215
216
 
216
217
  let(:client) do
218
+ require 'faraday/typhoeus' if is_faraday_v2?
219
+
217
220
  described_class.new(adapter: :typhoeus, enable_meta_header: false)
218
221
  end
219
222
 
@@ -234,7 +237,7 @@ describe Elastic::Transport::Client do
234
237
  it 'uses Faraday with the adapter' do
235
238
  expect(adapter).to eq Faraday::Adapter::Patron
236
239
  end
237
- end
240
+ end unless jruby?
238
241
 
239
242
  context 'when the adapter can be detected', unless: jruby? do
240
243
  around do |example|
@@ -274,7 +277,7 @@ describe Elastic::Transport::Client do
274
277
  it 'sets the logger' do
275
278
  expect(handlers).to include(Faraday::Response::Logger)
276
279
  end
277
- end
280
+ end unless jruby?
278
281
  end
279
282
 
280
283
  shared_examples_for 'a client that extracts hosts' do
@@ -1263,6 +1266,8 @@ describe Elastic::Transport::Client do
1263
1266
  end
1264
1267
 
1265
1268
  context 'when the Faraday adapter is set in the block' do
1269
+ require 'faraday/net_http_persistent' if is_faraday_v2?
1270
+
1266
1271
  let(:client) do
1267
1272
  Elastic::Transport::Client.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
1268
1273
  client.adapter(:net_http_persistent)
@@ -1414,6 +1419,8 @@ describe Elastic::Transport::Client do
1414
1419
  end
1415
1420
 
1416
1421
  context 'when using the HTTPClient adapter' do
1422
+ require 'faraday/httpclient'
1423
+
1417
1424
  let(:client) do
1418
1425
  described_class.new(hosts: ELASTICSEARCH_HOSTS, compression: true, adapter: :httpclient, enable_meta_header: false)
1419
1426
  end
@@ -155,7 +155,7 @@ describe Elastic::Transport::Client do
155
155
  expect(headers).to include('x-elastic-client-meta' => meta)
156
156
 
157
157
  Typhoeus = @klass if was_required
158
- end unless jruby?
158
+ end
159
159
 
160
160
  it 'sets adapter in the meta header' do
161
161
  require 'typhoeus'
@@ -163,7 +163,7 @@ describe Elastic::Transport::Client do
163
163
  meta = "#{meta_header},ty=#{Typhoeus::VERSION}"
164
164
  expect(headers).to include('x-elastic-client-meta' => meta)
165
165
  end
166
- end
166
+ end unless jruby?
167
167
 
168
168
  unless jruby?
169
169
  let(:adapter) { :patron }
data/spec/spec_helper.rb CHANGED
@@ -74,6 +74,10 @@ def default_client
74
74
  $client ||= Elastic::Transport::Client.new(hosts: ELASTICSEARCH_HOSTS)
75
75
  end
76
76
 
77
+ def is_faraday_v2?
78
+ Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
79
+ end
80
+
77
81
  module Config
78
82
  def self.included(context)
79
83
  # Get the hosts to use to connect an elasticsearch client.
@@ -21,7 +21,7 @@ if JRUBY
21
21
  require 'elastic/transport/transport/http/manticore'
22
22
 
23
23
  class Elastic::Transport::ClientManticoreIntegrationTest < Minitest::Test
24
- context "Transport" do
24
+ context 'Transport' do
25
25
  setup do
26
26
  uri = URI(HOST)
27
27
  @host = {
@@ -18,9 +18,8 @@
18
18
  require 'test_helper'
19
19
 
20
20
  class Elastic::Transport::ClientIntegrationTest < Minitest::Test
21
- context "Transport" do
21
+ context 'Transport' do
22
22
  setup do
23
- begin; Object.send(:remove_const, :Patron); rescue NameError; end
24
23
  uri = URI(HOST)
25
24
  @host = {
26
25
  host: uri.host,
@@ -30,69 +29,116 @@ class Elastic::Transport::ClientIntegrationTest < Minitest::Test
30
29
  }
31
30
  end
32
31
 
33
- should "allow to customize the Faraday adapter to Typhoeus" do
34
- require 'typhoeus'
35
- require 'typhoeus/adapters/faraday'
36
-
32
+ should 'use the default Faraday adapter' do
37
33
  transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
38
34
  f.response :logger
39
- f.adapter :typhoeus
40
35
  end
41
36
 
42
37
  client = Elastic::Transport::Client.new(transport: transport)
38
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttp)
43
39
  client.perform_request 'GET', ''
44
- end unless jruby?
40
+ end
45
41
 
46
- should "allow to customize the Faraday adapter to NetHttpPersistent" do
47
- require 'net/http/persistent'
42
+ unless jruby?
43
+ should 'allow to customize the Faraday adapter to Typhoeus' do
44
+ if is_faraday_v2?
45
+ require 'faraday/typhoeus'
46
+ else
47
+ require 'typhoeus'
48
+ end
49
+
50
+ transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
51
+ f.response :logger
52
+ f.adapter :typhoeus
53
+ end
54
+
55
+ client = Elastic::Transport::Client.new(transport: transport)
56
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Typhoeus)
57
+ client.perform_request 'GET', ''
58
+ end
48
59
 
49
- transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
50
- f.response :logger
51
- f.adapter :net_http_persistent
60
+ should 'use the Curb client' do
61
+ require 'curb'
62
+ require 'elastic/transport/transport/http/curb'
63
+
64
+ transport = Elastic::Transport::Transport::HTTP::Curb.new(hosts: [@host]) do |curl|
65
+ curl.verbose = true
66
+ end
67
+
68
+ client = Elastic::Transport::Client.new(transport: transport)
69
+ assert_equal(client.transport.class, Elastic::Transport::Transport::HTTP::Curb)
70
+ client.perform_request 'GET', ''
52
71
  end
53
72
 
54
- client = Elastic::Transport::Client.new(transport: transport)
55
- client.perform_request 'GET', ''
56
- end
73
+ should 'deserialize JSON responses in the Curb client' do
74
+ require 'curb'
75
+ require 'elastic/transport/transport/http/curb'
57
76
 
58
- should "allow to define connection parameters and pass them" do
59
- transport = Elastic::Transport::Transport::HTTP::Faraday.new(
60
- hosts: [@host],
61
- options: { transport_options: { params: { format: 'yaml' } } }
62
- )
77
+ transport = Elastic::Transport::Transport::HTTP::Curb.new(hosts: [@host]) do |curl|
78
+ curl.verbose = true
79
+ end
63
80
 
64
- client = Elastic::Transport::Client.new transport: transport
65
- response = client.perform_request 'GET', ''
81
+ client = Elastic::Transport::Client.new(transport: transport)
82
+ response = client.perform_request 'GET', ''
66
83
 
67
- assert response.body.start_with?("---\n"), "Response body should be YAML: #{response.body.inspect}"
84
+ assert_respond_to(response.body, :to_hash)
85
+ assert_not_nil response.body['name']
86
+ assert_equal 'application/json', response.headers['content-type']
87
+ assert_equal 'Elasticsearch', response.headers['x-elastic-product']
88
+ end
89
+
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 = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
97
+ f.response :logger
98
+ f.adapter :patron
99
+ end
100
+
101
+ client = Elastic::Transport::Client.new(transport: transport)
102
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::Patron)
103
+ client.perform_request 'GET', ''
104
+ end
68
105
  end
69
106
 
70
- should "use the Curb client" do
71
- require 'curb'
72
- require 'elastic/transport/transport/http/curb'
107
+ should 'allow to customize the Faraday adapter to NetHttpPersistent' do
108
+ require 'faraday/net_http_persistent'
73
109
 
74
- transport = Elastic::Transport::Transport::HTTP::Curb.new(hosts: [@host]) do |curl|
75
- curl.verbose = true
110
+ transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
111
+ f.response :logger
112
+ f.adapter :net_http_persistent
76
113
  end
77
114
 
78
115
  client = Elastic::Transport::Client.new(transport: transport)
116
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::NetHttpPersistent)
79
117
  client.perform_request 'GET', ''
80
- end unless JRUBY
118
+ end
81
119
 
82
- should "deserialize JSON responses in the Curb client" do
83
- require 'curb'
84
- require 'elastic/transport/transport/http/curb'
120
+ should 'allow to customize the Faraday adapter to HTTPClient' do
121
+ require 'faraday/httpclient'
85
122
 
86
- transport = Elastic::Transport::Transport::HTTP::Curb.new(hosts: [@host]) do |curl|
87
- curl.verbose = true
123
+ transport = Elastic::Transport::Transport::HTTP::Faraday.new(hosts: [@host]) do |f|
124
+ f.response :logger
125
+ f.adapter :httpclient
88
126
  end
89
127
 
90
128
  client = Elastic::Transport::Client.new(transport: transport)
91
- response = client.perform_request 'GET', ''
129
+ assert_equal(client.transport.connections.first.connection.adapter, Faraday::Adapter::HTTPClient)
130
+ client.perform_request 'GET', ''
131
+ end
92
132
 
93
- assert_respond_to(response.body, :to_hash)
94
- assert_not_nil response.body['name']
95
- assert_equal 'application/json', response.headers['content-type']
96
- end unless jruby?
133
+ should 'allow to define connection parameters and pass them' do
134
+ transport = Elastic::Transport::Transport::HTTP::Faraday.new(
135
+ hosts: [@host],
136
+ options: { transport_options: { params: { format: 'yaml' } } }
137
+ )
138
+
139
+ client = Elastic::Transport::Client.new transport: transport
140
+ response = client.perform_request 'GET', ''
141
+ assert response.body.start_with?("---\n"), "Response body should be YAML: #{response.body.inspect}"
142
+ end
97
143
  end
98
144
  end
data/test/test_helper.rb CHANGED
@@ -14,6 +14,7 @@
14
14
  # KIND, either express or implied. See the License for the
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
+ require 'uri'
17
18
 
18
19
  password = ENV['ELASTIC_PASSWORD'] || 'changeme'
19
20
  host = ENV['TEST_ES_SERVER'] || 'http://localhost:9200'
@@ -29,17 +30,16 @@ if ENV['COVERAGE']
29
30
  SimpleCov.start { add_filter %r{^/test/} }
30
31
  end
31
32
 
33
+ require 'ansi/code'
32
34
  require 'minitest/autorun'
33
35
  require 'minitest/reporters'
34
- require 'shoulda/context'
35
36
  require 'mocha/minitest'
36
- require 'ansi/code'
37
+ require 'shoulda/context'
37
38
 
38
- require 'require-prof' if ENV["REQUIRE_PROF"]
39
39
  require 'elastic-transport'
40
- require 'logger'
41
-
42
40
  require 'hashie'
41
+ require 'logger'
42
+ require 'require-prof' if ENV["REQUIRE_PROF"]
43
43
 
44
44
  RequireProf.print_timing_infos if ENV["REQUIRE_PROF"]
45
45
 
@@ -80,4 +80,8 @@ module Minitest
80
80
  end
81
81
  end
82
82
 
83
+ def is_faraday_v2?
84
+ Gem::Version.new(Faraday::VERSION) >= Gem::Version.new(2)
85
+ end
86
+
83
87
  Minitest::Reporters.use! FixedMinitestSpecReporter.new
@@ -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 Elastic::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 = Elastic::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 = Elastic::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 = Elastic::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 = Elastic::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 = Elastic::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
@@ -83,11 +83,10 @@ else
83
83
  should "set application/json response header" do
84
84
  @transport.connections.first.connection.expects(:http).with(:GET).returns(stub_everything)
85
85
  @transport.connections.first.connection.expects(:body_str).returns('{"foo":"bar"}')
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')
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")
87
87
 
88
88
  response = @transport.perform_request 'GET', '/'
89
-
90
- assert_equal 'application/json', response.headers['content-type']
89
+ assert_equal 'application/json; charset=UTF-8', response.headers['content-type']
91
90
  end
92
91
 
93
92
  should "handle HTTP methods" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.1
4
+ version: 8.1.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
@@ -10,10 +10,10 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-05-12 00:00:00.000000000 Z
13
+ date: 2022-08-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: multi_json
16
+ name: faraday
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - ">="
@@ -27,27 +27,13 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  - !ruby/object:Gem::Dependency
30
- name: faraday
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - "~>"
34
- - !ruby/object:Gem::Version
35
- version: '1'
36
- type: :runtime
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '1'
43
- - !ruby/object:Gem::Dependency
44
- name: bundler
30
+ name: multi_json
45
31
  requirement: !ruby/object:Gem::Requirement
46
32
  requirements:
47
33
  - - ">="
48
34
  - !ruby/object:Gem::Version
49
35
  version: '0'
50
- type: :development
36
+ type: :runtime
51
37
  prerelease: false
52
38
  version_requirements: !ruby/object:Gem::Requirement
53
39
  requirements:
@@ -55,7 +41,7 @@ dependencies:
55
41
  - !ruby/object:Gem::Version
56
42
  version: '0'
57
43
  - !ruby/object:Gem::Dependency
58
- name: cane
44
+ name: curb
59
45
  requirement: !ruby/object:Gem::Requirement
60
46
  requirements:
61
47
  - - ">="
@@ -69,7 +55,7 @@ dependencies:
69
55
  - !ruby/object:Gem::Version
70
56
  version: '0'
71
57
  - !ruby/object:Gem::Dependency
72
- name: curb
58
+ name: bundler
73
59
  requirement: !ruby/object:Gem::Requirement
74
60
  requirements:
75
61
  - - ">="
@@ -83,7 +69,7 @@ dependencies:
83
69
  - !ruby/object:Gem::Version
84
70
  version: '0'
85
71
  - !ruby/object:Gem::Dependency
86
- name: hashie
72
+ name: cane
87
73
  requirement: !ruby/object:Gem::Requirement
88
74
  requirements:
89
75
  - - ">="
@@ -97,7 +83,7 @@ dependencies:
97
83
  - !ruby/object:Gem::Version
98
84
  version: '0'
99
85
  - !ruby/object:Gem::Dependency
100
- name: httpclient
86
+ name: hashie
101
87
  requirement: !ruby/object:Gem::Requirement
102
88
  requirements:
103
89
  - - ">="
@@ -152,34 +138,6 @@ dependencies:
152
138
  - - ">="
153
139
  - !ruby/object:Gem::Version
154
140
  version: '0'
155
- - !ruby/object:Gem::Dependency
156
- name: net-http-persistent
157
- requirement: !ruby/object:Gem::Requirement
158
- requirements:
159
- - - ">="
160
- - !ruby/object:Gem::Version
161
- version: '0'
162
- type: :development
163
- prerelease: false
164
- version_requirements: !ruby/object:Gem::Requirement
165
- requirements:
166
- - - ">="
167
- - !ruby/object:Gem::Version
168
- version: '0'
169
- - !ruby/object:Gem::Dependency
170
- name: patron
171
- requirement: !ruby/object:Gem::Requirement
172
- requirements:
173
- - - ">="
174
- - !ruby/object:Gem::Version
175
- version: '0'
176
- type: :development
177
- prerelease: false
178
- version_requirements: !ruby/object:Gem::Requirement
179
- requirements:
180
- - - ">="
181
- - !ruby/object:Gem::Version
182
- version: '0'
183
141
  - !ruby/object:Gem::Dependency
184
142
  name: pry
185
143
  requirement: !ruby/object:Gem::Requirement
@@ -278,20 +236,6 @@ dependencies:
278
236
  - - "~>"
279
237
  - !ruby/object:Gem::Version
280
238
  version: '2'
281
- - !ruby/object:Gem::Dependency
282
- name: typhoeus
283
- requirement: !ruby/object:Gem::Requirement
284
- requirements:
285
- - - "~>"
286
- - !ruby/object:Gem::Version
287
- version: '1.4'
288
- type: :development
289
- prerelease: false
290
- version_requirements: !ruby/object:Gem::Requirement
291
- requirements:
292
- - - "~>"
293
- - !ruby/object:Gem::Version
294
- version: '1.4'
295
239
  - !ruby/object:Gem::Dependency
296
240
  name: yard
297
241
  requirement: !ruby/object:Gem::Requirement
@@ -325,6 +269,7 @@ files:
325
269
  - ".gitignore"
326
270
  - CHANGELOG.md
327
271
  - Gemfile
272
+ - Gemfile-faraday1.gemfile
328
273
  - LICENSE
329
274
  - README.md
330
275
  - Rakefile
@@ -361,6 +306,7 @@ files:
361
306
  - test/integration/transport_test.rb
362
307
  - test/profile/client_benchmark_test.rb
363
308
  - test/test_helper.rb
309
+ - test/unit/adapters_test.rb
364
310
  - test/unit/connection_test.rb
365
311
  - test/unit/response_test.rb
366
312
  - test/unit/serializer_test.rb
@@ -388,11 +334,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
388
334
  version: '2.5'
389
335
  required_rubygems_version: !ruby/object:Gem::Requirement
390
336
  requirements:
391
- - - ">="
337
+ - - ">"
392
338
  - !ruby/object:Gem::Version
393
- version: '0'
339
+ version: 1.3.1
394
340
  requirements: []
395
- rubygems_version: 3.3.3
341
+ rubygems_version: 3.3.7
396
342
  signing_key:
397
343
  specification_version: 4
398
344
  summary: Low level Ruby client for Elastic services.
@@ -411,6 +357,7 @@ test_files:
411
357
  - test/integration/transport_test.rb
412
358
  - test/profile/client_benchmark_test.rb
413
359
  - test/test_helper.rb
360
+ - test/unit/adapters_test.rb
414
361
  - test/unit/connection_test.rb
415
362
  - test/unit/response_test.rb
416
363
  - test/unit/serializer_test.rb