mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-24 23:27:25 -04:00
Make MockLogAppender itself Releasable (#108526)
Existing uses of MockLogAppender first construct an appender, then call capturing on the instance in a try-with-resources block. This commit adds a new method, capture, which creates an appender and sets up the capture the the same time. The intent is that this will replace the existing capturing calls, but there are too many to change in one PR.
This commit is contained in:
parent
05d728e3ef
commit
b02d06c2d2
5 changed files with 88 additions and 68 deletions
|
@ -206,16 +206,16 @@ public class SpawnerNoBootstrapTests extends LuceneTestCase {
|
|||
|
||||
String stdoutLoggerName = "test_plugin-controller-stdout";
|
||||
String stderrLoggerName = "test_plugin-controller-stderr";
|
||||
MockLogAppender appender = new MockLogAppender();
|
||||
Loggers.setLevel(LogManager.getLogger(stdoutLoggerName), Level.TRACE);
|
||||
Loggers.setLevel(LogManager.getLogger(stderrLoggerName), Level.TRACE);
|
||||
CountDownLatch messagesLoggedLatch = new CountDownLatch(2);
|
||||
if (expectSpawn) {
|
||||
appender.addExpectation(new ExpectedStreamMessage(stdoutLoggerName, "I am alive", messagesLoggedLatch));
|
||||
appender.addExpectation(new ExpectedStreamMessage(stderrLoggerName, "I am an error", messagesLoggedLatch));
|
||||
}
|
||||
|
||||
try (var ignore = appender.capturing(stdoutLoggerName, stderrLoggerName)) {
|
||||
try (var appender = MockLogAppender.capture(stdoutLoggerName, stderrLoggerName)) {
|
||||
if (expectSpawn) {
|
||||
appender.addExpectation(new ExpectedStreamMessage(stdoutLoggerName, "I am alive", messagesLoggedLatch));
|
||||
appender.addExpectation(new ExpectedStreamMessage(stderrLoggerName, "I am an error", messagesLoggedLatch));
|
||||
}
|
||||
|
||||
Spawner spawner = new Spawner();
|
||||
spawner.spawnNativeControllers(environment);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue