Fix failing logging listener tests
The logging listener tests started failing after
953a8a959b
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.
This commit is contained in:
parent
afcf683228
commit
3a4ffd7b86
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue