KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > repository > PerformanceTests


1 /**
2  * Copyright (C) 2002 Kelua SA
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.kilim.repository;
19
20 import houseexample.House;
21 import houseexample.Man;
22
23 import javax.swing.JTextArea JavaDoc;
24 import javax.xml.parsers.ParserConfigurationException JavaDoc;
25 import junit.framework.TestCase;
26
27 import org.objectweb.kilim.InternalException;
28 import org.objectweb.kilim.KilimException;
29 import org.objectweb.kilim.description.TemplateDescription;
30 import org.objectweb.kilim.model.Component;
31 import org.objectweb.kilim.model.ComponentFactory;
32 import org.objectweb.kilim.model.ComponentInterface;
33 import org.objectweb.kilim.model.ComponentSlot;
34 import org.objectweb.kilim.model.RtComponent;
35 import org.objectweb.kilim.model.RtComponentElement;
36 import org.objectweb.kilim.model.RtSingleValuePort;
37 import org.objectweb.kilim.model.mapping.DefaultMappingContext;
38 import org.objectweb.kilim.model.mapping.NullMapper;
39 import org.objectweb.kilim.model.mapping.JavaRuntimeMapper;
40 import org.objectweb.kilim.model.mapping.MappingContext;
41 import org.objectweb.kilim.model.mapping.TextAreaMapper;
42 import org.objectweb.kilim.model.mapping.TreeModelMapper;
43 import org.objectweb.kilim.model.instanciation.DefaultInstanciationStrategy;
44 import org.objectweb.kilim.model.instanciation.InstanciationStrategy;
45 import org.objectweb.kilim.model.instanciation.NullInstanciationMger;
46 import org.objectweb.kilim.tools.KilimComponentViewer;
47 import org.objectweb.kilim.tools.KilimTemplateViewer;
48 import org.objectweb.kilim.tools.KilimTraceTreeModel;
49 import org.objectweb.kilim.tools.KilimTraceTreeViewer;
50
51 import org.xml.sax.SAXException JavaDoc;
52
53 /**
54  * @author delpiano
55  *
56  * To change this generated comment edit the template variable "typecomment":
57  * Window>Preferences>Java>Templates.
58  * To enable and disable the creation of type comments go to
59  * Window>Preferences>Java>Code Generation.
60  */

61 public class PerformanceTests extends TestCase {
62
63     private ResourceRepository rep;
64     private ResourceRepository rep1;
65
66     /**
67      * Constructor for TemplateParserTest.
68      * @param arg0 for junit
69      * @throws SAXException should not happen
70      * @throws ParserConfigurationException should not happen
71      */

72     public PerformanceTests(String JavaDoc arg0) throws SAXException JavaDoc, ParserConfigurationException JavaDoc {
73         super(arg0);
74         TemplateDescriptionParser parser = new TemplateDescriptionParser(true);
75         rep = new ResourceRepository(parser);
76         rep.setResourceLoader(new ClassLoaderResourceLoader(this.getClass().getClassLoader()));
77         rep1 = new ResourceRepository1(parser);
78         rep1.setResourceLoader(new ClassLoaderResourceLoader(this.getClass().getClassLoader()));
79     }
80     
81     /**
82      * Method testParsing16.
83      * @throws ResourceNotFoundException :
84      * @throws SAXException :
85      * @throws ParserConfigurationException :
86      */

87     public void testPerformance1() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc {
88         try {
89             Runtime JavaDoc rtime = Runtime.getRuntime();
90             int nbCompo = 50000;
91             System.out.println("total memory " + rtime.totalMemory() + " ======= free memory " + rtime.freeMemory());
92             TemplateDescription ts0 = rep.getTemplateDescription("writers/LoopWriter");
93             Component[] compo = new Component[nbCompo];
94             ComponentInterface[] interf = new ComponentInterface[nbCompo];
95             for (int i = 0; i < nbCompo; i++) {
96                 compo[i] = ComponentFactory.newComponent(ts0);
97                 interf[i] = compo[i].getInterface("writer");
98                 Object JavaDoc res = interf[i].getValue();
99                 if (rtime.freeMemory() < 100000) {
100                     System.out.println("iteration n. : " + i + " [nb compo = " + RtComponentElement.getNbComponent() + "]" + " [nb elem = " + RtComponentElement.getNbElement() + "]");
101                     rtime.gc();
102                     if (rtime.freeMemory() < 5000) {
103                         return;
104                     }
105                 }
106             }
107         } catch (Exception JavaDoc ex) {
108             throw new InternalException(ex);
109         } catch (OutOfMemoryError JavaDoc ex) {}
110     }
111     
112     public void testPerformance2() throws ResourceNotFoundException, SAXException JavaDoc, ParserConfigurationException JavaDoc, KilimException {
113         try {
114             Runtime JavaDoc rtime = Runtime.getRuntime();
115             int nbCompo = 50000;
116             System.out.println("total memory " + rtime.totalMemory() + " ======= free memory " + rtime.freeMemory());
117             TemplateDescription ts0 = rep1.getTemplateDescription("test/Plugging Plug into Container with NAry Slot");
118             Component[] compo = new Component[nbCompo];
119             ComponentInterface[] interf = new ComponentInterface[nbCompo];
120             for (int i =0; i < nbCompo; i++) {
121                 compo[i] = ComponentFactory.newComponent(ts0);
122                 interf[i] = compo[i].getInterface("result");
123                 StringBuffer JavaDoc rslt = (StringBuffer JavaDoc) interf[i].getValue();
124                 if (rtime.freeMemory() < 100000) {
125                     System.out.println("iteration n. : " + i + " [nb compo = " + RtComponentElement.getNbComponent() + "]" + " [nb elem = " + RtComponentElement.getNbElement() + "]");
126                     rtime.gc();
127                     if (rtime.freeMemory() < 5000) {
128                         return;
129                     }
130                 }
131             }
132         } catch (Exception JavaDoc ex) {
133             ex.printStackTrace();
134             throw new InternalException(ex);
135         } catch (OutOfMemoryError JavaDoc ex) {}
136     }
137
138 }
139
Popular Tags