01: /*******************************************************************************
02: * Copyright (c) 2005, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.ui.tests.performance.parts;
11:
12: import java.io.File;
13: import java.net.URL;
14:
15: import junit.framework.Test;
16: import junit.framework.TestSuite;
17:
18: import org.eclipse.core.runtime.NullProgressMonitor;
19: import org.eclipse.pde.core.plugin.TargetPlatform;
20: import org.eclipse.pde.internal.core.ExecutionEnvironmentAnalyzer;
21: import org.eclipse.pde.internal.core.PDECore;
22: import org.eclipse.pde.internal.core.PDEState;
23: import org.eclipse.pde.internal.core.PluginPathFinder;
24: import org.eclipse.test.performance.Dimension;
25: import org.eclipse.test.performance.PerformanceTestCase;
26:
27: public class InitializeModelsPerfTest extends PerformanceTestCase {
28:
29: public static Test suite() {
30: return new TestSuite(InitializeModelsPerfTest.class);
31: }
32:
33: protected void setUp() throws Exception {
34: super .setUp();
35: deleteContent(new File(PDECore.getDefault().getStateLocation()
36: .toOSString()));
37: ExecutionEnvironmentAnalyzer.getKnownExecutionEnvironments();
38: }
39:
40: public void testModels() throws Exception {
41: tagAsGlobalSummary("Initialize Plug-ins (no caching)",
42: Dimension.ELAPSED_PROCESS);
43: URL[] paths = getURLs();
44: startMeasuring();
45: new PDEState(paths, false, new NullProgressMonitor());
46: stopMeasuring();
47: commitMeasurements();
48: assertPerformance();
49: }
50:
51: public void testCachedModels() throws Exception {
52: tagAsSummary("Initialize Plug-ins (with caching)",
53: Dimension.ELAPSED_PROCESS);
54: URL[] paths = getURLs();
55: new PDEState(paths, true, new NullProgressMonitor());
56: startMeasuring();
57: new PDEState(paths, true, new NullProgressMonitor());
58: stopMeasuring();
59: commitMeasurements();
60: assertPerformance();
61: }
62:
63: protected void tearDown() throws Exception {
64: deleteContent(new File(PDECore.getDefault().getStateLocation()
65: .toOSString()));
66: }
67:
68: private void deleteContent(File curr) {
69: if (curr.exists()) {
70: if (curr.isDirectory()) {
71: File[] children = curr.listFiles();
72: if (children != null) {
73: for (int i = 0; i < children.length; i++) {
74: deleteContent(children[i]);
75: }
76: }
77: }
78: curr.delete();
79: }
80: }
81:
82: private URL[] getURLs() {
83: URL[] paths = PluginPathFinder.getPluginPaths(TargetPlatform
84: .getLocation());
85: // FAIR ANALYSIS: this is the number of plug-ins in 3.1.x
86: URL[] result = new URL[89];
87: System.arraycopy(paths, 0, result, 0, 89);
88: return result;
89: }
90:
91: }
|