use copy-on-write list in InMemoryAppender (#8808)

* use copy-on-write synchronized list in InMemoryAppender

* use copy-on-write list in InMemoryAppender

* Fix comment
This commit is contained in:
Zhenxiao Luo 2019-11-07 10:11:40 -08:00 committed by Roman Leventov
parent 517c14632e
commit fca23d0c32
1 changed files with 5 additions and 5 deletions

View File

@ -28,9 +28,8 @@ import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.junit.rules.ExternalResource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* JUnit rule to capture a class's logger output to an in-memory buffer to allow verification of log messages in tests.
@ -78,12 +77,13 @@ public class LoggerCaptureRule extends ExternalResource
{
static final String NAME = InMemoryAppender.class.getName();
private final List<LogEvent> logEvents;
// logEvents has concurrent iteration and modification in CuratorModuleTest::exitsJvmWhenMaxRetriesExceeded(), needs to be thread safe
private final CopyOnWriteArrayList<LogEvent> logEvents;
InMemoryAppender()
{
super(NAME, null, null);
logEvents = new ArrayList<>();
logEvents = new CopyOnWriteArrayList<>();
}
@Override
@ -94,7 +94,7 @@ public class LoggerCaptureRule extends ExternalResource
List<LogEvent> getLogEvents()
{
return Collections.unmodifiableList(logEvents);
return logEvents;
}
void clearLogEvents()