mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
make a couple of testFramework modules groovy-free to speed-up compilation
This commit is contained in:
+1
-1
@@ -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());
|
||||
}
|
||||
|
||||
+1
-1
@@ -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());
|
||||
}
|
||||
|
||||
-51
@@ -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())
|
||||
}
|
||||
|
||||
}
|
||||
+38
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
-133
@@ -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..<s.size()) {
|
||||
final c = s.charAt(i)
|
||||
myFixture.type(c)
|
||||
joinAutopopup() // for the autopopup handler's alarm, or the restartCompletion's invokeLater
|
||||
joinCompletion()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
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.impl.LookupImpl;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.ex.DocumentEx;
|
||||
import com.intellij.openapi.util.EmptyRunnable;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.testFramework.EdtTestUtil;
|
||||
import com.intellij.testFramework.TestModeFlags;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.util.TimeoutUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class CompletionAutoPopupTester {
|
||||
private final CodeInsightTestFixture myFixture;
|
||||
|
||||
public CompletionAutoPopupTester(CodeInsightTestFixture fixture) {
|
||||
myFixture = fixture;
|
||||
}
|
||||
|
||||
public void runWithAutoPopupEnabled(Runnable r) {
|
||||
assert !ApplicationManager.getApplication().isDispatchThread();
|
||||
TestModeFlags.set(CompletionAutoPopupHandler.ourTestingAutopopup, true);
|
||||
try {
|
||||
r.run();
|
||||
}
|
||||
finally {
|
||||
TestModeFlags.reset(CompletionAutoPopupHandler.ourTestingAutopopup);
|
||||
((DocumentEx)myFixture.getEditor().getDocument()).setModificationStamp(0);// to force possible autopopup handler's invokeLater cancel itself
|
||||
}
|
||||
}
|
||||
|
||||
public void joinCompletion() {
|
||||
waitPhase(phase -> !(phase instanceof CompletionPhase.CommittingDocuments ||
|
||||
phase instanceof CompletionPhase.Synchronous ||
|
||||
phase instanceof CompletionPhase.BgCalculation));
|
||||
}
|
||||
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
private static void waitPhase(Predicate<CompletionPhase> 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user