1 22 package org.jboss.test.load.test; 23 24 import java.util.Hashtable ; 25 26 import javax.naming.Context ; 27 import javax.naming.InitialContext ; 28 import java.lang.reflect.UndeclaredThrowableException ; 29 30 import javax.ejb.*; 31 32 import org.jboss.test.testbean.interfaces.*; 33 34 43 public class Worker 44 extends Thread 45 { 46 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 47 48 Hashtable config; 50 51 Worker (ThreadGroup _group, Hashtable _config) 52 { 53 super (_group, (String )_config.get ("name") + "_" + _config.get("number").toString ()); 54 config = _config; 55 } 56 57 58 59 public Hashtable getConfig () 60 { 61 return config; 62 } 63 64 public void run() 65 { 66 int beans = ((Integer )config.get ("beans")).intValue (); 68 int loops = ((Integer )config.get ("loops")).intValue (); 69 boolean verbose = ((Boolean )config.get ("verbose")).booleanValue (); 70 boolean remove = !((Boolean )config.get ("noremove")).booleanValue (); 71 String logTag = "["+getName ()+"] "; 72 73 int txs = 0; 74 long start = System.currentTimeMillis (); 75 76 EnterpriseEntity[] entity = new EnterpriseEntity[beans]; 77 try 78 { 79 EnterpriseEntityHome home = (EnterpriseEntityHome) new InitialContext ().lookup ("nextgen.EnterpriseEntity"); 81 if (home == null) 82 { 83 log.debug (logTag + "EJBHomeInterface lookup returned null?!"); 84 log.debug (logTag + "died."); 85 prepareExit (true, txs, start, System.currentTimeMillis ()); 86 return; 87 } 88 for (int i = 0; i < beans; ++i) 89 { 90 String key = getName () + "_" + i; 91 try 92 { 93 entity[i] = home.findByPrimaryKey (key); 95 if (entity[i] == null) 96 { 97 log.debug (logTag + "EJBHome.findByPrimaryKey () returned null?!"); 98 log.debug (logTag + "died."); 99 prepareExit (true, txs, start, System.currentTimeMillis ()); 100 return; 101 } 102 ++txs; 103 if (verbose) log.debug (logTag + "reuse bean: "+entity[i].getPrimaryKey ()); 104 } 105 catch (FinderException _fe) 106 { 107 entity[i] = home.create (key); 109 if (entity[i] == null) 110 { 111 log.debug (logTag + "EJBHome.create () returned null?!"); 112 log.debug (logTag + "died."); 113 prepareExit (true, txs, start, System.currentTimeMillis ()); 114 return; 115 } 116 ++txs; 117 if (verbose) log.debug (logTag + "create bean: "+entity[i].getPrimaryKey ()); 118 } 119 } 120 } 121 catch (Exception _e) 122 { 123 log.debug (logTag+ "problem while finding/creating beans: "+_e.toString ()); 124 if (_e instanceof UndeclaredThrowableException ) 125 log.debug(logTag+ "target exception: " + ((UndeclaredThrowableException )_e).getUndeclaredThrowable().toString()); 126 127 log.debug (logTag+" died!"); 128 prepareExit (true, txs, start, System.currentTimeMillis ()); 129 return; 130 } 131 132 for (int b = 0; b < beans; ++b) 134 { 135 try 136 { 137 entity[b].setOtherField (0); 138 ++txs; 139 } 140 catch (Exception _e) 141 { 142 log.debug (logTag+ "cannot prepare bean #"+b+": "+_e.toString ()); 143 log.debug (logTag+" died!"); 144 prepareExit (true, txs, start, System.currentTimeMillis ()); 145 return; 146 } 147 } 148 149 for (int l = 0; l < loops; ++l) 151 { 152 for (int b = 0; b < beans; ++b) 153 { 154 int value = -1; 155 try 156 { 157 value = entity[b].getOtherField (); 158 ++txs; 159 } 160 catch (Exception _e) 161 { 162 prepareExit (true, txs, start, System.currentTimeMillis ()); 163 log.debug (logTag + "error in getOtherField () on bean #"+b+" in loop "+l+ ": "+_e.toString ()); 164 if (value != l) 165 log.debug (logTag + "unexpected value in bean #"+b+" in loop "+l); 166 } 167 168 try 169 { 170 entity[b].setOtherField (l + 1); 171 ++txs; 172 } 173 catch (Exception _e) 174 { 175 prepareExit (true, txs, start, System.currentTimeMillis ()); 176 log.debug (logTag + "error in setOtherField () on bean #"+b+" in loop "+l+ ": "+_e.toString ()); 177 } 178 } 179 } 180 181 182 if (remove) 184 { 185 for (int b = 0; b < beans; ++b) 186 { 187 try 188 { 189 if (verbose) log.debug (logTag + "remove bean #"+b); 190 entity[b].remove (); 191 ++txs; 192 } 193 catch (Exception _e) 194 { 195 log.debug (logTag + "error in removing bean #"+b+": "+_e.toString ()); 196 prepareExit (true, txs, start, System.currentTimeMillis ()); 197 } 199 } 200 } 201 prepareExit (false, txs, start, System.currentTimeMillis ()); 202 } 203 204 private void prepareExit (boolean _failed, int _transactions, long _start, long _stop) 205 { 206 config.put ("transactions", new Integer (_transactions)); 207 config.put ("time", new Long (_stop-_start)); 208 config.put ("failed", new Boolean (_failed)); 209 } 210 211 } 212 | Popular Tags |