Skip to content
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 @@ -15,7 +15,7 @@
public class LogChecker {

private final LogExpectation expectation;
private int count = 0;
private volatile int count = 0;
private List<LogEvent> matchingEvents;
private List<LogEvent> extraEvents;

Expand Down Expand Up @@ -43,26 +43,30 @@ public void appendFailure(Description description, String newline) {
}
}

// This must be synchronized to avoid problems when multiple threads issue log events concurrently
synchronized void process(LogEvent event) {
void process(LogEvent event) {
if ( expectation.getMaxExpectedCount() == null && expectation.getMinExpectedCount() <= count ) {
// We don't care about events anymore, expectations are met and it won't change
return;
}
if ( expectation.getMatcher().matches( event ) ) {
++count;
if ( expectation.getMaxExpectedCount() != null && count > expectation.getMaxExpectedCount() ) {
if ( extraEvents == null ) {
extraEvents = new ArrayList<>();
}
extraEvents.add( event.toImmutable() );
processMatching( event );
}
}

// This must be synchronized to avoid problems when multiple threads issue log events concurrently
private synchronized void processMatching(LogEvent event) {
++count;
if ( expectation.getMaxExpectedCount() != null && count > expectation.getMaxExpectedCount() ) {
if ( extraEvents == null ) {
extraEvents = new ArrayList<>();
}
else {
if ( matchingEvents == null ) {
matchingEvents = new ArrayList<>();
}
matchingEvents.add( event.toImmutable() );
extraEvents.add( event.toImmutable() );
}
else {
if ( matchingEvents == null ) {
matchingEvents = new ArrayList<>();
}
matchingEvents.add( event.toImmutable() );
}
}

Expand Down