fix flacky webflux tests caused by two symbol indexers being created and used in different places

This commit is contained in:
Martin Lippert
2019-03-21 15:56:55 +01:00
parent e2d604f023
commit 7cfbfd3ad7
9 changed files with 40 additions and 30 deletions

View File

@@ -20,6 +20,9 @@ import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.SpringLiveHoverWatchdog;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheOnDisc;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.jdt.ls.JavaProjectsService;
import org.springframework.ide.vscode.boot.jdt.ls.JavaProjectsServiceWithFallback;
import org.springframework.ide.vscode.boot.jdt.ls.JdtLsProjectCache;
@@ -68,6 +71,7 @@ public class BootLanguageServerParams {
//Boot Java
public final RunningAppProvider runningAppProvider;
public final Duration watchDogInterval;
public final SymbolCache symbolCache;
public BootLanguageServerParams(
JavaProjectFinder projectFinder,
@@ -75,8 +79,8 @@ public class BootLanguageServerParams {
SpringPropertyIndexProvider indexProvider,
TypeUtilProvider typeUtilProvider,
RunningAppProvider runningAppProvider,
Duration watchDogInterval
) {
Duration watchDogInterval,
SymbolCache symbolCache) {
super();
Assert.isNotNull(projectObserver); // null is bad should be ProjectObserver.NULL
this.projectFinder = projectFinder;
@@ -85,6 +89,7 @@ public class BootLanguageServerParams {
this.typeUtilProvider = typeUtilProvider;
this.runningAppProvider = runningAppProvider;
this.watchDogInterval = watchDogInterval;
this.symbolCache = symbolCache;
}
public static BootLanguageServerParams createDefault(SimpleLanguageServer server, ValueProviderRegistry valueProviders, boolean isJandexIndex) {
@@ -99,13 +104,22 @@ public class BootLanguageServerParams {
DefaultSpringPropertyIndexProvider indexProvider = new DefaultSpringPropertyIndexProvider(jdtProjectCache, jdtProjectCache, fileObserver, valueProviders);
indexProvider.setProgressService(server.getProgressService());
SymbolCache symbolCache = null;
if ("true".equals(System.getProperty("boot.ls.symbols.caching.enabled", "true"))) {
symbolCache = new SymbolCacheOnDisc();
}
else {
symbolCache = new SymbolCacheVoid();
}
return new BootLanguageServerParams(
jdtProjectCache.filter(project -> SpringProjectUtil.isBootProject(project) || SpringProjectUtil.isSpringProject(project)),
jdtProjectCache,
indexProvider,
(SourceLinks sourceLinks, IDocument doc) -> new TypeUtil(sourceLinks, jdtProjectCache.find(new TextDocumentIdentifier(doc.getUri()))),
RunningAppProvider.createDefault(server),
SpringLiveHoverWatchdog.DEFAULT_INTERVAL
SpringLiveHoverWatchdog.DEFAULT_INTERVAL,
symbolCache
);
}
@@ -173,7 +187,8 @@ public class BootLanguageServerParams {
indexProvider,
(SourceLinks sourceLinks, IDocument doc) -> new TypeUtil(sourceLinks, javaProjectFinder.find(new TextDocumentIdentifier(doc.getUri()))),
RunningAppProvider.NULL,
SpringLiveHoverWatchdog.DEFAULT_INTERVAL
SpringLiveHoverWatchdog.DEFAULT_INTERVAL,
new SymbolCacheVoid()
);
}
}

View File

@@ -141,20 +141,9 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
ReferencesHandler referencesHandler = createReferenceHandler(server, projectFinder);
documents.onReferences(referencesHandler);
if ("true".equals(System.getProperty("boot.ls.symbols.caching.enabled", "true"))) {
try {
this.symbolCache = new SymbolCacheOnDisc();
}
catch (Exception e) {
log.warn("symbol cache directory could not be created, no cache enabled");
this.symbolCache = new SymbolCacheVoid();
}
}
else {
this.symbolCache = new SymbolCacheVoid();
}
this.symbolCache = this.serverParams.symbolCache;
this.indexer = createAnnotationIndexer(server, serverParams, symbolCache);
indexer = createAnnotationIndexer(server, serverParams, symbolCache);
documents.onDidSave(params -> {
TextDocument document = params.getDocument();
// Spring Boot LS get events from boot properties files as well, so filter them out

View File

@@ -49,11 +49,11 @@ public class SymbolCacheOnDisc implements SymbolCache {
private static final Logger log = LoggerFactory.getLogger(SymbolCacheOnDisc.class);
public SymbolCacheOnDisc() throws Exception {
public SymbolCacheOnDisc() {
this(new File(System.getProperty("user.home") + File.separatorChar + ".sts4" + File.separatorChar + ".symbolCache"));
}
public SymbolCacheOnDisc(File cacheDirectory) throws Exception {
public SymbolCacheOnDisc(File cacheDirectory) {
this.cacheDirectory = cacheDirectory;
this.stores = new ConcurrentHashMap<>();
@@ -62,7 +62,7 @@ public class SymbolCacheOnDisc implements SymbolCache {
}
if (!this.cacheDirectory.exists()) {
throw new Exception("symbol cache directory could not be created:");
log.warn("symbol cache directory does not exist and cannot be created: " + this.cacheDirectory.toString());
}
}
@@ -254,5 +254,4 @@ public class SymbolCacheOnDisc implements SymbolCache {
}
}
}