KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > java > integrity > UnderPressure


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * UnderPressure.java
22  *
23  * Created on August 2, 2000, 3:42 PM
24  */

25
26 package org.netbeans.test.java.integrity.UnderPressure;
27
28 import org.openide.filesystems.*;
29 import org.openide.loaders.*;
30 import org.openide.cookies.SaveCookie;
31 import org.netbeans.test.java.*;
32
33 //import org.openide.src.ClassElement;
34

35
36    /** <B>Java Module General API Test: UnderPressure</B>
37     * <BR><BR><I>What it tests:</I><BR>
38     * Checks behavior, if module is overloaded.
39     * Test is focused on monitoring of creating/deleting Elements.
40     * <BR><BR><I>How it works:</I><BR>
41     * Lots of classes are created/deleted using API.
42     * This processes are logged to .out and compared with golden file
43     * <BR><BR><I>Output:</I><BR>
44     * Log of created/deleted classes.
45     * <BR><BR><I>Possible reasons of failure:</I><BR>
46     * <BR><BR><U>Some classes were not created or deleted properly</U><BR>
47     * It's look like race condition, espacially if other tests passed.
48     * <BR><BR><I>Exception occured:</I><BR>
49     * See .out or .diff file for StackTrace
50     *
51     *
52     * @author Jan.Becicka@sun.com
53     */

54
55 public class UnderPressure extends org.netbeans.test.java.LogTestCase {
56     
57     private static final String JavaDoc packageName = "org.netbeans.test.java.testsources";
58     private static final String JavaDoc postPackageName = packageName + ".post";
59     private static final String JavaDoc name="JavaTestSource";
60     private static final String JavaDoc javaFileExtension="java";
61
62
63     public UnderPressure(java.lang.String JavaDoc testName) {
64         super(testName);
65     }
66     
67     public static void main(java.lang.String JavaDoc[] args) {
68         junit.textui.TestRunner.run(UnderPressure.class);
69     }
70     
71     
72     public void testRun() {
73         
74         Common.setPrintWriter(ref);
75         try {
76             java.util.Vector JavaDoc objects;
77             for( int i=0; i<100; i++ ){
78                 //objects = org.netbeans.test.java.Common.createObjects(packageName);
79
// writeObjects( objects );
80
// if( i%2==0 )
81
// deleteObjects( objects );
82
}
83             FileObject fo=Repository.getDefault().find(postPackageName,"Department", "java");
84             DataObject dob=DataObject.find(fo);
85             dob.delete();
86             fo=Repository.getDefault().find(postPackageName,"Employee", "java");
87             dob=DataObject.find(fo);
88             dob.delete();
89             ref( "program terminated successfully" );
90         }
91         catch (Exception JavaDoc e){
92             e.printStackTrace(log);
93             assertTrue(e.getMessage(), false);
94         }
95         
96     }
97     
98     public void writeObjects(java.util.Vector JavaDoc objects) throws Exception JavaDoc{
99 // ClassElement clazz;
100
// for (java.util.Iterator i=objects.iterator(); i.hasNext();){
101
// writeClassElement( (ClassElement) i.next() );
102
// }
103

104     }
105     
106     public void deleteObjects(java.util.Vector JavaDoc objects) throws Exception JavaDoc{
107 // for( java.util.Iterator i=objects.iterator(); i.hasNext(); )
108
// deleteFileObject( (ClassElement) i.next() );
109
}
110     
111 // public void deleteFileObject(ClassElement clazz) throws Exception {
112
// String className=clazz.getName().getFullName();
113
// int index=className.lastIndexOf('.');
114
// String dirName=index==-1?"":className.substring(0, index).replace('.', '/');
115
// String fileName=index==-1?className:className.substring(index+1);
116
// org.openide.filesystems.Repository repository=Repository.getDefault();
117
// FileObject directory=repository.findResource(dirName);
118
// FileObject file;
119
//
120
// if( directory==null ){
121
// throw new Exception("retrieveFileObject: can not find directory "+dirName);
122
// }
123
//
124
// file = directory.getFileObject( fileName, javaFileExtension );
125
// if( file!=null ){
126
// file.delete( file.lock() );
127
// ref( "deleted ClassElement "+className );
128
// }
129
// }
130

131     
132 // public DataObject writeClassElement(ClassElement clazz) throws Exception {
133
// DataObject jdo=null;
134
// String className="";
135
// try {
136
// className=clazz.getName().getFullName();
137
// int index=className.lastIndexOf('.');
138
// String dirName=index==-1?"":className.substring(0, index).replace('.', '/');
139
// String fileName=index==-1?className:className.substring(index+1);
140
// org.openide.filesystems.Repository repository=Repository.getDefault();
141
// FileObject directory=repository.findResource(dirName);
142
// FileObject file;
143
//
144
// if( directory==null ){
145
// ref( "writeClassElement: can not find directory "+dirName );
146
// return null;
147
// }
148
//
149
// org.openide.cookies.SourceCookie srcCockie;
150
// org.openide.src.SourceElement srcElement;
151
// ClassElement existingClass;
152
//
153
// file = directory.getFileObject( fileName, javaFileExtension );
154
// if( file!=null )
155
// file.delete( file.lock() );
156
//
157
// file = directory.createData( fileName, javaFileExtension );
158
// jdo = DataObject.find( file );
159
// srcCockie = (org.openide.cookies.SourceCookie) jdo.getCookie( org.openide.cookies.SourceCookie.class );
160
// srcElement = srcCockie.getSource();
161
// srcElement.setPackage( org.openide.src.Identifier.create(postPackageName));
162
// srcElement.addImport( new org.openide.src.Import(org.openide.src.Identifier.create("java.util.HashSet"), org.openide.src.Import.CLASS) );
163
// srcElement.addClass( clazz );
164
// } catch (Exception e) {
165
// ((SaveCookie)jdo.getCookie(SaveCookie.class)).save();
166
// ref( "class "+className+" written" );
167
// throw e;
168
// }
169
// ((SaveCookie)jdo.getCookie(SaveCookie.class)).save();
170
// ref( "class "+className+" written" );
171
// return jdo;
172
// }
173

174 }
175
176
Popular Tags