@Override public void projectOpened() { try { WriteAction.run(new ThrowableRunnable<Throwable>() { @Override public void run() throws Throwable { String ignoredFiles = FileTypeManager.getInstance().getIgnoredFilesList(); if (ignoredFiles.length() == 0) { ignoredFiles = "*.dso"; } else { ignoredFiles = ignoredFiles + ";*.dso"; } FileTypeManager.getInstance().setIgnoredFilesList(ignoredFiles); } }); } catch (Throwable ignored) { } }
@Override protected void setUp() throws Exception { if (ourOutputRoot == null) { ourOutputRoot = FileUtil.createTempDirectory("ExecutionTestCase", null, true); } myModuleOutputDir = new File(ourOutputRoot, PathUtil.getFileName(getTestAppPath())); myChecker = initOutputChecker(); EdtTestUtil.runInEdtAndWait(new ThrowableRunnable<Throwable>() { @Override public void run() throws Throwable { ExecutionTestCase.super.setUp(); } }); if (!myModuleOutputDir.exists()) { myCompilerTester = new CompilerTester(myProject, Arrays.asList(ModuleManager.getInstance(myProject).getModules())); List<CompilerMessage> messages = myCompilerTester.rebuild(); for (CompilerMessage message : messages) { if (message.getCategory() == CompilerMessageCategory.ERROR) { FileUtil.delete(myModuleOutputDir); fail("Compilation failed: " + message); } } } }
@Override protected void tearDown() throws Exception { if (myCompilerTester != null) { myCompilerTester.tearDown(); } EdtTestUtil.runInEdtAndWait(new ThrowableRunnable<Throwable>() { @Override public void run() throws Throwable { ExecutionTestCase.super.tearDown(); } }); //myChecker.checkValid(getTestProjectJdk()); //probably some thread is destroyed right now because of log exception //wait a little bit synchronized (this) { wait(300); } }
private List<HighlightInfo> startTest(int maxMillis) { PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); getFile().getText(); //to load text CodeInsightTestFixtureImpl.ensureIndexesUpToDate(getProject()); final List<HighlightInfo> infos = new ArrayList<HighlightInfo>(); PlatformTestUtil.startPerformanceTest(getTestName(false), maxMillis, new ThrowableRunnable() { @Override public void run() throws Exception { infos.clear(); DaemonCodeAnalyzer.getInstance(getProject()).restart(); List<HighlightInfo> h = doHighlighting(); infos.addAll(h); } }).cpuBound().usesAllCPUCores().assertTiming(); return highlightErrors(); }
public void testLargeTextFileWithManyTypos() { final int typoCount = 50000; @SuppressWarnings("SpellCheckingInspection") String text = StringUtil.repeat("aaaaaaaaa ", typoCount); // about 0.5M long start = System.currentTimeMillis(); VirtualFile file = myFixture.addFileToProject("foo.txt", text).getVirtualFile(); System.out.println("creation took " + (System.currentTimeMillis() - start) + " ms"); start = System.currentTimeMillis(); myFixture.configureFromExistingVirtualFile(file); System.out.println("configure took " + (System.currentTimeMillis() - start) + " ms"); myFixture.enableInspections(getInspectionTools()); start = System.currentTimeMillis(); assertSize(typoCount, myFixture.doHighlighting()); System.out.println("warm-up took " + (System.currentTimeMillis() - start) + " ms"); PlatformTestUtil.startPerformanceTest("many typos highlighting", 1000, new ThrowableRunnable() { @Override public void run() { assertSize(typoCount, myFixture.doHighlighting()); } }).cpuBound().assertTiming(); }
@Override public void computeDeployments(@NotNull final ComputeDeploymentsCallback callback) { getTaskExecutor().submit(new ThrowableRunnable<Exception>() { @Override public void run() throws Exception { try { for (CloudApplicationRuntime application : getApplications()) { Deployment deployment = callback.addDeployment(application.getApplicationName(), application, application.getStatus(), application.getStatusText(), application.getGroup()); application.setDeploymentModel(deployment); } callback.succeeded(); } catch (ServerRuntimeException e) { callback.errorOccurred(e.getMessage()); } } }, callback); }
@Override public void undeploy(@NotNull final UndeploymentTaskCallback callback) { myTaskExecutor.submit(new ThrowableRunnable<Exception>() { @Override public void run() throws Exception { getApplication().undeploy(new CloudAgentDeploymentCallback() { @Override public void succeeded() { callback.succeeded(); } @Override public void errorOccurred(String errorMessage) { callback.errorOccurred(errorMessage); } }); } }, callback); }
@After @Override public void tearDown() throws Exception { try { EdtTestUtil.runInEdtAndWait(new ThrowableRunnable<Throwable>() { @Override public void run() throws Throwable { CompilerTestUtil.disableExternalCompiler(myProject); tearDownFixtures(); } }); myProject = null; if (!FileUtil.delete(myTestDir) && myTestDir.exists()) { System.err.println("Cannot delete " + myTestDir); //printDirectoryContent(myDir); myTestDir.deleteOnExit(); } } finally { super.tearDown(); resetClassFields(getClass()); } }
private void setUpProject() throws IOException { File tempDirectory = FileUtil.createTempDirectory(myName, ""); PlatformTestCase.synchronizeTempDirVfs(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory)); myFilesToDelete.add(tempDirectory); String projectPath = FileUtil.toSystemIndependentName(tempDirectory.getPath()) + "/" + myName + ProjectFileType.DOT_DEFAULT_EXTENSION; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); new Throwable(projectPath).printStackTrace(new PrintStream(buffer)); myProject = PlatformTestCase.createProject(projectPath, buffer.toString()); EdtTestUtil.runInEdtAndWait(new ThrowableRunnable<Throwable>() { @SuppressWarnings("TestOnlyProblems") @Override public void run() throws Throwable { ProjectManagerEx.getInstanceEx().openTestProject(myProject); for (ModuleFixtureBuilder moduleFixtureBuilder : myModuleFixtureBuilders) { moduleFixtureBuilder.getFixture().setUp(); } LightPlatformTestCase.clearUncommittedDocuments(myProject); ((FileTypeManagerImpl)FileTypeManager.getInstance()).drainReDetectQueue(); } }); }
public void restoreDefaultValue() { final Property property = getSelectionProperty(); if (property != null) { if (isEditing()) { cellEditor.stopCellEditing(); } doRestoreDefault(new ThrowableRunnable<Exception>() { @Override public void run() throws Exception { for (PropertiesContainer component : myContainers) { if (!property.isDefaultRecursively(component)) { property.setDefaultValue(component); } } } }); repaint(); } }
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 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 testInitialRegisterPerformance() { PlatformTestUtil.startPerformanceTest("IElementType add", 100, new ThrowableRunnable() { @Override public void run() throws Throwable { Language language = Language.ANY; IElementType[] old = IElementType.push(new IElementType[0]); try { for (short i = 0; i < 15000; i++) { IElementType type = new IElementType("i " + i, language); assertEquals(i, type.getIndex()); } } finally { IElementType.push(old); } } }).assertTiming(); }
@Test public void performance() throws Exception { final IElementType[] elementTypes = IElementType.enumerate(IElementType.TRUE); final TokenSet set = TokenSet.create(); final int shift = new Random().nextInt(500000); PlatformTestUtil.startPerformanceTest("TokenSet.contains() performance", 25, new ThrowableRunnable() { @Override public void run() throws Throwable { for (int i = 0; i < 1000000; i++) { final IElementType next = elementTypes[((i + shift) % elementTypes.length)]; assertFalse(set.contains(next)); } } }).cpuBound().assertTiming(); }
public void testReformatAndShortenClassRefPerformance() throws IOException { final String testName = getTestName(false); final String ext = "java"; final String message = "Reformat And Shorten Class Ref Performance"; options.setToReformatAccordingToStyle(true); options.setToShortenFQN(true); try { PlatformTestUtil.startPerformanceTest("SSR should work fast", 3500, new ThrowableRunnable() { public void run() { doTest(testName, ext, message); } } ).cpuBound().assertTiming(); } finally { options.setToReformatAccordingToStyle(false); options.setToShortenFQN(false); } }
public static boolean wrap(final ThrowableRunnable<VcsException> runnable, final Project project, final String title) { final VcsException[] exc = new VcsException[1]; final Runnable process = new Runnable() { @Override public void run() { try { runnable.run(); } catch (VcsException e) { exc[0] = e; } } }; final boolean notCanceled; if (ApplicationManager.getApplication().isDispatchThread()) { notCanceled = ProgressManager.getInstance().runProcessWithProgressSynchronously(process, title, true, project); } else { process.run(); notCanceled = true; } if (exc[0] != null) { AbstractVcsHelper.getInstance(project).showError(exc[0], title); return false; } return notCanceled; }
public static void runExport(final Project project, @NotNull ThrowableRunnable<IOException> runnable) { try { runnable.run(); } catch (IOException e) { Runnable showError = new Runnable() { @Override public void run() { Messages.showMessageDialog( project, InspectionsBundle.message("inspection.export.error.writing.to", "export file"), InspectionsBundle.message("inspection.export.results.error.title"), Messages.getErrorIcon() ); } }; ApplicationManager.getApplication().invokeLater(showError, ModalityState.NON_MODAL); throw new ProcessCanceledException(); } }
@Override public <T extends Throwable> void performActionWithFormatterDisabled(final ThrowableRunnable<T> r) throws T { final Throwable[] throwable = new Throwable[1]; performActionWithFormatterDisabled(new Computable<Object>() { @Override public Object compute() { try { r.run(); } catch (Throwable t) { throwable[0] = t; } return null; } }); if (throwable[0] != null) { //noinspection unchecked throw (T)throwable[0]; } }
private void doIndentTest(int time) { configureByFile(getBasePath() + getTestName(false)+".xml"); doHighlighting(); myEditor.getSelectionModel().setSelection(0,myEditor.getDocument().getTextLength()); PlatformTestUtil.startPerformanceTest("Fix long indent/unindent "+time, time, new ThrowableRunnable() { @Override public void run() { EditorActionManager.getInstance().getActionHandler("EditorIndentSelection").execute(myEditor, DataManager.getInstance().getDataContext()); EditorActionManager.getInstance().getActionHandler("EditorUnindentSelection").execute(myEditor, DataManager.getInstance().getDataContext()); } }).assertTiming(); final int startOffset = myEditor.getCaretModel().getOffset(); myEditor.getSelectionModel().setSelection(startOffset,startOffset); checkResultByFile(getBasePath() + getTestName(false)+".xml"); }
public void _testReparsePerformance() throws Exception { final String text = loadFile("performance2.xml"); final PsiFile file = createFile("test.xml", text); transformAllChildren(file.getNode()); final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); System.gc(); System.gc(); new WriteCommandAction(getProject(), file) { @Override protected void run(@NotNull final Result result) throws Throwable { PlatformTestUtil.startPerformanceTest("XML reparse using PsiBuilder", 2500, new ThrowableRunnable() { @Override public void run() throws Exception { for (int i = 0; i < 10; i++) { final long tm = System.currentTimeMillis(); doc.insertString(0, "<additional root=\"tag\"/>"); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); System.out.println("Reparsed for: " + (System.currentTimeMillis() - tm)); } } }).cpuBound().assertTiming(); } }.execute(); }
@Override protected void executeWithReparse(ThrowableRunnable<Exception> operation) { if (!ReadonlyStatusHandler.ensureFilesWritable(getProject(), myFile)) { return; } try { myPsiChangeListener.stop(); operation.run(); myPsiChangeListener.start(); reparseFile(); } catch (Throwable e) { showError("Execute command", e); myPsiChangeListener.start(); } }
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 testBigFile() throws Exception { configureByFiles(null, getVirtualFile(getTestName(false) + ".xml"), getVirtualFile("buildserver.xml"), getVirtualFile("buildserver.properties")); try { myIgnoreInfos = true; PlatformTestUtil.startPerformanceTest("Should be quite performant !", 25000, new ThrowableRunnable() { @Override public void run() { doDoTest(true, false); } }).cpuBound().assertTiming(); } finally { myIgnoreInfos = false; } }
@After @Override public void tearDown() throws Exception { try { if (myTempDir != null) { FileUtil.delete(myTempDir); } } finally { EdtTestUtil.runInEdtAndWait(new ThrowableRunnable() { @Override public void run() throws Throwable { GitRepositoryReaderTest.super.tearDown(); } }); } }
@Override protected void tearDown() throws Exception { try { if (myDialogManager != null) { myDialogManager.cleanup(); } if (myVcsNotifier != null) { myVcsNotifier.cleanup(); } } finally { try { EdtTestUtil.runInEdtAndWait(new ThrowableRunnable<Throwable>() { @Override public void run() throws Exception { GitPlatformTest.super.tearDown(); } }); } finally { if (myAssertionsInTestDetected) { TestLoggerFactory.dumpLogToStdout(myTestStartedIndicator); } } } }
private static void edt(@NotNull final ThrowableRunnable<Exception> runnable) throws Exception { final AtomicReference<Exception> exception = new AtomicReference<Exception>(); UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { try { runnable.run(); } catch (Exception throwable) { exception.set(throwable); } } }); //noinspection ThrowableResultOfMethodCallIgnored if (exception.get() != null) { throw exception.get(); } }
protected Command createCommand(CvsRootProvider root, CvsExecutionEnvironment cvsExecutionEnvironment) { final CheckoutCommand command = new CheckoutCommand(new ThrowableRunnable<IOCommandException>() { public void run() throws IOCommandException { ((CheckoutAdminWriter) myAdminWriter).finish(); } }); command.setRecursive(true); for (String myModuleName : myModuleNames) { command.addModule(myModuleName); } root.getRevisionOrDate().setForCommand(command); command.setAlternativeCheckoutDirectory(myAlternateCheckoutDirectory); command.setPruneDirectories(myPruneEmptyDirectories); command.setKeywordSubstitution(myKeywordSubstitution); return command; }
@Override public void actionPerformed(AnActionEvent e) { myDesigner.getToolProvider().execute(new ThrowableRunnable<Exception>() { @Override public void run() throws Exception { List<RadComponent> newComponents = new ArrayList<RadComponent>(); for (RadComponent component : myComponents) { RadComponent newComponent = component.morphingTo(myTarget); if (newComponent != null) { newComponents.add(newComponent); } } myArea.setSelection(newComponents); } }, "Run Morphing action", true); }
@Override public void deleteElement(final @NotNull DataContext dataContext) { myDesigner.getToolProvider().execute(new ThrowableRunnable<Exception>() { @Override public void run() throws Exception { EditableArea area = getArea(dataContext); List<RadComponent> selection = area.getSelection(); if (selection.isEmpty()) { return; } myDesigner.getToolProvider().loadDefaultTool(); List<RadComponent> components = RadComponent.getPureSelection(selection); updateSelectionBeforeDelete(area, components.get(0), selection); handleDeletion(components); } }, DesignerBundle.message("command.delete.selection"), true); }
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(); }
public void testChainingPerformance() throws Throwable { myFixture.configureByFile(getTestName(false) + ".java"); PlatformTestUtil.startPerformanceTest(getTestName(false), 1000, new ThrowableRunnable() { @Override public void run() throws Exception { configure(); assertNotNull(myItems); LookupManager.getInstance(getProject()).hideActiveLookup(); } }).cpuBound().assertTiming(); }
public void testManyOverloadsWithVarargs() throws Exception { PlatformTestUtil.startPerformanceTest("Overload resolution with 14 overloads", 20000, new ThrowableRunnable() { @Override public void run() throws Throwable { doTest(false); } }).assertTiming(); }
public void testConstructorOverloadsWithDiamonds() throws Exception { PlatformTestUtil.startPerformanceTest("Overload resolution with chain constructor calls with diamonds", 10000, new ThrowableRunnable() { @Override public void run() throws Throwable { doTest(false); } }).assertTiming(); }
public void testToStringOnUnqualified() throws Throwable { 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" + "}\n"); myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); PlatformTestUtil.startPerformanceTest(getTestName(false), 50, new ThrowableRunnable() { @Override public void run() throws Exception { final PsiElement[] impls = new GotoImplementationHandler().getSourceAndTargetElements(myFixture.getEditor(), file).targets; assertEquals(3, impls.length); } }).cpuBound().usesAllCPUCores().assertTiming(); }
public void testToStringOnQualified() throws Throwable { final PsiFile file = myFixture.addFileToProject("Foo.java", "public class Fix {\n" + " {\n" + " Fix ff = new FixImpl1();\n" + " ff.<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" + "}\n"); myFixture.configureFromExistingVirtualFile(file.getVirtualFile()); PlatformTestUtil.startPerformanceTest(getTestName(false), 50, new ThrowableRunnable() { @Override public void run() throws Exception { final PsiElement[] impls = new GotoImplementationHandler().getSourceAndTargetElements(myFixture.getEditor(), file).targets; assertEquals(3, impls.length); } }).cpuBound().usesAllCPUCores().assertTiming(); }
private ThrowableRunnable getSetupRunnable(@NotNull String initial, @NotNull Document document) { return () -> { CommandProcessor.getInstance().executeCommand( getProject(), () -> ApplicationManager.getApplication().runWriteAction( () -> document.replaceString(0, document.getTextLength(), initial) ), null, null); PsiDocumentManager.getInstance(getProject()).commitDocument(document); }; }
private ThrowableRunnable getReformatRunnable(@NotNull PsiFile file, @NotNull List<TextRange> ranges) { CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(getProject()); return () -> CommandProcessor.getInstance().executeCommand( getProject(), () -> ApplicationManager.getApplication().runWriteAction( () -> codeStyleManager.reformatTextWithContext(file, ranges) ), null, null); }
public void testLocalScopeSearchPerformance() throws Exception { final int fileCount = 3000; final int lineCount = 500; TempDirTestFixture fixture = new LightTempDirTestFixtureImpl(); fixture.setUp(); try { String sampleText = StringUtil.repeat("zoo TargetWord foo bar goo\n", lineCount); for (int i = 0; i < fileCount; i++) { fixture.createFile("a" + i + ".txt", sampleText); } PsiTestUtil.addSourceContentToRoots(myModule, fixture.getFile("")); VirtualFile file = fixture.createFile("target.txt", sampleText); PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); assertNotNull(psiFile); final FindModel findModel = new FindModel(); findModel.setStringToFind("TargetWord"); findModel.setWholeWordsOnly(true); findModel.setFromCursor(false); findModel.setGlobal(true); findModel.setMultipleFiles(true); findModel.setCustomScope(true); ThrowableRunnable test = () -> assertSize(lineCount, findUsages(findModel)); findModel.setCustomScope(GlobalSearchScope.fileScope(psiFile)); PlatformTestUtil.startPerformanceTest("slow", 400, test).attempts(2).cpuBound().usesAllCPUCores().assertTiming(); findModel.setCustomScope(new LocalSearchScope(psiFile)); PlatformTestUtil.startPerformanceTest("slow", 400, test).attempts(2).cpuBound().usesAllCPUCores().assertTiming(); } finally { fixture.tearDown(); } }
private Dictionary loadDictionaryPerformanceTest(final String name, int time) { final Ref<Dictionary> ref = Ref.create(); PlatformTestUtil.startPerformanceTest("load dictionary", time, new ThrowableRunnable() { @Override public void run() { ref.set(CompressedDictionary.create(getLoader(name), myTransformation)); } }).cpuBound().assertTiming(); assertFalse(ref.isNull()); return ref.get(); }
private void containsWordPerformanceTest(final Dictionary dictionary, int time) { final Set<String> wordsToCheck = createWordSets(dictionary, 50000, 1).first; PlatformTestUtil.startPerformanceTest("contains word", time, new ThrowableRunnable() { @Override public void run() { for (String s : wordsToCheck) { assertEquals(Boolean.TRUE, dictionary.contains(s)); } } }).cpuBound().assertTiming(); }