decouple spellchecker from testFramework-java

This commit is contained in:
Dmitry Jemerov
2010-03-17 15:38:32 +03:00
parent 7a4e117fe5
commit 6d8a86f245
5 changed files with 62 additions and 62 deletions
@@ -27,8 +27,6 @@ import com.intellij.openapi.vfs.VirtualFileFilter;
import com.intellij.util.containers.HashMap;
import com.intellij.util.io.ZipUtil;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.FilenameFilter;
@@ -38,11 +36,6 @@ import java.util.jar.JarFile;
public class IdeaTestUtil extends PlatformTestUtil {
/**
* Measured on dual core p4 3HZ 1gig ram
*/
private static final long ETALON_TIMING = 438;
public static final Comparator<AbstractTreeNode> DEFAULT_COMPARATOR = new Comparator<AbstractTreeNode>() {
public int compare(AbstractTreeNode o1, AbstractTreeNode o2) {
@@ -52,7 +45,6 @@ public class IdeaTestUtil extends PlatformTestUtil {
}
};
public static final boolean COVERAGE_ENABLED_BUILD = "true".equals(System.getProperty("idea.coverage.enabled.build"));
public static final CvsVirtualFileFilter CVS_FILE_FILTER = new CvsVirtualFileFilter();
private static HashMap<String, VirtualFile> buildNameToFileMap(VirtualFile[] files, VirtualFileFilter filter) {
@@ -153,56 +145,6 @@ public class IdeaTestUtil extends PlatformTestUtil {
assertDirectoriesEqual(dirAfter, dirBefore, CVS_FILE_FILTER);
}
public static void assertTiming(String message, long expected, long actual) {
if (COVERAGE_ENABLED_BUILD) return;
long expectedOnMyMachine = Math.max(1, expected * Timings.MACHINE_TIMING / ETALON_TIMING);
final double acceptableChangeFactor = 1.1;
// Allow 10% more in case of test machine is busy.
// For faster machines (expectedOnMyMachine < expected) allow nonlinear performance rating:
// just perform better than acceptable expected
if (actual > expectedOnMyMachine * acceptableChangeFactor &&
(expectedOnMyMachine > expected || actual > expected * acceptableChangeFactor)) {
int percentage = (int)(((float)100 * (actual - expectedOnMyMachine)) / expectedOnMyMachine);
Assert.fail(message + ". Operation took " + percentage + "% longer than expected. Expected on my machine: " + expectedOnMyMachine +
". Actual: " + actual + ". Expected on Etalon machine: " + expected + "; Actual on Etalon: " +
(actual * ETALON_TIMING / Timings.MACHINE_TIMING));
}
else {
int percentage = (int)(((float)100 * (actual - expectedOnMyMachine)) / expectedOnMyMachine);
System.out.println(message + ". Operation took " + percentage + "% longer than expected. Expected on my machine: " +
expectedOnMyMachine + ". Actual: " + actual + ". Expected on Etalon machine: " + expected +
"; Actual on Etalon: " + (actual * ETALON_TIMING / Timings.MACHINE_TIMING));
}
}
public static void assertTiming(String message, long expected, @NotNull Runnable actionToMeasure) {
assertTiming(message, expected, 4, actionToMeasure);
}
public static long measure(@NotNull Runnable actionToMeasure) {
long start = System.currentTimeMillis();
actionToMeasure.run();
long finish = System.currentTimeMillis();
return finish - start;
}
public static void assertTiming(String message, long expected, int attempts, @NotNull Runnable actionToMeasure) {
while (true) {
attempts--;
long duration = measure(actionToMeasure);
try {
assertTiming(message, expected, duration);
break;
}
catch (AssertionFailedError e) {
if (attempts == 0) throw e;
System.gc();
System.gc();
System.gc();
}
}
}
public static void main(String[] args) {
printDetectedPerformanceTimings();
}
@@ -39,7 +39,9 @@ import com.intellij.util.ArrayUtil;
import com.intellij.util.SystemProperties;
import com.intellij.util.ui.UIUtil;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -51,6 +53,12 @@ import java.util.*;
* @author yole
*/
public class PlatformTestUtil {
/**
* Measured on dual core p4 3HZ 1gig ram
*/
protected static final long ETALON_TIMING = 438;
public static final boolean COVERAGE_ENABLED_BUILD = "true".equals(System.getProperty("idea.coverage.enabled.build"));
public static <T> void registerExtension(final ExtensionPointName<T> name, final T t, final Disposable parentDisposable) {
registerExtension(Extensions.getRootArea(), name, t, parentDisposable);
}
@@ -326,4 +334,55 @@ public class PlatformTestUtil {
Assert.assertTrue(presentation.isEnabled());
action.actionPerformed(event);
}
public static void assertTiming(String message, long expected, long actual) {
if (COVERAGE_ENABLED_BUILD) return;
long expectedOnMyMachine = Math.max(1, expected * Timings.MACHINE_TIMING / ETALON_TIMING);
final double acceptableChangeFactor = 1.1;
// Allow 10% more in case of test machine is busy.
// For faster machines (expectedOnMyMachine < expected) allow nonlinear performance rating:
// just perform better than acceptable expected
if (actual > expectedOnMyMachine * acceptableChangeFactor &&
(expectedOnMyMachine > expected || actual > expected * acceptableChangeFactor)) {
int percentage = (int)(((float)100 * (actual - expectedOnMyMachine)) / expectedOnMyMachine);
Assert.fail(message + ". Operation took " + percentage + "% longer than expected. Expected on my machine: " + expectedOnMyMachine +
". Actual: " + actual + ". Expected on Etalon machine: " + expected + "; Actual on Etalon: " +
(actual * ETALON_TIMING / Timings.MACHINE_TIMING));
}
else {
int percentage = (int)(((float)100 * (actual - expectedOnMyMachine)) / expectedOnMyMachine);
System.out.println(message + ". Operation took " + percentage + "% longer than expected. Expected on my machine: " +
expectedOnMyMachine + ". Actual: " + actual + ". Expected on Etalon machine: " + expected +
"; Actual on Etalon: " + (actual * ETALON_TIMING / Timings.MACHINE_TIMING));
}
}
public static void assertTiming(String message, long expected, @NotNull Runnable actionToMeasure) {
assertTiming(message, expected, 4, actionToMeasure);
}
public static long measure(@NotNull Runnable actionToMeasure) {
long start = System.currentTimeMillis();
actionToMeasure.run();
long finish = System.currentTimeMillis();
return finish - start;
}
public static void assertTiming(String message, long expected, int attempts, @NotNull Runnable actionToMeasure) {
while (true) {
attempts--;
long duration = measure(actionToMeasure);
try {
assertTiming(message, expected, duration);
break;
}
catch (AssertionFailedError e) {
if (attempts == 0) throw e;
System.gc();
System.gc();
System.gc();
}
}
}
}
-1
View File
@@ -14,7 +14,6 @@
<orderEntry type="module" module-name="platform-impl" />
<orderEntry type="module" module-name="xml-openapi" />
<orderEntry type="module" module-name="testFramework" scope="TEST" />
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
</component>
</module>
@@ -21,7 +21,7 @@ import com.intellij.spellchecker.StreamLoader;
import com.intellij.spellchecker.dictionary.Dictionary;
import com.intellij.spellchecker.dictionary.Loader;
import com.intellij.spellchecker.engine.Transformation;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.util.Consumer;
import gnu.trove.THashSet;
import junit.framework.TestCase;
@@ -62,7 +62,7 @@ public class DictionaryTest extends TestCase {
public void loadDictionaryTest(@NotNull final String name, int wordCount) throws IOException {
final Transformation transform = new Transformation();
IdeaTestUtil.assertTiming("Dictionary load time depends on words count. Approximate word count: " + wordCount + ".", times.get(name),
PlatformTestUtil.assertTiming("Dictionary load time depends on words count. Approximate word count: " + wordCount + ".", times.get(name),
new Runnable() {
public void run() {
dictionary = CompressedDictionary.create(new StreamLoader(DefaultBundledDictionariesProvider.class.getResourceAsStream(name), name), transform);
@@ -70,7 +70,7 @@ public class DictionaryTest extends TestCase {
});
final Set<String> wordsToStoreAndCheck = createWordSets(name, 50000, 1).getFirst();
IdeaTestUtil.assertTiming("Invoke 'contains' " + wordsToStoreAndCheck.size() + " times", 2000, new Runnable() {
PlatformTestUtil.assertTiming("Invoke 'contains' " + wordsToStoreAndCheck.size() + " times", 2000, new Runnable() {
public void run() {
for (String s : wordsToStoreAndCheck) {
assertTrue(dictionary.contains(s));