Skip to content

Commit

Permalink
[FLINK-2392][yarn tests] Address concurrent modification exception
Browse files Browse the repository at this point in the history
  • Loading branch information
rmetzger committed Sep 22, 2015
1 parent a3df109 commit 47afdfb
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,27 @@ public static LoggingEvent getEventContainingString(String expected) {
throw new NullPointerException("Initialize test appender first");
}
LoggingEvent found = null;
for(LoggingEvent event: testAppender.events) {
if(event.getMessage().toString().contains(expected)) {
found = event;
break;
// make sure that different threads are not logging while the logs are checked
synchronized (testAppender.events) {
for (LoggingEvent event : testAppender.events) {
if (event.getMessage().toString().contains(expected)) {
found = event;
break;
}
}
}
return found;
}

public static class TestAppender extends AppenderSkeleton {
public List<LoggingEvent> events = new ArrayList<LoggingEvent>();
public final List<LoggingEvent> events = new ArrayList<>();
public void close() {}
public boolean requiresLayout() {return false;}
@Override
protected void append(LoggingEvent event) {
events.add(event);
synchronized (events){
events.add(event);
}
}
}
}
Expand Down

0 comments on commit 47afdfb

Please sign in to comment.