diff -r 67160ba16f76 performance/languages/test/qa-functional/src/org/netbeans/performance/languages/ScriptingUtilities.java --- a/performance/languages/test/qa-functional/src/org/netbeans/performance/languages/ScriptingUtilities.java Wed Sep 02 06:19:20 2009 +0400 +++ b/performance/languages/test/qa-functional/src/org/netbeans/performance/languages/ScriptingUtilities.java Wed Sep 02 17:59:29 2009 +0200 @@ -57,8 +57,18 @@ * @author mkhramov@netneans.org */ public class ScriptingUtilities extends CommonUtilities { - private static final String menuItemName = org.netbeans.jellytools.Bundle.getString("org.netbeans.modules.web.project.ui.Bundle", "LBL_Fix_Missing_Server_Action"); - private static final String dialogName = org.netbeans.jellytools.Bundle.getString("org.netbeans.modules.j2ee.common.ui.Bundle", "LBL_Resolve_Missing_Server_Title"); + private static String menuItemName; + static { + try { + menuItemName = org.netbeans.jellytools.Bundle.getString("org.netbeans.modules.web.project.ui.Bundle", "LBL_Fix_Missing_Server_Action"); + } catch (Exception ex) {} + } + private static String dialogName; + static { + try { + dialogName = org.netbeans.jellytools.Bundle.getString("org.netbeans.modules.j2ee.common.ui.Bundle", "LBL_Resolve_Missing_Server_Title"); + } catch (Exception ex) {} + } public static void verifyAndResolveMissingWebServer(String projectName, String serverName) { ProjectRootNode projectNode = new ProjectsTabOperator().getProjectRootNode(projectName); diff -r 67160ba16f76 performance/languages/test/qa-functional/src/org/netbeans/performance/languages/actions/CountingSecurityManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/performance/languages/test/qa-functional/src/org/netbeans/performance/languages/actions/CountingSecurityManager.java Wed Sep 02 17:59:29 2009 +0200 @@ -0,0 +1,282 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.performance.languages.actions; + +import java.io.File; +import java.io.FileDescriptor; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.security.Permission; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeSet; +import java.util.concurrent.atomic.AtomicLong; +import junit.framework.Assert; +import org.openide.util.Exceptions; + +/** + * + * @author Jaroslav Tulach + */ +public final class CountingSecurityManager extends SecurityManager { + private static int cnt; + private static StringWriter msgs; + private static PrintWriter pw; + private static String prefix = "NONE"; + + public static void register() { + initialize("NONE"); + } + + public static void initialize(String prefix) { + Assert.assertNotNull(prefix); + + if (! (System.getSecurityManager() instanceof CountingSecurityManager)) { + setAllowedReplace(true); + System.setSecurityManager(new CountingSecurityManager()); + setAllowedReplace(false); + } + if (!System.getSecurityManager().getClass().getName().equals(CountingSecurityManager.class.getName())) { + throw new IllegalStateException("Wrong security manager: " + System.getSecurityManager()); + } + cnt = 0; + msgs = new StringWriter(); + pw = new PrintWriter(msgs); + Statistics.reset(); + CountingSecurityManager.prefix = prefix; + try { + CountingSecurityManager.prefix = new File(prefix).getCanonicalPath(); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + System.err.println("setting prefix to " + CountingSecurityManager.prefix); + } + + public static void assertCounts(String msg, int expectedCnt, AtomicLong property) { + msgs = new StringWriter(); + pw = new PrintWriter(msgs); + Statistics.getDefault().print(pw); + + property.set(cnt); + + if (cnt < expectedCnt / 10) { + throw new AssertionError("Too small expectations:\n" + msg + "\n" + msgs + " exp: " + expectedCnt + " was: " + cnt); + } + if (expectedCnt < cnt) { + throw new AssertionError(msg + " exp: " + expectedCnt + " was: " + cnt + "\n" + msgs); + } + cnt = 0; + msgs = new StringWriter(); + pw = new PrintWriter(msgs); + Statistics.getDefault().print(pw); + } + + @Override + public void checkRead(String file) { + if (file.startsWith(prefix)) { + cnt++; + Statistics.fileIsDirectory(file); +// pw.println("checkRead: " + file); +// new Exception().printStackTrace(pw); + } + } + + @Override + public void checkRead(String file, Object context) { + if (file.startsWith(prefix)) { + cnt++; + Statistics.fileIsDirectory(file); + pw.println("checkRead2: " + file); + } + } + + @Override + public void checkWrite(FileDescriptor fd) { + cnt++; + pw.println("Fd: " + fd); + } + + @Override + public void checkWrite(String file) { + if (file.startsWith(prefix)) { + cnt++; + Statistics.fileIsDirectory(file); + pw.println("checkWrite: " + file); + } + } + + @Override + public void checkPermission(Permission perm) { + if (perm.getName().equals("setSecurityManager")) { // NOI18N - hardcoded in java.lang + if (!isAllowedReplace()) { + throw new SecurityException(); + } + } + } + + @Override + public void checkPermission(Permission perm, Object context) { + } + + private static boolean isAllowedReplace() { + return Boolean.getBoolean("CountingSecurityManager.allowReplace"); + } + + private static void setAllowedReplace(boolean aAllowedReplace) { + System.setProperty("CountingSecurityManager.allowReplace", String.valueOf(aAllowedReplace)); + } + + /** + * Collects data and print them when JVM shutting down. + * + * @author Pavel Flaška + */ + private static class Statistics implements Comparator> { + + private static final boolean streamLog = false; + private static final boolean dirLog = true; + private static final boolean streamCreation = false; + /** singleton instance */ + private static Statistics INSTANCE; + private Map isDirInvoc = Collections.synchronizedMap(new HashMap()); + private Map stacks = Collections.synchronizedMap(new HashMap()); + + private Statistics() { + } + + /** + * Get the class instance. + * + * @return singleton of Statistics class. + */ + static synchronized Statistics getDefault() { + if (INSTANCE == null) { + INSTANCE = new Statistics(); + } + return INSTANCE; + } + + static synchronized void reset() { + INSTANCE = null; + } + + /** + * Counts in isDirectory() call on file. + * + * @param file file name + */ + public static void fileIsDirectory(String file) { + if (!dirLog) { + return; + } + Integer i = Statistics.getDefault().isDirInvoc.get(file); + if (i == null) { + i = 1; + } else { + i++; + } + Statistics.getDefault().isDirInvoc.put(file, i); + + //////////////////// + StringBuilder sb = new StringBuilder(300); + StackTraceElement[] ste = Thread.currentThread().getStackTrace(); + for (i = 2; i < ste.length; i++) { + sb.append(ste[i].toString()).append('\n'); + } + String s = sb.toString(); + i = Statistics.getDefault().stacks.get(s); + if (i == null) { + i = 1; + } else { + i++; + } + Statistics.getDefault().stacks.put(s, i); + } + + public int compare(Map.Entry one, Map.Entry two) { + int r = one.getValue().compareTo(two.getValue()); + if (r == 0) { + return one.getKey().compareTo(two.getKey()); + } else { + return r; + } + } + + //////////////////////////////////////////////////////////////////////////// + // private members + void print(PrintWriter out) { + synchronized (isDirInvoc) { + TreeSet> sort = new TreeSet>(Collections.reverseOrder(this)); + sort.addAll(isDirInvoc.entrySet()); + int cnt = 0; + for (Map.Entry e : sort) { + if (cnt++ > 100) { + break; + } + String s = e.getKey(); + out.printf("%4d", isDirInvoc.get(s)); + out.println("; " + s); + } + } + int absoluteStacks = 0; + synchronized (stacks) { + for (String s : stacks.keySet()) { + int value = stacks.get(s); + absoluteStacks += value; + } + int min = absoluteStacks / 50; + for (String s : stacks.keySet()) { + int value = stacks.get(s); + if (value > min) { + out.printf("count %5d; Stack:\n", value); + for (String line : s.split("\n")) { + out.printf(" %s\n", line); + } + } + } + } + out.println("Total stacks recorded: " + absoluteStacks); + } + } + +} diff -r 67160ba16f76 performance/languages/test/qa-functional/src/org/netbeans/performance/languages/actions/OpenScriptingFilesTest.java --- a/performance/languages/test/qa-functional/src/org/netbeans/performance/languages/actions/OpenScriptingFilesTest.java Wed Sep 02 06:19:20 2009 +0400 +++ b/performance/languages/test/qa-functional/src/org/netbeans/performance/languages/actions/OpenScriptingFilesTest.java Wed Sep 02 17:59:29 2009 +0200 @@ -41,6 +41,8 @@ package org.netbeans.performance.languages.actions; +import java.awt.event.KeyEvent; +import java.util.concurrent.atomic.AtomicLong; import org.netbeans.modules.performance.utilities.PerformanceTestCase; import org.netbeans.modules.performance.guitracker.ActionTracker; import org.netbeans.performance.languages.Projects; @@ -59,6 +61,9 @@ import java.util.logging.Logger; import java.util.logging.LogRecord; import java.util.logging.Level; +import org.netbeans.jellytools.EditorWindowOperator; +import org.netbeans.jellytools.actions.Action.Shortcut; +import org.netbeans.jellytools.actions.ActionNoBlock; /** * @@ -93,6 +98,7 @@ } public static NbTestSuite suite() { + CountingSecurityManager.initialize("non-existant"); NbTestSuite suite = new NbTestSuite(); suite.addTest(NbModuleSuite.create(NbModuleSuite.createConfiguration(ScriptingSetup.class) .addTest(OpenScriptingFilesTest.class) @@ -158,32 +164,7 @@ repaintManager().resetRegionFilters(); } - public void testOpening20kbRubyFile() { - testProject = Projects.RUBY_PROJECT; - WAIT_AFTER_OPEN = 2000; - menuItem = OPEN; - fileName = "ruby20kb.rb"; - nodePath = "Source Files"; - doMeasurement(); - } - public void testOpening20kbRHTMLFile() { - testProject = Projects.RAILS_PROJECT; - WAIT_AFTER_OPEN = 2000; - menuItem = OPEN; - fileName = "rhtml20kb.rhtml"; - nodePath = "Test Files|unit"; - doMeasurement(); - } - - public void testOpening20kbJSFile() { - testProject = Projects.SCRIPTING_PROJECT; - WAIT_AFTER_OPEN = 2000; - menuItem = OPEN; - fileName = "javascript20kb.js"; - nodePath = "Web Pages"; - doMeasurement(); - } public void testOpening20kbPHPFile() { testProject = Projects.PHP_PROJECT; @@ -191,70 +172,29 @@ menuItem = OPEN; fileName = "php20kb.php"; nodePath = "Source Files"; - doMeasurement(); + + String path = nodePath+"|"+fileName; + fileToBeOpened = new Node(getProjectNode(testProject),path); + popup = fileToBeOpened.callPopup(); + popup.pushMenu(menuItem); + + EditorOperator editorOperator1 = EditorWindowOperator.getEditor(fileName); + editorOperator1.makeComponentVisible(); + editorOperator1.select(1, 1); + + new ActionNoBlock(null, null, new Shortcut(KeyEvent.VK_END, KeyEvent.CTRL_MASK)).perform(editorOperator1); +// try { +// SourceUtils.waitScanFinished(); +// } catch (InterruptedException ex) { +// fail("No interrupts please"); +// } + AtomicLong l = new AtomicLong(); + new ActionNoBlock(null, null, new Shortcut(KeyEvent.VK_ENTER, 0)).perform(editorOperator1); + CountingSecurityManager.initialize(""); + new ActionNoBlock(null, null, new Shortcut(KeyEvent.VK_ENTER, 0)).perform(editorOperator1); + CountingSecurityManager.assertCounts("No files touched", 0, l); + } - public void testOpening20kbJSONFile() { - testProject = Projects.SCRIPTING_PROJECT; - WAIT_AFTER_OPEN = 2000; - menuItem = OPEN; - nodePath = "Web Pages"; - fileName = "json20kb.json"; - doMeasurement(); - } - - public void testOpening20kbCSSFile() { - testProject = Projects.SCRIPTING_PROJECT; - WAIT_AFTER_OPEN = 2000; - menuItem = OPEN; - nodePath = "Web Pages"; - fileName = "css20kb.css"; - doMeasurement(); - } - - public void testOpening20kbYMLFile() { - testProject = Projects.RAILS_PROJECT; - WAIT_AFTER_OPEN = 2000; - menuItem = OPEN; - fileName = "yaml20kb.yml"; - nodePath = "Test Files|unit"; - doMeasurement(); - } - - public void testOpening20kbBATFile() { - testProject = Projects.SCRIPTING_PROJECT; - WAIT_AFTER_OPEN = 2000; - menuItem = OPEN; - nodePath = "Web Pages"; - fileName = "bat20kb.bat"; - doMeasurement(); - } - - public void testOpening20kbDIFFFile() { - testProject = Projects.SCRIPTING_PROJECT; - WAIT_AFTER_OPEN = 2000; - menuItem = OPEN; - nodePath = "Web Pages"; - fileName = "diff20kb.diff"; - doMeasurement(); - } - - public void testOpening20kbManifestFile() { - testProject = Projects.SCRIPTING_PROJECT; - WAIT_AFTER_OPEN = 2000; - menuItem = OPEN; - nodePath = "Web Pages"; - fileName = "manifest20kb.mf"; - doMeasurement(); - } - - public void testOpening20kbShFile() { - testProject = Projects.SCRIPTING_PROJECT; - WAIT_AFTER_OPEN = 2000; - menuItem = OPEN; - nodePath = "Web Pages"; - fileName = "sh20kb.sh"; - doMeasurement(); - } }