From ba044829bec634691d73f6c2541fe88e76df9220 Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Tue, 17 Dec 2024 09:59:44 +0100 Subject: [PATCH 1/2] Improving stability of Java code completion (sealed) tests. --- .../JavaCompletionTask121FeaturesTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask121FeaturesTest.java b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask121FeaturesTest.java index 5237ac4e88f7..9d9d3d65c6e3 100644 --- a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask121FeaturesTest.java +++ b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/JavaCompletionTask121FeaturesTest.java @@ -19,9 +19,14 @@ package org.netbeans.modules.java.completion; +import java.util.concurrent.CountDownLatch; import org.netbeans.api.java.classpath.ClassPath; import org.netbeans.api.java.classpath.GlobalPathRegistry; +import org.netbeans.api.java.source.ClassIndexListener; +import org.netbeans.api.java.source.ClasspathInfo; +import org.netbeans.api.java.source.RootsEvent; import org.netbeans.api.java.source.SourceUtils; +import org.netbeans.api.java.source.TypesEvent; import org.netbeans.modules.java.source.parsing.JavacParser; import org.netbeans.modules.parsing.api.indexing.IndexingManager; import org.netbeans.spi.java.classpath.support.ClassPathSupport; @@ -171,8 +176,27 @@ public void testNonSealedTypeSwitch1() throws Exception { protected void afterTestSetup() throws Exception { if (getName().startsWith("testSealed")) { classPathRegistered = ClassPathSupport.createClassPath(getWorkDir().toURI().toURL()); + CountDownLatch started = new CountDownLatch(1); + ClasspathInfo info = ClasspathInfo.create(ClassPath.EMPTY, ClassPath.EMPTY, classPathRegistered); + ClassIndexListener listener = new ClassIndexListener() { + @Override + public void typesAdded(TypesEvent event) {} + @Override + public void typesRemoved(TypesEvent event) {} + @Override + public void typesChanged(TypesEvent event) {} + @Override + public void rootsAdded(RootsEvent event) { + started.countDown(); + } + @Override + public void rootsRemoved(RootsEvent event) {} + }; + info.getClassIndex().addClassIndexListener(listener); GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {classPathRegistered}); IndexingManager.getDefault().refreshAllIndices(true, true, getWorkDir()); + started.await(); + info.getClassIndex().removeClassIndexListener(listener); SourceUtils.waitScanFinished(); } } From f5cd319f913856e747edd04d694b6f4358a4a0b9 Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Tue, 17 Dec 2024 19:18:52 +0100 Subject: [PATCH 2/2] Prevent too many logs in Java code completion tests, by mbien. --- .../modules/java/completion/CompletionTestBaseBase.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/CompletionTestBaseBase.java b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/CompletionTestBaseBase.java index a25e9cf0b5a5..589b00dd5ff8 100644 --- a/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/CompletionTestBaseBase.java +++ b/java/java.completion/test/unit/src/org/netbeans/modules/java/completion/CompletionTestBaseBase.java @@ -67,6 +67,9 @@ public class CompletionTestBaseBase extends NbTestCase { JavaCompletionTaskBasicTest.class.getClassLoader().setDefaultAssertionStatus(true); SourceUtilsTestUtil2.disableArtificalParameterNames(); System.setProperty("org.netbeans.modules.java.source.parsing.JavacParser.no_parameter_names", "true"); + // bump tresholds to avoid context dumps from "excessive indexing" warnings + System.setProperty("org.netbeans.modules.parsing.impl.indexing.LogContext$EventType.PATH.treshold", "100"); + System.setProperty("org.netbeans.modules.parsing.impl.indexing.LogContext$EventType.MANAGER.treshold", "100"); } static final int FINISH_OUTTIME = 5 * 60 * 1000;