diff --git a/.travis.yml b/.travis.yml index 6791508b4..4199554dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,22 +25,18 @@ matrix: jdk: oraclejdk8 env: RAILS_VERSIONS=3.0 - - rvm: 2.3 + - rvm: 2.3.8 jdk: oraclejdk8 env: RAILS_VERSIONS=5.0 - - rvm: 2.4 + - rvm: 2.6.1 jdk: oraclejdk8 - env: RAILS_VERSIONS=5.0 + env: RAILS_VERSIONS=4.0,5.0 - - rvm: jruby-9.1 + - rvm: jruby-9.2.5.0 jdk: oraclejdk8 env: RAILS_VERSIONS=5.0 - - rvm: 2.5 - jdk: oraclejdk8 - env: RAILS_VERSIONS=4.0,5.0 - env: global: - ELASTICSEARCH_VERSION=6.4.0 @@ -53,8 +49,8 @@ before_install: - shasum -a 512 -c elasticsearch-${ELASTICSEARCH_VERSION}.deb.sha512 - sudo dpkg -i --force-confnew elasticsearch-${ELASTICSEARCH_VERSION}.deb - sudo service elasticsearch start - - gem update --system -q - - gem update bundler -q + - gem update --system + - gem update bundler - gem --version - bundle version diff --git a/elasticsearch-model/lib/elasticsearch/model/indexing.rb b/elasticsearch-model/lib/elasticsearch/model/indexing.rb index 0fb5ff862..a88dd12fb 100644 --- a/elasticsearch-model/lib/elasticsearch/model/indexing.rb +++ b/elasticsearch-model/lib/elasticsearch/model/indexing.rb @@ -269,7 +269,8 @@ def delete_index!(options={}) self.client.indices.delete index: target_index rescue Exception => e if e.class.to_s =~ /NotFound/ && options[:force] - STDERR.puts "[!!!] Index does not exist (#{e.class})" + client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger + nil else raise e end @@ -295,7 +296,8 @@ def refresh_index!(options={}) self.client.indices.refresh index: target_index rescue Exception => e if e.class.to_s =~ /NotFound/ && options[:force] - STDERR.puts "[!!!] Index does not exist (#{e.class})" + client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger + nil else raise e end diff --git a/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb b/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb index 7040d4992..54656d4df 100644 --- a/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb @@ -612,7 +612,7 @@ class ::DummyIndexingModelForRecreate context 'when the index is not found' do let(:client) do - double('client', indices: indices) + double('client', indices: indices, transport: double('transport', { logger: nil })) end let(:indices) do @@ -622,7 +622,7 @@ class ::DummyIndexingModelForRecreate end before do - expect(DummyIndexingModelForRecreate).to receive(:client).and_return(client) + expect(DummyIndexingModelForRecreate).to receive(:client).at_most(3).times.and_return(client) end context 'when the force option is true' do @@ -630,6 +630,26 @@ class ::DummyIndexingModelForRecreate it 'deletes the index without raising an exception' do expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil end + + context 'when the client has a logger' do + + let(:logger) do + Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG } + end + + let(:client) do + double('client', indices: indices, transport: double('transport', { logger: logger })) + end + + it 'deletes the index without raising an exception' do + expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil + end + + it 'logs the message that the index is not found' do + expect(logger).to receive(:debug) + expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil + end + end end context 'when the force option is not provided' do @@ -799,6 +819,8 @@ class ::DummyIndexingModelForCreate expect(DummyIndexingModelForCreate.create_index!(index: 'custom-foo')) end end + + context 'when the logging level is debug' end describe '#refresh_index!' do @@ -824,7 +846,7 @@ class ::DummyIndexingModelForRefresh end let(:client) do - double('client', indices: indices) + double('client', indices: indices, transport: double('transport', { logger: nil })) end let(:indices) do @@ -832,7 +854,7 @@ class ::DummyIndexingModelForRefresh end before do - expect(DummyIndexingModelForRefresh).to receive(:client).and_return(client) + expect(DummyIndexingModelForRefresh).to receive(:client).at_most(3).times.and_return(client) end context 'when the force option is true' do @@ -846,6 +868,26 @@ class ::DummyIndexingModelForRefresh it 'does not raise an exception' do expect(DummyIndexingModelForRefresh.refresh_index!(force: true)).to be_nil end + + context 'when the client has a logger' do + + let(:logger) do + Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG } + end + + let(:client) do + double('client', indices: indices, transport: double('transport', { logger: logger })) + end + + it 'does not raise an exception' do + expect(DummyIndexingModelForRefresh.refresh_index!(force: true)).to be_nil + end + + it 'logs the message that the index is not found' do + expect(logger).to receive(:debug) + expect(DummyIndexingModelForRefresh.refresh_index!(force: true)).to be_nil + end + end end context 'when the operation raises another type of exception' do