diff --git a/logstash-core/spec/logstash/runner_spec.rb b/logstash-core/spec/logstash/runner_spec.rb index b0894edec5d..66e2652e247 100644 --- a/logstash-core/spec/logstash/runner_spec.rb +++ b/logstash-core/spec/logstash/runner_spec.rb @@ -263,8 +263,6 @@ let(:runner_deprecation_logger_stub) { double("DeprecationLogger(Runner)").as_null_object } before(:each) { allow(runner).to receive(:deprecation_logger).and_return(runner_deprecation_logger_stub) } - let(:configuration_spy) { configure_log_spy } - def configure_log_spy java_import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory java_import org.apache.logging.log4j.Level @@ -308,7 +306,10 @@ def configure_log_spy subject.run("bin/logstash", args) + expect(appender_spy.messages).not_to be_empty expect(appender_spy.messages[0]).to match(/`http.host` is a deprecated alias for `api.http.host`/) + + log_ctx.close end end diff --git a/logstash-core/spec/logstash/settings/setting_with_deprecated_alias_spec.rb b/logstash-core/spec/logstash/settings/setting_with_deprecated_alias_spec.rb index 3dc879824d7..168162ee088 100644 --- a/logstash-core/spec/logstash/settings/setting_with_deprecated_alias_spec.rb +++ b/logstash-core/spec/logstash/settings/setting_with_deprecated_alias_spec.rb @@ -27,22 +27,34 @@ let(:settings) { LogStash::Settings.new } let(:canonical_setting) { LogStash::Setting::StringSetting.new(canonical_setting_name, default_value, true) } - let(:log_ctx) { setup_logger_spy } - let(:log_spy) { retrieve_logger_spy(log_ctx) } + log_spy = nil + log_ctx = nil - before(:each) do - # Initialization of appender and logger use to spy, need to be done before executing any code that logs, - # that's the reason wy to refer the spying logger context before any test. - log_ctx + def log_ctx + @log_ctx + end + + def log_spy + @log_spy end before(:each) do + # Initialization of appender and logger use to spy, need to be freshly recreated on each test is context shutdown is used. + @log_ctx = setup_logger_spy + @log_spy = retrieve_logger_spy(@log_ctx) + allow(LogStash::Settings).to receive(:logger).and_return(double("SettingsLogger").as_null_object) allow(LogStash::Settings).to receive(:deprecation_logger).and_return(double("SettingsDeprecationLogger").as_null_object) settings.register(canonical_setting.with_deprecated_alias(deprecated_setting_name)) end + after(:each) do + @log_ctx.close + @log_spy = nil + @log_ctx = nil + end + shared_examples '#validate_value success' do context '#validate_value' do it "returns without raising" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5403b41cf78..4e0800d3330 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -93,21 +93,6 @@ def installed_plugins def setup_logger_spy - java_import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory - java_import org.apache.logging.log4j.Level - config_builder = ConfigurationBuilderFactory.newConfigurationBuilder - configure_log_spy = config_builder - .add( - config_builder - .newAppender("LOG_SPY", "List") - .add(config_builder.newLayout("PatternLayout").addAttribute("pattern", "%-5p [%t]: %m%n")) - ) - .add( - config_builder - .newRootLogger(Level::INFO) - .add(config_builder.newAppenderRef("LOG_SPY"))) - .build(false) - java_import org.apache.logging.log4j.core.config.Configurator java_import org.apache.logging.log4j.core.config.Configuration @@ -121,7 +106,25 @@ def setup_logger_spy expect(log_ctx).not_to be nil log_ctx.reconfigure(configure_log_spy) # force the programmatic configuration, without this it's not used - return log_ctx + log_ctx +end + +def configure_log_spy + java_import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory + java_import org.apache.logging.log4j.Level + config_builder = ConfigurationBuilderFactory.newConfigurationBuilder + configuration = config_builder + .add( + config_builder + .newAppender("LOG_SPY", "List") + .add(config_builder.newLayout("PatternLayout").addAttribute("pattern", "%-5p [%t]: %m%n")) + ) + .add( + config_builder + .newRootLogger(Level::INFO) + .add(config_builder.newAppenderRef("LOG_SPY"))) + .build(false) + configuration end def retrieve_logger_spy(log_ctx)