Skip to content

Commit c73c5a4

Browse files
authored
[MODEL] Use logger to log index not found message (#868)
* [MODEL] Use logger to log index not found message * [CI] Remove Gemfile.lock on Travis * [CI] Update Travis matrix
1 parent bb1fc82 commit c73c5a4

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=6.4.0
@@ -53,8 +49,8 @@ before_install:
5349
- shasum -a 512 -c elasticsearch-${ELASTICSEARCH_VERSION}.deb.sha512
5450
- sudo dpkg -i --force-confnew elasticsearch-${ELASTICSEARCH_VERSION}.deb
5551
- sudo service elasticsearch start
56-
- gem update --system -q
57-
- gem update bundler -q
52+
- gem update --system
53+
- gem update bundler
5854
- gem --version
5955
- bundle version
6056

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ def delete_index!(options={})
269269
self.client.indices.delete index: target_index
270270
rescue Exception => e
271271
if e.class.to_s =~ /NotFound/ && options[:force]
272-
STDERR.puts "[!!!] Index does not exist (#{e.class})"
272+
client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger
273+
nil
273274
else
274275
raise e
275276
end
@@ -295,7 +296,8 @@ def refresh_index!(options={})
295296
self.client.indices.refresh index: target_index
296297
rescue Exception => e
297298
if e.class.to_s =~ /NotFound/ && options[:force]
298-
STDERR.puts "[!!!] Index does not exist (#{e.class})"
299+
client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger
300+
nil
299301
else
300302
raise e
301303
end

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

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

614614
let(:client) do
615-
double('client', indices: indices)
615+
double('client', indices: indices, transport: double('transport', { logger: nil }))
616616
end
617617

618618
let(:indices) do
@@ -622,14 +622,34 @@ class ::DummyIndexingModelForRecreate
622622
end
623623

624624
before do
625-
expect(DummyIndexingModelForRecreate).to receive(:client).and_return(client)
625+
expect(DummyIndexingModelForRecreate).to receive(:client).at_most(3).times.and_return(client)
626626
end
627627

628628
context 'when the force option is true' do
629629

630630
it 'deletes the index without raising an exception' do
631631
expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil
632632
end
633+
634+
context 'when the client has a logger' do
635+
636+
let(:logger) do
637+
Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG }
638+
end
639+
640+
let(:client) do
641+
double('client', indices: indices, transport: double('transport', { logger: logger }))
642+
end
643+
644+
it 'deletes the index without raising an exception' do
645+
expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil
646+
end
647+
648+
it 'logs the message that the index is not found' do
649+
expect(logger).to receive(:debug)
650+
expect(DummyIndexingModelForRecreate.delete_index!(force: true)).to be_nil
651+
end
652+
end
633653
end
634654

635655
context 'when the force option is not provided' do
@@ -799,6 +819,8 @@ class ::DummyIndexingModelForCreate
799819
expect(DummyIndexingModelForCreate.create_index!(index: 'custom-foo'))
800820
end
801821
end
822+
823+
context 'when the logging level is debug'
802824
end
803825

804826
describe '#refresh_index!' do
@@ -824,15 +846,15 @@ class ::DummyIndexingModelForRefresh
824846
end
825847

826848
let(:client) do
827-
double('client', indices: indices)
849+
double('client', indices: indices, transport: double('transport', { logger: nil }))
828850
end
829851

830852
let(:indices) do
831853
double('indices')
832854
end
833855

834856
before do
835-
expect(DummyIndexingModelForRefresh).to receive(:client).and_return(client)
857+
expect(DummyIndexingModelForRefresh).to receive(:client).at_most(3).times.and_return(client)
836858
end
837859

838860
context 'when the force option is true' do
@@ -846,6 +868,26 @@ class ::DummyIndexingModelForRefresh
846868
it 'does not raise an exception' do
847869
expect(DummyIndexingModelForRefresh.refresh_index!(force: true)).to be_nil
848870
end
871+
872+
context 'when the client has a logger' do
873+
874+
let(:logger) do
875+
Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG }
876+
end
877+
878+
let(:client) do
879+
double('client', indices: indices, transport: double('transport', { logger: logger }))
880+
end
881+
882+
it 'does not raise an exception' do
883+
expect(DummyIndexingModelForRefresh.refresh_index!(force: true)).to be_nil
884+
end
885+
886+
it 'logs the message that the index is not found' do
887+
expect(logger).to receive(:debug)
888+
expect(DummyIndexingModelForRefresh.refresh_index!(force: true)).to be_nil
889+
end
890+
end
849891
end
850892

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

0 commit comments

Comments
 (0)