001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package startup;
043:
044: //import java.awt.Component;
045: //import java.awt.Container;
046: import java.io.File;
047: import java.io.IOException;
048:
049: //import java.util.Set;
050: //import org.openide.windows.TopComponent;
051:
052: /**
053: * Measure startup time by org.netbeans.core.perftool.StartLog.
054: * Number of starts with new userdir is defined by property
055: * <br> <code> org.netbeans.performance.repeat.with.new.userdir </code>
056: * <br> and number of starts with old userdir is defined by property
057: * <br> <code> org.netbeans.performance.repeat </code>
058: * Run measurement defined number times, but forget first measured value,
059: * it's a attempt to have still the same testing conditions with
060: * loaded and cached files.
061: *
062: * @author mmirilovic@netbeans.org, mkhramov@netbeags.org
063: */
064: public class ComplexVisualWebProjectStartup
065: extends
066: org.netbeans.performance.test.utilities.MeasureStartupTimeTestCase {
067:
068: private static final String TCN = "org.netbeans.modules.visualweb.designer.DesignerPane";
069: private long MAX_TIMEOUT = 1000000;
070: private long SLEEP_TIME = 50;
071:
072: private long timeoutTime = 0;
073:
074: /** Define testcase
075: * @param testName name of the testcase
076: */
077: public ComplexVisualWebProjectStartup(String testName) {
078: super (testName);
079: }
080:
081: /** Testing start of IDE with measurement of the startup time.
082: * @throws IOException
083: */
084: public void testStartIDEWithOpenedVWProject()
085: throws java.io.IOException {
086: measureComplexStartupTime("Startup Time with opened Visual Web project");
087: }
088:
089: protected long runIDEandMeasureStartup(String performanceDataName,
090: File measureFile, File userdir, long timeout)
091: throws IOException {
092: long startupTimeNoDocLoaded = super .runIDEandMeasureStartup(
093: performanceDataName, measureFile, userdir, timeout);
094: long docLoadTime = waitDocumentLoaded();
095: reportPerformance(performanceDataName + " | Page load",
096: docLoadTime, "ms", 1);
097: return startupTimeNoDocLoaded + docLoadTime;
098:
099: }
100:
101: private long waitDocumentLoaded() {
102: // long startTime = System.currentTimeMillis();
103: // try {
104: // waitDocumentLoadedViaAPI();
105: // } catch(InterruptedException ie) {
106: // fail("Document loading failed because of "+ie.toString());
107: // }
108: // long stopTime = System.currentTimeMillis();
109: // long delta = stopTime-startTime;
110: // if(delta <= 0) {
111: // fail("Measured value ["+delta+"] is not > 0 !");
112: // }
113: return 0; //delta;
114: }
115: /*
116: private void waitDocumentLoadedViaAPI() throws InterruptedException {
117: long startTime = System.currentTimeMillis();
118:
119: // Wait for TopComponent
120: TopComponent tc;
121: while((tc = findTopComponent("Page1")) == null) {
122: Thread.currentThread().sleep(SLEEP_TIME);
123: if(timeoutExceed(startTime)) {
124: fail("waitDocumentLoadedViaAPI:findTopComponent wait exceeds "+MAX_TIMEOUT);
125: }
126: }
127:
128: startTime = System.currentTimeMillis();
129: //Wait for Designer Surface loaded into TopComponent
130: while(findNestedComponent(tc, TCN) == false) {
131: Thread.currentThread().sleep(SLEEP_TIME);
132: if(timeoutExceed(startTime)) {
133: fail("waitDocumentLoadedViaAPI:findNestedComponent wait exceeds "+MAX_TIMEOUT);
134: }
135: }
136: }
137: private boolean timeoutExceed(long startTime) {
138: long timeout = System.currentTimeMillis() - startTime;
139: if(timeout >= MAX_TIMEOUT) {
140: return true;
141: }
142: return false;
143: }
144: private TopComponent findTopComponent(String componentName) {
145: log("finding TopComponent...");
146: Set<TopComponent> tcs = TopComponent.getRegistry().getOpened();
147: log("taken a list of TCs");
148:
149: for (TopComponent tc : tcs) {
150: if(tc.getName().equals(componentName) && (tc.isShowing())) {
151: log("function findTopComponent passed with success");
152: return tc;
153: }
154: }
155: log("function findTopComponent passed with no result");
156: return null;
157: }
158: private boolean compareClass(Component x) {
159: return x.getClass().getName().equals(TCN);
160: }
161: private boolean findNestedComponent(Container x, String componentClassName) {
162: log("finding nested components");
163: Component[] child = x.getComponents();
164:
165: if(child.length == 0) { // No nested components
166: log("no nested components found in container. returning");
167: return false;
168: }
169: log("enumeration nested components");
170: // Passed component has nested components
171: for(Component c : child) {
172: if(compareClass(c) && c.isShowing()) {
173: log("expected component found in container. returning");
174: return true;
175: }
176: log("try to find expected component in current");
177: if(findNestedComponent((Container)c,componentClassName)) { return true; }
178: }
179: log("expected component not found neither in nested components nor in current container");
180: return false;
181: }
182: */
183: }
|