Search in sources :

Example 6 with DaemonProgressIndicator

use of com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator in project intellij-community by JetBrains.

the class ProgressIndicatorTest method testSOEUnderExtremelyNestedWrappedIndicator.

public void testSOEUnderExtremelyNestedWrappedIndicator() {
    ProgressIndicator indicator = new DaemonProgressIndicator();
    for (int i = 0; i < 10000; i++) {
        indicator = new SensitiveProgressWrapper(indicator);
    }
    ProgressManager.getInstance().executeProcessUnderProgress(() -> {
        ProgressIndicator progressIndicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
        assertTrue(progressIndicator instanceof SensitiveProgressWrapper);
        progressIndicator.checkCanceled();
        progressIndicator.isCanceled();
    }, indicator);
}
Also used : DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) DelegatingProgressIndicator(com.intellij.ide.util.DelegatingProgressIndicator) BombedProgressIndicator(com.intellij.testFramework.BombedProgressIndicator) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) SensitiveProgressWrapper(com.intellij.concurrency.SensitiveProgressWrapper)

Example 7 with DaemonProgressIndicator

use of com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator in project intellij-community by JetBrains.

the class PsiConcurrencyStressTest method testStress.

public void testStress() throws Exception {
    DaemonProgressIndicator.setDebug(false);
    int numOfThreads = Runtime.getRuntime().availableProcessors();
    int iterations = Timings.adjustAccordingToMySpeed(20, true);
    System.out.println("iterations = " + iterations);
    final int readIterations = iterations * 3;
    synchronized (this) {
        PsiClass myClass = myJavaFacade.findClass("StressClass", GlobalSearchScope.allScope(myProject));
        assertNotNull(myClass);
        myFile = (PsiJavaFile) myClass.getContainingFile();
    }
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
    final CountDownLatch reads = new CountDownLatch(numOfThreads);
    final Random random = new Random();
    List<Thread> threads = ContainerUtil.map(Collections.nCopies(numOfThreads, ""), i -> new Thread(() -> {
        for (int i1 = 0; i1 < readIterations; i1++) {
            if (myPsiManager == null)
                return;
            ProgressManager.getInstance().runProcess(() -> ApplicationManager.getApplication().runReadAction(() -> {
                assertFalse(writeActionInProgress);
                readStep(random);
            }), new DaemonProgressIndicator());
        }
        reads.countDown();
    }, "stress thread" + i));
    threads.forEach(Thread::start);
    final Document document = documentManager.getDocument(myFile);
    for (int i = 0; i < iterations; i++) {
        Thread.sleep(100);
        new WriteCommandAction(myProject, myFile) {

            @Override
            protected void run(@NotNull final Result result) throws Throwable {
                writeActionInProgress = true;
                documentManager.commitAllDocuments();
                writeStep(random);
                documentManager.commitAllDocuments();
                assertEquals(document.getText(), myFile.getText());
                writeActionInProgress = false;
            }
        }.execute();
    }
    assertTrue("Timed out", reads.await(5, TimeUnit.MINUTES));
    ConcurrencyUtil.joinAll(threads);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) CountDownLatch(java.util.concurrent.CountDownLatch) Document(com.intellij.openapi.editor.Document) Result(com.intellij.openapi.application.Result) Random(java.util.Random)

Example 8 with DaemonProgressIndicator

use of com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator in project intellij-community by JetBrains.

the class JobUtilTest method testDaemonDoesNotPauseWhenEventDispatcherHasEventsInTheQueue.

public void testDaemonDoesNotPauseWhenEventDispatcherHasEventsInTheQueue() throws Throwable {
    assertTrue(SwingUtilities.isEventDispatchThread());
    PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue();
    final AtomicInteger jobsStarted = new AtomicInteger();
    final int N_EVENTS = 50;
    final int N_JOBS = 10000 * JobSchedulerImpl.CORES_COUNT;
    ProgressIndicator indicator = new DaemonProgressIndicator();
    Job<Void> job = JobLauncher.getInstance().submitToJobThread(() -> JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(N_JOBS, null), indicator, false, o -> {
        jobsStarted.incrementAndGet();
        TimeoutUtil.sleep(10);
        return true;
    }), null);
    for (int i = 0; i < N_EVENTS; i++) {
        //noinspection SSBasedInspection
        SwingUtilities.invokeLater(() -> {
            int jobs0 = jobsStarted.get();
            long start = System.currentTimeMillis();
            while (jobsStarted.get() < jobs0 + JobSchedulerImpl.CORES_COUNT && jobsStarted.get() < N_JOBS) {
                if (System.currentTimeMillis() > start + 10000) {
                    System.err.println(ThreadDumper.dumpThreadsToString());
                    fail();
                    break;
                }
            }
        //int jobs1 = jobsStarted.get();
        //System.out.println("jobs0 = "+jobs0+"; jobs1 = "+jobs1);
        });
        UIUtil.dispatchAllInvocationEvents();
    }
    indicator.cancel();
    job.cancel();
    while (!job.isDone()) {
        try {
            job.waitForCompletion(1000);
            UIUtil.dispatchAllInvocationEvents();
            break;
        } catch (TimeoutException ignored) {
        }
    }
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) UIUtil(com.intellij.util.ui.UIUtil) ProgressIndicatorBase(com.intellij.openapi.progress.util.ProgressIndicatorBase) java.util(java.util) PlatformTestUtil(com.intellij.testFramework.PlatformTestUtil) PlatformTestCase(com.intellij.testFramework.PlatformTestCase) java.util.concurrent(java.util.concurrent) AbstractProgressIndicatorBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorBase) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) ThreadDumper(com.intellij.diagnostic.ThreadDumper) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) BigDecimal(java.math.BigDecimal) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TimeoutUtil(com.intellij.util.TimeoutUtil) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) javax.swing(javax.swing) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DaemonProgressIndicator(com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)

Aggregations

DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)8 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 DocumentWindow (com.intellij.injected.editor.DocumentWindow)2 DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Document (com.intellij.openapi.editor.Document)2 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 AbstractProgressIndicatorBase (com.intellij.openapi.progress.util.AbstractProgressIndicatorBase)2 Nullable (org.jetbrains.annotations.Nullable)2 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 GlobalInspectionToolWrapper (com.intellij.codeInspection.ex.GlobalInspectionToolWrapper)1 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)1 OfflineProblemDescriptor (com.intellij.codeInspection.offline.OfflineProblemDescriptor)1 RefElement (com.intellij.codeInspection.reference.RefElement)1 JobLauncher (com.intellij.concurrency.JobLauncher)1 SensitiveProgressWrapper (com.intellij.concurrency.SensitiveProgressWrapper)1 ThreadDumper (com.intellij.diagnostic.ThreadDumper)1 DelegatingProgressIndicator (com.intellij.ide.util.DelegatingProgressIndicator)1 EditorWindowImpl (com.intellij.injected.editor.EditorWindowImpl)1