Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use copy-on-write list in InMemoryAppender #8808

Merged
merged 3 commits into from
Nov 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
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.
Expand Down Expand Up @@ -78,12 +77,13 @@ private static class InMemoryAppender extends AbstractAppender
{
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
Expand All @@ -94,7 +94,7 @@ public void append(LogEvent logEvent)

List<LogEvent> getLogEvents()
{
return Collections.unmodifiableList(logEvents);
return logEvents;
}

void clearLogEvents()
Expand Down