From 3a4ffd7b86fcbbe878540610fe61be0c730148a6 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 30 Sep 2016 08:09:35 +0200 Subject: [PATCH] Fix failing logging listener tests The logging listener tests started failing after 953a8a959b6c116d99ff41cb329adfcbbca94269 when the tests are run with tests.es.logger.level set to any level other than debug. This is because these tests were based around the assumption that the default logging level was info, which was the case before that commit fixed setting the default logging level via that system property. This commit fixes these failing tests by adjusting this assumption to account for the fact that the default logging level could be different. --- .../test/test/LoggingListenerTests.java | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/test/framework/src/test/java/org/elasticsearch/test/test/LoggingListenerTests.java b/test/framework/src/test/java/org/elasticsearch/test/test/LoggingListenerTests.java index 2d428202741..f5f1cb77a73 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/test/LoggingListenerTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/test/LoggingListenerTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.test.test; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Logger; +import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.junit.annotations.TestLogging; @@ -50,27 +51,28 @@ public class LoggingListenerTests extends ESTestCase { Logger xyzLogger = Loggers.getLogger("xyz"); Logger abcLogger = Loggers.getLogger("abc"); - assertEquals(Level.INFO, abcLogger.getLevel()); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); - assertThat(abcLogger.getLevel(), equalTo(Level.INFO)); + final Level level = ESLoggerFactory.getRootLogger().getLevel(); + + assertThat(xyzLogger.getLevel(), equalTo(level)); + assertThat(abcLogger.getLevel(), equalTo(level)); loggingListener.testRunStarted(suiteDescription); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); - assertThat(abcLogger.getLevel(), equalTo(Level.INFO)); + assertThat(xyzLogger.getLevel(), equalTo(level)); + assertThat(abcLogger.getLevel(), equalTo(level)); Method method = TestClass.class.getMethod("annotatedTestMethod"); TestLogging annotation = method.getAnnotation(TestLogging.class); Description testDescription = Description.createTestDescription(LoggingListenerTests.class, "annotatedTestMethod", annotation); loggingListener.testStarted(testDescription); assertThat(xyzLogger.getLevel(), equalTo(Level.TRACE)); - assertThat(abcLogger.getLevel(), equalTo(Level.INFO)); + assertThat(abcLogger.getLevel(), equalTo(level)); loggingListener.testFinished(testDescription); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); - assertThat(abcLogger.getLevel(), equalTo(Level.INFO)); + assertThat(xyzLogger.getLevel(), equalTo(level)); + assertThat(abcLogger.getLevel(), equalTo(level)); loggingListener.testRunFinished(new Result()); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); - assertThat(abcLogger.getLevel(), equalTo(Level.INFO)); + assertThat(xyzLogger.getLevel(), equalTo(level)); + assertThat(abcLogger.getLevel(), equalTo(level)); } public void testCustomLevelPerClass() throws Exception { @@ -81,24 +83,26 @@ public class LoggingListenerTests extends ESTestCase { Logger abcLogger = Loggers.getLogger("abc"); Logger xyzLogger = Loggers.getLogger("xyz"); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); - assertThat(abcLogger.getLevel(), equalTo(Level.INFO)); + final Level level = ESLoggerFactory.getRootLogger().getLevel(); + + assertThat(xyzLogger.getLevel(), equalTo(level)); + assertThat(abcLogger.getLevel(), equalTo(level)); loggingListener.testRunStarted(suiteDescription); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); + assertThat(xyzLogger.getLevel(), equalTo(level)); assertThat(abcLogger.getLevel(), equalTo(Level.WARN)); Description testDescription = Description.createTestDescription(LoggingListenerTests.class, "test"); loggingListener.testStarted(testDescription); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); + assertThat(xyzLogger.getLevel(), equalTo(level)); assertThat(abcLogger.getLevel(), equalTo(Level.WARN)); loggingListener.testFinished(testDescription); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); + assertThat(xyzLogger.getLevel(), equalTo(level)); assertThat(abcLogger.getLevel(), equalTo(Level.WARN)); loggingListener.testRunFinished(new Result()); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); - assertThat(abcLogger.getLevel(), equalTo(Level.INFO)); + assertThat(xyzLogger.getLevel(), equalTo(level)); + assertThat(abcLogger.getLevel(), equalTo(level)); } public void testCustomLevelPerClassAndPerMethod() throws Exception { @@ -109,10 +113,12 @@ public class LoggingListenerTests extends ESTestCase { Logger abcLogger = Loggers.getLogger("abc"); Logger xyzLogger = Loggers.getLogger("xyz"); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); - assertThat(abcLogger.getLevel(), equalTo(Level.INFO)); + final Level level = ESLoggerFactory.getRootLogger().getLevel(); + + assertThat(xyzLogger.getLevel(), equalTo(level)); + assertThat(abcLogger.getLevel(), equalTo(level)); loggingListener.testRunStarted(suiteDescription); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); + assertThat(xyzLogger.getLevel(), equalTo(level)); assertThat(abcLogger.getLevel(), equalTo(Level.WARN)); Method method = TestClass.class.getMethod("annotatedTestMethod"); @@ -123,7 +129,7 @@ public class LoggingListenerTests extends ESTestCase { assertThat(abcLogger.getLevel(), equalTo(Level.WARN)); loggingListener.testFinished(testDescription); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); + assertThat(xyzLogger.getLevel(), equalTo(level)); assertThat(abcLogger.getLevel(), equalTo(Level.WARN)); Method method2 = TestClass.class.getMethod("annotatedTestMethod2"); @@ -134,12 +140,12 @@ public class LoggingListenerTests extends ESTestCase { assertThat(abcLogger.getLevel(), equalTo(Level.TRACE)); loggingListener.testFinished(testDescription2); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); + assertThat(xyzLogger.getLevel(), equalTo(level)); assertThat(abcLogger.getLevel(), equalTo(Level.WARN)); loggingListener.testRunFinished(new Result()); - assertThat(xyzLogger.getLevel(), equalTo(Level.INFO)); - assertThat(abcLogger.getLevel(), equalTo(Level.INFO)); + assertThat(xyzLogger.getLevel(), equalTo(level)); + assertThat(abcLogger.getLevel(), equalTo(level)); } /**