avoiding variation in timing caused by lazy initialization
diff --git a/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/perf/ContentTypePerformanceTest.java b/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/perf/ContentTypePerformanceTest.java
index 699ffa7..7dcf5e2 100644
--- a/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/perf/ContentTypePerformanceTest.java
+++ b/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/perf/ContentTypePerformanceTest.java
@@ -16,6 +16,7 @@
import java.util.Random;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.eclipse.core.internal.content.ContentType;
import org.eclipse.core.internal.content.ContentTypeBuilder;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
@@ -100,7 +101,7 @@
return maximumPerLevel;
return minimumPerLevel + getRandom().nextInt(maximumPerLevel - minimumPerLevel);
}
-
+
public static Test suite() {
TestSuite suite = new TestSuite(ContentTypePerformanceTest.class.getName());
@@ -186,10 +187,29 @@
}
return installed;
}
+
+ /**
+ * Returns a loaded content type manager. Except for load time tests, this method should
+ * be called outside the scope of performance monitoring.
+ */
+ private IContentTypeManager loadContentTypeManager() {
+ // the content type catalog is built right away
+ return Platform.getContentTypeManager();
+ }
+
+ /** Forces all describers to be loaded.*/
+ private void loadDescribers() {
+ final IContentTypeManager manager = Platform.getContentTypeManager();
+ IContentType[] allTypes = manager.getAllContentTypes();
+ for (int i = 0; i < allTypes.length; i++)
+ ((ContentType) allTypes[i]).getDescriber();
+ }
+
/** Tests how much the size of the catalog affects the performance of content type matching by content analysis */
public void testContentMatching() {
- final IContentTypeManager manager = Platform.getContentTypeManager();
+ final IContentTypeManager manager = loadContentTypeManager();
+ loadDescribers();
new PerformanceTestRunner() {
protected void test() {
IContentType[] associated = null;
@@ -198,7 +218,7 @@
} catch (IOException e) {
fail("2.0", e);
}
- // we know at least the etxt content type should be here
+ // we know at least the text content type should be there
assertTrue("2.1", associated.length >= 1);
for (int i = 0; i < associated.length; i++)
if (associated[i].getId().equals(IContentTypeManager.CT_TEXT))
@@ -232,7 +252,7 @@
public void testIsKindOf() {
int numberOfLevels = 10;
int elementsPerLevel = 2;
- IContentTypeManager manager = Platform.getContentTypeManager();
+ IContentTypeManager manager = loadContentTypeManager();
final IContentType lastRoot = manager.getContentType(getContentTypeId(elementsPerLevel));
assertNotNull("2.0", lastRoot);
final IContentType lastLeaf = manager.getContentType(getContentTypeId(computeNumberOfElements(elementsPerLevel, numberOfLevels)));
@@ -245,20 +265,19 @@
}
/**
- * This test is intended for running as a session test. Use a non-standard prefix to avoid automatic inclusion in test suite.
+ * This test is intended for running as a session test.
*/
public void testLoadCatalog() {
new PerformanceTestRunner() {
protected void test() {
- // any cheap interaction that cause the catalog to be built
- Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT);
+ loadContentTypeManager();
}
}.run(this, 1, /* must run only once - the suite controls how many sessions are run */1);
}
/** Tests how much the size of the catalog affects the performance of content type matching by name */
public void testNameMatching() {
- final IContentTypeManager manager = Platform.getContentTypeManager();
+ final IContentTypeManager manager = loadContentTypeManager();
new PerformanceTestRunner() {
protected void test() {
IContentType[] associated = manager.findContentTypesFor("foo.txt");