-
Notifications
You must be signed in to change notification settings - Fork 317
/
PerformanceTest.java
156 lines (145 loc) · 6.16 KB
/
PerformanceTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* Copyright (c) 2013, 2017 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtend.performance.tests;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.ui.texteditor.MarkerUtilities;
import org.eclipse.xtend.ide.tests.AbstractXtendUITestCase;
import org.eclipse.xtend.ide.tests.StopwatchRule;
import org.eclipse.xtext.builder.nature.ToggleXtextNatureCommand;
import org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil;
import org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil;
import org.eclipse.xtext.ui.testing.util.TargetPlatformUtil;
import org.eclipse.xtext.util.StringInputStream;
import org.eclipse.xtext.util.internal.Stopwatches;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
public class PerformanceTest extends AbstractXtendUITestCase {
@Rule
public StopwatchRule rule = new StopwatchRule(true);
@BeforeClass
public static void createTestProject() throws Exception {
// manually setting the TP allows the Tycho build to succeed
// otherwise, the required bundles taken from the workspace
// have a wrong layout in "Plug-in Dependencies", and their
// classes cannot be resolved
TargetPlatformUtil.setTargetPlatform(PerformanceTest.class);
PerformanceTestProjectSetup.setUp();
IResourcesSetupUtil.waitForBuild();
PerformanceTest.assertNoErrorsInWorkspace();
}
@AfterClass
public static void deleteTestProject() throws Exception {
PerformanceTestProjectSetup.tearDown();
}
@Test
public void testCleanBuild() throws Exception {
IProject project = PerformanceTestProjectSetup.testProject.getProject();
project.build(IncrementalProjectBuilder.CLEAN_BUILD, null);
project.build(IncrementalProjectBuilder.CLEAN_BUILD, null);
Stopwatches.resetAll();
project.build(IncrementalProjectBuilder.CLEAN_BUILD, null);
}
@Test
public void testIncrementalBuild() throws Exception {
internalTestIncrementalBuild();
internalTestIncrementalBuild();
Stopwatches.resetAll();
internalTestIncrementalBuild();
}
public void internalTestIncrementalBuild() throws Exception {
IProject project = PerformanceTestProjectSetup.testProject.getProject();
IFile file = project.getFile("src/org/eclipse/xtext/xbase/formatting/XbaseFormatter2.xtend");
file.appendContents(new StringInputStream("//foo\n"), true, true, null);
PerformanceTestProjectSetup.waitForBuild();
}
@Test
public void testBuildOfDownstreamProject() throws Exception {
IJavaProject project = PerformanceTestProjectSetup.testProject;
IJavaProject downStreamProject = PerformanceTestProjectSetup.createJavaProject("performance.test.project.downstream",
new String[] { JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature" });
JavaProjectSetupUtil.addProjectReference(downStreamProject, project);
new ToggleXtextNatureCommand().toggleNature(downStreamProject.getProject());
IFolder sourceFolder = JavaProjectSetupUtil.addSourceFolder(downStreamProject, "src");
JavaProjectSetupUtil.addSourceFolder(downStreamProject, "xtend-gen");
sourceFolder.getFolder("foo").create(true, true, null);
IFile sourceFile = sourceFolder.getFile("foo/MyFile.xtend");
sourceFile.create(new StringInputStream(
"package foo\n"
+ "\n"
+ "import org.eclipse.xtext.xbase.formatting.BasicFormatterPreferenceKeys\n"
+ "import org.eclipse.xtext.xbase.formatting.FormattableDocument\n"
+ "import org.eclipse.xtext.xbase.formatting.HiddenLeafAccess\n"
+ "import org.eclipse.xtext.xbase.formatting.NodeModelAccess\n"
+ "import org.eclipse.xtext.xbase.formatting.XbaseFormatter2\n"
+ "\n"
+ "class MyFile extends XbaseFormatter2 {\n"
+ "\n"
+ " def a(BasicFormatterPreferenceKeys keys) {\n"
+ " BasicFormatterPreferenceKeys::indentation\n"
+ " }\n"
+ "\n"
+ " def b(FormattableDocument doc) {\n"
+ " doc.cfg.get(BasicFormatterPreferenceKeys::indentation)\n"
+ " }\n"
+ "\n"
+ " def c(HiddenLeafAccess x) {\n"
+ " x.getHiddenLeafsAfter(null).newLines\n"
+ " }\n"
+ "\n"
+ " def d(NodeModelAccess x) {\n"
+ " x.nodeForEObject(null).asTreeIterable\n"
+ " }\n"
+ "}"), true, null);
IProject p = downStreamProject.getProject();
p.build(IncrementalProjectBuilder.FULL_BUILD, null);
p.build(IncrementalProjectBuilder.FULL_BUILD, null);
Stopwatches.resetAll();
p.build(IncrementalProjectBuilder.FULL_BUILD, null);
}
@Test
public void testFullBuild() throws Exception {
IProject project = PerformanceTestProjectSetup.testProject.getProject();
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
Stopwatches.resetAll();
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
}
@Test
public void testCleanFullBuild() throws Exception {
IProject project = PerformanceTestProjectSetup.testProject.getProject();
project.build(IncrementalProjectBuilder.CLEAN_BUILD, null);
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
project.build(IncrementalProjectBuilder.CLEAN_BUILD, null);
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
Stopwatches.resetAll();
project.build(IncrementalProjectBuilder.CLEAN_BUILD, null);
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
}
protected static void assertNoErrorsInWorkspace() throws CoreException {
IMarker[] markers = PerformanceTestProjectSetup.testProject.getProject().findMarkers(IMarker.PROBLEM, true,
IResource.DEPTH_INFINITE);
for (IMarker marker : markers) {
assertFalse(MarkerUtilities.getMessage(marker),
MarkerUtilities.getSeverity(marker) == IMarker.SEVERITY_ERROR);
}
}
}