Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 8.3.3 #83

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 8.3.3

- Small updates in source code documentation.
- Updates meta header for Elasticsearch Serverless.

## 8.3.2

- OpenTelemetry: In v8.3.0 and v8.3.1, the environment variable `OTEL_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY` was available but is now deprecated in favor of `OTEL_RUBY_INSTRUMENTATION_ELASTICSEARCH_CAPTURE_SEARCH_QUERY`.
Expand Down
2 changes: 1 addition & 1 deletion lib/elastic/transport/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

module Elastic
module Transport
VERSION = '8.3.2'.freeze
VERSION = '8.3.3'.freeze
end
end
72 changes: 35 additions & 37 deletions test/unit/connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,66 +20,66 @@
class Elastic::Transport::Transport::Connections::ConnectionTest < Minitest::Test
include Elastic::Transport::Transport::Connections

context "Connection" do
should "be initialized with :host, :connection, and :options" do
context 'Connection' do
should 'be initialized with :host, :connection, and :options' do
c = Connection.new :host => 'x', :connection => 'y', :options => {}
assert_equal 'x', c.host
assert_equal 'y', c.connection
assert_instance_of Hash, c.options
end

should "return full path" do
should 'return full path' do
c = Connection.new
assert_equal '_search', c.full_path('_search')
assert_equal '_search', c.full_path('_search', {})
assert_equal '_search?foo=bar', c.full_path('_search', {:foo => 'bar'})
assert_equal '_search?foo=bar+bam', c.full_path('_search', {:foo => 'bar bam'})
assert_equal '_search?foo=bar', c.full_path('_search', {foo: 'bar'})
assert_equal '_search?foo=bar+bam', c.full_path('_search', {foo: 'bar bam'})
end

should "return full url" do
c = Connection.new :host => { :protocol => 'http', :host => 'localhost', :port => '9200' }
assert_equal 'http://localhost:9200/_search?foo=bar', c.full_url('_search', {:foo => 'bar'})
should 'return full url' do
c = Connection.new host: { protocol: 'http', host: 'localhost', port: '9200' }
assert_equal 'http://localhost:9200/_search?foo=bar', c.full_url('_search', { foo: 'bar' })
end

should "return full url with credentials" do
c = Connection.new :host => { :protocol => 'http', :user => 'U', :password => 'P', :host => 'localhost', :port => '9200' }
assert_equal 'http://U:P@localhost:9200/_search?foo=bar', c.full_url('_search', {:foo => 'bar'})
should 'return full url with credentials' do
c = Connection.new host: { protocol: 'http', user: 'U', password: 'P', host: 'localhost', port: '9200' }
assert_equal 'http://U:P@localhost:9200/_search?foo=bar', c.full_url('_search', { foo: 'bar' })
end

should "return full url with escaped credentials" do
c = Connection.new :host => { :protocol => 'http', :user => 'U$$$', :password => 'P^^^', :host => 'localhost', :port => '9200' }
assert_equal 'http://U%24%24%24:P%5E%5E%5E@localhost:9200/_search?foo=bar', c.full_url('_search', {:foo => 'bar'})
should 'return full url with escaped credentials' do
c = Connection.new host: { protocol: 'http', user: 'U$$$', password: 'P^^^', host: 'localhost', port: '9200' }
assert_equal 'http://U%24%24%24:P%5E%5E%5E@localhost:9200/_search?foo=bar', c.full_url('_search', { foo: 'bar' })
end

should "return full url with path" do
c = Connection.new :host => { :protocol => 'http', :host => 'localhost', :port => '9200', :path => '/foo' }
assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('_search', {:foo => 'bar'})
should 'return full url with path' do
c = Connection.new host: { protocol: 'http', host: 'localhost', port: '9200', path: '/foo' }
assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('_search', { foo: 'bar' })
end

should "return right full url with path when path starts with /" do
c = Connection.new :host => { :protocol => 'http', :host => 'localhost', :port => '9200', :path => '/foo' }
assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('/_search', {:foo => 'bar'})
should 'return right full url with path when path starts with /' do
c = Connection.new host: { protocol: 'http', host: 'localhost', port: '9200', path: '/foo' }
assert_equal 'http://localhost:9200/foo/_search?foo=bar', c.full_url('/_search', { foo: 'bar' })
end

should "have a string representation" do
c = Connection.new :host => 'x'
should 'have a string representation' do
c = Connection.new(host: 'x')
assert_match(/host: x/, c.to_s)
assert_match(/alive/, c.to_s)
end

should "not be dead by default" do
should 'not be dead by default' do
c = Connection.new
assert ! c.dead?
end

should "be dead when marked" do
should 'be dead when marked' do
c = Connection.new.dead!
assert c.dead?
assert_equal 1, c.failures
assert_in_delta c.dead_since, Time.now, 1
end

should "be alive when marked" do
should 'be alive when marked' do
c = Connection.new.dead!
assert c.dead?
assert_equal 1, c.failures
Expand All @@ -90,7 +90,7 @@ class Elastic::Transport::Transport::Connections::ConnectionTest < Minitest::Tes
assert_equal 1, c.failures
end

should "be healthy when marked" do
should 'be healthy when marked' do
c = Connection.new.dead!
assert c.dead?
assert_equal 1, c.failures
Expand All @@ -101,35 +101,33 @@ class Elastic::Transport::Transport::Connections::ConnectionTest < Minitest::Tes
assert_equal 0, c.failures
end

should "be resurrected if timeout passed" do
should 'be resurrected if timeout passed' do
c = Connection.new.dead!

now = Time.now + 60
Time.stubs(:now).returns(now)

assert c.resurrect!, c.inspect
assert ! c.dead?, c.inspect
assert(c.resurrect!, c.inspect)
assert(!c.dead?, c.inspect)
end

should "be resurrected if timeout passed for multiple failures" do
should 'be resurrected if timeout passed for multiple failures' do
c = Connection.new.dead!.dead!

now = Time.now + 60*2
now = Time.now + 60 * 2
Time.stubs(:now).returns(now)

assert c.resurrect!, c.inspect
assert ! c.dead?, c.inspect
end

should "implement the equality operator" do
c1 = Connection.new(:host => { :protocol => 'http', :host => 'foo', :port => 123 })
c2 = Connection.new(:host => { :protocol => 'http', :host => 'foo', :port => 123 })
c3 = Connection.new(:host => { :protocol => 'http', :host => 'foo', :port => 456 })
should 'implement the equality operator' do
c1 = Connection.new(host: { protocol: 'http', host: 'foo', port: 123 })
c2 = Connection.new(host: { protocol: 'http', host: 'foo', port: 123 })
c3 = Connection.new(host: { protocol: 'http', host: 'foo', port: 456 })

assert c1 == c2, "Connection #{c1} should be equal to #{c2}"
assert c2 != c3, "Connection #{c2} should NOT be equal to #{c3}"
end

end

end