Attempt to fix failing XML HyperLink unit test

This commit is contained in:
aboyko
2025-01-28 22:42:05 -05:00
parent cc06fd97c3
commit b81a224756
4 changed files with 38 additions and 28 deletions

View File

@@ -387,28 +387,29 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
log.debug("Project with NULL name is being initialized");
return CompletableFuture.completedFuture(null);
} else {
synchronized(this) { // synchronized since the `indexers` array can change via a settings change
@SuppressWarnings("unchecked")
CompletableFuture<Void>[] futures = new CompletableFuture[this.indexers.length + 1];
@SuppressWarnings("unchecked")
CompletableFuture<Void>[] futures = new CompletableFuture[this.indexers.length + 1];
// clean future
futures[0] = CompletableFuture.runAsync(() -> {
removeSymbolsByProject(project);
springIndex.removeBeans(project.getElementName());
}, this.updateQueue);
// index futures
for (int i = 0; i < this.indexers.length; i++) {
InitializeProject initializeItem = new InitializeProject(project, this.indexers[i], clean);
futures[i + 1] = CompletableFuture.runAsync(initializeItem, this.updateQueue);
}
CompletableFuture<Void> future = CompletableFuture.allOf(futures);
future = future.thenAccept(v -> server.getClient().indexUpdated()).thenAccept(v -> listeners.fire(v));
// clean future
futures[0] = CompletableFuture.runAsync(() -> {
removeSymbolsByProject(project);
springIndex.removeBeans(project.getElementName());
}, this.updateQueue);
// index futures
for (int i = 0; i < this.indexers.length; i++) {
InitializeProject initializeItem = new InitializeProject(project, this.indexers[i], clean);
futures[i + 1] = CompletableFuture.runAsync(initializeItem, this.updateQueue);
this.latestScheduledTaskByProject.put(project.getElementName(), future);
return future;
}
CompletableFuture<Void> future = CompletableFuture.allOf(futures);
future = future.thenAccept(v -> server.getClient().indexUpdated()).thenAccept(v -> listeners.fire(v));
this.latestScheduledTaskByProject.put(project.getElementName(), future);
return future;
}
} else {
return deleteProject(project);
@@ -715,15 +716,17 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
ImmutableList.Builder<WorkspaceSymbol> builder = ImmutableList.builder();
if (project != null && doc != null) {
// Collect symbols from the opened document
for (SpringIndexer indexer : this.indexers) {
if (indexer.isInterestedIn(docURI)) {
try {
for (EnhancedSymbolInformation enhanced : indexer.computeSymbols(project, docURI,
doc.get())) {
builder.add(enhanced.getSymbol());
synchronized(this) {
for (SpringIndexer indexer : this.indexers) {
if (indexer.isInterestedIn(docURI)) {
try {
for (EnhancedSymbolInformation enhanced : indexer.computeSymbols(project, docURI,
doc.get())) {
builder.add(enhanced.getSymbol());
}
} catch (Exception e) {
log.error("{}", e);
}
} catch (Exception e) {
log.error("{}", e);
}
}
}

View File

@@ -73,6 +73,8 @@ public class XMLBeanRefContentAssistTest {
settings.put("boot-java", bootJavaObj);
harness.changeConfiguration(new Settings(new Gson().toJsonTree(settings)));
// Configuration change updates indexer hence we need to wait until this occurs as well
indexer.waitOperation();
directory = new File(ProjectsHarness.class.getResource("/test-projects/test-xml-hyperlinks/").toURI());

View File

@@ -100,6 +100,8 @@ public class XMLBeansHyperlinkTest {
settings.put("boot-java", bootJavaObj);
harness.changeConfiguration(new Settings(new Gson().toJsonTree(settings)));
// Configuration change updates indexer hence we need to wait until this occurs as well
indexer.waitOperation();
project = projects.mavenProject("test-xml-hyperlinks");
@@ -178,8 +180,9 @@ public class XMLBeansHyperlinkTest {
@Test
// @Disabled
void testBeanRefHyperlink() throws Exception {
assertEquals(springIndex.getBeans().length, 4);
Bean[] beans = springIndex.getBeansWithName(project.getElementName(), "simpleObj");
assertEquals(1, beans.length);
assertEquals("simpleObj", beans[0].getName());
assertEquals("u.t.r.SimpleObj", beans[0].getType());

View File

@@ -78,6 +78,8 @@ public class XMLContentAssistTest {
settings.put("boot-java", bootJavaObj);
harness.changeConfiguration(new Settings(new Gson().toJsonTree(settings)));
// Configuration change updates indexer hence we need to wait until this occurs as well
indexer.waitOperation();
project = projects.mavenProject("test-xml-hyperlinks");