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

Lock a map that might be updated concurrently #1632

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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 @@ -74,12 +74,15 @@ public void normaliseShouldResumeFromPreviousNormalisation() {
excerptAppender.normaliseEOFs();
}
final Pattern logPattern = Pattern.compile("Normalising from cycle (\\d+)");
// Note a defensive copy of exceptionMap is used as this code has yielded concurrent modification exceptions leading to flakiness under load
final List<Integer> startIndices = new LinkedHashMap<>(exceptionMap).keySet().stream()
.map(exceptionKey -> logPattern.matcher(exceptionKey.message))
.filter(Matcher::matches)
.map(matcher -> Integer.parseInt(matcher.group(1)))
.collect(Collectors.toList());
// Note: lock the exceptionMap to avoid a concurrent modification exceptions leading to flakiness under load
final List<Integer> startIndices;
synchronized (exceptionMap) {
startIndices = exceptionMap.keySet().stream()
.map(exceptionKey -> logPattern.matcher(exceptionKey.message))
.filter(Matcher::matches)
.map(matcher -> Integer.parseInt(matcher.group(1)))
.collect(Collectors.toList());
}

// There is at least 5 calls to normaliseEOF and the start index increases each time
assertTrue(startIndices.size() >= 5);
Expand Down