Skip to content

Commit

Permalink
CLDR-7646 TestCache changes
Browse files Browse the repository at this point in the history
- STFactory: notify on change when state changes, not just value
- SurveyMain: extra print of ST Init failed stack
- TestCache: add logging
- Factory: lazy init TestCache
  • Loading branch information
srl295 committed Jan 5, 2024
1 parent d2071e8 commit 31d4142
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ public void voteForValueWithType(
}

String oldVal = dataBackedSource.getValueAtDPath(distinguishingXpath);
String oldFullPath = dataBackedSource.getFullPathAtDPath(distinguishingXpath);

// sanity check, should have been caught before
if (readonly) {
Expand All @@ -911,7 +912,8 @@ public void voteForValueWithType(
}

String newVal = dataBackedSource.getValueAtDPath(distinguishingXpath);
if (newVal != null && !newVal.equals(oldVal)) {
String newFullPath = dataBackedSource.getFullPathAtDPath(distinguishingXpath);
if (newVal != null && (!newVal.equals(oldVal) || !oldFullPath.equals(newFullPath))) {
dataBackedSource.notifyListeners(distinguishingXpath);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ public final void init(final ServletConfig config) throws ServletException {
SurveyThreadManager.getExecutorService().submit(this::doStartup);
klm = new KeepLoggedInManager(null);
} catch (Throwable t) {
t.printStackTrace();
SurveyLog.logException(logger, t, "Initializing SurveyTool");
SurveyMain.busted("Error initializing SurveyTool.", t);
}
Expand Down
19 changes: 11 additions & 8 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,7 @@
import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import org.unicode.cldr.test.CheckCLDR.CheckStatus;
import org.unicode.cldr.test.CheckCLDR.Options;
import org.unicode.cldr.util.CLDRConfig;
Expand All @@ -25,6 +26,8 @@
* @see XMLSource#addListener(org.unicode.cldr.util.XMLSource.Listener)
*/
public class TestCache implements XMLSource.Listener {
private static final Logger logger = Logger.getLogger(TestCache.class.getSimpleName());

public class TestResultBundle {
private final CheckCLDR cc = CheckCLDR.getCheckAll(getFactory(), nameMatcher);
final CLDRFile file;
Expand Down Expand Up @@ -95,11 +98,8 @@ public List<CheckStatus> getPossibleProblems() {
/** Get the bundle for this test */
public TestResultBundle getBundle(CheckCLDR.Options options) {
TestResultBundle b = testResultCache.getIfPresent(options);
if (DEBUG) {
if (b != null) {
System.err.println("Bundle refvalid: " + options + " -> " + (b != null));
}
System.err.println("Bundle " + b + " for " + options + " in " + this.toString());
if (b != null) {
logger.finest(() -> this + " Bundle refvalid: " + options);
}
if (b == null) {
// ElapsedTimer et = new ElapsedTimer("New test bundle " + locale + " opt " + options);
Expand All @@ -117,10 +117,12 @@ protected Factory getFactory() {
/** construct a new TestCache with this factory. Intended for use from within Factory. */
public TestCache(Factory f) {
this.factory = f;
logger.fine(() -> toString() + " - init(" + f + ")");
}

/** Change which checks are run. Invalidates all caches. */
public void setNameMatcher(String nameMatcher) {
logger.finest(() -> toString() + " - setNameMatcher(" + nameMatcher + ")");
this.nameMatcher = nameMatcher;
invalidateAllCached();
}
Expand All @@ -137,6 +139,8 @@ public String toString() {
"{"
+ this.getClass().getSimpleName()
+ super.toString()
+ " F="
+ factory.getClass().getSimpleName()
+ " Size: "
+ testResultCache.size()
+ " (");
Expand Down Expand Up @@ -179,9 +183,7 @@ public void valueChanged(String xpath, XMLSource source) {
* @param locale the CLDRLocale
*/
private void valueChangedInvalidateRecursively(String xpath, final CLDRLocale locale) {
if (DEBUG) {
System.err.println("BundDelLoc " + locale + " @ " + xpath);
}
logger.finer(() -> "BundDelLoc " + locale + " @ " + xpath);
/*
* Call self recursively for all sub-locales
*/
Expand Down Expand Up @@ -310,6 +312,7 @@ private static void updateExampleGeneratorCache(String xpath, CLDRLocale locale)

/** Public for tests. Invalidate cache. */
public void invalidateAllCached() {
logger.fine(() -> toString() + " - invalidateAllCached()");
testResultCache.invalidateAll();
exampleGeneratorCache.invalidateAll();
}
Expand Down
11 changes: 6 additions & 5 deletions tools/cldr-code/src/main/java/org/unicode/cldr/util/Factory.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.unicode.cldr.util;

import com.google.common.base.Suppliers;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Supplier;
import org.unicode.cldr.test.TestCache;
import org.unicode.cldr.util.CLDRFile.DraftStatus;
import org.unicode.cldr.util.CLDRLocale.SublocaleProvider;
Expand Down Expand Up @@ -338,16 +340,15 @@ public Set<CLDRLocale> calculateSubLocalesOf(CLDRLocale locale, Set<CLDRLocale>
*/
public abstract List<File> getSourceDirectoriesForLocale(String localeName);

private final TestCache testCache;
/** thread-safe lazy load of TestCache */
private Supplier<TestCache> testCache = Suppliers.memoize(() -> new TestCache(this));

/** subclass contructor */
protected Factory() {
testCache = new TestCache(this);
}
protected Factory() {}

/** get the TestCache owned by this Factory */
public final TestCache getTestCache() {
return testCache;
return testCache.get();
}

/**
Expand Down

0 comments on commit 31d4142

Please sign in to comment.