Search in sources :

Example 51 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class VirtualFilePointerTest method testStressConcurrentAccess.

public void testStressConcurrentAccess() throws Throwable {
    final File tempDirectory = createTempDirectory();
    VirtualFilePointer fileToCreatePointer = createPointerByFile(tempDirectory, null);
    assertNotNull(fileToCreatePointer);
    VirtualFilePointerListener listener = new VirtualFilePointerListener() {
    };
    long start = System.currentTimeMillis();
    int i;
    for (i = 0; System.currentTimeMillis() < start + 15_000; i++) {
        Disposable disposable = Disposer.newDisposable();
        // supply listener to separate pointers under one root so that it will be removed on dispose
        VirtualFilePointerImpl bb = (VirtualFilePointerImpl) VirtualFilePointerManager.getInstance().create(fileToCreatePointer.getUrl() + "/bb", disposable, listener);
        if (i % 1000 == 0)
            LOG.info("i = " + i);
        int NThreads = Runtime.getRuntime().availableProcessors();
        CountDownLatch ready = new CountDownLatch(NThreads);
        Runnable read = () -> {
            try {
                ready.countDown();
                while (run) {
                    bb.myNode.myLastUpdated = -15;
                    bb.getUrl();
                }
            } catch (Throwable e) {
                exception = e;
            }
        };
        run = true;
        List<Thread> threads = IntStream.range(0, NThreads).mapToObj(n -> new Thread(read, "reader" + n)).collect(Collectors.toList());
        threads.forEach(Thread::start);
        ready.await();
        VirtualFilePointer bc = VirtualFilePointerManager.getInstance().create(fileToCreatePointer.getUrl() + "/b/c", disposable, listener);
        run = false;
        ConcurrencyUtil.joinAll(threads);
        if (exception != null)
            throw exception;
        Disposer.dispose(disposable);
    }
    System.out.println("final i = " + i);
}
Also used : Disposable(com.intellij.openapi.Disposable) IntStream(java.util.stream.IntStream) VirtualFilePointerManager(com.intellij.openapi.vfs.pointers.VirtualFilePointerManager) UIUtil(com.intellij.util.ui.UIUtil) ArrayUtil(com.intellij.util.ArrayUtil) com.intellij.testFramework(com.intellij.testFramework) JobLauncher(com.intellij.concurrency.JobLauncher) NonNls(org.jetbrains.annotations.NonNls) TimeoutException(java.util.concurrent.TimeoutException) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) PathManagerEx(com.intellij.openapi.application.ex.PathManagerEx) Library(com.intellij.openapi.roots.libraries.Library) Job(com.intellij.concurrency.Job) OrderEntryUtil(com.intellij.openapi.roots.impl.OrderEntryUtil) Disposer(com.intellij.openapi.util.Disposer) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) VirtualFilePointerListener(com.intellij.openapi.vfs.pointers.VirtualFilePointerListener) FileUtil(com.intellij.openapi.util.io.FileUtil) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) OrderRootType(com.intellij.openapi.roots.OrderRootType) LibraryUtil(com.intellij.openapi.roots.libraries.LibraryUtil) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Collection(java.util.Collection) ConcurrencyUtil(com.intellij.util.ConcurrencyUtil) IOException(java.io.IOException) MockVirtualFile(com.intellij.mock.MockVirtualFile) Collectors(java.util.stream.Collectors) Disposable(com.intellij.openapi.Disposable) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) TempFileSystem(com.intellij.openapi.vfs.ex.temp.TempFileSystem) Nullable(org.jetbrains.annotations.Nullable) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.openapi.vfs(com.intellij.openapi.vfs) NotNull(org.jetbrains.annotations.NotNull) CountDownLatch(java.util.concurrent.CountDownLatch) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) VirtualFilePointerListener(com.intellij.openapi.vfs.pointers.VirtualFilePointerListener) MockVirtualFile(com.intellij.mock.MockVirtualFile) File(java.io.File)

Example 52 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class CodeInsightTestUtil method addTemplate.

public static void addTemplate(final Template template, Disposable parentDisposable) {
    final TemplateSettings settings = TemplateSettings.getInstance();
    settings.addTemplate(template);
    Disposer.register(parentDisposable, new Disposable() {

        @Override
        public void dispose() {
            settings.removeTemplate(template);
        }
    });
}
Also used : TemplateSettings(com.intellij.codeInsight.template.impl.TemplateSettings) Disposable(com.intellij.openapi.Disposable)

Example 53 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class ParsingTestCase method registerApplicationService.

protected <T> void registerApplicationService(final Class<T> aClass, T object) {
    getApplication().registerService(aClass, object);
    Disposer.register(myProject, new Disposable() {

        @Override
        public void dispose() {
            getApplication().getPicoContainer().unregisterComponent(aClass.getName());
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable)

Example 54 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class ParsingTestCase method addExplicitExtension.

protected <T> void addExplicitExtension(final LanguageExtension<T> instance, final Language language, final T object) {
    instance.addExplicitExtension(language, object);
    Disposer.register(myProject, new Disposable() {

        @Override
        public void dispose() {
            instance.removeExplicitExtension(language, object);
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable)

Example 55 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class Disposer method register.

public static void register(@NotNull Disposable parent, @NotNull Disposable child, @NonNls @Nullable final String key) {
    ourTree.register(parent, child);
    if (key != null) {
        Disposable v = get(key);
        if (v != null)
            throw new IllegalArgumentException("Key " + key + " already registered: " + v);
        ourKeyDisposables.put(key, child);
        register(child, new Disposable() {

            @Override
            public void dispose() {
                ourKeyDisposables.remove(key);
            }
        });
    }
}
Also used : Disposable(com.intellij.openapi.Disposable)

Aggregations

Disposable (com.intellij.openapi.Disposable)282 NotNull (org.jetbrains.annotations.NotNull)52 Test (org.junit.Test)25 Project (com.intellij.openapi.project.Project)18 TestOnly (org.jetbrains.annotations.TestOnly)17 ArrayList (java.util.ArrayList)13 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 RelativePoint (com.intellij.ui.awt.RelativePoint)11 Nullable (org.jetbrains.annotations.Nullable)10 Document (com.intellij.openapi.editor.Document)9 File (java.io.File)9 ProcessHandler (com.intellij.execution.process.ProcessHandler)6 Editor (com.intellij.openapi.editor.Editor)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)6 VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)6 Content (com.intellij.ui.content.Content)6 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)5 Alarm (com.intellij.util.Alarm)5 ActionEvent (java.awt.event.ActionEvent)5 ListSelectionEvent (javax.swing.event.ListSelectionEvent)5