1 18 package org.objectweb.kilim.repository; 19 20 import houseexample.House; 21 import houseexample.Man; 22 23 import javax.swing.JTextArea ; 24 import javax.xml.parsers.ParserConfigurationException ; 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 ; 52 53 61 public class PerformanceTests extends TestCase { 62 63 private ResourceRepository rep; 64 private ResourceRepository rep1; 65 66 72 public PerformanceTests(String arg0) throws SAXException , ParserConfigurationException { 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 87 public void testPerformance1() throws ResourceNotFoundException, SAXException , ParserConfigurationException { 88 try { 89 Runtime 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 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 ex) { 108 throw new InternalException(ex); 109 } catch (OutOfMemoryError ex) {} 110 } 111 112 public void testPerformance2() throws ResourceNotFoundException, SAXException , ParserConfigurationException , KilimException { 113 try { 114 Runtime 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 rslt = (StringBuffer ) 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 ex) { 133 ex.printStackTrace(); 134 throw new InternalException(ex); 135 } catch (OutOfMemoryError ex) {} 136 } 137 138 } 139 | Popular Tags |