|
486 | 486 |
|
487 | 487 | context 'handling elasticsearch document-level status meant for the DLQ' do |
488 | 488 | let(:options) { { "manage_template" => false } } |
489 | | - let(:logger) { subject.instance_variable_get(:@logger) } |
490 | 489 |
|
491 | 490 | context 'when @dlq_writer is nil' do |
492 | 491 | before { subject.instance_variable_set '@dlq_writer', nil } |
493 | 492 |
|
494 | 493 | context 'resorting to previous behaviour of logging the error' do |
495 | 494 | context 'getting an invalid_index_name_exception' do |
496 | 495 | it 'should log at ERROR level' do |
497 | | - expect(logger).to receive(:error).with(/Could not index/, hash_including(:status, :action, :response)) |
| 496 | + subject.instance_variable_set(:@logger, double("logger").as_null_object) |
498 | 497 | mock_response = { 'index' => { 'error' => { 'type' => 'invalid_index_name_exception' } } } |
499 | 498 | subject.handle_dlq_status("Could not index event to Elasticsearch.", |
500 | 499 | [:action, :params, :event], :some_status, mock_response) |
|
503 | 502 |
|
504 | 503 | context 'when getting any other exception' do |
505 | 504 | it 'should log at WARN level' do |
506 | | - expect(logger).to receive(:warn).with(/Could not index/, hash_including(:status, :action, :response)) |
| 505 | + dlog = double_logger = double("logger").as_null_object |
| 506 | + subject.instance_variable_set(:@logger, dlog) |
| 507 | + expect(dlog).to receive(:warn).with(/Could not index/, hash_including(:status, :action, :response)) |
507 | 508 | mock_response = { 'index' => { 'error' => { 'type' => 'illegal_argument_exception' } } } |
508 | 509 | subject.handle_dlq_status("Could not index event to Elasticsearch.", |
509 | 510 | [:action, :params, :event], :some_status, mock_response) |
|
512 | 513 |
|
513 | 514 | context 'when the response does not include [error]' do |
514 | 515 | it 'should not fail, but just log a warning' do |
515 | | - expect(logger).to receive(:warn).with(/Could not index/, hash_including(:status, :action, :response)) |
| 516 | + dlog = double_logger = double("logger").as_null_object |
| 517 | + subject.instance_variable_set(:@logger, dlog) |
| 518 | + expect(dlog).to receive(:warn).with(/Could not index/, hash_including(:status, :action, :response)) |
516 | 519 | mock_response = { 'index' => {} } |
517 | 520 | expect do |
518 | 521 | subject.handle_dlq_status("Could not index event to Elasticsearch.", |
|
532 | 535 | # We should still log when sending to the DLQ. |
533 | 536 | # This shall be solved by another issue, however: logstash-output-elasticsearch#772 |
534 | 537 | it 'should send the event to the DLQ instead, and not log' do |
535 | | - expect(dlq_writer).to receive(:write).with(:event, /Could not index/) |
| 538 | + expect(dlq_writer).to receive(:write).once.with(:event, /Could not index/) |
536 | 539 | mock_response = { 'index' => { 'error' => { 'type' => 'illegal_argument_exception' } } } |
537 | 540 | subject.handle_dlq_status("Could not index event to Elasticsearch.", |
538 | 541 | [:action, :params, :event], :some_status, mock_response) |
|
0 commit comments