1 22 package org.jboss.test.pooled.test; 23 24 import java.rmi.*; 25 26 27 import javax.naming.Context ; 28 import javax.naming.InitialContext ; 29 import javax.ejb.DuplicateKeyException ; 30 import javax.ejb.Handle ; 31 import javax.ejb.EJBMetaData ; 32 import javax.ejb.EJBHome ; 33 import javax.ejb.HomeHandle ; 34 import javax.ejb.ObjectNotFoundException ; 35 36 import java.util.Date ; 37 import java.util.Properties ; 38 import java.util.Collection ; 39 import java.util.Iterator ; 40 import java.util.Enumeration ; 41 42 import junit.framework.Test; 43 import junit.framework.TestCase; 44 import junit.framework.TestSuite; 45 46 import org.jboss.test.pooled.interfaces.StatelessSessionHome; 47 import org.jboss.test.pooled.interfaces.StatelessSession; 48 import org.jboss.test.JBossTestCase; 49 import org.jboss.invocation.pooled.interfaces.PooledInvokerProxy; 50 51 57 public class BeanStressTestCase 58 extends JBossTestCase 59 { 60 org.jboss.logging.Logger log = getLog(); 61 62 static boolean deployed = false; 63 static int test = 0; 64 static Date startDate = new Date (); 65 public int NUM_THREADS = getThreadCount(); 66 public int iterations = getIterationCount(); 67 68 protected final String namingFactory = 69 System.getProperty(Context.INITIAL_CONTEXT_FACTORY); 70 71 protected final String providerURL = 72 System.getProperty(Context.PROVIDER_URL); 73 74 public BeanStressTestCase(String name) { 75 super(name); 76 } 77 78 79 boolean failed = false; 80 81 InitialContext ctx; 82 83 private StatelessSession getSession() throws Exception 84 { 85 86 StatelessSessionHome home = (StatelessSessionHome)new InitialContext ().lookup("nextgen.StatelessSession"); 87 return home.create(); 88 } 89 90 91 private class NewProxy implements Runnable 92 { 93 StatelessSessionHome home; 94 public NewProxy(StatelessSessionHome home) 95 { 96 this.home = home; 97 } 98 public void run() 99 { 100 for (int i = 0; i < iterations; i++) 101 { 102 try 103 { 104 StatelessSession obj = home.create(); 105 obj.noop(); 106 107 } 108 catch(Throwable t) 109 { 110 incFailures(); 112 } 113 } 114 } 115 } 116 117 118 private class OldProxy implements Runnable 119 { 120 StatelessSession proxy; 121 public OldProxy(StatelessSession proxy) 122 { 123 this.proxy = proxy; 124 } 125 public void run() 126 { 127 for (int i = 0; i < iterations; i++) 128 { 129 try 130 { 131 proxy.noop(); 132 133 } 134 catch(Throwable t) 135 { 136 incFailures(); 138 } 139 } 140 } 141 } 142 143 144 protected int failures = 0; 145 146 public void testNewProxy() throws Exception 147 { 148 ctx = new InitialContext (); 149 for (int i = 0; i < 2; i++) 150 { 151 runNewProxy("PooledStatelessSession"); 152 System.out.println("usedPooled: " + PooledInvokerProxy.usedPooled); 153 PooledInvokerProxy.usedPooled = 0; 154 runNewProxy("StatelessSession"); 155 } 156 } 157 160 protected void runNewProxy(String ejbname) throws Exception 161 { 162 failures = 0; 163 System.out.println("------------------------"); 164 System.out.println("**** NewProxy" + ejbname + " ****"); 165 166 StatelessSessionHome home = (StatelessSessionHome)ctx.lookup(ejbname); 167 Thread [] threads = new Thread [NUM_THREADS]; 168 for (int i = 0; i < NUM_THREADS; i++) 169 { 170 threads[i] = new Thread (new NewProxy(home)); 171 } 172 long start = System.currentTimeMillis(); 173 for (int i = 0; i < NUM_THREADS; i++) 174 { 175 threads[i].start(); 176 } 177 for (int i = 0; i < NUM_THREADS; i++) 178 { 179 threads[i].join(); 180 } 181 System.out.println("time: " + (System.currentTimeMillis() - start)); 182 System.out.println("failures: " + failures); 183 } 184 185 public void testOldProxy() throws Exception 186 { 187 ctx = new InitialContext (); 188 for (int i = 0; i < 2; i++) 189 { 190 runOldProxy("PooledStatelessSession"); 191 System.out.println("usedPooled: " + PooledInvokerProxy.usedPooled); 192 PooledInvokerProxy.usedPooled = 0; 193 runOldProxy("StatelessSession"); 194 } 195 } 196 199 protected void runOldProxy(String ejbname) throws Exception 200 { 201 failures = 0; 202 System.out.println("------------------------"); 203 System.out.println("**** OldProxy " + ejbname + " ****"); 204 205 StatelessSessionHome home = (StatelessSessionHome)ctx.lookup(ejbname); 206 StatelessSession proxy = home.create(); 207 Thread [] threads = new Thread [NUM_THREADS]; 208 for (int i = 0; i < NUM_THREADS; i++) 209 { 210 threads[i] = new Thread (new OldProxy(proxy)); 211 } 212 long start = System.currentTimeMillis(); 213 for (int i = 0; i < NUM_THREADS; i++) 214 { 215 threads[i].start(); 216 } 217 for (int i = 0; i < NUM_THREADS; i++) 218 { 219 threads[i].join(); 220 } 221 System.out.println("time: " + (System.currentTimeMillis() - start)); 222 System.out.println("failures: " + failures); 223 } 224 225 protected synchronized void incFailures() 226 { 227 failures++; 228 } 229 230 public static Test suite() throws Exception 231 { 232 return getDeploySetup(BeanStressTestCase.class, "pooled.jar"); 233 } 234 235 } 236 | Popular Tags |