001: /*******************************************************************************
002: * Copyright (c) 2006, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.ui.tests.performance.parts;
011:
012: import java.io.File;
013: import java.io.IOException;
014: import java.net.URL;
015:
016: import org.eclipse.core.runtime.FileLocator;
017: import org.eclipse.pde.internal.ui.tests.macro.MacroPlugin;
018: import org.eclipse.test.performance.PerformanceTestCase;
019: import org.osgi.framework.Bundle;
020:
021: /**
022: * AbstractSchemaPerfTest
023: *
024: */
025: public abstract class AbstractSchemaPerfTest extends
026: PerformanceTestCase {
027:
028: protected int fTestIterations;
029:
030: protected int fWarmupIterations;
031:
032: protected int fRuns;
033:
034: protected static final String F_FILENAME = "/tests/performance/schema/navigatorContent.exsd"; //$NON-NLS-1$
035:
036: protected static File fXSDFile;
037:
038: /* (non-Javadoc)
039: * @see org.eclipse.test.performance.PerformanceTestCase#setUp()
040: */
041: protected void setUp() throws Exception {
042: super .setUp();
043: setUpSchemaFile();
044: setUpIterations();
045: }
046:
047: /**
048: *
049: */
050: protected void setUpIterations() {
051: fTestIterations = 5;
052: fWarmupIterations = 50;
053: fRuns = 200;
054: }
055:
056: /**
057: * @throws Exception
058: * @throws IOException
059: */
060: private void setUpSchemaFile() throws Exception, IOException {
061: MacroPlugin plugin = MacroPlugin.getDefault();
062: if (plugin == null)
063: throw new Exception("ERROR: Macro plug-in uninitialized"); //$NON-NLS-1$
064: Bundle bundle = plugin.getBundle();
065: if (bundle == null)
066: throw new Exception("ERROR: Bundle uninitialized"); //$NON-NLS-1$
067: URL url = bundle.getEntry(F_FILENAME);
068: if (url == null)
069: throw new Exception("ERROR: URL not found: " + F_FILENAME); //$NON-NLS-1$
070: String path = FileLocator.resolve(url).getPath();
071: if ("".equals(path)) //$NON-NLS-1$
072: throw new Exception(
073: "ERROR: URL unresolved: " + F_FILENAME); //$NON-NLS-1$
074: fXSDFile = new File(path);
075: }
076:
077: /**
078: * @throws Exception
079: */
080: protected void executeTestRun() throws Exception {
081: // Warm-up Iterations
082: for (int i = 0; i < fWarmupIterations; i++) {
083: executeTest();
084: }
085: // Test Iterations
086: for (int j = 0; j < fRuns; j++) {
087: startMeasuring();
088: for (int i = 0; i < fTestIterations; i++) {
089: executeTest();
090: }
091: stopMeasuring();
092: }
093: commitMeasurements();
094: assertPerformance();
095: }
096:
097: /**
098: * @throws Exception
099: */
100: protected abstract void executeTest() throws Exception;
101:
102: }
|