KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > source > parsing > PerfBatchCompilationTest


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 package org.netbeans.modules.java.source.parsing;
21 import java.util.jar.JarFile JavaDoc;
22 import junit.extensions.TestSetup;
23 import junit.framework.*;
24 import java.io.File JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.LinkedList JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.zip.ZipFile JavaDoc;
30 import javax.tools.JavaFileObject;
31 import org.netbeans.api.java.classpath.ClassPath;
32 import org.netbeans.modules.java.source.StopWatch;
33 import org.netbeans.modules.java.source.TestUtil;
34 import org.netbeans.modules.java.source.usages.IndexUtil;
35 import org.netbeans.modules.java.source.util.Factory;
36 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
37 import org.openide.filesystems.FileUtil;
38
39 /** Tests performance of batch compilation large amount of files.
40  *
41  * This test will not work unless you have src.zip in the data/jdk
42  * directory.
43  *
44  * @author Petr Hrebejk
45  */

46 public class PerfBatchCompilationTest extends TestCase {
47     
48     private static Setup setup;
49     private CachingArchiveProvider archiveProvider;
50     
51     public PerfBatchCompilationTest(String JavaDoc testName) {
52         super(testName);
53     }
54     
55     protected void setUp() throws Exception JavaDoc {
56         archiveProvider = new CachingArchiveProvider();
57     }
58     
59     protected void tearDown() throws Exception JavaDoc {
60     }
61     
62     public static Test suite() {
63         //TestSuite suite = new TestSuite( ArchiveTest.class );
64
//return suite;
65
setup = new Setup( new TestSuite( PerfBatchCompilationTest.class ) );
66         return setup;
67     }
68     
69     
70     public void testJdkSourceCompilationAtOnce() throws Throwable JavaDoc {
71     
72     fail( "Would throw OutOfMemory error anyway" );
73     
74 // System.out.println("MAX MEM " + Runtime.getRuntime().maxMemory() );
75
//
76
// // Build list of sources to compile
77
// List<JavaFileObject> files = getFiles( setup.archiveProvider.getArchive( setup.srcFolder ) );
78
//
79
// URL rtUrl = FileUtil.getArchiveRoot(setup.rtFile.toURI().toURL());
80
// URL srcUrl = FileUtil.getArchiveRoot(setup.srcFolder.toURI().toURL());
81
//
82
// ClassPath bcp = ClassPathSupport.createClassPath(new URL[] {rtUrl});
83
// ClassPath ccp = ClassPathSupport.createClassPath(new URL[0]);
84
// ClassPath scp = ClassPathSupport.createClassPath(new URL[] {srcUrl});
85
// JavacInterface javacInterface = JavacInterface.create( setup.archiveProvider, bcp, ccp, scp);
86
//
87
// StopWatch swatch = new StopWatch();
88
// swatch.start();
89
// javacInterface.attrFiles( files );
90
// swatch.stop( "Attributed" );
91
// System.out.println("MEM eaten " + ( ( Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() ) / 1024 / 1000 ) + " MB" );
92
// System.gc(); System.gc(); System.gc();
93
// System.out.println("MEM eaten after gc "+ ( ( Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() ) / 1024 / 1000 ) + " MB" );
94
//
95
}
96     
97     public void testJdkSourceCompilationFileByFile() throws Throwable JavaDoc {
98
99     fail( "Would throw OutOfMemory error anyway" );
100         
101 // System.out.println("MAX MEM " + Runtime.getRuntime().maxMemory() );
102
//
103
// // Build list of sources to compile
104
// List<JavaFileObject> files = getFiles( setup.archiveProvider.getArchive( setup.srcFolder ) );
105
//
106
// URL rtUrl = FileUtil.getArchiveRoot(setup.rtFile.toURI().toURL());
107
// URL srcUrl = FileUtil.getArchiveRoot(setup.srcFolder.toURI().toURL());
108
//
109
// ClassPath bcp = ClassPathSupport.createClassPath(new URL[] {rtUrl});
110
// ClassPath ccp = ClassPathSupport.createClassPath(new URL[0]);
111
// ClassPath scp = ClassPathSupport.createClassPath(new URL[] {srcUrl});
112
// JavacInterface javacInterface = JavacInterface.create( setup.archiveProvider, bcp, ccp, scp);
113
//
114
// StopWatch swatch = new StopWatch();
115
// swatch.start();
116
//
117
// List<JavaFileObject> l = new ArrayList<JavaFileObject>(1);
118
// l.add( null );
119
// for( JavaFileObject jfo : files ) {
120
// l.set( 0, jfo);
121
// System.out.println("JFO " + jfo.getPath() + jfo.getName() );
122
// javacInterface = JavacInterface.create( setup.archiveProvider, bcp, ccp, scp);
123
// javacInterface.attrFiles( l );
124
// }
125
// swatch.stop( "Attributed" );
126
// System.out.println("MEM eaten " + ( ( Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() ) / 1024 / 1000 ) + " MB" );
127
// System.gc(); System.gc(); System.gc();
128
// System.out.println("MEM eaten after gc "+ ( ( Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() ) / 1024 / 1000 ) + " MB" );
129
//
130
}
131     
132     
133     // Private methods ---------------------------------------------------------
134

135 // private List<JavaFileObject> getFiles( Archive archive ) {
136
//
137
// List<JavaFileObject> result = new LinkedList<JavaFileObject>();
138
//
139
// Factory<JavaFileObject, Archive.Entry> factory = archive.getJavaFileObjectFactory();
140
// Indexed<Archive.Entry> entries = archive.getFiles();
141
// for( Archive.Entry entry : entries ) {
142
// if ( entry.getName().endsWith(".java" ) ) {
143
// result.add( factory.create( entry ) );
144
// }
145
// }
146
// return result;
147
// }
148

149     // Private innerclasses ----------------------------------------------------
150

151     
152     private static class Setup extends TestSetup {
153         
154         public File JavaDoc workDir;
155     public File JavaDoc rtFile, srcFile;
156         public File JavaDoc rtFolder, srcFolder;
157     public File JavaDoc javacSrcFolder;
158         public CachingArchiveProvider archiveProvider;
159         
160         public Setup( Test test ) {
161             super( test );
162         }
163         
164         protected void tearDown() throws Exception JavaDoc {
165         TestUtil.removeWorkFolder( workDir );
166             super.tearDown();
167         }
168         
169         protected void setUp() throws Exception JavaDoc {
170             super.setUp();
171         
172         File JavaDoc retouche = TestUtil.getDataDir().getParentFile().getParentFile().getParentFile().getParentFile();
173         File JavaDoc javac = new File JavaDoc( retouche, "Jsr199" );
174         
175             workDir = TestUtil.createWorkFolder();
176         System.out.println("Workdir " + workDir );
177             TestUtil.copyFiles( TestUtil.getJdkDir(), workDir, TestUtil.RT_JAR );
178             TestUtil.copyFiles( TestUtil.getJdkDir(), workDir, TestUtil.SRC_ZIP );
179         
180         rtFile = new File JavaDoc( workDir, TestUtil.RT_JAR );
181             JarFile JavaDoc rtJar = new JarFile JavaDoc( rtFile );
182             srcFile = new File JavaDoc( workDir, TestUtil.SRC_ZIP );
183             ZipFile JavaDoc srcZip = new ZipFile JavaDoc( srcFile );
184             
185         
186         
187             //rtFolder = new File( workDir, "rtFolder" );
188
//TestUtil.unzip( rtJar, rtFolder );
189

190             srcFolder = new File JavaDoc( workDir, "src" );
191             TestUtil.unzip( srcZip, srcFolder );
192             
193         // Create archive provider
194
archiveProvider = CachingArchiveProvider.getDefault();
195         
196         // Set up the output path
197
File JavaDoc cacheDir = new File JavaDoc( workDir, "cache" );
198         cacheDir.mkdirs();
199         IndexUtil.setCacheFolder( cacheDir );
200         
201         }
202         
203     }
204     
205 }
206
Popular Tags