1 18 19 package org.objectweb.speedo.stress; 20 21 import javax.jdo.JDOFatalException; 22 import javax.jdo.PersistenceManager; 23 24 import junit.framework.TestSuite; 25 import junit.textui.TestRunner; 26 27 import org.objectweb.speedo.Alea; 28 import org.objectweb.speedo.api.ExceptionHelper; 29 import org.objectweb.speedo.pobjects.basic.BasicA; 30 import org.objectweb.speedo.pobjects.collection.AMMB; 31 import org.objectweb.speedo.pobjects.collection.BMMB; 32 import org.objectweb.speedo.pobjects.collection.Ref2Ref2AMMB; 33 import org.objectweb.speedo.pobjects.ref.Department; 34 import org.objectweb.speedo.pobjects.ref.Employee; 35 import org.objectweb.speedo.pobjects.userid.AutoIncFieldId; 36 import org.objectweb.speedo.pobjects.userid.Ref2AutoIncFieldId; 37 import org.objectweb.speedo.runtime.query.TestQueries; 38 import org.objectweb.util.monolog.api.BasicLevel; 39 40 45 public class TestQueryConcurrency extends QueryHelper { 46 47 public static int RESULT_MAX = 1000; 48 49 protected String QUERYSUBSET = getLoggerName() + ".querysubset"; 50 51 private static TestQueries test = new TestQueries("TestQueryConcurrency"); 52 53 public TestQueryConcurrency(String s) { 54 super(s); 55 } 56 57 protected String [] getClassNamesToInit() { 58 return new String []{Employee.class.getName(), 59 Department.class.getName(), 60 AMMB.class.getName(), 61 BMMB.class.getName(), 62 Ref2Ref2AMMB.class.getName(), 63 Ref2AutoIncFieldId.class.getName(), 64 AutoIncFieldId.class.getName(), 65 BasicA.class.getName()}; 66 } 67 68 protected String getLoggerName() { 69 return STRESS_LOG_NAME + ".TestQueryConcurrency"; 70 } 71 72 public static void main(String [] args) { 73 TestRunner.run(new TestSuite(TestQueryConcurrency.class)); 74 } 75 76 protected void perform(StressHelper.Task task, 77 int threadId, 78 int txId, 79 Object _ctx, 80 StressHelper.PerformResult res) { 81 QueryCtx queryCtx = (QueryCtx) _ctx; 82 PersistenceManager pm = getPM(task, threadId, txId); 83 try { 84 res.beginTest(); 85 beginTx(pm, task, threadId, txId); 86 87 int query = queryCtx.queries[Alea.rand(0, queryCtx.queries.length-1)]; 88 launchTest(query, threadId); 90 91 commitTx(pm, task, threadId, txId); 92 res.endTest(); 93 } catch (JDOFatalException e) { 94 rollbackOnException(pm, e, res, task, threadId, txId); 95 } catch (Throwable e) { 96 stopOnError(pm, e, res, task, threadId, txId); 97 } finally { 98 closePM(pm, threadId, txId, task, res); 99 } 100 } 101 102 106 public void testInteractive() { 107 if (interactive) { 108 perform(Integer.getInteger(THREAD, 10).intValue(), 109 Integer.getInteger(TX, 100).intValue(), 110 Integer.getInteger(TIMEOUT, 200000).intValue(), 111 new QueryCtx(System.getProperty(QUERYSUBSET))); 112 } 113 } 114 115 118 private void performQuery( 119 int nbThread, 120 int nbTx, 121 int threadTimeout) { 122 perform(nbThread, nbTx, threadTimeout, new QueryCtx(System.getProperty(QUERYSUBSET))); 123 } 124 125 128 public void testQueryConcurrencyTh1Tx100Qu1() { 129 if (!interactive) { 130 performQuery(1, 100, 1000000); 131 } 132 } 133 134 137 138 public void testQueryConcurrencyTh1Tx1000Qu1() { 139 if (!interactive) { 140 performQuery(1, 1000, 1000000); 141 } 142 } 143 144 147 148 public void testQueryConcurrencyTh1Tx10000Qu1() { 149 if (!interactive) { 150 performQuery(1, 10000, 1000000); 151 } 152 } 153 154 157 158 public void testQueryConcurrencyTh1Tx100000Qu1() { 159 if (!interactive) { 160 performQuery(1, 100000, 1000000); 161 } 162 } 163 164 167 public void testQueryConcurrencyTh10Tx100Qu1() { 168 if (!interactive) { 169 performQuery(10, 100, 1000000); 170 } 171 } 172 173 176 177 public void testQueryConcurrencyTh10Tx1000Qu1() { 178 if (!interactive) { 179 performQuery(10, 1000, 1000000); 180 } 181 } 182 183 186 187 public void testQueryConcurrencyTh10Tx10000Qu1() { 188 if (!interactive) { 189 performQuery(10, 10000, 1000000); 190 } 191 } 192 193 196 197 public void testQueryConcurrencyTh10Tx100000Qu1() { 198 if (!interactive) { 199 performQuery(10, 100000, 1000000); 200 } 201 } 202 203 204 private void launchTest(int queryidx, int threadId) { 205 String msg = "Thread " + threadId + " method: "; 206 try { 207 switch(queryidx) { 208 case 0: 209 msg += "test0Parameter"; 210 logger.log(BasicLevel.DEBUG, msg); 211 test.test0Parameter(); 212 break; 213 case 1: 214 msg += "test10rder"; 215 logger.log(BasicLevel.DEBUG, msg); 216 test.test10rder(); 217 break; 218 case 2: 219 msg += "test20rder"; 220 logger.log(BasicLevel.DEBUG, msg); 221 test.test20rder(); 222 break; 223 case 3: 224 msg += "test1Parameter"; 225 logger.log(BasicLevel.DEBUG, msg); 226 test.test1Parameter(); 227 break; 228 case 4: 229 msg += "testFieldParameter"; 230 logger.log(BasicLevel.DEBUG, msg); 231 test.testFieldParameter(); 232 break; 233 case 5: 234 msg += "test2Parameters"; 235 logger.log(BasicLevel.DEBUG, msg); 236 test.test2Parameters(); 237 break; 238 case 6: 239 msg += "test3Parameters"; 240 logger.log(BasicLevel.DEBUG, msg); 241 test.test3Parameters(); 242 break; 243 case 7: 244 msg += "testMapParameters"; 245 logger.log(BasicLevel.DEBUG, msg); 246 test.testMapParameters(); 247 break; 248 case 8: 249 msg += "testArrayParameters"; 250 logger.log(BasicLevel.DEBUG, msg); 251 test.testArrayParameters(); 252 break; 253 case 9: 254 msg += "testFieldRef"; 255 logger.log(BasicLevel.DEBUG, msg); 256 test.testFieldRef(); 257 break; 258 case 10: 259 msg += "testThis"; 260 logger.log(BasicLevel.DEBUG, msg); 261 test.testThis(); 262 break; 263 case 11: 264 msg += "testParamRef"; 265 logger.log(BasicLevel.DEBUG, msg); 266 test.testParamRef(); 267 break; 268 case 12: 269 msg += "testBsContainsParamA0B0"; 270 logger.log(BasicLevel.DEBUG, msg); 271 test.testBsContainsParamA0B0(); 272 break; 273 case 13: 274 msg += "testBsContainsParamA0B2"; 275 logger.log(BasicLevel.DEBUG, msg); 276 test.testBsContainsParamA0B2(); 277 break; 278 case 14: 279 msg += "testBsContainsVarB3EmptyShortPath"; 280 logger.log(BasicLevel.DEBUG, msg); 281 test.testBsContainsVarB3EmptyShortPath(); 282 break; 283 case 15: 284 msg += "testBsContainsVarB0ShortPath"; 285 logger.log(BasicLevel.DEBUG, msg); 286 test.testBsContainsVarB0ShortPath(); 287 break; 288 case 16: 289 msg += "testBsContainsVarB1ShortPath"; 290 logger.log(BasicLevel.DEBUG, msg); 291 test.testBsContainsVarB1ShortPath(); 292 break; 293 case 17: 294 msg += "testBsContainsVarB3EmptyLongPath"; 295 logger.log(BasicLevel.DEBUG, msg); 296 test.testBsContainsVarB3EmptyLongPath(); 297 break; 298 case 18: 299 msg += "testBsContainsVarB0LongPath"; 300 logger.log(BasicLevel.DEBUG, msg); 301 test.testBsContainsVarB0LongPath(); 302 break; 303 case 19: 304 msg += "testBsContainsVarB1LongPath"; 305 logger.log(BasicLevel.DEBUG, msg); 306 test.testBsContainsVarB1LongPath(); 307 break; 308 case 20: 309 msg += "testBsIsEmptyA0"; 310 logger.log(BasicLevel.DEBUG, msg); 311 test.testBsIsEmptyA0(); 312 break; 313 case 21: 314 msg += "testBsIsEmptyA3"; 315 logger.log(BasicLevel.DEBUG, msg); 316 test.testBsIsEmptyA3(); 317 break; 318 case 22: 319 msg += "testBsIsEmptyA0WithNot"; 320 logger.log(BasicLevel.DEBUG, msg); 321 test.testBsIsEmptyA0WithNot(); 322 break; 323 case 23: 324 msg += "testBsIsEmptyA3WithNot"; 325 logger.log(BasicLevel.DEBUG, msg); 326 test.testBsIsEmptyA3WithNot(); 327 break; 328 case 24: 329 msg += "testBsContainsVarB3EmptyLongPath"; 330 logger.log(BasicLevel.DEBUG, msg); 331 test.testBsContainsVarB3EmptyLongPath(); 332 break; 333 case 25: 334 msg += "testBsContainsVarB3EmptyLongPath"; 335 logger.log(BasicLevel.DEBUG, msg); 336 test.testBsContainsVarB3EmptyLongPath(); 337 break; 338 case 26: 339 msg += "testBsIsNotEmptyA0Global"; 340 logger.log(BasicLevel.DEBUG, msg); 341 test.testBsIsNotEmptyA0Global(); 342 break; 343 case 27: 344 msg += "testBsIsNotEmptyA0Local"; 345 logger.log(BasicLevel.DEBUG, msg); 346 test.testBsIsNotEmptyA0Local(); 347 break; 348 case 28: 349 msg += "testBsIsNotEmptyA3Global"; 350 logger.log(BasicLevel.DEBUG, msg); 351 test.testBsIsNotEmptyA3Global(); 352 break; 353 case 29: 354 msg += "testNotA0"; 355 logger.log(BasicLevel.DEBUG, msg); 356 test.testNotA0(); 357 break; 358 case 30: 359 msg += "testExtentAMMBfalse"; 360 logger.log(BasicLevel.DEBUG, msg); 361 test.testExtentAMMBfalse(); 362 break; 363 case 31: 364 msg += "testExtentBMMBfalse"; 365 logger.log(BasicLevel.DEBUG, msg); 366 test.testExtentBMMBfalse(); 367 break; 368 case 32: 369 msg += "testQueryBasedOnExtent"; 370 logger.log(BasicLevel.DEBUG, msg); 371 test.testQueryBasedOnExtent(); 372 break; 373 case 33: 374 msg += "testSequenceIdNavigateToPrimitive"; 375 logger.log(BasicLevel.DEBUG, msg); 376 test.testSequenceIdNavigateToPrimitive(); 377 break; 378 case 34: 379 msg += "testSequenceIdNavigateToPrimitive2"; 380 logger.log(BasicLevel.DEBUG, msg); 381 test.testSequenceIdNavigateToPrimitive2(); 382 break; 383 } 384 } catch (Exception e) { 385 Exception ie = ExceptionHelper.getNested(e); 386 logger.log(BasicLevel.ERROR, msg, ie); 387 fail(msg + ie.getMessage()); 388 } 389 } 390 391 392 393 } 394 | Popular Tags |