Search in sources :

Example 16 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class CompilerTestUtil method enableExternalCompiler.

@TestOnly
public static void enableExternalCompiler() {
    final JavaAwareProjectJdkTableImpl table = JavaAwareProjectJdkTableImpl.getInstanceEx();
    new WriteAction() {

        @Override
        protected void run(@NotNull final Result result) {
            table.addJdk(table.getInternalJdk());
        }
    }.execute();
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) JavaAwareProjectJdkTableImpl(com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl) Result(com.intellij.openapi.application.Result) TestOnly(org.jetbrains.annotations.TestOnly)

Example 17 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class FileManagerImpl method checkConsistency.

@TestOnly
public void checkConsistency() {
    Map<VirtualFile, FileViewProvider> fileToViewProvider = new HashMap<>(myVFileToViewProviderMap);
    myVFileToViewProviderMap.clear();
    for (VirtualFile vFile : fileToViewProvider.keySet()) {
        final FileViewProvider fileViewProvider = fileToViewProvider.get(vFile);
        LOG.assertTrue(vFile.isValid());
        PsiFile psiFile1 = findFile(vFile);
        if (psiFile1 != null && fileViewProvider != null && fileViewProvider.isPhysical()) {
            // might get collected
            PsiFile psi = fileViewProvider.getPsi(fileViewProvider.getBaseLanguage());
            assert psi != null : fileViewProvider + "; " + fileViewProvider.getBaseLanguage() + "; " + psiFile1;
            assert psiFile1.getClass().equals(psi.getClass()) : psiFile1 + "; " + psi + "; " + psiFile1.getClass() + "; " + psi.getClass();
        }
    }
    HashMap<VirtualFile, PsiDirectory> fileToPsiDirMap = new HashMap<>(myVFileToPsiDirMap);
    myVFileToPsiDirMap.clear();
    for (VirtualFile vFile : fileToPsiDirMap.keySet()) {
        LOG.assertTrue(vFile.isValid());
        PsiDirectory psiDir1 = findDirectory(vFile);
        LOG.assertTrue(psiDir1 != null);
        VirtualFile parent = vFile.getParent();
        if (parent != null) {
            LOG.assertTrue(myVFileToPsiDirMap.containsKey(parent));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) THashMap(gnu.trove.THashMap) TestOnly(org.jetbrains.annotations.TestOnly)

Example 18 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class PsiDocumentManagerBase method disableBackgroundCommit.

@TestOnly
public void disableBackgroundCommit(@NotNull Disposable parentDisposable) {
    assert myPerformBackgroundCommit;
    myPerformBackgroundCommit = false;
    Disposer.register(parentDisposable, new Disposable() {

        @Override
        public void dispose() {
            myPerformBackgroundCommit = true;
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) TestOnly(org.jetbrains.annotations.TestOnly)

Example 19 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class PsiManagerImpl method setAssertOnFileLoadingFilter.

@Override
@TestOnly
public void setAssertOnFileLoadingFilter(@NotNull VirtualFileFilter filter, @NotNull Disposable parentDisposable) {
    // Find something to ensure there's no changed files waiting to be processed in repository indices.
    myAssertOnFileLoadingFilter = filter;
    Disposer.register(parentDisposable, new Disposable() {

        @Override
        public void dispose() {
            myAssertOnFileLoadingFilter = VirtualFileFilter.NONE;
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) TestOnly(org.jetbrains.annotations.TestOnly)

Example 20 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class ConcurrencyUtil method awaitQuiescence.

/**
   * Awaits for all tasks in the {@code executor} to finish for the specified {@code timeout}
   */
@TestOnly
public static void awaitQuiescence(@NotNull ThreadPoolExecutor executor, long timeout, @NotNull TimeUnit unit) {
    // no need for zombies in tests
    executor.setKeepAliveTime(1, TimeUnit.NANOSECONDS);
    // interrupt idle workers
    executor.setCorePoolSize(0);
    ReentrantLock mainLock = ReflectionUtil.getField(executor.getClass(), executor, ReentrantLock.class, "mainLock");
    Set workers;
    mainLock.lock();
    try {
        HashSet workersField = ReflectionUtil.getField(executor.getClass(), executor, HashSet.class, "workers");
        // to be able to iterate thread-safely outside the lock
        workers = new HashSet(workersField);
    } finally {
        mainLock.unlock();
    }
    for (Object worker : workers) {
        Thread thread = ReflectionUtil.getField(worker.getClass(), worker, Thread.class, "thread");
        try {
            thread.join(unit.toMillis(timeout));
        } catch (InterruptedException e) {
            String trace = "Thread leaked: " + thread + "; " + thread.getState() + " (" + thread.isAlive() + ")\n--- its stacktrace:\n";
            for (final StackTraceElement stackTraceElement : thread.getStackTrace()) {
                trace += " at " + stackTraceElement + "\n";
            }
            trace += "---\n";
            System.err.println("Executor " + executor + " is still active after " + unit.toSeconds(timeout) + " seconds://///\n" + "Thread " + thread + " dump:\n" + trace + "all thread dump:\n" + ThreadDumper.dumpThreadsToString() + "\n/////");
            break;
        }
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) TestOnly(org.jetbrains.annotations.TestOnly)

Aggregations

TestOnly (org.jetbrains.annotations.TestOnly)56 Disposable (com.intellij.openapi.Disposable)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 NotNull (org.jetbrains.annotations.NotNull)7 Project (com.intellij.openapi.project.Project)5 Application (com.intellij.openapi.application.Application)4 Document (com.intellij.openapi.editor.Document)3 Editor (com.intellij.openapi.editor.Editor)3 THashSet (gnu.trove.THashSet)3 Nullable (org.jetbrains.annotations.Nullable)3 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)2 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)2 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 CollectionListModel (com.intellij.ui.CollectionListModel)2 THashMap (gnu.trove.THashMap)2 BackgroundEditorHighlighter (com.intellij.codeHighlighting.BackgroundEditorHighlighter)1 Pass (com.intellij.codeHighlighting.Pass)1 AutoPopupController (com.intellij.codeInsight.AutoPopupController)1 com.intellij.codeInsight.daemon (com.intellij.codeInsight.daemon)1