Skip to content

Commit 0059634

Browse files
committed
[MODEL] Use logger to log index not found message (elastic#868)
* [MODEL] Use logger to log index not found message * [CI] Remove Gemfile.lock on Travis * [CI] Update Travis matrix
1 parent 266b59c commit 0059634

File tree

3 files changed

+56
-16
lines changed

3 files changed

+56
-16
lines changed

.travis.yml

+6-10
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,18 @@ matrix:
2525
jdk: oraclejdk8
2626
env: RAILS_VERSIONS=3.0
2727

28-
- rvm: 2.3
28+
- rvm: 2.3.8
2929
jdk: oraclejdk8
3030
env: RAILS_VERSIONS=5.0
3131

32-
- rvm: 2.4
32+
- rvm: 2.6.1
3333
jdk: oraclejdk8
34-
env: RAILS_VERSIONS=5.0
34+
env: RAILS_VERSIONS=4.0,5.0
3535

36-
- rvm: jruby-9.1
36+
- rvm: jruby-9.2.5.0
3737
jdk: oraclejdk8
3838
env: RAILS_VERSIONS=5.0
3939

40-
- rvm: 2.5
41-
jdk: oraclejdk8
42-
env: RAILS_VERSIONS=4.0,5.0
43-
4440
env:
4541
global:
4642
- ELASTICSEARCH_VERSION=7.0.0
@@ -49,8 +45,8 @@ env:
4945

5046
before_install:
5147
- ELASTICSEARCH_VERSION=7.0.0 TEST_CLUSTER_PORT=9250 source ./travis_before_script.sh
52-
- gem update --system -q
53-
- gem update bundler -q
48+
- gem update --system
49+
- gem update bundler
5450
- gem --version
5551
- bundle version
5652

elasticsearch-model/lib/elasticsearch/model/indexing.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ def delete_index!(options={})
286286
self.client.indices.delete index: target_index
287287
rescue Exception => e
288288
if e.class.to_s =~ /NotFound/ && options[:force]
289-
STDERR.puts "[!!!] Index does not exist (#{e.class})"
289+
client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger
290+
nil
290291
else
291292
raise e
292293
end
@@ -312,7 +313,8 @@ def refresh_index!(options={})
312313
self.client.indices.refresh index: target_index
313314
rescue Exception => e
314315
if e.class.to_s =~ /NotFound/ && options[:force]
315-
STDERR.puts "[!!!] Index does not exist (#{e.class})"
316+
client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger
317+
nil
316318
else
317319
raise e
318320
end

elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb

+46-4
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ class ::DummyIndexingModelForRecreate
629629
context 'when the index is not found' do
630630

631631
let(:client) do
632-
double('client', indices: indices)
632+
double('client', indices: indices, transport: double('transport', { logger: nil }))
633633
end
634634

635635
let(:indices) do
@@ -639,14 +639,34 @@ class ::DummyIndexingModelForRecreate
639639
end
640640

641641
before do
642-
expect(DummyIndexingModelForRecreate).to receive(:client).and_return(client)
642+
expect(DummyIndexingModelForRecreate).to receive(:client).at_most(3).times.and_return(client)
643643
end
644644

645645
context 'when the force option is true' do
646646

647647
it 'deletes the index without raising an exception' do
648648
expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil
649649
end
650+
651+
context 'when the client has a logger' do
652+
653+
let(:logger) do
654+
Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG }
655+
end
656+
657+
let(:client) do
658+
double('client', indices: indices, transport: double('transport', { logger: logger }))
659+
end
660+
661+
it 'deletes the index without raising an exception' do
662+
expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil
663+
end
664+
665+
it 'logs the message that the index is not found' do
666+
expect(logger).to receive(:debug)
667+
expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil
668+
end
669+
end
650670
end
651671

652672
context 'when the force option is not provided' do
@@ -816,6 +836,8 @@ class ::DummyIndexingModelForCreate
816836
expect(DummyIndexingModelForCreate.create_index!(index: 'custom-foo'))
817837
end
818838
end
839+
840+
context 'when the logging level is debug'
819841
end
820842

821843
describe '#refresh_index!' do
@@ -841,15 +863,15 @@ class ::DummyIndexingModelForRefresh
841863
end
842864

843865
let(:client) do
844-
double('client', indices: indices)
866+
double('client', indices: indices, transport: double('transport', { logger: nil }))
845867
end
846868

847869
let(:indices) do
848870
double('indices')
849871
end
850872

851873
before do
852-
expect(DummyIndexingModelForRefresh).to receive(:client).and_return(client)
874+
expect(DummyIndexingModelForRefresh).to receive(:client).at_most(3).times.and_return(client)
853875
end
854876

855877
context 'when the force option is true' do
@@ -863,6 +885,26 @@ class ::DummyIndexingModelForRefresh
863885
it 'does not raise an exception' do
864886
expect(DummyIndexingModelForRefresh.refresh_index!(force: true)).to be_nil
865887
end
888+
889+
context 'when the client has a logger' do
890+
891+
let(:logger) do
892+
Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG }
893+
end
894+
895+
let(:client) do
896+
double('client', indices: indices, transport: double('transport', { logger: logger }))
897+
end
898+
899+
it 'does not raise an exception' do
900+
expect(DummyIndexingModelForRefresh.refresh_index!(force: true)).to be_nil
901+
end
902+
903+
it 'logs the message that the index is not found' do
904+
expect(logger).to receive(:debug)
905+
expect(DummyIndexingModelForRefresh.refresh_index!(force: true)).to be_nil
906+
end
907+
end
866908
end
867909

868910
context 'when the operation raises another type of exception' do

0 commit comments

Comments
 (0)