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 memory;
043:
044: import gui.window.WebFormDesignerOperator;
045: import org.netbeans.jellytools.EditorOperator;
046: import org.netbeans.jellytools.ProjectsTabOperator;
047: import org.netbeans.jellytools.nodes.Node;
048: import org.netbeans.jemmy.JemmyProperties;
049: import org.netbeans.jemmy.TimeoutExpiredException;
050: import org.netbeans.jemmy.operators.ComponentOperator;
051: import org.netbeans.junit.NbTestSuite;
052:
053: /**
054: *
055: * @author mkhramov@netbeans.org
056: */
057: public class MultyViewSwitchMemTest extends
058: org.netbeans.performance.test.utilities.MemoryFootprintTestCase {
059: private Node pagesRoot = null;
060: private long oldTimeout;
061: private WebFormDesignerOperator designer;
062: private Runtime rt = Runtime.getRuntime();
063:
064: public MultyViewSwitchMemTest(String testName) {
065: super (testName);
066: repeat_memory = 1;
067: }
068:
069: public MultyViewSwitchMemTest(String testName,
070: String performanceDataName) {
071: super (testName, performanceDataName);
072: repeat_memory = 1;
073: }
074:
075: @Override
076: public void initialize() {
077: super .initialize();
078: //ProjectSupport.openProject(System.getProperty("xtest.tmpdir")+ java.io.File.separatorChar +"UltraLargeWA");
079: }
080:
081: @Override
082: public void prepare() {
083: EditorOperator.closeDiscardAll();
084: ProjectsTabOperator.invoke();
085: Node projectRoot = new ProjectsTabOperator()
086: .getProjectRootNode("UltraLargeWA");
087: pagesRoot = new Node(projectRoot, "Web Pages");
088: Node PageNode = new Node(pagesRoot, "Page1.jsp");
089:
090: oldTimeout = JemmyProperties.getCurrentTimeouts().getTimeout(
091: "ComponentOperator.WaitComponentTimeout");
092: JemmyProperties.getCurrentTimeouts().setTimeout(
093: "ComponentOperator.WaitComponentTimeout", 120000);
094: PageNode.performPopupActionNoBlock("Open");
095: try {
096: designer = WebFormDesignerOperator
097: .findWebFormDesignerOperator("Page1");
098: } catch (TimeoutExpiredException tex) {
099: log("timeout for Opening page expired");
100: }
101: JemmyProperties.getCurrentTimeouts().setTimeout(
102: "ComponentOperator.WaitComponentTimeout", oldTimeout);
103: }
104:
105: @Override
106: public ComponentOperator open() {
107: for (int i = 0; i < 100; i++) {
108: designer.switchToJSPView();
109: designer.switchToCodeView();
110: designer.switchToDesignView();
111: logJVMStats(i);
112: }
113: return null;
114:
115: }
116:
117: @Override
118: public void close() {
119: designer.closeDiscard();
120: }
121:
122: private void logJVMStats(int attempt) {
123: long totalmemory = rt.totalMemory();
124: long freememory = rt.freeMemory();
125: long usedmemory = (totalmemory - freememory) / 1024;
126: log("Attempt: " + attempt + "Used memory: " + usedmemory);
127: }
128:
129: public void testMem() {
130: doMeasurement();
131: }
132:
133: /** Creates suite from particular test cases. You can define order of testcases here. */
134: public static NbTestSuite suite() {
135: NbTestSuite suite = new NbTestSuite();
136: suite.addTest(new MultyViewSwitchMemTest("testMem",
137: "Memory footprint test"));
138: return suite;
139: }
140:
141: /* Method allowing test execution directly from the IDE. */
142: public static void main(java.lang.String[] args) {
143: junit.textui.TestRunner.run(suite());
144:
145: }
146: }
|