use of com.intellij.openapi.progress.util.ProgressIndicatorBase in project intellij-community by JetBrains.
the class ProgressIndicatorTest method testReadTaskCanceledShouldNotHappenAfterEdtContinuation.
public void testReadTaskCanceledShouldNotHappenAfterEdtContinuation() {
for (int i = 0; i < 1000; i++) {
final AtomicBoolean afterContinuation = new AtomicBoolean();
final ProgressIndicatorBase indicator = new ProgressIndicatorBase();
ProgressIndicatorUtils.scheduleWithWriteActionPriority(indicator, new ReadTask() {
@Nullable
@Override
public Continuation performInReadAction(@NotNull ProgressIndicator indicator) throws ProcessCanceledException {
return new Continuation(() -> afterContinuation.set(true));
}
@Override
public void onCanceled(@NotNull ProgressIndicator indicator) {
assertFalse(afterContinuation.get());
}
});
UIUtil.dispatchAllInvocationEvents();
ApplicationManager.getApplication().runWriteAction(() -> {
if (!afterContinuation.get()) {
assertTrue(indicator.isCanceled());
}
});
UIUtil.dispatchAllInvocationEvents();
}
}
use of com.intellij.openapi.progress.util.ProgressIndicatorBase in project intellij-community by JetBrains.
the class JobUtilTest method testUnbalancedTaskJobUtilPerformance.
public void testUnbalancedTaskJobUtilPerformance() {
List<Integer> things = new ArrayList<>(Collections.nCopies(10000, null));
int sum = 0;
for (int i = 0; i < things.size(); i++) {
int v = i < 9950 ? 1 : 1000;
things.set(i, v);
sum += things.get(i);
}
assertEquals(59950, sum);
long start = System.currentTimeMillis();
boolean b = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(things, new ProgressIndicatorBase(), false, false, o -> {
busySleep(o);
return true;
});
assertTrue(b);
long elapsed = System.currentTimeMillis() - start;
int expected = 2 * (9950 + 50 * 1000) / JobSchedulerImpl.CORES_COUNT;
String message = "Elapsed: " + elapsed + "; expected: " + expected;
System.out.println(message);
assertTrue(message, elapsed < expected);
}
use of com.intellij.openapi.progress.util.ProgressIndicatorBase in project intellij-community by JetBrains.
the class BombedProgressIndicator method runBombed.
/**
* @return whether the indicator was canceled during runnable execution.
*/
public boolean runBombed(final Runnable runnable) {
myThread = Thread.currentThread();
final Semaphore canStart = new Semaphore();
canStart.down();
final Semaphore finished = new Semaphore();
finished.down();
// ProgressManager invokes indicator.checkCanceled only when there's at least one canceled indicator. So we have to create a mock one
// on an unrelated thread and cancel it immediately.
Future<?> future = ApplicationManager.getApplication().executeOnPooledThread(() -> {
final ProgressIndicatorBase mockIndicator = new ProgressIndicatorBase();
ProgressManager.getInstance().runProcess(() -> {
mockIndicator.cancel();
canStart.up();
finished.waitFor();
try {
ProgressManager.checkCanceled();
TestCase.fail();
} catch (ProcessCanceledException ignored) {
}
}, mockIndicator);
});
ProgressManager.getInstance().runProcess(() -> {
canStart.waitFor();
try {
runnable.run();
} catch (ProcessCanceledException ignore) {
} finally {
finished.up();
}
}, this);
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
return isCanceled();
}
use of com.intellij.openapi.progress.util.ProgressIndicatorBase in project intellij-community by JetBrains.
the class FindManagerTest method runAsyncTest.
private void runAsyncTest(String text, FindModel findModel) throws InterruptedException {
final Ref<FindResult> result = new Ref<>();
final CountDownLatch progressStarted = new CountDownLatch(1);
final ProgressIndicatorBase progressIndicatorBase = new ProgressIndicatorBase();
final Thread thread = new Thread(() -> ProgressManager.getInstance().runProcess(() -> {
try {
progressStarted.countDown();
result.set(myFindManager.findString(text, 0, findModel, new LightVirtualFile("foo.java")));
} catch (ProcessCanceledException ex) {
result.set(new FindResultImpl());
}
}, progressIndicatorBase), "runAsyncTest");
thread.start();
progressStarted.await();
thread.join(100);
progressIndicatorBase.cancel();
thread.join(500);
assertNotNull(result.get());
assertTrue(!result.get().isStringFound());
thread.join();
}
use of com.intellij.openapi.progress.util.ProgressIndicatorBase in project intellij-community by JetBrains.
the class AsyncEditorLoader method scheduleLoading.
private Future<Runnable> scheduleLoading() {
PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(myProject);
long startStamp = myEditor.getDocument().getModificationStamp();
return ourExecutor.submit(() -> {
Ref<Runnable> ref = new Ref<>();
try {
while (!myEditorComponent.isDisposed()) {
ProgressIndicatorUtils.runWithWriteActionPriority(() -> ref.set(psiDocumentManager.commitAndRunReadAction(() -> myProject.isDisposed() ? EmptyRunnable.INSTANCE : myTextEditor.loadEditorInBackground())), new ProgressIndicatorBase());
Runnable continuation = ref.get();
if (continuation != null) {
invokeLater(() -> {
if (startStamp == myEditor.getDocument().getModificationStamp())
loadingFinished(continuation);
else if (!myProject.isDisposed() && !myEditorComponent.isDisposed())
scheduleLoading();
});
return continuation;
}
ProgressIndicatorUtils.yieldToPendingWriteActions();
}
} finally {
if (ref.isNull())
invokeLater(() -> loadingFinished(null));
}
return null;
});
}
Aggregations