From a3f755c9c56e6bfdacdb1b22566e35c8db4fa576 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 14 Aug 2017 16:28:17 +0300 Subject: [PATCH] cleanup --- .../testFramework/LightVirtualFileBase.java | 7 ++-- .../progress/util/ProgressIndicatorUtils.java | 9 ++--- .../progress/impl/ProgressIndicatorTest.java | 34 +++++++++++++------ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/platform/core-api/src/com/intellij/testFramework/LightVirtualFileBase.java b/platform/core-api/src/com/intellij/testFramework/LightVirtualFileBase.java index c23b9474376d..22ef71f04d4b 100644 --- a/platform/core-api/src/com/intellij/testFramework/LightVirtualFileBase.java +++ b/platform/core-api/src/com/intellij/testFramework/LightVirtualFileBase.java @@ -21,7 +21,6 @@ import com.intellij.openapi.vfs.NonPhysicalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileSystem; import com.intellij.util.IncorrectOperationException; -import com.intellij.util.LocalTimeCounter; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,8 +32,8 @@ import java.io.IOException; */ public abstract class LightVirtualFileBase extends VirtualFile { private FileType myFileType; - private String myName = ""; - private long myModStamp = LocalTimeCounter.currentTime(); + private String myName; + private long myModStamp; private boolean myIsWritable = true; private boolean myValid = true; private VirtualFile myOriginalFile; @@ -45,7 +44,7 @@ public abstract class LightVirtualFileBase extends VirtualFile { myModStamp = modificationStamp; } - public void setFileType(final FileType fileType) { + public void setFileType(@NotNull FileType fileType) { myFileType = fileType; } diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressIndicatorUtils.java b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressIndicatorUtils.java index e5db57b0c811..a20c461c3341 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressIndicatorUtils.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressIndicatorUtils.java @@ -61,13 +61,8 @@ public class ProgressIndicatorUtils { return progress; } - @NotNull - public static CompletableFuture submitWithWriteActionPriority(@NotNull ReadTask task) { - return scheduleWithWriteActionPriority(new ProgressIndicatorBase(), task); - } - public static void scheduleWithWriteActionPriority(@NotNull ReadTask task) { - submitWithWriteActionPriority(task); + scheduleWithWriteActionPriority(new ProgressIndicatorBase(), task); } @NotNull @@ -229,7 +224,7 @@ public class ProgressIndicatorUtils { } }); } - catch (RuntimeException | Error e) { + catch (Throwable e) { future.completeExceptionally(e); throw e; } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java index 2068ce884cbd..6e2fe3c01617 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/progress/impl/ProgressIndicatorTest.java @@ -50,9 +50,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.List; import java.util.Random; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -91,7 +89,7 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { private volatile long prevTime; private volatile long now; - public void testCheckCanceledGranularity() throws InterruptedException { + public void testCheckCanceledGranularity() { prevTime = now = 0; final long warmupEnd = System.currentTimeMillis() + 1000; final TLongArrayList times = new TLongArrayList(); @@ -123,10 +121,10 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { assertTrue(averageDelay < CoreProgressManager.CHECK_CANCELED_DELAY_MILLIS *3); } - public void testProgressIndicatorUtilsScheduleWithWriteActionPriority() throws Throwable { + public void testProgressIndicatorUtilsScheduleWithWriteActionPriority() throws Exception { final AtomicBoolean insideReadAction = new AtomicBoolean(); final ProgressIndicatorBase indicator = new ProgressIndicatorBase(); - ProgressIndicatorUtils.scheduleWithWriteActionPriority(indicator, new ReadTask() { + CompletableFuture future = ProgressIndicatorUtils.scheduleWithWriteActionPriority(indicator, new ReadTask() { @Override public void computeInReadAction(@NotNull ProgressIndicator indicator) { insideReadAction.set(true); @@ -145,13 +143,14 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { } ApplicationManager.getApplication().runWriteAction(() -> assertTrue(indicator.isCanceled())); assertTrue(indicator.isCanceled()); + waitForComplete(future); } - public void testReadTaskCanceledShouldNotHappenAfterEdtContinuation() { + public void testReadTaskCanceledShouldNotHappenAfterEdtContinuation() throws Exception { for (int i = 0; i < 1000; i++) { final AtomicBoolean afterContinuation = new AtomicBoolean(); final ProgressIndicatorBase indicator = new ProgressIndicatorBase(); - ProgressIndicatorUtils.scheduleWithWriteActionPriority(indicator, new ReadTask() { + CompletableFuture future = ProgressIndicatorUtils.scheduleWithWriteActionPriority(indicator, new ReadTask() { @Override public Continuation performInReadAction(@NotNull ProgressIndicator indicator) throws ProcessCanceledException { return new Continuation(() -> afterContinuation.set(true)); @@ -169,6 +168,19 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { } }); UIUtil.dispatchAllInvocationEvents(); + waitForComplete(future); + } + } + + private static void waitForComplete(CompletableFuture future) throws InterruptedException, ExecutionException { + while (true) { + try { + future.get(1, TimeUnit.MILLISECONDS); + break; + } + catch (TimeoutException e) { + UIUtil.dispatchAllInvocationEvents(); + } } } @@ -199,7 +211,7 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { private volatile boolean taskCanceled; private volatile boolean taskSucceeded; private volatile Throwable exception; - public void testProgressManagerCheckCanceledDoesNotDelegateToProgressIndicatorIfThereAreNoCanceledIndicators() throws Throwable { + public void testProgressManagerCheckCanceledDoesNotDelegateToProgressIndicatorIfThereAreNoCanceledIndicators() { final long warmupEnd = System.currentTimeMillis() + 1000; final long end = warmupEnd + 10000; checkCanceledCalled = false; @@ -354,7 +366,7 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { for (int i=0;i<100000;i++) { ProgressManager.getInstance().executeProcessUnderProgress(EmptyRunnable.getInstance(), indicator); } - }).useLegacyScaling().assertTiming(); + }).assertTiming(); } public void testWrapperIndicatorGotCanceledTooWhenInnerIndicatorHas() { @@ -659,7 +671,7 @@ public class ProgressIndicatorTest extends LightPlatformTestCase { assertFalse(progressManager.isInNonCancelableSection()); } - public void testProgressIndicatorUtilsScheduleWithWriteActionPriorityMustRemoveListenerBeforeContinuationStartsExecutingInEDT() throws Throwable { + public void testProgressIndicatorUtilsScheduleWithWriteActionPriorityMustRemoveListenerBeforeContinuationStartsExecutingInEDT() { final AtomicBoolean canceled = new AtomicBoolean(); final ProgressIndicatorBase indicator = new ProgressIndicatorBase(); AtomicReference> future = new AtomicReference<>();