1 24 25 package org.objectweb.cjdbc.scenario.tools.testlet; 26 27 import java.util.Hashtable ; 28 29 import junit.framework.TestCase; 30 31 45 public abstract class AbstractTestLet extends TestCase 46 { 47 48 public static final String TABLE_NAME = "TABLE_NAME"; 49 50 public static final String COLUMN_NAME = "COLUMN_NAME"; 51 52 public static final String UPDATED_COLUMN_VALUE = "UPDATED_COLUMN_VALUE"; 53 54 public static final String SELECTED_COLUMNS = "SELECTED_COLUMNS"; 55 56 public static final String USE_PREPARED_STATEMENT = "USE_PREPARED_STATEMENT"; 57 58 public static final String VIRTUAL_DATABASE = "VIRTUAL_DATABASE"; 59 60 public static final String IGNORE_CASE = "IGNORE_CASE"; 61 62 public static final String TABLE_METADATA_COLUMNS = "TABLE_METADATA_COLUMNS"; 63 64 public static final String USE_TRANSACTIONS = "USE_TRANSACTIONS"; 65 66 public static final String USE_CJDBC_CLASS = "USE_CJDBC_CLASS"; 67 68 public static final String FILE_NAME = "FILE_NAME"; 69 70 public static final String LIST_FAILOVER_BACKENDS = "LIST_FAILOVER_BACKENDS"; 71 72 public static final String ITERATION = "ITERATION"; 73 74 public static final String PROCEDURE_NAME = "PROCEDURE"; 75 76 public static final String USE_UPDATE_STATEMENT = "USE_UPDATE_STATEMENT"; 77 78 public static final String NUMBER_OF_UPDATES = "NUMBER_OF_UPDATES"; 79 80 public static final String USE_OPTIMIZED_STATEMENT = "USE_OPTIMIZED_STATEMENT"; 81 82 public static final String MACRO_NAME = "MACRO_NAME"; 83 84 protected Hashtable config; 85 private long initialMemoryUsage; 86 private long initialTime; 87 88 91 public AbstractTestLet() 92 { 93 config = new Hashtable (); 94 System.gc(); 95 initialMemoryUsage = checkMemoryUsage(); 96 initialTime = System.currentTimeMillis(); 97 } 98 99 105 public abstract void execute() throws Exception ; 106 107 112 public long checkMemoryUsage() 113 { 114 long total = Runtime.getRuntime().totalMemory(); 115 long before = Runtime.getRuntime().freeMemory(); 116 return (total - before) / 1024; 117 } 118 119 128 public void executeBatch(String batchCategory, Object [] batchValues) 129 throws Exception 130 { 131 for (int i = 0; i < batchValues.length; i++) 132 { 133 set(batchCategory, batchValues[i]); 134 execute(); 135 } 136 } 137 138 143 public void executeBatch(int numberOfTimes) throws Exception 144 { 145 for (int i = 0; i < numberOfTimes; i++) 146 execute(); 147 } 148 149 157 public void configure(Hashtable properties) throws Exception 158 { 159 properties.putAll(properties); 160 } 161 162 168 public boolean getConfigBoolean(String key) 169 { 170 return Boolean.valueOf((String ) config.get(key)).booleanValue(); 171 } 172 173 178 public Hashtable getConfig() 179 { 180 return config; 181 } 182 183 188 public void setConfig(Hashtable config) 189 { 190 this.config = config; 191 } 192 193 199 public void set(String key, Object value) 200 { 201 config.put(key, value); 202 } 203 204 209 public boolean usePreparedStatement() 210 { 211 return Boolean.valueOf((String ) config.get(USE_PREPARED_STATEMENT)) 212 .booleanValue(); 213 } 214 215 220 public boolean ignoreCase() 221 { 222 return Boolean.valueOf((String ) config.get(IGNORE_CASE)).booleanValue(); 223 } 224 225 230 public boolean useTransaction() 231 { 232 return Boolean.valueOf((String ) config.get(USE_TRANSACTIONS)) 233 .booleanValue(); 234 } 235 236 242 public boolean useCJDBCClass() 243 { 244 return Boolean.valueOf((String ) config.get(USE_CJDBC_CLASS)).booleanValue(); 245 } 246 247 252 public long getInitialMemoryUsage() 253 { 254 return initialMemoryUsage; 255 } 256 257 262 public long getTotalMemoryUsage() 263 { 264 System.gc(); 265 return checkMemoryUsage() - initialMemoryUsage; 266 } 267 268 273 public long getTotalTimeUsage() 274 { 275 return (System.currentTimeMillis() - initialTime) / 1000; 276 } 277 } | Popular Tags |