Ejemplo n.º 1
0
  public void loadDictionaryTest(@NotNull final String name, int wordCount) throws IOException {
    final Transformation transform = new Transformation();
    PlatformTestUtil.startPerformanceTest(
            "load dictionary",
            times.get(name),
            new ThrowableRunnable() {
              @Override
              public void run() throws Exception {
                dictionary =
                    CompressedDictionary.create(
                        new StreamLoader(
                            DefaultBundledDictionariesProvider.class.getResourceAsStream(name),
                            name),
                        transform);
              }
            })
        .cpuBound()
        .assertTiming();

    final Set<String> wordsToStoreAndCheck = createWordSets(name, 50000, 1).getFirst();
    PlatformTestUtil.startPerformanceTest(
            "words contain",
            2000,
            new ThrowableRunnable() {
              @Override
              public void run() throws Exception {
                for (String s : wordsToStoreAndCheck) {
                  assertTrue(dictionary.contains(s));
                }
              }
            })
        .cpuBound()
        .assertTiming();
  }
  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 testToStringOnUnqualified() {
    final PsiFile file =
        myFixture.addFileToProject(
            "Foo.java",
            "public class Fix {\n"
                + "    {\n"
                + "        <caret>toString();\n"
                + "    }\n"
                + "}\n"
                + "class FixImpl1 extends Fix {\n"
                + "    @Override\n"
                + "    public String toString() {\n"
                + "        return \"Impl1\";\n"
                + "    }\n"
                + "}\n"
                + "class FixImpl2 extends Fix {\n"
                + "    @Override\n"
                + "    public String toString() {\n"
                + "        return \"Impl2\";\n"
                + "    }\n"
                + "}");
    myFixture.configureFromExistingVirtualFile(file.getVirtualFile());

    PlatformTestUtil.startPerformanceTest(
            getTestName(false),
            150,
            () -> {
              PsiElement[] impls = getTargets(file);
              assertEquals(3, impls.length);
            })
        .cpuBound()
        .usesAllCPUCores()
        .assertTiming();
  }
  protected void doTest(final PerformAction performAction, final String testName) throws Exception {
    String path = getTestDataPath() + getTestRoot() + testName;

    String pathBefore = path + "/before";
    final VirtualFile rootDir =
        PsiTestUtil.createTestProjectStructure(
            myProject, myModule, pathBefore, myFilesToDelete, false);
    prepareProject(rootDir);
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();

    String pathAfter = path + "/after";
    final VirtualFile rootAfter =
        LocalFileSystem.getInstance().findFileByPath(pathAfter.replace(File.separatorChar, '/'));

    performAction.performAction(rootDir, rootAfter);
    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              public void run() {
                myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
              }
            });

    FileDocumentManager.getInstance().saveAllDocuments();

    if (myDoCompare) {
      PlatformTestUtil.assertDirectoriesEqual(rootAfter, rootDir);
    }
  }
  public void testRangeHighlighterLinesInRangeForLongLinePerformance() throws Exception {
    final int N = 50000;
    Document document =
        EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol('x', 2 * N));

    final MarkupModelEx markupModel =
        (MarkupModelEx) DocumentMarkupModel.forDocument(document, ourProject, true);
    for (int i = 0; i < N - 1; i++) {
      markupModel.addRangeHighlighter(2 * i, 2 * i + 1, 0, null, HighlighterTargetArea.EXACT_RANGE);
    }
    markupModel.addRangeHighlighter(
        N / 2, N / 2 + 1, 0, null, HighlighterTargetArea.LINES_IN_RANGE);

    PlatformTestUtil.startPerformanceTest(
            "slow highlighters lookup",
            (int) (N * Math.log(N) / 1000),
            new ThrowableRunnable() {
              @Override
              public void run() {
                List<RangeHighlighterEx> list = new ArrayList<RangeHighlighterEx>();
                CommonProcessors.CollectProcessor<RangeHighlighterEx> coll =
                    new CommonProcessors.CollectProcessor<RangeHighlighterEx>(list);
                for (int i = 0; i < N - 1; i++) {
                  list.clear();
                  markupModel.processRangeHighlightersOverlappingWith(2 * i, 2 * i + 1, coll);
                  assertEquals(2, list.size()); // 1 line plus one exact range marker
                }
              }
            })
        .assertTiming();
  }
  public void testExternalFileModificationWhileProjectClosed() throws Exception {
    VirtualFile root = ProjectRootManager.getInstance(myProject).getContentRoots()[0];

    PsiClass objectClass =
        myJavaFacade.findClass(
            CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject()));
    assertNotNull(objectClass);
    checkUsages(objectClass, new String[] {});
    FileBasedIndex.getInstance()
        .getContainingFiles(
            TodoIndex.NAME,
            new TodoIndexEntry("todo", true),
            GlobalSearchScope.allScope(getProject()));

    final String projectLocation = myProject.getPresentableUrl();
    assert projectLocation != null : myProject;
    PlatformTestUtil.saveProject(myProject);
    final VirtualFile content = ModuleRootManager.getInstance(getModule()).getContentRoots()[0];
    Project project = myProject;
    ProjectUtil.closeAndDispose(project);
    InjectedLanguageManagerImpl.checkInjectorsAreDisposed(project);

    assertTrue("Project was not disposed", myProject.isDisposed());
    myModule = null;

    final File file = new File(root.getPath(), "1.java");
    assertTrue(file.exists());

    FileUtil.writeToFile(file, "class A{ Object o;}".getBytes(CharsetToolkit.UTF8_CHARSET));
    root.refresh(false, true);

    LocalFileSystem.getInstance().refresh(false);

    myProject = ProjectManager.getInstance().loadAndOpenProject(projectLocation);
    InjectedLanguageManagerImpl.pushInjectors(getProject());

    setUpModule();
    setUpJdk();
    ProjectManagerEx.getInstanceEx().openTestProject(myProject);
    UIUtil.dispatchAllInvocationEvents(); // startup activities

    runStartupActivities();
    PsiTestUtil.addSourceContentToRoots(getModule(), content);

    assertNotNull(myProject);
    myPsiManager = (PsiManagerImpl) PsiManager.getInstance(myProject);
    myJavaFacade = JavaPsiFacadeEx.getInstanceEx(myProject);

    objectClass =
        myJavaFacade.findClass(
            CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject()));
    assertNotNull(objectClass);
    checkUsages(objectClass, new String[] {"1.java"});
  }
Ejemplo n.º 7
0
  public void testFindChildByNamePerformance() throws IOException {
    File tempDir =
        new WriteAction<File>() {
          @Override
          protected void run(Result<File> result) throws Throwable {
            File res = createTempDirectory();
            result.setResult(res);
          }
        }.execute().getResultObject();
    final VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(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");
                  assertSame(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 testPerformance() throws Exception {
    final String path = PathManagerEx.getTestDataPath() + "/psi/stub/StubPerformanceTest.java";
    String text = FileUtil.loadFile(new File(path));
    final PsiJavaFile file = (PsiJavaFile) createLightFile("test.java", text);

    PlatformTestUtil.startPerformanceTest(
            "Source file size: " + text.length(),
            2000,
            new ThrowableRunnable() {
              @Override
              public void run() throws Exception {
                NEW_BUILDER.buildStubTree(file);
              }
            })
        .cpuBound()
        .assertTiming();
  }
Ejemplo n.º 9
0
  public void testFindRootPerformance() {
    File tempDir =
        new WriteAction<File>() {
          @Override
          protected void run(Result<File> result) throws Throwable {
            File res = createTempDirectory();
            new File(res, "x.jar").createNewFile();
            result.setResult(res);
          }
        }.execute().getResultObject();
    final VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir);
    final VirtualFile jar = vDir.findChild("x.jar");
    assertNotNull(jar);

    final NewVirtualFile root =
        ManagingFS.getInstance().findRoot(jar.getPath() + "!/", JarFileSystem.getInstance());
    PlatformTestUtil.startPerformanceTest(
            "find root is slow",
            500,
            new ThrowableRunnable() {
              @Override
              public void run() throws Throwable {
                final String path = jar.getPath() + "!/";
                final JarFileSystem fileSystem = JarFileSystem.getInstance();
                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, fileSystem);
                              assertNotNull(rootJar);
                              assertSame(root, rootJar);
                            }
                            return true;
                          }
                        });
              }
            })
        .assertTiming();
  }
  public void testCopyDir() throws Exception {
    File fromDir = createTempDirectory();
    File toDir = createTempDirectory();

    VirtualFile fromVDir =
        LocalFileSystem.getInstance()
            .findFileByPath(fromDir.getPath().replace(File.separatorChar, '/'));
    VirtualFile toVDir =
        LocalFileSystem.getInstance()
            .findFileByPath(toDir.getPath().replace(File.separatorChar, '/'));
    assertNotNull(fromVDir);
    assertNotNull(toVDir);
    final VirtualFile dirToCopy = fromVDir.createChildDirectory(this, "dir");
    final VirtualFile file = dirToCopy.createChildData(this, "temp_file");
    file.setBinaryContent(new byte[] {0, 1, 2, 3});
    final String newName = "dir";
    final VirtualFile dirCopy = dirToCopy.copy(this, toVDir, newName);
    assertEquals(newName, dirCopy.getName());
    PlatformTestUtil.assertDirectoriesEqual(toVDir, fromVDir);
  }
  public void testCustomAttrsPerformance() throws Throwable {
    myFixture.copyFileToProject("dom/resources/bigfile.xml", "res/values/bigfile.xml");
    myFixture.copyFileToProject("dom/resources/bigattrs.xml", "res/values/bigattrs.xml");
    myFixture.copyFileToProject("dom/resources/bigattrs.xml", "res/values/bigattrs1.xml");
    myFixture.copyFileToProject("dom/resources/bigattrs.xml", "res/values/bigattrs2.xml");
    myFixture.copyFileToProject("dom/resources/bigattrs.xml", "res/values/bigattrs3.xml");
    VirtualFile f = copyFileToProject("bigfile.xml");
    myFixture.configureFromExistingVirtualFile(f);

    PlatformTestUtil.startPerformanceTest(
            "android custom attrs highlighting is slow",
            800,
            new ThrowableRunnable() {
              @Override
              public void run() throws Throwable {
                myFixture.doHighlighting();
              }
            })
        .attempts(2)
        .cpuBound()
        .usesAllCPUCores()
        .assertTiming();
  }
  public void testfieldImplicitWrite() throws Exception {
    PlatformTestUtil.registerExtension(
        ImplicitUsageProvider.EP_NAME,
        new ImplicitUsageProvider() {
          @Override
          public boolean isImplicitUsage(PsiElement element) {
            return isImplicitWrite(element);
          }

          @Override
          public boolean isImplicitRead(PsiElement element) {
            return false;
          }

          @Override
          public boolean isImplicitWrite(PsiElement element) {
            return element instanceof PsiField
                && "implicitWrite".equals(((PsiNamedElement) element).getName());
          }
        },
        getTestRootDisposable());

    doTest();
  }
Ejemplo n.º 13
0
  public void testPerformance() {
    @NonNls
    final String longName =
        "ThisIsAQuiteLongNameWithParentheses().Dots.-Minuses-_UNDERSCORES_digits239:colons:/slashes\\AndOfCourseManyLetters";
    final List<MinusculeMatcher> matching = new ArrayList<MinusculeMatcher>();
    final List<MinusculeMatcher> nonMatching = new ArrayList<MinusculeMatcher>();

    for (String s :
        ContainerUtil.ar("*", "*i", "*a", "*u", "T", "ti", longName, longName.substring(0, 20))) {
      matching.add(new MinusculeMatcher(s, NameUtil.MatchingCaseSensitivity.NONE));
    }
    for (String s : ContainerUtil.ar("A", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "tag")) {
      nonMatching.add(new MinusculeMatcher(s, NameUtil.MatchingCaseSensitivity.NONE));
    }

    PlatformTestUtil.startPerformanceTest(
            "Matcher is slow",
            3000,
            new ThrowableRunnable() {
              @Override
              public void run() {
                for (int i = 0; i < 100000; i++) {
                  for (MinusculeMatcher matcher : matching) {
                    assertTrue(matcher.toString(), matcher.matches(longName));
                    matcher.matchingDegree(longName);
                  }
                  for (MinusculeMatcher matcher : nonMatching) {
                    assertFalse(matcher.toString(), matcher.matches(longName));
                  }
                }
              }
            })
        .cpuBound()
        .attempts(20)
        .assertTiming();
  }
 @Override
 protected String getTestDataPath() {
   return PlatformTestUtil.getCommunityPath() + "/xml/tests/testData/documentation/";
 }
 @Override
 protected String getTestDataPath() {
   return PlatformTestUtil.getCommunityPath() + "/java/typeMigration/testData/inspections/guava";
 }
 @Override
 protected String getTestDataPath() {
   return PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + getBasePath();
 }
 void assertUpdates(String expected) {
   List<Object> entries = Arrays.asList(myElementUpdate.values().toArray());
   Assert.assertEquals(expected + "\n", PlatformTestUtil.print(entries) + "\n");
   myElementUpdate.clear();
 }