KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > container > test > TestContainer


1 package org.exoplatform.container.test;
2
3 import java.util.List JavaDoc;
4 import org.exoplatform.container.PortalContainer;
5 import org.exoplatform.container.RootContainer;
6 import org.exoplatform.test.BasicTestCase;
7 /**
8  * Created by the Exo Development team.
9  * Author : Mestrallet Benjamin
10  * benjamin.mestrallet@exoplatform.com
11  */

12 public class TestContainer extends BasicTestCase {
13
14   public void testPortalContainer() throws Exception JavaDoc {
15         RootContainer rootContainer = RootContainer.getInstance() ;
16     PortalContainer pcontainer = rootContainer.getPortalContainer("portal") ;
17     Object JavaDoc parent = pcontainer.getParent() ;
18     assertTrue("Root container should not be null", parent != null) ;
19     pcontainer.createSessionContainer("sessioncontainer1", "anon") ;
20     pcontainer.createSessionContainer("sessioncontainer2", "anon") ;
21     List JavaDoc sessions = pcontainer.getLiveSessions() ;
22     assertEquals("expect 2 session container", 2 , sessions.size()) ;
23     //performance test
24

25     int INSERTLOOP = 0 ;
26     long start = System.currentTimeMillis() ;
27     for(int i = 0 ; i < INSERTLOOP; i++) {
28       rootContainer.getPortalContainer("name-" + Integer.toString(i)) ;
29     }
30     System.out.println("Insert 1000 components " + (System.currentTimeMillis() - start ) +"ms") ;
31     
32     int LOOP = 10000000 ;
33     start = System.currentTimeMillis() ;
34     for(int i = 0 ; i < LOOP; i++) {
35       pcontainer = (PortalContainer)rootContainer.getComponentInstance("portal") ;
36       assertTrue("not null", pcontainer != null) ;
37     }
38     System.out.println("Retrieve compoponent 10M times " + (System.currentTimeMillis() - start ) +"ms") ;
39     System.out.println("AVG = " + (System.currentTimeMillis() - start )/LOOP +"ms") ;
40     System.out.println("-------------------------------------------------------------------------") ;
41     Object JavaDoc oo = pcontainer.getComponentInstance("org/exoplatform/container/groovy/test/TestGroovyObject.groovy") ;
42     System.out.println("++++++++" +oo) ;
43     pcontainer.getGroovyManager().reloadGroovyObjects() ;
44     pcontainer.getComponentInstance("org/exoplatform/container/groovy/test/TestGroovyObject.groovy") ;
45     }
46 }
Popular Tags