From 87d61edc673ce362906ba43bf04063c4d3898d13 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 21 Mar 2019 17:01:30 +0100 Subject: [PATCH] make a couple of testFramework modules groovy-free to speed-up compilation --- .../template/LiveTemplateAutoPopupTest.java | 2 +- .../completion/TemplatesCompletionTest.java | 2 +- .../CompletionAutoPopupTestCase.groovy | 51 ------- .../CompletionAutoPopupTestCase.java | 38 +++++ .../fixtures/CompletionAutoPopupTester.groovy | 133 ------------------ .../fixtures/CompletionAutoPopupTester.java | 112 +++++++++++++++ 6 files changed, 152 insertions(+), 186 deletions(-) delete mode 100644 java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy create mode 100644 java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.java delete mode 100644 platform/testFramework/src/com/intellij/testFramework/fixtures/CompletionAutoPopupTester.groovy create mode 100644 platform/testFramework/src/com/intellij/testFramework/fixtures/CompletionAutoPopupTester.java diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/template/LiveTemplateAutoPopupTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/template/LiveTemplateAutoPopupTest.java index 2ceada74057f..e01042e4533f 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/template/LiveTemplateAutoPopupTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/template/LiveTemplateAutoPopupTest.java @@ -14,7 +14,7 @@ import com.intellij.util.containers.ContainerUtil; public class LiveTemplateAutoPopupTest extends CompletionAutoPopupTestCase { @Override - protected void setUp() { + protected void setUp() throws Exception { super.setUp(); LiveTemplateCompletionContributor.setShowTemplatesInTests(true, myFixture.getTestRootDisposable()); } diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/template/postfix/completion/TemplatesCompletionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/template/postfix/completion/TemplatesCompletionTest.java index 11be5c05a4f7..06ba35e3ae86 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/template/postfix/completion/TemplatesCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/template/postfix/completion/TemplatesCompletionTest.java @@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable; public class TemplatesCompletionTest extends CompletionAutoPopupTestCase { @Override - public void setUp() { + public void setUp() throws Exception { super.setUp(); LiveTemplateCompletionContributor.setShowTemplatesInTests(false, myFixture.getTestRootDisposable()); } diff --git a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy deleted file mode 100644 index 33cad72dc80d..000000000000 --- a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.groovy +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2000-2016 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.codeInsight.completion - -import com.intellij.codeInsight.lookup.LookupManager -import com.intellij.codeInsight.lookup.impl.LookupImpl -import com.intellij.testFramework.fixtures.CompletionAutoPopupTester -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase -import org.jetbrains.annotations.NotNull - -/** - * @author peter - */ -abstract class CompletionAutoPopupTestCase extends LightCodeInsightFixtureTestCase { - protected CompletionAutoPopupTester myTester - - @Override protected void setUp() { - super.setUp() - myTester = new CompletionAutoPopupTester(myFixture) - } - - void type(String s) { - myTester.typeWithPauses(s) - } - - @Override protected boolean runInDispatchThread() { - return false - } - - @Override protected void invokeTestRunnable(@NotNull Runnable runnable) { - myTester.runWithAutoPopupEnabled(runnable) - } - - LookupImpl getLookup() { - (LookupImpl)LookupManager.getActiveLookup(myFixture.getEditor()) - } - -} diff --git a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.java b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.java new file mode 100644 index 000000000000..c043ba4e6924 --- /dev/null +++ b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionAutoPopupTestCase.java @@ -0,0 +1,38 @@ +package com.intellij.codeInsight.completion; + +import com.intellij.codeInsight.lookup.impl.LookupImpl; +import com.intellij.testFramework.fixtures.CompletionAutoPopupTester; +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; +import org.jetbrains.annotations.NotNull; + +/** + * @author peter + */ +public abstract class CompletionAutoPopupTestCase extends LightCodeInsightFixtureTestCase { + protected CompletionAutoPopupTester myTester; + + @Override + protected void setUp() throws Exception { + super.setUp(); + myTester = new CompletionAutoPopupTester(myFixture); + } + + public void type(String s) { + myTester.typeWithPauses(s); + } + + @Override + protected boolean runInDispatchThread() { + return false; + } + + @Override + protected void invokeTestRunnable(@NotNull Runnable runnable) { + myTester.runWithAutoPopupEnabled(runnable); + } + + public LookupImpl getLookup() { + return (LookupImpl)myFixture.getLookup(); + } + +} diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/CompletionAutoPopupTester.groovy b/platform/testFramework/src/com/intellij/testFramework/fixtures/CompletionAutoPopupTester.groovy deleted file mode 100644 index 39233028c001..000000000000 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/CompletionAutoPopupTester.groovy +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.testFramework.fixtures - -import com.intellij.codeInsight.completion.CompletionPhase -import com.intellij.codeInsight.completion.impl.CompletionServiceImpl -import com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler -import com.intellij.codeInsight.lookup.LookupManager -import com.intellij.codeInsight.lookup.impl.LookupImpl -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.editor.ex.DocumentEx -import com.intellij.psi.PsiDocumentManager -import com.intellij.testFramework.EdtTestUtil -import com.intellij.testFramework.TestModeFlags -import com.intellij.testFramework.UsefulTestCase -import com.intellij.util.ui.UIUtil -import groovy.transform.CompileStatic - -import java.util.concurrent.atomic.AtomicBoolean -import java.util.concurrent.atomic.AtomicInteger -/** - * @author peter - */ -@CompileStatic -class CompletionAutoPopupTester { - private final CodeInsightTestFixture myFixture - - CompletionAutoPopupTester(CodeInsightTestFixture fixture) { - myFixture = fixture - } - - void runWithAutoPopupEnabled(Runnable r) { - assert !ApplicationManager.application.isDispatchThread() - TestModeFlags.set(CompletionAutoPopupHandler.ourTestingAutopopup, true) - try { - r.run() - } - finally { - TestModeFlags.reset(CompletionAutoPopupHandler.ourTestingAutopopup) - def document = myFixture?.editor?.document - if (document) { - ((DocumentEx)document).setModificationStamp(0) // to force possible autopopup handler's invokeLater cancel itself - } - } - } - - void joinCompletion() { - waitPhase { !(it instanceof CompletionPhase.CommittingDocuments || it instanceof CompletionPhase.Synchronous || it instanceof CompletionPhase.BgCalculation) } - } - - private static void waitPhase(Closure condition) { - for (j in 1..1000) { - def phase = null - EdtTestUtil.runInEdtAndWait { phase = CompletionServiceImpl.completionPhase } - if (condition(phase)) { - return - } - if (j >= 400 && j % 100 == 0) { - println "Free memory: " + Runtime.runtime.freeMemory() + " of " + Runtime.runtime.totalMemory() + "\n" - UsefulTestCase.printThreadDump() - println "\n\n----------------------------\n\n" -/* - if (SystemInfo.isLinux) { - try { - Process process = new ProcessBuilder().command(["top", "-b", "-n", "1"] as String[]).redirectErrorStream(true).start() - println FileUtil.loadTextAndClose(process.getInputStream()) - } - catch (IOException e) { - e.printStackTrace() - } - } - println "\n\n----------------------------\n\n" -*/ - } - Thread.sleep(10) - } - UsefulTestCase.fail("Too long completion: " + CompletionServiceImpl.completionPhase) - } - - final static AtomicInteger cnt = new AtomicInteger() - def joinCommit(Closure c1={}) { - final AtomicBoolean committed = new AtomicBoolean() - final AtomicBoolean run = new AtomicBoolean() - boolean executed=true - def closureSeq = cnt.getAndIncrement() - Runnable r = new Runnable() { - @Override - void run() { - run.set(true) - ApplicationManager.application.invokeLater { - c1() - committed.set(true) - } - } - - @Override - String toString() { - return "Closure "+closureSeq - } - } - EdtTestUtil.runInEdtAndWait { - executed = PsiDocumentManager.getInstance(myFixture.project).performWhenAllCommitted(r) - } - assert !ApplicationManager.getApplication().isWriteAccessAllowed() - assert !ApplicationManager.getApplication().isReadAccessAllowed() - assert !ApplicationManager.getApplication().isDispatchThread() - def start = System.currentTimeMillis() - while (!committed.get()) { - if (System.currentTimeMillis() - start >= 20000) { - UsefulTestCase.fail("too long waiting for documents to be committed. executed: $executed; r: $r; run: $run; ") - UsefulTestCase.printThreadDump() - } - UIUtil.pump() - } - } - - void joinAutopopup() { - waitPhase { !(it instanceof CompletionPhase.CommittingDocuments) } - } - - LookupImpl getLookup() { - (LookupImpl)LookupManager.getInstance(myFixture.project).getActiveLookup() - } - - void typeWithPauses(String s) { - for (i in 0.. !(phase instanceof CompletionPhase.CommittingDocuments || + phase instanceof CompletionPhase.Synchronous || + phase instanceof CompletionPhase.BgCalculation)); + } + + @SuppressWarnings("UseOfSystemOutOrSystemErr") + private static void waitPhase(Predicate condition) { + for (int j = 1; j < 1000; j++) { + if (condition.test(CompletionServiceImpl.getCompletionPhase())) { + return; + } + if (j >= 400 && j % 100 == 0) { + System.out.println("Free memory: " + Runtime.getRuntime().freeMemory() + " of " + Runtime.getRuntime().totalMemory() + "\n"); + UsefulTestCase.printThreadDump(); + System.out.println("\n\n----------------------------\n\n"); + } + + TimeoutUtil.sleep(10); + } + + TestCase.fail("Too long completion: " + CompletionServiceImpl.getCompletionPhase()); + } + + public void joinCommit(Runnable c1) { + AtomicBoolean committed = new AtomicBoolean(); + AtomicBoolean run = new AtomicBoolean(); + AtomicBoolean executed = new AtomicBoolean(true); + EdtTestUtil.runInEdtAndWait(() -> executed.set(PsiDocumentManager.getInstance(myFixture.getProject()).performWhenAllCommitted(() -> { + run.set(true); + ApplicationManager.getApplication().invokeLater(() -> { + c1.run(); + committed.set(true); + }); + }))); + assert !ApplicationManager.getApplication().isWriteAccessAllowed(); + assert !ApplicationManager.getApplication().isReadAccessAllowed(); + assert !ApplicationManager.getApplication().isDispatchThread(); + long start = System.currentTimeMillis(); + while (!committed.get()) { + if (System.currentTimeMillis() - start >= 20000) { + UsefulTestCase.printThreadDump(); + TestCase.fail("too long waiting for documents to be committed. executed: " + executed + "; run: " + run + "; "); + } + + UIUtil.pump(); + } + } + + public void joinCommit() { + joinCommit(EmptyRunnable.getInstance()); + } + + public void joinAutopopup() { + waitPhase(phase -> !(phase instanceof CompletionPhase.CommittingDocuments)); + } + + public LookupImpl getLookup() { + return (LookupImpl)myFixture.getLookup(); + } + + public void typeWithPauses(String s) { + for (int i = 0; i < s.length(); i++) { + myFixture.type(s.charAt(i)); + joinAutopopup();// for the autopopup handler's alarm, or the restartCompletion's invokeLater + joinCompletion(); + } + } + +}