This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 171337
Collapse All | Expand All

(-)a/performance/languages/test/qa-functional/src/org/netbeans/performance/languages/ScriptingUtilities.java (-2 / +12 lines)
Lines 57-64 Link Here
57
 * @author mkhramov@netneans.org
57
 * @author mkhramov@netneans.org
58
 */
58
 */
59
public class ScriptingUtilities extends CommonUtilities {
59
public class ScriptingUtilities extends CommonUtilities {
60
    private static final String menuItemName = org.netbeans.jellytools.Bundle.getString("org.netbeans.modules.web.project.ui.Bundle", "LBL_Fix_Missing_Server_Action");
60
    private static  String menuItemName;
61
    private static final String dialogName = org.netbeans.jellytools.Bundle.getString("org.netbeans.modules.j2ee.common.ui.Bundle", "LBL_Resolve_Missing_Server_Title");
61
    static {
62
        try {
63
        menuItemName = org.netbeans.jellytools.Bundle.getString("org.netbeans.modules.web.project.ui.Bundle", "LBL_Fix_Missing_Server_Action");
64
        } catch (Exception ex) {}
65
    }
66
    private static  String dialogName;
67
    static {
68
        try {
69
        dialogName = org.netbeans.jellytools.Bundle.getString("org.netbeans.modules.j2ee.common.ui.Bundle", "LBL_Resolve_Missing_Server_Title");
70
        } catch (Exception ex) {}
71
    }
62
    
72
    
63
    public static void verifyAndResolveMissingWebServer(String projectName, String serverName) {
73
    public static void verifyAndResolveMissingWebServer(String projectName, String serverName) {
64
        ProjectRootNode projectNode = new ProjectsTabOperator().getProjectRootNode(projectName);
74
        ProjectRootNode projectNode = new ProjectsTabOperator().getProjectRootNode(projectName);
(-)67160ba16f76 (+282 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.performance.languages.actions;
41
42
import java.io.File;
43
import java.io.FileDescriptor;
44
import java.io.IOException;
45
import java.io.PrintWriter;
46
import java.io.StringWriter;
47
import java.security.Permission;
48
import java.util.Collections;
49
import java.util.Comparator;
50
import java.util.HashMap;
51
import java.util.Map;
52
import java.util.TreeSet;
53
import java.util.concurrent.atomic.AtomicLong;
54
import junit.framework.Assert;
55
import org.openide.util.Exceptions;
56
57
/**
58
 *
59
 * @author Jaroslav Tulach <jaroslav.tulach@netbeans.org>
60
 */
61
public final class CountingSecurityManager extends SecurityManager {
62
    private static int cnt;
63
    private static StringWriter msgs;
64
    private static PrintWriter pw;
65
    private static String prefix = "NONE";
66
    
67
    public static void register() {
68
        initialize("NONE");
69
    }
70
    
71
    public static void initialize(String prefix) {
72
        Assert.assertNotNull(prefix);
73
        
74
        if (! (System.getSecurityManager() instanceof CountingSecurityManager)) {
75
            setAllowedReplace(true);
76
            System.setSecurityManager(new CountingSecurityManager());
77
            setAllowedReplace(false);
78
        }
79
        if (!System.getSecurityManager().getClass().getName().equals(CountingSecurityManager.class.getName())) {
80
            throw new IllegalStateException("Wrong security manager: " + System.getSecurityManager());
81
        }
82
        cnt = 0;
83
        msgs = new StringWriter();
84
        pw = new PrintWriter(msgs);
85
        Statistics.reset();
86
        CountingSecurityManager.prefix = prefix;
87
        try {
88
            CountingSecurityManager.prefix = new File(prefix).getCanonicalPath();
89
        } catch (IOException ex) {
90
            Exceptions.printStackTrace(ex);
91
        }
92
        System.err.println("setting prefix to " + CountingSecurityManager.prefix);
93
    }
94
    
95
    public static void assertCounts(String msg, int expectedCnt, AtomicLong property) {
96
        msgs = new StringWriter();
97
        pw = new PrintWriter(msgs);
98
        Statistics.getDefault().print(pw);
99
100
        property.set(cnt);
101
        
102
        if (cnt < expectedCnt / 10) {
103
            throw new AssertionError("Too small expectations:\n" + msg + "\n" + msgs + " exp: " + expectedCnt + " was: " + cnt);
104
        }
105
        if (expectedCnt < cnt) {
106
            throw new AssertionError(msg + " exp: " + expectedCnt + " was: " + cnt + "\n" + msgs);
107
        }
108
        cnt = 0;
109
        msgs = new StringWriter();
110
        pw = new PrintWriter(msgs);
111
        Statistics.getDefault().print(pw);
112
    }
113
114
    @Override
115
    public void checkRead(String file) {
116
        if (file.startsWith(prefix)) {
117
            cnt++;
118
            Statistics.fileIsDirectory(file);
119
//            pw.println("checkRead: " + file);
120
//            new Exception().printStackTrace(pw);
121
        }
122
    }
123
124
    @Override
125
    public void checkRead(String file, Object context) {
126
        if (file.startsWith(prefix)) {
127
            cnt++;
128
            Statistics.fileIsDirectory(file);
129
            pw.println("checkRead2: " + file);
130
        }
131
    }
132
133
    @Override
134
    public void checkWrite(FileDescriptor fd) {
135
        cnt++;
136
        pw.println("Fd: " + fd);
137
    }
138
139
    @Override
140
    public void checkWrite(String file) {
141
        if (file.startsWith(prefix)) {
142
            cnt++;
143
            Statistics.fileIsDirectory(file);
144
            pw.println("checkWrite: " + file);
145
        }
146
    }
147
148
    @Override
149
    public void checkPermission(Permission perm) {
150
        if (perm.getName().equals("setSecurityManager")) { // NOI18N - hardcoded in java.lang
151
            if (!isAllowedReplace()) {
152
                throw new SecurityException();
153
            }
154
        }
155
    }
156
157
    @Override
158
    public void checkPermission(Permission perm, Object context) {
159
    }
160
161
    private static boolean isAllowedReplace() {
162
        return Boolean.getBoolean("CountingSecurityManager.allowReplace");
163
    }
164
165
    private static void setAllowedReplace(boolean aAllowedReplace) {
166
        System.setProperty("CountingSecurityManager.allowReplace", String.valueOf(aAllowedReplace));
167
    }
168
169
    /**
170
     * Collects data and print them when JVM shutting down.
171
     * 
172
     * @author Pavel Flaška
173
     */
174
    private static class Statistics implements Comparator<Map.Entry<String,Integer>> {
175
176
        private static final boolean streamLog = false;
177
        private static final boolean dirLog = true;
178
        private static final boolean streamCreation = false;
179
        /** singleton instance */
180
        private static Statistics INSTANCE;
181
        private Map<String, Integer> isDirInvoc = Collections.synchronizedMap(new HashMap<String, Integer>());
182
        private Map<String, Integer> stacks = Collections.synchronizedMap(new HashMap<String, Integer>());
183
184
        private Statistics() {
185
        }
186
187
        /**
188
         * Get the class instance.
189
         * 
190
         * @return singleton of Statistics class.
191
         */
192
        static synchronized Statistics getDefault() {
193
            if (INSTANCE == null) {
194
                INSTANCE = new Statistics();
195
            }
196
            return INSTANCE;
197
        }
198
199
        static synchronized void reset() {
200
            INSTANCE = null;
201
        }
202
203
        /**
204
         * Counts in isDirectory() call on <tt>file</tt>.
205
         * 
206
         * @param file  file name
207
         */
208
        public static void fileIsDirectory(String file) {
209
            if (!dirLog) {
210
                return;
211
            }
212
            Integer i = Statistics.getDefault().isDirInvoc.get(file);
213
            if (i == null) {
214
                i = 1;
215
            } else {
216
                i++;
217
            }
218
            Statistics.getDefault().isDirInvoc.put(file, i);
219
220
            ////////////////////
221
            StringBuilder sb = new StringBuilder(300);
222
            StackTraceElement[] ste = Thread.currentThread().getStackTrace();
223
            for (i = 2; i < ste.length; i++) {
224
                sb.append(ste[i].toString()).append('\n');
225
            }
226
            String s = sb.toString();
227
            i = Statistics.getDefault().stacks.get(s);
228
            if (i == null) {
229
                i = 1;
230
            } else {
231
                i++;
232
            }
233
            Statistics.getDefault().stacks.put(s, i);
234
        }
235
236
        public int compare(Map.Entry<String,Integer> one, Map.Entry<String,Integer> two) {
237
            int r = one.getValue().compareTo(two.getValue());
238
            if (r == 0) {
239
                return one.getKey().compareTo(two.getKey());
240
            } else {
241
                return r;
242
            }
243
        }
244
245
        ////////////////////////////////////////////////////////////////////////////
246
        // private members
247
        void print(PrintWriter out) {
248
            synchronized (isDirInvoc) {
249
                TreeSet<Map.Entry<String,Integer>> sort = new TreeSet<Map.Entry<String,Integer>>(Collections.reverseOrder(this));
250
                sort.addAll(isDirInvoc.entrySet());
251
                int cnt = 0;
252
                for (Map.Entry<String, Integer> e : sort) {
253
                    if (cnt++ > 100) {
254
                        break;
255
                    }
256
                    String s = e.getKey();
257
                    out.printf("%4d", isDirInvoc.get(s));
258
                    out.println("; " + s);
259
                }
260
            }
261
            int absoluteStacks = 0;
262
            synchronized (stacks) {
263
                for (String s : stacks.keySet()) {
264
                    int value = stacks.get(s);
265
                    absoluteStacks += value;
266
                }
267
                int min = absoluteStacks / 50;
268
                for (String s : stacks.keySet()) {
269
                    int value = stacks.get(s);
270
                    if (value > min) {
271
                        out.printf("count %5d; Stack:\n", value);
272
                        for (String line : s.split("\n")) {
273
                            out.printf("    %s\n", line);
274
                        }
275
                    }
276
                }
277
            }
278
            out.println("Total stacks recorded: " + absoluteStacks);
279
        }
280
    }
281
    
282
}
(-)a/performance/languages/test/qa-functional/src/org/netbeans/performance/languages/actions/OpenScriptingFilesTest.java (-88 / +28 lines)
Lines 41-46 Link Here
41
41
42
package org.netbeans.performance.languages.actions;
42
package org.netbeans.performance.languages.actions;
43
43
44
import java.awt.event.KeyEvent;
45
import java.util.concurrent.atomic.AtomicLong;
44
import org.netbeans.modules.performance.utilities.PerformanceTestCase;
46
import org.netbeans.modules.performance.utilities.PerformanceTestCase;
45
import org.netbeans.modules.performance.guitracker.ActionTracker;
47
import org.netbeans.modules.performance.guitracker.ActionTracker;
46
import org.netbeans.performance.languages.Projects;
48
import org.netbeans.performance.languages.Projects;
Lines 59-64 Link Here
59
import java.util.logging.Logger;
61
import java.util.logging.Logger;
60
import java.util.logging.LogRecord;
62
import java.util.logging.LogRecord;
61
import java.util.logging.Level;
63
import java.util.logging.Level;
64
import org.netbeans.jellytools.EditorWindowOperator;
65
import org.netbeans.jellytools.actions.Action.Shortcut;
66
import org.netbeans.jellytools.actions.ActionNoBlock;
62
67
63
/**
68
/**
64
 *
69
 *
Lines 93-98 Link Here
93
    }
98
    }
94
99
95
    public static NbTestSuite suite() {
100
    public static NbTestSuite suite() {
101
        CountingSecurityManager.initialize("non-existant");
96
        NbTestSuite suite = new NbTestSuite();
102
        NbTestSuite suite = new NbTestSuite();
97
        suite.addTest(NbModuleSuite.create(NbModuleSuite.createConfiguration(ScriptingSetup.class)
103
        suite.addTest(NbModuleSuite.create(NbModuleSuite.createConfiguration(ScriptingSetup.class)
98
             .addTest(OpenScriptingFilesTest.class)
104
             .addTest(OpenScriptingFilesTest.class)
Lines 158-189 Link Here
158
        repaintManager().resetRegionFilters();
164
        repaintManager().resetRegionFilters();
159
    }
165
    }
160
    
166
    
161
    public void testOpening20kbRubyFile() {
162
        testProject = Projects.RUBY_PROJECT;
163
        WAIT_AFTER_OPEN = 2000;
164
        menuItem = OPEN;
165
        fileName = "ruby20kb.rb";
166
        nodePath = "Source Files";        
167
        doMeasurement();        
168
    }
169
167
170
    public void testOpening20kbRHTMLFile() {
171
        testProject = Projects.RAILS_PROJECT;
172
        WAIT_AFTER_OPEN = 2000;
173
        menuItem = OPEN;
174
        fileName = "rhtml20kb.rhtml";
175
        nodePath = "Test Files|unit";
176
        doMeasurement();          
177
    }
178
179
    public void testOpening20kbJSFile() {
180
        testProject = Projects.SCRIPTING_PROJECT;
181
        WAIT_AFTER_OPEN = 2000;
182
        menuItem = OPEN;
183
        fileName = "javascript20kb.js";
184
        nodePath = "Web Pages";        
185
        doMeasurement();          
186
    }
187
168
188
    public void testOpening20kbPHPFile() {
169
    public void testOpening20kbPHPFile() {
189
        testProject = Projects.PHP_PROJECT;
170
        testProject = Projects.PHP_PROJECT;
Lines 191-260 Link Here
191
        menuItem = OPEN;
172
        menuItem = OPEN;
192
        fileName = "php20kb.php";
173
        fileName = "php20kb.php";
193
        nodePath = "Source Files";
174
        nodePath = "Source Files";
194
        doMeasurement();
175
176
        String path = nodePath+"|"+fileName;
177
        fileToBeOpened = new Node(getProjectNode(testProject),path);
178
        popup =  fileToBeOpened.callPopup();
179
        popup.pushMenu(menuItem);
180
181
        EditorOperator editorOperator1 = EditorWindowOperator.getEditor(fileName);
182
        editorOperator1.makeComponentVisible();
183
        editorOperator1.select(1, 1);
184
185
        new ActionNoBlock(null, null, new Shortcut(KeyEvent.VK_END, KeyEvent.CTRL_MASK)).perform(editorOperator1);
186
//        try {
187
//            SourceUtils.waitScanFinished();
188
//        } catch (InterruptedException ex) {
189
//            fail("No interrupts please");
190
//        }
191
        AtomicLong l = new AtomicLong();
192
        new ActionNoBlock(null, null, new Shortcut(KeyEvent.VK_ENTER, 0)).perform(editorOperator1);
193
        CountingSecurityManager.initialize("");
194
        new ActionNoBlock(null, null, new Shortcut(KeyEvent.VK_ENTER, 0)).perform(editorOperator1);
195
        CountingSecurityManager.assertCounts("No files touched", 0, l);
196
195
    }
197
    }
196
198
197
    public void testOpening20kbJSONFile() {
198
        testProject = Projects.SCRIPTING_PROJECT;
199
        WAIT_AFTER_OPEN = 2000;
200
        menuItem = OPEN;
201
        nodePath = "Web Pages";
202
        fileName = "json20kb.json";
203
        doMeasurement();          
204
    }
205
206
    public void testOpening20kbCSSFile() {
207
        testProject = Projects.SCRIPTING_PROJECT;
208
        WAIT_AFTER_OPEN = 2000;
209
        menuItem = OPEN;
210
        nodePath = "Web Pages";
211
        fileName = "css20kb.css";
212
        doMeasurement();          
213
    }
214
215
    public void testOpening20kbYMLFile() {
216
        testProject = Projects.RAILS_PROJECT;
217
        WAIT_AFTER_OPEN = 2000;
218
        menuItem = OPEN;
219
        fileName = "yaml20kb.yml";
220
        nodePath = "Test Files|unit";
221
        doMeasurement();          
222
    }
223
224
    public void testOpening20kbBATFile() {
225
        testProject = Projects.SCRIPTING_PROJECT;
226
        WAIT_AFTER_OPEN = 2000;
227
        menuItem = OPEN;
228
        nodePath = "Web Pages";
229
        fileName = "bat20kb.bat";
230
        doMeasurement();          
231
    }
232
233
    public void testOpening20kbDIFFFile() {
234
        testProject = Projects.SCRIPTING_PROJECT;
235
        WAIT_AFTER_OPEN = 2000;
236
        menuItem = OPEN;
237
        nodePath = "Web Pages";
238
        fileName = "diff20kb.diff";
239
        doMeasurement();          
240
    }
241
242
    public void testOpening20kbManifestFile() {
243
        testProject = Projects.SCRIPTING_PROJECT;
244
        WAIT_AFTER_OPEN = 2000;
245
        menuItem = OPEN;
246
        nodePath = "Web Pages";
247
        fileName = "manifest20kb.mf";
248
        doMeasurement();          
249
    }
250
251
    public void testOpening20kbShFile() {
252
        testProject = Projects.SCRIPTING_PROJECT;
253
        WAIT_AFTER_OPEN = 2000;
254
        menuItem = OPEN;
255
        nodePath = "Web Pages";
256
        fileName = "sh20kb.sh";
257
        doMeasurement();          
258
    }
259
199
260
}
200
}

Return to bug 171337