| 1 17 18 package org.sape.carbon.services.ejb.remote.test; 19 20 21 import javax.ejb.EJBHome ; 22 23 import org.sape.carbon.core.component.Lookup; 24 import org.sape.carbon.services.ejb.EnterpriseBeanConfiguration; 25 import org.sape.carbon.services.ejb.remote.RemoteHomeFactory; 26 27 import junit.framework.Test; 28 import junit.framework.TestCase; 29 import junit.framework.TestSuite; 30 31 import org.apache.commons.logging.Log; 32 import org.apache.commons.logging.LogFactory; 33 34 public class RemoteHomeCachePerformanceTest extends TestCase { 35 36 39 private Log log = LogFactory.getLog(this.getClass()); 40 41 44 public static final String TEST_REMOTE_HOME_FACTORY = 45 "/ejb/test/RemoteHomeFactoryTest"; 46 47 48 51 public static final String TEST_REMOTE_EJB = 52 "org.sape.carbon.services.ejb.remote.test.Tester"; 53 54 55 58 public static final long TEST_LOOKUP_ITERATIONS = 2000; 59 60 61 public RemoteHomeCachePerformanceTest(String name) { 62 super(name); 63 } 64 65 66 public static void main(String args[]) throws Exception { 67 } 68 69 70 74 public void testRemoteHomeCachePerformance() { 75 76 long startTime = 0; 77 long elapsedTime = 0; 78 79 EJBHome ejbHome = null; 80 81 RemoteHomeFactory homeFactory = (RemoteHomeFactory) 82 Lookup.getInstance().fetchComponent(TEST_REMOTE_HOME_FACTORY); 83 84 if (log.isInfoEnabled()) { 85 log.info("Testing EJB home cache performance"); 86 87 log.info("Performing " 89 + TEST_LOOKUP_ITERATIONS 90 + " home interface lookups for EJB: " 91 + TEST_REMOTE_EJB 92 + " without using cache"); 93 } 94 95 startTime = System.currentTimeMillis(); 97 98 try { 99 for (long i = 0; i < TEST_LOOKUP_ITERATIONS; i++) { 101 102 ejbHome = homeFactory.lookup(TEST_REMOTE_EJB); 103 } 104 105 } catch (Exception e) { 106 fail("Test of EJB home cache performance failed due to: " + e); 107 } 108 109 elapsedTime = System.currentTimeMillis() - startTime; 111 if (log.isInfoEnabled()) { 112 log.info("Total elapsed time: " 113 + elapsedTime); 114 log.info("Lookups/Second: " 115 + ((double) TEST_LOOKUP_ITERATIONS/elapsedTime*1000) 116 + " lps"); 117 } 118 119 EnterpriseBeanConfiguration ejbDetails = 121 homeFactory.getEJBDetails(TEST_REMOTE_EJB); 122 123 if (ejbDetails != null) { 124 ejbDetails.setCacheable(true); 125 } else { 126 fail("Test of EJB home cache performance failed; " 127 + "unable to retrieve EJB details for logical name: " 128 + TEST_REMOTE_EJB); 129 } 130 131 if (log.isInfoEnabled()) { 132 log.info("Performing " 133 + TEST_LOOKUP_ITERATIONS 134 + " home interface lookups for EJB: " 135 + TEST_REMOTE_EJB 136 + " using cache"); 137 } 138 139 startTime = System.currentTimeMillis(); 141 142 try { 143 for (long i = 0; i < TEST_LOOKUP_ITERATIONS; i++) { 144 145 ejbHome = homeFactory.lookup(TEST_REMOTE_EJB); 146 } 147 } catch (Exception e) { 148 fail("Test of EJB home cache performance failed due to: " + e); 149 } 150 151 elapsedTime = System.currentTimeMillis() - startTime; 153 if (log.isInfoEnabled()) { 154 log.info("Total elapsed time: " 155 + elapsedTime); 156 log.info("Lookups/Second: " 157 + ((double) TEST_LOOKUP_ITERATIONS/elapsedTime*1000) 158 + " lps"); 159 } 160 } 161 162 166 public static Test suite() { 167 168 TestSuite test = new TestSuite(); 169 170 test.addTest(new RemoteHomeCachePerformanceTest( 171 "testRemoteHomeCachePerformance")); 172 173 return test; 174 } 175 } 176 | Popular Tags |