test: VFS performance tests extracted along with couple of utility methods
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Tue, 20 Jan 2015 11:45:49 +0000 (12:45 +0100)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Tue, 20 Jan 2015 19:10:57 +0000 (20:10 +0100)
platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java [new file with mode: 0644]
platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java
platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java
platform/testFramework/src/com/intellij/testFramework/UsefulTestCase.java
platform/util/src/com/intellij/util/ui/UIUtil.java

diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java
new file mode 100644 (file)
index 0000000..af9b337
--- /dev/null
@@ -0,0 +1,290 @@
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.openapi.vfs;
+
+import com.intellij.concurrency.JobLauncher;
+import com.intellij.openapi.command.WriteCommandAction;
+import com.intellij.openapi.progress.ProgressManager;
+import com.intellij.openapi.util.Ref;
+import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.openapi.util.io.IoTestUtil;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.openapi.vfs.newvfs.ManagingFS;
+import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
+import com.intellij.testFramework.PlatformLangTestCase;
+import com.intellij.testFramework.PlatformTestUtil;
+import com.intellij.testFramework.SkipSlowTestLocally;
+import com.intellij.util.Processor;
+import com.intellij.util.ThrowableRunnable;
+import com.intellij.util.TimeoutUtil;
+import com.intellij.util.ui.UIUtil;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+@SkipSlowTestLocally
+public class VfsUtilPerformanceTest extends PlatformLangTestCase {
+  @Override
+  protected boolean isRunInEdt() {
+    return false;
+  }
+
+  @Override
+  protected boolean isRunInWriteAction() {
+    return false;
+  }
+
+  @Override
+  protected void setUp() throws Exception {
+    invokeAndWaitIfNeeded(new ThrowableRunnable<Exception>() {
+      @Override
+      public void run() throws Exception {
+        VfsUtilPerformanceTest.super.setUp();
+      }
+    });
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    invokeAndWaitIfNeeded(new ThrowableRunnable<Exception>() {
+      @Override
+      public void run() throws Exception {
+        VfsUtilPerformanceTest.super.tearDown();
+      }
+    });
+  }
+
+  public void testFindChildByNamePerformance() throws IOException {
+    File tempDir = createTempDirectory();
+    final VirtualFile vDir = refreshAndFindFile(tempDir);
+    assertNotNull(vDir);
+    assertTrue(vDir.isDirectory());
+
+    new WriteCommandAction.Simple(getProject()) {
+      @Override
+      protected void run() throws Throwable {
+        for (int i = 0; i < 10000; i++) {
+          final String name = i + ".txt";
+          vDir.createChildData(vDir, name);
+        }
+      }
+    }.execute();
+
+    final VirtualFile theChild = vDir.findChild("5111.txt");
+    System.out.println("Start searching...");
+    PlatformTestUtil.startPerformanceTest("find child is slow", 450, new ThrowableRunnable() {
+      @Override
+      public void run() throws Throwable {
+        for (int i = 0; i < 1000000; i++) {
+          VirtualFile child = vDir.findChild("5111.txt");
+          assertEquals(theChild, child);
+        }
+      }
+    }).assertTiming();
+
+    new WriteCommandAction.Simple(getProject()) {
+      @Override
+      protected void run() throws Throwable {
+        for (VirtualFile file : vDir.getChildren()) {
+          file.delete(this);
+        }
+      }
+    }.execute().throwException();
+  }
+
+  public void testFindRootPerformance() throws IOException {
+    File tempJar = IoTestUtil.createTestJar();
+    final VirtualFile jar = refreshAndFindFile(tempJar);
+    assertNotNull(jar);
+
+    final JarFileSystem fs = JarFileSystem.getInstance();
+    final NewVirtualFile root = ManagingFS.getInstance().findRoot(jar.getPath() + "!/", fs);
+    PlatformTestUtil.startPerformanceTest("find root is slow", 500, new ThrowableRunnable() {
+      @Override
+      public void run() throws Throwable {
+        final String path = jar.getPath() + "!/";
+        JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(500, null), null, false, new Processor<Object>() {
+          @Override
+          public boolean process(Object o) {
+            for (int i = 0; i < 1000; i++) {
+              NewVirtualFile rootJar = ManagingFS.getInstance().findRoot(path, fs);
+              assertNotNull(rootJar);
+              assertSame(root, rootJar);
+            }
+            return true;
+          }
+        });
+      }
+    }).assertTiming();
+  }
+
+  public void testGetParentPerformance() throws IOException {
+    File tempDir = createTempDirectory();
+    final VirtualFile vDir = refreshAndFindFile(tempDir);
+    assertNotNull(vDir);
+    assertTrue(vDir.isDirectory());
+    final int depth = 10;
+    new WriteCommandAction.Simple(getProject()) {
+      @Override
+      protected void run() throws Throwable {
+        VirtualFile dir = vDir;
+        for (int i = 0; i < depth; i++) {
+          dir = dir.createChildDirectory(this, "foo");
+        }
+        final VirtualFile leafDir = dir;
+        ThrowableRunnable checkPerformance = new ThrowableRunnable() {
+          private VirtualFile findRoot(VirtualFile file) {
+            while (true) {
+              VirtualFile parent = file.getParent();
+              if (parent == null) {
+                return file;
+              }
+              file = parent;
+            }
+          }
+
+          @Override
+          public void run() throws Throwable {
+            for (int i = 0; i < 5000000; i++) {
+              checkRootsEqual();
+            }
+          }
+
+          private void checkRootsEqual() {
+            assertEquals(findRoot(vDir), findRoot(leafDir));
+          }
+        };
+        int time = 1200;
+        PlatformTestUtil.startPerformanceTest("getParent is slow before movement", time, checkPerformance).assertTiming();
+        VirtualFile dir1 = vDir.createChildDirectory(this, "dir1");
+        VirtualFile dir2 = vDir.createChildDirectory(this, "dir2");
+        for (int i = 0; i < 13; i++) {  /*13 is max length with THashMap capacity of 17, we get plenty collisions then*/
+          dir1.createChildData(this, "a" + i + ".txt").move(this, dir2);
+        }
+        PlatformTestUtil.startPerformanceTest("getParent is slow after movement", time, checkPerformance).assertTiming();
+      }
+    }.execute();
+  }
+
+  public void testGetPathPerformance() throws IOException, InterruptedException {
+    final File dir = createTempDirectory();
+
+    String path = dir.getPath() + StringUtil.repeat("/xxx", 50) + "/fff.txt";
+    File ioFile = new File(path);
+    boolean b = ioFile.getParentFile().mkdirs();
+    assertTrue(b);
+    boolean c = ioFile.createNewFile();
+    assertTrue(c);
+    final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(ioFile.getPath().replace(File.separatorChar, '/'));
+    assertNotNull(file);
+
+    PlatformTestUtil.startPerformanceTest("VF.getPath() performance failed", 4000, new ThrowableRunnable() {
+      @Override
+      public void run() {
+        for (int i = 0; i < 1000000; ++i) {
+          file.getPath();
+        }
+      }
+    }).cpuBound().assertTiming();
+  }
+
+  public void testAsyncRefresh() throws Throwable {
+    final Ref<Throwable> ex = Ref.create();
+    boolean success = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(
+      Arrays.asList(new Object[8]), ProgressManager.getInstance().getProgressIndicator(), true,
+      new Processor<Object>() {
+        @Override
+        public boolean process(Object o) {
+          try {
+            doAsyncRefreshTest();
+          }
+          catch (Throwable t) {
+            ex.set(t);
+          }
+          return true;
+        }
+      });
+
+    if (!ex.isNull()) throw ex.get();
+    if (!success) fail("!success");
+  }
+
+  private void doAsyncRefreshTest() throws Exception {
+    final int N = 1000;
+    final byte[] data = "xxx".getBytes(CharsetToolkit.UTF8_CHARSET);
+
+    File temp = createTempDirectory();
+    LocalFileSystem fs = LocalFileSystem.getInstance();
+    VirtualFile vTemp = fs.findFileByIoFile(temp);
+    assertNotNull(vTemp);
+
+    VirtualFile[] children = new VirtualFile[N];
+    long[] timestamp = new long[N];
+
+    for (int i = 0; i < N; i++) {
+      File file = new File(temp, i + ".txt");
+      FileUtil.writeToFile(file, data);
+      VirtualFile child = fs.refreshAndFindFileByIoFile(file);
+      assertNotNull(child);
+      children[i] = child;
+      timestamp[i] = file.lastModified();
+    }
+
+    vTemp.refresh(false, true);
+
+    for (int i = 0; i < N; i++) {
+      File file = new File(temp, i + ".txt");
+      assertEquals(timestamp[i], file.lastModified());
+      VirtualFile child = fs.findFileByIoFile(file);
+      assertNotNull(child);
+      IoTestUtil.assertTimestampsEqual(timestamp[i], child.getTimeStamp());
+    }
+
+    for (int i = 0; i < N; i++) {
+      File file = new File(temp, i + ".txt");
+      FileUtil.writeToFile(file, data);
+      assertTrue(file.setLastModified(timestamp[i] - 2000));
+      long modified = file.lastModified();
+      assertTrue("File:" + file.getPath() + "; time:" + modified, timestamp[i] != modified);
+      timestamp[i] = modified;
+      IoTestUtil.assertTimestampsNotEqual(children[i].getTimeStamp(), modified);
+    }
+
+    final CountDownLatch latch = new CountDownLatch(N);
+    for (final VirtualFile child : children) {
+      child.refresh(true, true, new Runnable() {
+        @Override
+        public void run() {
+          latch.countDown();
+        }
+      });
+      TimeoutUtil.sleep(10);
+    }
+    while (latch.getCount() > 0) {
+      latch.await(100, TimeUnit.MILLISECONDS);
+      UIUtil.pump();
+    }
+
+    for (int i = 0; i < N; i++) {
+      VirtualFile child = children[i];
+      IoTestUtil.assertTimestampsEqual(timestamp[i], child.getTimeStamp());
+    }
+  }
+}
index 7f747f90ff0714200a5a88c5ed1e2dd1c20190d4..1fbbb68c8a715d69c2d7f04d55aba5b330c57529 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 package com.intellij.openapi.vfs;
 
-import com.intellij.concurrency.JobLauncher;
 import com.intellij.openapi.application.Result;
 import com.intellij.openapi.application.WriteAction;
 import com.intellij.openapi.application.ex.PathManagerEx;
-import com.intellij.openapi.command.WriteCommandAction;
-import com.intellij.openapi.progress.ProgressManager;
-import com.intellij.openapi.util.Computable;
 import com.intellij.openapi.util.SystemInfo;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.io.IoTestUtil;
-import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.newvfs.ManagingFS;
 import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
 import com.intellij.testFramework.PlatformLangTestCase;
-import com.intellij.testFramework.PlatformTestUtil;
 import com.intellij.testFramework.UsefulTestCase;
 import com.intellij.testFramework.vcs.DirectoryData;
-import com.intellij.util.Processor;
 import com.intellij.util.ThrowableRunnable;
-import com.intellij.util.TimeoutUtil;
-import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.File;
@@ -44,16 +35,12 @@ import java.net.URI;
 import java.net.URL;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
 
 public class VfsUtilTest extends PlatformLangTestCase {
   @Override
-  protected void runBareRunnable(Runnable runnable) throws Throwable {
-    runnable.run();
+  protected boolean isRunInEdt() {
+    return false;
   }
 
   @Override
@@ -63,30 +50,20 @@ public class VfsUtilTest extends PlatformLangTestCase {
 
   @Override
   protected void setUp() throws Exception {
-    UIUtil.invokeAndWaitIfNeeded(new Runnable() {
+    invokeAndWaitIfNeeded(new ThrowableRunnable<Exception>() {
       @Override
-      public void run() {
-        try {
-          VfsUtilTest.super.setUp();
-        }
-        catch (Exception e) {
-          throw new RuntimeException(e);
-        }
+      public void run() throws Exception {
+        VfsUtilTest.super.setUp();
       }
     });
   }
 
   @Override
   protected void tearDown() throws Exception {
-    UIUtil.invokeAndWaitIfNeeded(new Runnable() {
+    invokeAndWaitIfNeeded(new ThrowableRunnable<Exception>() {
       @Override
-      public void run() {
-        try {
-          VfsUtilTest.super.tearDown();
-        }
-        catch (Exception e) {
-          throw new RuntimeException(e);
-        }
+      public void run() throws Exception {
+        VfsUtilTest.super.tearDown();
       }
     });
   }
@@ -177,89 +154,6 @@ public class VfsUtilTest extends PlatformLangTestCase {
     }
   }
 
-  public void testAsyncRefresh() throws Throwable {
-    final File tempDir = createTempDirectory();
-
-    final Throwable[] ex = {null};
-    boolean success = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(
-      Arrays.asList(new Object[8]),
-      ProgressManager.getInstance().getProgressIndicator(), true, new Processor<Object>() {
-      @Override
-      public boolean process(Object o) {
-        try {
-          doAsyncRefreshTest(tempDir);
-        }
-        catch (Throwable t) {
-          ex[0] = t;
-        }
-        return true;
-      }
-    });
-
-    if (ex[0] != null) throw ex[0];
-    if (!success) fail("!success");
-  }
-
-  private static void doAsyncRefreshTest(File temp) throws Exception {
-    final int N = 1000;
-    final byte[] data = "xxx".getBytes(CharsetToolkit.UTF8_CHARSET);
-
-    LocalFileSystem fs = LocalFileSystem.getInstance();
-    VirtualFile vTemp = fs.findFileByIoFile(temp);
-    assertNotNull(vTemp);
-    VirtualFile[] children = new VirtualFile[N];
-
-    long[] timestamp = new long[N];
-    for (int i = 0; i < N; i++) {
-      File file = new File(temp, i + ".txt");
-      FileUtil.writeToFile(file, data);
-      VirtualFile child = fs.refreshAndFindFileByIoFile(file);
-      assertNotNull(child);
-      children[i] = child;
-      timestamp[i] = file.lastModified();
-    }
-
-    vTemp.refresh(false, true);
-
-    for (int i = 0; i < N; i++) {
-      File file = new File(temp, i + ".txt");
-      assertEquals(timestamp[i], file.lastModified());
-      VirtualFile child = fs.findFileByIoFile(file);
-      assertNotNull(child);
-      IoTestUtil.assertTimestampsEqual(timestamp[i], child.getTimeStamp());
-    }
-
-    for (int i = 0; i < N; i++) {
-      File file = new File(temp, i + ".txt");
-      FileUtil.writeToFile(file, data);
-      assertTrue(file.setLastModified(timestamp[i] - 2000));
-      long modified = file.lastModified();
-      assertTrue("File:" + file.getPath() + "; time:" + modified, timestamp[i] != modified);
-      timestamp[i] = modified;
-      IoTestUtil.assertTimestampsNotEqual(children[i].getTimeStamp(), modified);
-    }
-
-    final CountDownLatch latch = new CountDownLatch(N);
-    for (final VirtualFile child : children) {
-      child.refresh(true, true, new Runnable() {
-        @Override
-        public void run() {
-          latch.countDown();
-        }
-      });
-      TimeoutUtil.sleep(10);
-    }
-    while (latch.getCount() > 0) {
-      latch.await(100, TimeUnit.MILLISECONDS);
-      UIUtil.pump();
-    }
-
-    for (int i = 0; i < N; i++) {
-      VirtualFile child = children[i];
-      IoTestUtil.assertTimestampsEqual(timestamp[i], child.getTimeStamp());
-    }
-  }
-
   public void testFindChildWithTrailingSpace() throws IOException {
     File tempDir = createTempDirectory();
     VirtualFile vDir = LocalFileSystem.getInstance().findFileByIoFile(tempDir);
@@ -295,15 +189,6 @@ public class VfsUtilTest extends PlatformLangTestCase {
     assertTrue(vFile2.isDirectory());
   }
 
-  private static VirtualFile refreshAndFindFile(final File file) {
-    return UIUtil.invokeAndWaitIfNeeded(new Computable<VirtualFile>() {
-      @Override
-      public VirtualFile compute() {
-        return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
-      }
-    });
-  }
-
   public void testPresentableUrlSurvivesDeletion() throws IOException {
     final VirtualFile file = createTempFile("txt", null, "content", Charset.defaultCharset());
     String url = file.getPresentableUrl();
@@ -379,128 +264,18 @@ public class VfsUtilTest extends PlatformLangTestCase {
     assertFalse(VfsUtilCore.isEqualOrAncestor("file:///my/dir/", "file:///my/dir2"));
   }
 
-  public void testFindChildByNamePerformance() throws IOException {
-    File tempDir = createTempDirectory();
-    final VirtualFile vDir = refreshAndFindFile(tempDir);
-    assertNotNull(vDir);
-    assertTrue(vDir.isDirectory());
-
-    new WriteCommandAction.Simple(getProject()) {
-      @Override
-      protected void run() throws Throwable {
-        for (int i=0; i<10000; i++) {
-          final String name = i + ".txt";
-          vDir.createChildData(vDir, name);
-        }
-      }
-    }.execute();
-    final VirtualFile theChild = vDir.findChild("5111.txt");
-    System.out.println("Start searching...");
-    PlatformTestUtil.startPerformanceTest("find child is slow", 450, new ThrowableRunnable() {
-      @Override
-      public void run() throws Throwable {
-        for (int i = 0; i < 1000000; i++) {
-          VirtualFile child = vDir.findChild("5111.txt");
-          assertEquals(theChild, child);
-        }
-      }
-    }).assertTiming();
-
-    new WriteCommandAction.Simple(getProject()) {
-      @Override
-      protected void run() throws Throwable {
-        for (VirtualFile file : vDir.getChildren()) {
-          file.delete(this);
-        }
-      }
-    }.execute().throwException();
-
-  }
-
-  public void testGetParentPerformance() throws IOException {
-    File tempDir = createTempDirectory();
-    final VirtualFile vDir = refreshAndFindFile(tempDir);
-    assertNotNull(vDir);
-    assertTrue(vDir.isDirectory());
-    final int depth = 10;
-    new WriteCommandAction.Simple(getProject()) {
-      @Override
-      protected void run() throws Throwable {
-        VirtualFile dir = vDir;
-        for (int i=0; i<depth; i++) {
-          dir = dir.createChildDirectory(this, "foo");
-        }
-        final VirtualFile leafDir = dir;
-        ThrowableRunnable checkPerformance = new ThrowableRunnable() {
-          private VirtualFile findRoot(VirtualFile file) {
-            while (true) {
-              VirtualFile parent = file.getParent();
-              if (parent == null) {
-                return file;
-              }
-              file = parent;
-            }
-          }
-          @Override
-          public void run() throws Throwable {
-            for (int i = 0; i < 5000000; i++) {
-              checkRootsEqual();
-            }
-          }
-          private void checkRootsEqual() {
-            assertEquals(findRoot(vDir), findRoot(leafDir));
-          }
-        };
-        int time = 1200;
-        PlatformTestUtil.startPerformanceTest("getParent is slow before movement", time, checkPerformance).assertTiming();
-        VirtualFile dir1 = vDir.createChildDirectory(this, "dir1");
-        VirtualFile dir2 = vDir.createChildDirectory(this, "dir2");
-        for (int i = 0; i < 13; i++) {  /*13 is max length with THashMap capacity of 17, we get plenty collisions then*/
-          dir1.createChildData(this, "a" + i + ".txt").move(this, dir2);
-        }
-        PlatformTestUtil.startPerformanceTest("getParent is slow after movement", time, checkPerformance).assertTiming();
-      }
-    }.execute();
-  }
-
   public void testFindRootWithDenormalizedPath() throws IOException {
     File tempJar = IoTestUtil.createTestJar();
     VirtualFile jar = refreshAndFindFile(tempJar);
     assertNotNull(jar);
 
     JarFileSystem fs = JarFileSystem.getInstance();
-    NewVirtualFile root1 = ManagingFS.getInstance().findRoot(jar.getPath()+"!/", fs);
-    NewVirtualFile root2 = ManagingFS.getInstance().findRoot(jar.getParent().getPath() + "//"+ jar.getName()+"!/", fs);
+    NewVirtualFile root1 = ManagingFS.getInstance().findRoot(jar.getPath() + "!/", fs);
+    NewVirtualFile root2 = ManagingFS.getInstance().findRoot(jar.getParent().getPath() + "//" + jar.getName() + "!/", fs);
     assertNotNull(root1);
     assertSame(root1, root2);
   }
 
-  public void testFindRootPerformance() throws IOException {
-    File tempJar = IoTestUtil.createTestJar();
-    final VirtualFile jar = refreshAndFindFile(tempJar);
-    assertNotNull(jar);
-
-    final JarFileSystem fs = JarFileSystem.getInstance();
-    final NewVirtualFile root = ManagingFS.getInstance().findRoot(jar.getPath()+"!/", fs);
-    PlatformTestUtil.startPerformanceTest("find root is slow", 500, new ThrowableRunnable() {
-      @Override
-      public void run() throws Throwable {
-        final String path = jar.getPath() + "!/";
-        JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(500, null), null, false, new Processor<Object>() {
-          @Override
-          public boolean process(Object o) {
-            for (int i = 0; i < 1000; i++) {
-              NewVirtualFile rootJar = ManagingFS.getInstance().findRoot(path, fs);
-              assertNotNull(rootJar);
-              assertSame(root, rootJar);
-            }
-            return true;
-          }
-        });
-      }
-    }).assertTiming();
-  }
-
   public void testNotCanonicallyNamedChild() throws IOException {
     File tempDir = createTempDirectory();
     assertTrue(new File(tempDir, "libFiles").createNewFile());
@@ -527,26 +302,4 @@ public class VfsUtilTest extends PlatformLangTestCase {
     assertNull(vDir.findChild("xxx/extFiles"));
     assertNull(vDir.findChild("xxx//extFiles"));
   }
-
-  public void testGetPathPerformance() throws IOException, InterruptedException {
-    final File dir = createTempDirectory();
-
-    String path = dir.getPath() + StringUtil.repeat("/xxx", 50) + "/fff.txt";
-    File ioFile = new File(path);
-    boolean b = ioFile.getParentFile().mkdirs();
-    assertTrue(b);
-    boolean c = ioFile.createNewFile();
-    assertTrue(c);
-    final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(ioFile.getPath().replace(File.separatorChar, '/'));
-    assertNotNull(file);
-
-    PlatformTestUtil.startPerformanceTest("VF.getPath() performance failed", 4000, new ThrowableRunnable() {
-      @Override
-      public void run() {
-        for (int i = 0; i < 1000000; ++i) {
-          file.getPath();
-        }
-      }
-    }).cpuBound().assertTiming();
-  }
 }
index 4903d158a6ecb2a6be230ce59baddf6797083e56..2da9ce6d28d525b3a6bf51f554d6a9f194b8abdf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -707,8 +707,17 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
     }
   }
 
+  protected boolean isRunInEdt() {
+    return true;
+  }
+
   protected void runBareRunnable(Runnable runnable) throws Throwable {
-    SwingUtilities.invokeAndWait(runnable);
+    if (isRunInEdt()) {
+      SwingUtilities.invokeAndWait(runnable);
+    }
+    else {
+      runnable.run();
+    }
   }
 
   protected boolean isRunInWriteAction() {
@@ -918,6 +927,4 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
       }
     }.execute().throwException();
   }
-
-
 }
index fae50fd1acbb1c8496a1e6a9eab2dd5aee4e6576..fdfe79d47afaaa9b18ee84a8968b9d180b5b285c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,10 +31,7 @@ import com.intellij.openapi.util.*;
 import com.intellij.openapi.util.io.FileSystemUtil;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.vfs.CharsetToolkit;
-import com.intellij.openapi.vfs.VfsUtilCore;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.openapi.vfs.VirtualFileVisitor;
+import com.intellij.openapi.vfs.*;
 import com.intellij.psi.PsiDocumentManager;
 import com.intellij.psi.codeStyle.CodeStyleSchemes;
 import com.intellij.psi.codeStyle.CodeStyleSettings;
@@ -1038,4 +1035,35 @@ public abstract class UsefulTestCase extends TestCase {
     }.process(test);
     return testSuite;
   }
+
+  @Nullable
+  public static VirtualFile refreshAndFindFile(@NotNull final File file) {
+    return UIUtil.invokeAndWaitIfNeeded(new Computable<VirtualFile>() {
+      @Override
+      public VirtualFile compute() {
+        return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
+      }
+    });
+  }
+
+  public static <E extends Exception> void invokeAndWaitIfNeeded(@NotNull final ThrowableRunnable<E> runnable) throws Exception {
+    if (SwingUtilities.isEventDispatchThread()) {
+      runnable.run();
+    }
+    else {
+      final Ref<Exception> ref = Ref.create();
+      SwingUtilities.invokeAndWait(new Runnable() {
+        @Override
+        public void run() {
+          try {
+            runnable.run();
+          }
+          catch (Exception e) {
+            ref.set(e);
+          }
+        }
+      });
+      if (!ref.isNull()) throw ref.get();
+    }
+  }
 }
index 02bed0eedf02bb566317c190dbc47cdc036e92a7..4b092a1b07fd3aae47a003e3b497420e8a8666e0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -2368,6 +2368,7 @@ public class UIUtil {
       runnable.run();
     }
     else {
+      //noinspection SSBasedInspection
       SwingUtilities.invokeLater(runnable);
     }
   }
@@ -2377,8 +2378,9 @@ public class UIUtil {
    * or in the current thread if the current thread
    * is event queue thread.
    * DO NOT INVOKE THIS METHOD FROM UNDER READ ACTION.
+   *
    * @param runnable a runnable to invoke
-   * @see #invokeAndWaitIfNeeded(com.intellij.util.ThrowableRunnable)
+   * @see #invokeAndWaitIfNeeded(ThrowableRunnable)
    */
   public static void invokeAndWaitIfNeeded(@NotNull Runnable runnable) {
     if (SwingUtilities.isEventDispatchThread()) {
@@ -2399,8 +2401,9 @@ public class UIUtil {
    * or in the current thread if the current thread
    * is event queue thread.
    * DO NOT INVOKE THIS METHOD FROM UNDER READ ACTION.
+   *
    * @param computable a runnable to invoke
-   * @see #invokeAndWaitIfNeeded(com.intellij.util.ThrowableRunnable)
+   * @see #invokeAndWaitIfNeeded(ThrowableRunnable)
    */
   public static <T> T invokeAndWaitIfNeeded(@NotNull final Computable<T> computable) {
     final Ref<T> result = Ref.create();
@@ -2418,15 +2421,16 @@ public class UIUtil {
    * or in the current thread if the current thread
    * is event queue thread.
    * DO NOT INVOKE THIS METHOD FROM UNDER READ ACTION.
+   *
    * @param runnable a runnable to invoke
-   * @see #invokeAndWaitIfNeeded(com.intellij.util.ThrowableRunnable)
+   * @see #invokeAndWaitIfNeeded(ThrowableRunnable)
    */
   public static void invokeAndWaitIfNeeded(@NotNull final ThrowableRunnable runnable) throws Throwable {
     if (SwingUtilities.isEventDispatchThread()) {
       runnable.run();
     }
     else {
-      final Ref<Throwable> ref = new Ref<Throwable>();
+      final Ref<Throwable> ref = Ref.create();
       SwingUtilities.invokeAndWait(new Runnable() {
         @Override
         public void run() {