Skip to content

Commit

Permalink
Ensure JULBridgeTests resets root logging level after test (#100441)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira authored Oct 6, 2023
1 parent f0f86a1 commit 7ab9c67
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
import org.junit.BeforeClass;

import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.instanceOf;

public class JULBridgeTests extends ESTestCase {

private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger("");
private static java.util.logging.Level savedLevel;
private static java.util.logging.Handler[] savedHandlers;
private static Handler[] savedHandlers;

@BeforeClass
public static void saveLoggerState() {
Expand Down Expand Up @@ -60,17 +60,20 @@ public static void restoreLoggerState() {

private void assertLogged(Runnable loggingCode, LoggingExpectation... expectations) {
Logger testLogger = LogManager.getLogger("");
Loggers.setLevel(testLogger, Level.ALL);
Level savedLevel = testLogger.getLevel();
MockLogAppender mockAppender = new MockLogAppender();
mockAppender.start();

try {
Loggers.setLevel(testLogger, Level.ALL);
mockAppender.start();
Loggers.addAppender(testLogger, mockAppender);
for (var expectation : expectations) {
mockAppender.addExpectation(expectation);
}
loggingCode.run();
mockAppender.assertAllExpectationsMatched();
} finally {
Loggers.setLevel(testLogger, savedLevel);
Loggers.removeAppender(testLogger, mockAppender);
mockAppender.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.util.SetOnce;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ActionListener;
Expand Down Expand Up @@ -228,7 +227,6 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.Mockito.mock;

@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/100434")
public class SnapshotResiliencyTests extends ESTestCase {

private DeterministicTaskQueue deterministicTaskQueue;
Expand Down

0 comments on commit 7ab9c67

Please sign in to comment.