mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-13 06:59:44 +07:00
Disable WorkspaceEntitiesLifecycleActivity in unit tests by default
(cherry picked from commit 73934f5796d84186576ecc8b755f033dd24a7f9b) GitOrigin-RevId: 03ca9b870763aead7cfea780c1a081db8ac2966f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0ab15c65e6
commit
cb73ccd751
@@ -87,7 +87,9 @@ import com.intellij.util.io.PersistentMapImpl;
|
||||
import com.intellij.util.ref.GCUtil;
|
||||
import com.intellij.util.ref.GCWatcher;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.workspaceModel.ide.impl.WorkspaceEntityLifecycleSupporterUtils;
|
||||
import com.siyeh.ig.JavaOverridingMethodUtil;
|
||||
import kotlin.Unit;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -547,7 +549,7 @@ public class IndexTest extends JavaCodeInsightFixtureTestCase {
|
||||
myFixture.addFileToProject("foo/Foo" + i + ".java", "package foo; class Foo" + i + " {}").getVirtualFile();
|
||||
assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo" + i, scope));
|
||||
String newName = "Bar" + i + ".java";
|
||||
WriteCommandAction.runWriteCommandAction(getProject(), (ThrowableComputable<?,IOException>) () -> {
|
||||
WriteCommandAction.runWriteCommandAction(getProject(), (ThrowableComputable<?, IOException>)() -> {
|
||||
file.rename(this, newName);
|
||||
return null;
|
||||
});
|
||||
@@ -597,12 +599,12 @@ public class IndexTest extends JavaCodeInsightFixtureTestCase {
|
||||
|
||||
public void test_no_index_stamp_update_when_no_change_2() throws IOException {
|
||||
@Language("JAVA") String text0 = """
|
||||
class Main111 {
|
||||
static void staticMethod(Object o) {
|
||||
staticMethod(null);
|
||||
}
|
||||
}
|
||||
""";
|
||||
class Main111 {
|
||||
static void staticMethod(Object o) {
|
||||
staticMethod(null);
|
||||
}
|
||||
}
|
||||
""";
|
||||
final VirtualFile vFile = myFixture.configureByText(JavaFileType.INSTANCE, text0).getVirtualFile();
|
||||
long stamp = FileBasedIndex.getInstance().getIndexModificationStamp(JavaNullMethodArgumentIndex.INDEX_ID, getProject());
|
||||
JavaNullMethodArgumentIndex.MethodCallData data = new JavaNullMethodArgumentIndex.MethodCallData("staticMethod", 0);
|
||||
@@ -612,12 +614,12 @@ public class IndexTest extends JavaCodeInsightFixtureTestCase {
|
||||
assertEquals(files.iterator().next(), vFile);
|
||||
|
||||
@Language("JAVA") final String text = """
|
||||
class Main {
|
||||
static void staticMethod(Object o) {
|
||||
staticMethod(null);
|
||||
}
|
||||
}
|
||||
""";
|
||||
class Main {
|
||||
static void staticMethod(Object o) {
|
||||
staticMethod(null);
|
||||
}
|
||||
}
|
||||
""";
|
||||
WriteAction.run(() -> VfsUtil.saveText(vFile, text));
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
|
||||
@@ -1438,40 +1440,51 @@ public class IndexTest extends JavaCodeInsightFixtureTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
public void test_indexes_should_be_wiped_after_scratch_removal() throws StorageException, IOException {
|
||||
final VirtualFile file =
|
||||
ScratchRootType.getInstance().createScratchFile(getProject(), "Foo.java", JavaLanguage.INSTANCE, "class Foo {}");
|
||||
int fileId = ((VirtualFileWithId)file).getId();
|
||||
deleteOnTearDown(file);
|
||||
public void test_indexes_should_be_wiped_after_scratch_removal() {
|
||||
WorkspaceEntityLifecycleSupporterUtils.INSTANCE.withAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(getProject(), () -> {
|
||||
final VirtualFile file =
|
||||
ScratchRootType.getInstance().createScratchFile(getProject(), "Foo.java", JavaLanguage.INSTANCE, "class Foo {}");
|
||||
int fileId = ((VirtualFileWithId)file).getId();
|
||||
deleteOnTearDown(file);
|
||||
|
||||
FileBasedIndexImpl fileBasedIndex = (FileBasedIndexImpl)FileBasedIndex.getInstance();
|
||||
ID<Integer, Void> trigramId = TrigramIndex.INDEX_ID;
|
||||
FileBasedIndexImpl fileBasedIndex = (FileBasedIndexImpl)FileBasedIndex.getInstance();
|
||||
ID<Integer, Void> trigramId = TrigramIndex.INDEX_ID;
|
||||
|
||||
fileBasedIndex.ensureUpToDate(trigramId, getProject(), GlobalSearchScope.everythingScope(getProject()));
|
||||
assertNotEmpty(fileBasedIndex.getIndex(trigramId).getIndexedFileData(fileId).values());
|
||||
fileBasedIndex.ensureUpToDate(trigramId, getProject(), GlobalSearchScope.everythingScope(getProject()));
|
||||
try {
|
||||
assertNotEmpty(fileBasedIndex.getIndex(trigramId).getIndexedFileData(fileId).values());
|
||||
|
||||
WriteCommandAction.runWriteCommandAction(getProject(), (ThrowableComputable<?, IOException>)() -> {
|
||||
file.delete(null);
|
||||
return null;
|
||||
WriteCommandAction.runWriteCommandAction(getProject(), (ThrowableComputable<?, IOException>)() -> {
|
||||
file.delete(null);
|
||||
return null;
|
||||
});
|
||||
fileBasedIndex.ensureUpToDate(trigramId, getProject(), GlobalSearchScope.everythingScope(getProject()));
|
||||
assertEmpty(fileBasedIndex.getIndex(trigramId).getIndexedFileData(fileId).values());
|
||||
}
|
||||
catch (StorageException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
fileBasedIndex.ensureUpToDate(trigramId, getProject(), GlobalSearchScope.everythingScope(getProject()));
|
||||
assertEmpty(fileBasedIndex.getIndex(trigramId).getIndexedFileData(fileId).values());
|
||||
}
|
||||
|
||||
public void test_requestReindex() {
|
||||
VirtualFile file = ScratchRootType.getInstance().createScratchFile(getProject(), "Foo.java", JavaLanguage.INSTANCE, "class Foo {}");
|
||||
deleteOnTearDown(file);
|
||||
WorkspaceEntityLifecycleSupporterUtils.INSTANCE.withAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(getProject(), () -> {
|
||||
VirtualFile file = ScratchRootType.getInstance().createScratchFile(getProject(), "Foo.java", JavaLanguage.INSTANCE, "class Foo {}");
|
||||
deleteOnTearDown(file);
|
||||
|
||||
CountingFileBasedIndexExtension.registerCountingFileBasedIndex(getTestRootDisposable());
|
||||
CountingFileBasedIndexExtension.registerCountingFileBasedIndex(getTestRootDisposable());
|
||||
|
||||
FileBasedIndex.getInstance().getFileData(CountingFileBasedIndexExtension.getINDEX_ID(), file, getProject());
|
||||
assertTrue(CountingFileBasedIndexExtension.getCOUNTER().get() > 0);
|
||||
FileBasedIndex.getInstance().getFileData(CountingFileBasedIndexExtension.getINDEX_ID(), file, getProject());
|
||||
assertTrue(CountingFileBasedIndexExtension.getCOUNTER().get() > 0);
|
||||
|
||||
CountingFileBasedIndexExtension.getCOUNTER().set(0);
|
||||
FileBasedIndex.getInstance().requestReindex(file);
|
||||
CountingFileBasedIndexExtension.getCOUNTER().set(0);
|
||||
FileBasedIndex.getInstance().requestReindex(file);
|
||||
|
||||
FileBasedIndex.getInstance().getFileData(CountingFileBasedIndexExtension.getINDEX_ID(), file, getProject());
|
||||
assertTrue(CountingFileBasedIndexExtension.getCOUNTER().get() > 0);
|
||||
FileBasedIndex.getInstance().getFileData(CountingFileBasedIndexExtension.getINDEX_ID(), file, getProject());
|
||||
assertTrue(CountingFileBasedIndexExtension.getCOUNTER().get() > 0);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
|
||||
public void test_modified_excluded_file_not_present_in_index() throws StorageException, IOException {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package com.intellij.workspaceModel.ide.impl
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.extensions.ExtensionNotApplicableException
|
||||
import com.intellij.openapi.extensions.ExtensionPointListener
|
||||
import com.intellij.openapi.extensions.PluginDescriptor
|
||||
import com.intellij.openapi.project.Project
|
||||
@@ -13,13 +14,13 @@ import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
private class WorkspaceEntitiesLifecycleActivity : ProjectActivity {
|
||||
override suspend fun execute(project: Project) {
|
||||
init {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||
//todo GoGutterMarkerTest failed without it - ideally, we should setup project in tests without this activity
|
||||
WorkspaceEntityLifecycleSupporterUtils.ensureAllEntitiesInWorkspaceAreAsProvidersDefined(project)
|
||||
return
|
||||
throw ExtensionNotApplicableException.create()
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun execute(project: Project) {
|
||||
coroutineScope {
|
||||
WorkspaceEntityLifecycleSupporter.EP_NAME.addExtensionPointListener(this, object : ExtensionPointListener<WorkspaceEntityLifecycleSupporter<out WorkspaceEntity, out WorkspaceEntity.Builder<out WorkspaceEntity>>> {
|
||||
override fun extensionAdded(extension: WorkspaceEntityLifecycleSupporter<out WorkspaceEntity, out WorkspaceEntity.Builder<out WorkspaceEntity>>, pluginDescriptor: PluginDescriptor) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.workspaceModel.ide.impl
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.backgroundWriteAction
|
||||
import com.intellij.openapi.components.serviceAsync
|
||||
import com.intellij.openapi.project.Project
|
||||
@@ -12,6 +13,7 @@ import com.intellij.platform.workspace.storage.MutableEntityStorage
|
||||
import com.intellij.platform.workspace.storage.WorkspaceEntity
|
||||
import com.intellij.platform.workspace.storage.toBuilder
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
|
||||
@ApiStatus.Internal
|
||||
object WorkspaceEntityLifecycleSupporterUtils {
|
||||
@@ -35,6 +37,49 @@ object WorkspaceEntityLifecycleSupporterUtils {
|
||||
builderRef.get()?.let { backgroundWriteAction { writeBuilder(workspaceModel, it) } }
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
fun withAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(project: Project, block: () -> Unit) {
|
||||
setUpAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(project)
|
||||
try {
|
||||
block()
|
||||
}
|
||||
finally {
|
||||
tearDownAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(project)
|
||||
}
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
fun setUpAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(project: Project) {
|
||||
val workspaceModel = WorkspaceModel.getInstance(project)
|
||||
val snapshot = workspaceModel.currentSnapshot
|
||||
val builderRef = Ref<MutableEntityStorage>()
|
||||
|
||||
WorkspaceEntityLifecycleSupporter.EP_NAME.forEachExtensionSafe { provider ->
|
||||
ensureInitialized(project = project, provider = provider, snapshot = snapshot, builderRef = builderRef)
|
||||
}
|
||||
builderRef.get()?.let { ApplicationManager.getApplication().runWriteAction { writeBuilder(workspaceModel, it) } }
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
fun tearDownAllEntitiesInWorkspaceFromProvidersDefinedOnEdt(project: Project) {
|
||||
val workspaceModel = WorkspaceModel.getInstance(project)
|
||||
val snapshot = workspaceModel.currentSnapshot
|
||||
val builderRef = Ref<MutableEntityStorage>()
|
||||
WorkspaceEntityLifecycleSupporter.EP_NAME.forEachExtensionSafe { provider ->
|
||||
val entitiesIterator = snapshot.entities(provider.getEntityClass()).iterator()
|
||||
if (entitiesIterator.hasNext()) {
|
||||
var builder = builderRef.get()
|
||||
if (builder == null) {
|
||||
builder = snapshot.toBuilder()
|
||||
builderRef.set(builder)
|
||||
}
|
||||
|
||||
entitiesIterator.forEach { builder.removeEntity(it) }
|
||||
}
|
||||
}
|
||||
builderRef.get()?.let { ApplicationManager.getApplication().runWriteAction { writeBuilder(workspaceModel, it) } }
|
||||
}
|
||||
|
||||
private fun writeBuilder(workspaceModel: WorkspaceModel, builder: MutableEntityStorage) {
|
||||
workspaceModel.updateProjectModel("ConstantEntitiesCheckActivity") {
|
||||
it.applyChangesFrom(builder)
|
||||
|
||||
Reference in New Issue
Block a user