1 18 19 package org.objectweb.speedo.stress; 20 21 import org.objectweb.speedo.Alea; 22 import org.objectweb.speedo.pobjects.userid.LinkedIntUserId; 23 import org.objectweb.util.monolog.api.BasicLevel; 24 25 import javax.jdo.PersistenceManager; 26 import javax.jdo.JDOFatalException; 27 28 33 public class TestGetObject extends LinkedIntUserIdHelper { 34 35 private String NBREAD = getLoggerName() + ".nbread"; 36 private String NBREADPERSISTENT = getLoggerName() + ".nbreadpersistent"; 37 38 public class GetCtx extends LIUICtx { 39 public int nbRead; 40 public int nbReadPersistent; 41 public ObjectStatistic stat = new ObjectStatistic(); 42 43 public GetCtx(int dbSize, int nbRead, int nbReadPersistent) { 44 super(dbSize); 45 this.nbRead = nbRead; 46 this.nbReadPersistent = nbReadPersistent; 47 } 48 49 public String toString() { 50 return super.toString() + " / nbRead = " + nbRead 51 + " / nbReadPersistent = " + nbReadPersistent; 52 } 53 } 54 55 public TestGetObject(String s) { 56 super(s); 57 } 58 59 protected String getLoggerName() { 60 return STRESS_LOG_NAME + ".TestGetObject"; 61 } 62 63 protected void perform(Task task, 64 int threadId, 65 int txId, 66 Object ctx, 67 PerformResult res) { 68 GetCtx gctx = (GetCtx) ctx; 69 PersistenceManager pm = getPM(task, threadId, txId); 70 try { 71 res.beginTest(); 72 beginTx(pm, task, threadId, txId); 73 LinkedIntUserId oUserId; 75 for (int no = 0; no < gctx.nbRead; no++) { 76 int oid = Alea.rand(0, gctx.dbSize - 1); 77 gctx.stat.touch(new Integer (oid)); 78 if (debug) { 79 logger.log(BasicLevel.DEBUG, "Reading object " + oid); 80 } 81 oUserId = (LinkedIntUserId) 82 pm.getObjectById(gctx.oids[oid], false); 83 assertNotNull("Null object (oid = " + oid + ")", oUserId); 84 oUserId.readName(gctx.nbReadPersistent); 85 } 86 commitTx(pm, task, threadId, txId); 87 res.endTest(); 88 } catch (JDOFatalException e) { 89 rollbackOnException(pm, e, res, task, threadId, txId); 90 } catch (Throwable e) { 91 stopOnError(pm, e, res, task, threadId, txId); 92 } finally { 93 closePM(pm, threadId, txId, task, res); 94 } 95 } 96 97 protected void logStatistic(TaskManager tm, long exectime, Object _ctx) { 98 GetCtx ctx = (GetCtx) _ctx; 99 logger.log(BasicLevel.INFO, getLogPrefix() + "\tGetObject: objects read:" 100 + ctx.stat.getAccessedOid().size() 101 + ", nb access: " + ctx.stat.getNbAccess()); 102 super.logStatistic(tm, exectime, ctx); 103 } 104 105 109 public void testInteractive() { 110 if (interactive) { 111 logger.log(BasicLevel.INFO, "testInteractive"); 112 perform(Integer.getInteger(THREAD, 10).intValue(), 113 Integer.getInteger(TX, 100).intValue(), 114 Integer.getInteger(TIMEOUT, 200000).intValue(), 115 new GetCtx( 116 Integer.getInteger(DBSIZE, 1000).intValue(), 117 Integer.getInteger(NBREAD, 10).intValue(), 118 Integer.getInteger(NBREADPERSISTENT, 10).intValue())); 119 } else { 120 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testInteractive"); 121 } 122 } 123 124 private void perform( 125 int nbThread, 126 int dbSize, 127 int nbTx, 128 int nbRead, 129 int nbReadPersistent, 130 int threadTimeout) { 131 perform(nbThread, nbTx, threadTimeout, 132 new GetCtx(dbSize, nbRead, nbReadPersistent)); 133 } 134 135 139 public void testGetObjectTh1Tx100Re1Rp1() { 140 if (!interactive) { 141 logger.log(BasicLevel.INFO, "testGetObjectTh1Tx100Re1Rp1"); 142 perform(1, 10000, 100, 1, 1, 1000000); 143 } else { 144 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh1Tx100Re1Rp1"); 145 } 146 } 147 148 152 public void testGetObjectTh2Tx100Re1Rp1() { 153 if (!interactive) { 154 logger.log(BasicLevel.INFO, "testGetObjectTh2Tx100Re1Rp1"); 155 perform(2, 10000, 100, 1, 1, 1000000); 156 } else { 157 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh2Tx100Re1Rp1"); 158 } 159 } 160 161 162 166 public void testGetObjectTh1Tx100Re1Rp10() { 167 if (!interactive) { 168 logger.log(BasicLevel.INFO, "testGetObjectTh1Tx100Re1Rp10"); 169 perform(1, 10000, 100, 1, 10, 1000000); 170 } else { 171 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh1Tx100Re1Rp10"); 172 } 173 } 174 175 179 public void testGetObjectTh2Tx100Re1Rp10() { 180 if (!interactive) { 181 logger.log(BasicLevel.INFO, "testGetObjectTh2Tx100Re1Rp10"); 182 perform(2, 10000, 100, 1, 10, 1000000); 183 } else { 184 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh2Tx100Re1Rp10"); 185 } 186 } 187 188 192 public void testGetObjectTh10Tx100Re1Rp10() { 193 if (!interactive) { 194 logger.log(BasicLevel.INFO, "testGetObjectTh10Tx100Re1Rp10"); 195 perform(10, 10000, 100, 1, 10, 1000000); 196 } else { 197 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh10Tx100Re1Rp10"); 198 } 199 } 200 201 206 public void testGetObjectTh1Tx1000Re10Rp100() { 207 if (!interactive) { 208 logger.log(BasicLevel.INFO, "testGetObjectTh1Tx1000Re10Rp100"); 209 perform(1, 10000, 1000, 10, 100, 1000000); 210 } else { 211 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh1Tx1000Re10Rp100"); 212 } 213 } 214 215 220 public void testGetObjectTh2Tx1000Re10Rp100() { 221 if (!interactive) { 222 logger.log(BasicLevel.INFO, "testGetObjectTh2Tx1000Re10Rp100"); 223 perform(2, 10000, 1000, 10, 100, 1000000); 224 } else { 225 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh2Tx1000Re10Rp100"); 226 } 227 } 228 229 234 public void testGetObjectTh10Tx1000Re10Rp100() { 235 if (!interactive) { 236 logger.log(BasicLevel.INFO, "testGetObjectTh10Tx1000Re10Rp100"); 237 perform(10, 10000, 1000, 10, 100, 1000000); 238 } else { 239 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh10Tx1000Re10Rp100"); 240 } 241 } 242 243 248 public void testGetObjectTh1Tx100Re100Rp100() { 249 if (!interactive) { 250 logger.log(BasicLevel.INFO, "testGetObjectTh1Tx100Re100Rp100"); 251 perform(1, 10000, 100, 100, 100, 1000000); 252 } else { 253 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh1Tx100Re100Rp100"); 254 } 255 } 256 257 262 public void testGetObjectTh2Tx100Re100Rp100() { 263 if (!interactive) { 264 logger.log(BasicLevel.INFO, "testGetObjectTh2Tx100Re100Rp100"); 265 perform(2, 10000, 100, 100, 100, 1000000); 266 } else { 267 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh2Tx100Re100Rp100"); 268 } 269 } 270 271 276 public void testGetObjectTh3Tx100Re100Rp100() { 277 if (!interactive) { 278 logger.log(BasicLevel.INFO, "testGetObjectTh3Tx100Re100Rp100"); 279 perform(3, 10000, 100, 100, 100, 1000000); 280 } else { 281 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh3Tx100Re100Rp100"); 282 } 283 } 284 285 290 public void testGetObjectTh10Tx100Re100Rp100() { 291 if (!interactive) { 292 logger.log(BasicLevel.INFO, "testGetObjectTh10Tx100Re100Rp100"); 293 perform(10, 10000, 100, 100, 100, 1000000); 294 } else { 295 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh10Tx100Re100Rp100"); 296 } 297 } 298 299 300 305 public void testGetObjectTh1Tx100Re100Rp10000() { 306 if (!interactive) { 307 logger.log(BasicLevel.INFO, "testGetObjectTh1Tx100Re100Rp10000"); 308 perform(1, 10000, 100, 100, 10000, 1000000); 309 } else { 310 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh1Tx100Re100Rp10000"); 311 } 312 } 313 314 319 public void testGetObjectTh3Tx100Re100Rp10000() { 320 if (!interactive) { 321 logger.log(BasicLevel.INFO, "testGetObjectTh3Tx100Re100Rp10000"); 322 perform(3, 10000, 100, 100, 10000, 1000000); 323 } else { 324 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh3Tx100Re100Rp10000"); 325 } 326 } 327 328 333 public void testGetObjectTh100Tx100Re100Rp100() { 334 if (!interactive) { 335 logger.log(BasicLevel.INFO, "testGetObjectTh100Tx100Re100Rp100"); 336 perform(100, 10000, 100, 100, 100, 1000000); 337 } else { 338 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh100Tx100Re100Rp100"); 339 } 340 } 341 342 347 public void testGetObjectTh1000Tx100Re100Rp100() { 348 if (!interactive) { 349 logger.log(BasicLevel.INFO, "testGetObjectTh1000Tx100Re100Rp100"); 350 perform(100, 10000, 1000, 100, 100, 1000000); 351 } else { 352 logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh1000Tx100Re100Rp100"); 353 } 354 } 355 } 356 | Popular Tags |