Java源码示例:com.intellij.testFramework.PlatformTestUtil
示例1
private void doTest(final int iterations) {
myFixture.configureByFile("functions_issue96.bash");
enableInspections();
long start = System.currentTimeMillis();
PlatformTestUtil.startPerformanceTest(getTestName(true), iterations * 2000, () -> {
for (int i = 0; i < iterations; i++) {
long innerStart = System.currentTimeMillis();
Editor editor = myFixture.getEditor();
editor.getCaretModel().moveToOffset(editor.getDocument().getTextLength());
myFixture.type("\n");
myFixture.type("echo \"hello world\"\n");
myFixture.type("pri");
myFixture.complete(CompletionType.BASIC);
System.out.println("Cycle duration: " + (System.currentTimeMillis() - innerStart));
}
}).usesAllCPUCores().attempts(1).assertTiming();
System.out.println("Complete duration: " + (System.currentTimeMillis() - start));
}
示例2
public void testCopyDir() throws Exception {
File fromDir = createTempDirectory();
File toDir = createTempDirectory();
VirtualFile fromVDir = myFS.findFileByPath(fromDir.getPath().replace(File.separatorChar, '/'));
VirtualFile toVDir = myFS.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);
}
示例3
public void testGetPath() throws IOException, InterruptedException {
final File dir = FileUtil.createTempDirectory("GetPath","");
dir.deleteOnExit();
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();
}
示例4
public void testManyPointersUpdatePerformance() throws IOException {
LoggingListener listener = new LoggingListener();
final List<VFileEvent> events = new ArrayList<VFileEvent>();
final File ioTempDir = createTempDirectory();
final VirtualFile temp = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioTempDir);
for (int i=0; i<100000; i++) {
myVirtualFilePointerManager.create(VfsUtilCore.pathToUrl("/a/b/c/d/" + i), disposable, listener);
String name = "xxx" + (i % 20);
events.add(new VFileCreateEvent(this, temp, name, true, null, null, true, null));
}
PlatformTestUtil.startPerformanceTest("vfp update", 10000, new ThrowableRunnable() {
@Override
public void run() throws Throwable {
for (int i=0; i<100; i++) {
// simulate VFS refresh events since launching the actual refresh is too slow
AsyncFileListener.ChangeApplier applier = myVirtualFilePointerManager.prepareChange(events);
applier.beforeVfsChange();
applier.afterVfsChange();
}
}
}).assertTiming();
}
示例5
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();
}
示例6
@Test
public void performance() throws Exception {
final IElementType[] elementTypes = IElementType.enumerate(CommonProcessors.<IElementType>alwaysTrue());
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();
}
示例7
private void doTest(final String expected, final boolean showFields) {
myFixture.testStructureView(component -> {
component.setActionActive("SHOW_FIELDS", showFields);
PlatformTestUtil.waitWhileBusy(component.getTree());
assertTreeEqual(component.getTree(), expected);
});
}
示例8
@Test
@Ignore
public void testHighlightingPerformanceLarge() throws Exception {
PlatformTestUtil.startPerformanceTest(getTestName(true), 10 * 2000, new ThrowableRunnable() {
@Override
public void run() throws Throwable {
doPerformanceTest("functions_issue96.bash", 10, 2000.0);
}
}).usesAllCPUCores().usesAllCPUCores().assertTiming();
// With tuning:
// Finished highlighting 10/10, avg: 20538,100000 ms, min: 18969 ms, max: 22855 ms
}
示例9
@Test
public void testHighlightingPerformanceSmall() throws Exception {
PlatformTestUtil.startPerformanceTest(getTestName(true), 35 * 500, new ThrowableRunnable() {
@Override
public void run() throws Throwable {
//Average: 550.4 ms
doPerformanceTest("AlsaUtils.bash", 35, 500.0);
}
}).usesAllCPUCores().usesAllCPUCores().assertTiming();
}
示例10
public void testFolding() {
myFixture.configureByFile("functions_issue96.bash");
myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getDocument().getTextLength());
PlatformTestUtil.startPerformanceTest(getTestName(true), 10 * 250, () -> {
for (int i = 0; i < 10; i++) {
long start = System.currentTimeMillis();
CodeFoldingManager.getInstance(getProject()).buildInitialFoldings(myFixture.getEditor());
myFixture.type("echo hello world\n");
System.out.printf("Cycle duration: %d\n", System.currentTimeMillis() - start);
}
}).usesAllCPUCores().assertTiming();
}
示例11
public void testFieldDefaults() {
final String testName = getTestName(true);
loadToPsiFile("/performance/" + testName + "/lombok.config");
final PsiFile psiFile = loadToPsiFile("/performance/" + testName + "/HugeClass.java");
PlatformTestUtil.startPerformanceTest(getTestName(false), 500, () -> {
type(' ');
PsiDocumentManager.getInstance(getProject()).commitDocument(getEditor().getDocument());
((PsiJavaFileImpl) psiFile).getClasses()[0].getFields()[0].hasModifierProperty(PsiModifier.FINAL);
backspace();
PsiDocumentManager.getInstance(getProject()).commitDocument(getEditor().getDocument());
((PsiJavaFileImpl) psiFile).getClasses()[0].getFields()[0].hasModifierProperty(PsiModifier.FINAL);
}).assertTiming();
}
示例12
void addClassIfTestCase(Class testCaseClass) {
if (shouldAddTestCase(testCaseClass, true) &&
testCaseClass != myFirstTestClass && testCaseClass != myLastTestClass &&
PlatformTestUtil.canRunTest(testCaseClass)) {
myClassList.add(testCaseClass);
}
}
示例13
public static boolean isBombed(final Method method) {
final Bombed bombedAnnotation = method.getAnnotation(Bombed.class);
if (bombedAnnotation == null) return false;
if (PlatformTestUtil.isRotten(bombedAnnotation)) {
String message = "Disarm the stale bomb for '" + method + "' in class '" + method.getDeclaringClass() + "'";
System.err.println(message);
//Assert.fail(message);
}
return !PlatformTestUtil.bombExplodes(bombedAnnotation);
}
示例14
public static boolean isBombed(final Class<?> testCaseClass) {
final Bombed bombedAnnotation = testCaseClass.getAnnotation(Bombed.class);
if (bombedAnnotation == null) return false;
if (PlatformTestUtil.isRotten(bombedAnnotation)) {
String message = "Disarm the stale bomb for '" + testCaseClass + "'";
System.err.println(message);
// Assert.fail(message);
}
return !PlatformTestUtil.bombExplodes(bombedAnnotation);
}
示例15
public void testGrouping() throws Exception {
assertStructureEqual("root\n" +
".Group:a\n" +
"..Group:d\n" +
"...ade\n" +
"....Group:a\n" +
".....Group:d\n" +
"......aed\n" +
"..abc\n" +
"...Group:a\n" +
"....Group:d\n" +
".....abc_de\n" +
".Group:b\n" +
"..Group:d\n" +
"...bcd\n" +
"....Group:b\n" +
".....bhg_yt\n" +
"..Group:f\n" +
"...bft\n" +
"....ttt\n" +
".Group:d\n" +
"..eed\n" +
"...zzz\n" +
".xxx\n" +
".xxx\n" +
"..Group:a\n" +
"...aaa\n" +
"....Group:b\n" +
".....bbb\n", PlatformTestUtil.createComparator(myPrintInfo));
}
示例16
public void testFiltering() throws Exception {
myModel.addFlter(new Filter() {
@Override
@Nonnull
public ActionPresentation getPresentation() {
throw new RuntimeException();
}
@Override
@Nonnull
public String getName() {
throw new RuntimeException();
}
@Override
public boolean isVisible(TreeElement treeNode) {
return !treeNode.toString().contains("a");
}
@Override
public boolean isReverted() {
return false;
}
});
assertStructureEqual("root\n" +
".Group:b\n" +
"..Group:d\n" +
"...bcd\n" +
"....Group:b\n" +
".....bhg_yt\n" +
"..Group:f\n" +
"...bft\n" +
"....ttt\n" +
".Group:d\n" +
"..eed\n" +
"...zzz\n" +
".xxx\n" +
".xxx\n", PlatformTestUtil.createComparator(myPrintInfo));
}
示例17
public void testContainerCreateDeletePerformance() throws Exception {
PlatformTestUtil.startPerformanceTest("VF container create/delete",200, new ThrowableRunnable() {
@Override
public void run() throws Exception {
Disposable parent = Disposable.newDisposable();
for (int i = 0; i < 10000; i++) {
myVirtualFilePointerManager.createContainer(parent);
}
Disposer.dispose(parent);
}
}).cpuBound().assertTiming();
}
示例18
public void testMultipleCreationOfTheSamePointerPerformance() throws IOException {
final LoggingListener listener = new LoggingListener();
final VirtualFilePointer thePointer = myVirtualFilePointerManager.create(VfsUtilCore.pathToUrl("/a/b/c/d/e"), disposable, listener);
TempFileSystem.getInstance();
PlatformTestUtil.startPerformanceTest("same url vfp create", 500, new ThrowableRunnable() {
@Override
public void run() throws Throwable {
for (int i=0; i<1000000; i++) {
VirtualFilePointer pointer = myVirtualFilePointerManager.create(VfsUtilCore.pathToUrl("/a/b/c/d/e"), disposable, listener);
assertSame(pointer, thePointer);
}
}
}).assertTiming();
}
示例19
public void testFindChildByNamePerformance() throws IOException {
File tempDir = WriteAction.compute(() -> {
File res = createTempDirectory();
return res;
});
final VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir);
assertNotNull(vDir);
assertTrue(vDir.isDirectory());
for (int i = 0; i < 10000; i++) {
final String name = i + ".txt";
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
vDir.createChildData(vDir, name);
}
}.execute().throwException();
}
final VirtualFile theChild = vDir.findChild("5111.txt");
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();
}
示例20
public void testFindRootPerformance() throws Exception {
File tempDir = WriteAction.compute(() -> {
File res = createTempDirectory();
new File(res, "x.jar").createNewFile();
return res;
});
final VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir);
final VirtualFile jar = vDir.findChild("x.jar");
assertNotNull(jar);
final NewVirtualFile root = ManagingFS.getInstance().findRoot(jar.getPath() + "!/", (NewVirtualFileSystem)StandardFileSystems.jar());
PlatformTestUtil.startPerformanceTest("find root is slow", 500, new ThrowableRunnable() {
@Override
public void run() throws Throwable {
final String path = jar.getPath() + "!/";
final NewVirtualFileSystem fileSystem = (NewVirtualFileSystem)StandardFileSystems.jar();
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();
}
示例21
@Test
@Ignore
public void containsAnyChar() throws Exception {
assertTrue(StringUtil.containsAnyChar(TEST_STRING, Integer.toString(new Random().nextInt())));
PlatformTestUtil.startPerformanceTest("StringUtil.containsAnyChar()", SystemInfo.isWindows ? 500 : 200, new ThrowableRunnable() {
@Override
public void run() throws Throwable {
for (int i = 0; i < 1000000; i++) {
StringUtil.containsAnyChar(TEST_STRING, "XYZ");
StringUtil.containsAnyChar("XYZ", TEST_STRING);
}
}
}).cpuBound().assertTiming();
}
示例22
public void testPerformance() {
myPolicy = FilePathSplittingPolicy.SPLIT_BY_SEPARATOR;
PlatformTestUtil.startPerformanceTest("FileNameSplitting performance", 70, new ThrowableRunnable() {
@Override
public void run() throws Exception {
for (int i = 0; i < 100; i++) {
for (int j = 0; j < FILE.getPath().length(); j++)
myPolicy.getPresentableName(FILE, j);
}
}
}).cpuBound().assertTiming();
}
示例23
public void testSequentialPerformance() {
assumeTrue(!PlatformTestUtil.COVERAGE_ENABLED_BUILD);
for (int i=0; i<10; i++) {
long spinTime = time(count, spinAlloc);
long regularTime = time(count, regularAlloc);
System.out.println("regular: " + regularTime + "; spin :" +spinTime+"; ratio: "+(10*spinTime/regularTime)/10.0+" times");
}
}
示例24
public void testConcurrentPerformance() {
assumeTrue(!PlatformTestUtil.COVERAGE_ENABLED_BUILD);
for (int i=0; i<10; i++) {
long spinTime = concurrentTime(count/THREADS, spinAlloc);
long regularTime = concurrentTime(count/THREADS, regularAlloc);
System.out.println("concurrent regular: " + regularTime + "; spin :" +spinTime+"; ratio: "+(10*spinTime/regularTime)/10.0+" times");
}
}
示例25
public void testPerformance() throws IOException {
final IntObjectCache<String> stringCache = new IntObjectCache<String>(2000);
final IntObjectCache.DeletedPairsListener listener = new IntObjectCache.DeletedPairsListener() {
@Override
public void objectRemoved(final int key, final Object value) {
try {
assertEquals(myEnumerator.enumerate((String)value), key);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
};
PlatformTestUtil.startPerformanceTest("PersistentStringEnumerator performance failed", 2500, new ThrowableRunnable() {
@Override
public void run() throws Exception {
stringCache.addDeletedPairsListener(listener);
for (int i = 0; i < 100000; ++i) {
final String string = createRandomString();
stringCache.cacheObject(myEnumerator.enumerate(string), string);
}
stringCache.removeDeletedPairsListener(listener);
stringCache.removeAll();
}
}).assertTiming();
myEnumerator.close();
System.out.printf("File size = %d bytes\n", myFile.length());
}
示例26
public void testPerformance() throws IOException {
final IntObjectCache<String> stringCache = new IntObjectCache<String>(2000);
final IntObjectCache.DeletedPairsListener listener = new IntObjectCache.DeletedPairsListener() {
@Override
public void objectRemoved(final int key, final Object value) {
try {
assertEquals(myEnumerator.enumerate((String)value), key);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
};
PlatformTestUtil.startPerformanceTest("PersistentStringEnumerator performance failed", 2500, new ThrowableRunnable() {
@Override
public void run() throws Exception {
stringCache.addDeletedPairsListener(listener);
for (int i = 0; i < 100000; ++i) {
final String string = createRandomString();
stringCache.cacheObject(myEnumerator.enumerate(string), string);
}
stringCache.removeDeletedPairsListener(listener);
stringCache.removeAll();
}
}).cpuBound().assertTiming();
myEnumerator.close();
System.out.printf("File size = %d bytes\n", myFile.length());
}
示例27
@Override
public Statement apply(Statement base, Description description) {
myName = PlatformTestUtil.lowercaseFirstLetter(FileUtil.sanitizeFileName(description.getMethodName(), false), true);
return super.apply(base, description);
}
示例28
private void assertStructureEqual(@NonNls String expected, @Nullable Comparator comparator) {
SmartTreeStructure structure = new SmartTreeStructure(myFixture.getProject(), myModel);
String actual = PlatformTestUtil.print(structure, structure.getRootElement(), 0, comparator, -1, '.', null).toString();
assertEquals(expected, actual);
}
示例29
protected VirtualFile getFile(String path) {
return LocalFileSystem.getInstance().refreshAndFindFileByPath(
PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + "/platform/platform-tests/testData/fileEditorManager" + path);
}
示例30
@Override
protected String getTestDataPath() {
return PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + "/platform/platform-tests/testData/fileEditorManager";
}