diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestCache.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestCache.java index 022370ad85b..d5cbfdd9669 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestCache.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/TestCache.java @@ -2,11 +2,12 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import com.google.common.collect.ImmutableList; import java.util.ArrayList; 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; @@ -60,12 +61,21 @@ public void check(String path, List result, String value) { */ result.clear(); Pair key = new Pair<>(path, value); - List cachedResult = pathCache.get(key); + List cachedResult = + pathCache.computeIfAbsent( + key, + (Pair k) -> { + List l = new ArrayList(); + 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)); } } @@ -88,6 +98,7 @@ public List getPossibleProblems() { private Cache testResultCache = CacheBuilder.newBuilder() .maximumSize(CLDRConfig.getInstance().getProperty("CLDR_TESTCACHE_SIZE", 12)) + .concurrencyLevel(1) .softValues() .build(); @@ -96,16 +107,13 @@ public List 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; }