Skip to content

Commit

Permalink
CLDR-7646 TestCache concurrency issues
Browse files Browse the repository at this point in the history
- fix the TestCacheBundle and TestCacheResult caches to be concurrent safe
  • Loading branch information
srl295 committed Jan 10, 2024
1 parent 3074dbd commit 0f050d6
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions tools/cldr-code/src/main/java/org/unicode/cldr/test/TestCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.unicode.cldr.test.CheckCLDR.CheckStatus;
import org.unicode.cldr.test.CheckCLDR.Options;
Expand Down Expand Up @@ -60,12 +62,13 @@ public void check(String path, List<CheckStatus> result, String value) {
*/
result.clear();
Pair<String, String> key = new Pair<>(path, value);
List<CheckStatus> cachedResult = pathCache.get(key);
List<CheckStatus> cachedResult = pathCache.computeIfAbsent(key, (Pair<String, String> k) -> {
List<CheckStatus> l = new ArrayList<CheckStatus>();
cc.check(k.getFirst(), file.getFullXPath(k.getFirst()), k.getSecond(), options, l);
return l;
});
if (cachedResult != null) {
result.addAll(cachedResult);
} else {
cc.check(path, file.getFullXPath(path), value, options, result);
pathCache.put(key, ImmutableList.copyOf(result));
}
}

Expand Down Expand Up @@ -96,16 +99,13 @@ public List<CheckStatus> getPossibleProblems() {
private String nameMatcher = ".*";

/** Get the bundle for this test */
public TestResultBundle getBundle(CheckCLDR.Options options) {
TestResultBundle b = testResultCache.getIfPresent(options);
if (b != null) {
logger.finest(() -> this + " Bundle refvalid: " + options);
}
if (b == null) {
// ElapsedTimer et = new ElapsedTimer("New test bundle " + locale + " opt " + options);
b = new TestResultBundle(options);
// System.err.println(et.toString());
testResultCache.put(options, b);
public TestResultBundle getBundle(final CheckCLDR.Options options) {
TestResultBundle b;
try {
b = testResultCache.get(options, () -> new TestResultBundle(options));
} catch (ExecutionException e) {
logger.log(Level.SEVERE, e, () -> "Failed to load " + options);
throw new RuntimeException(e);
}
return b;
}
Expand Down

0 comments on commit 0f050d6

Please sign in to comment.