1 18 19 package org.objectweb.speedo.stress; 20 21 import java.util.ArrayList ; 22 import java.util.List ; 23 24 25 import javax.jdo.JDOFatalException; 26 import javax.jdo.PersistenceManager; 27 28 import junit.framework.Assert; 29 import org.objectweb.speedo.Alea; 30 import org.objectweb.speedo.pobjects.collection.AllCollection; 31 import org.objectweb.util.monolog.api.BasicLevel; 32 33 38 public class TestCollectionConcurrency extends AllCollectionHelper { 39 40 public TestCollectionConcurrency(String s) { 41 super(s); 42 logger.log(BasicLevel.INFO, "TestCollectionConcurrency"); 43 } 44 45 protected String [] getClassNamesToInit() { 46 return new String []{AllCollection.class.getName()}; 47 } 48 49 protected String getLoggerName() { 50 return STRESS_LOG_NAME + ".TestCollectionConcurrency"; 51 } 52 53 protected void perform(Task task, int threadId, int txId, Object ctx, PerformResult res) { 54 long _oids = (txId * 6); 55 ACCtx acctx = (ACCtx) ctx; 56 PersistenceManager pm = getPM(task, threadId,txId); 57 try { 58 res.beginTest(); 59 60 long[] reverse = new long[]{_oids + 5, _oids + 4, _oids + 3, _oids + 2, _oids + 1, _oids}; 61 int oid = Alea.rand(0, acctx.dbSize - 1); 63 beginTx(pm, task, threadId, txId); 64 AllCollection ac = (AllCollection) pm.getObjectById(acctx.oids[oid], false); 65 66 logger.log(BasicLevel.DEBUG, "reverse data of "+ac.getId()); 68 ac.setLongs(reverse); 69 ac.setRefs(new Object []{ac}); 70 71 72 List expectedLong = new ArrayList (reverse.length); 74 for (int i = 0; i < reverse.length; i++) { 75 expectedLong.add(new Long (reverse[i])); 76 } 77 78 List expectedRef = new ArrayList (1); 79 expectedRef.add(ac); 80 81 Assert.assertNotNull("The collection of Long is null", ac.getCol_Long()); 83 assertSameCollection("The collection of Long", expectedLong, ac.getCol_Long()); 84 Assert.assertNotNull("The collection of reference is null", ac.getCol_ref()); 85 assertSameCollection("The collection of ref", expectedRef, ac.getCol_ref()); 86 87 Assert.assertNotNull("The Hashset of Long is null", ac.getHset_Long()); 89 assertSameCollection("The Hashset of Long", expectedLong, ac.getHset_Long()); 90 Assert.assertNotNull("The Hashset of reference is null", ac.getHset_ref()); 91 assertSameCollection("The Hashset of ref", expectedRef, ac.getHset_ref()); 92 93 Assert.assertNotNull("The list of Long is null", ac.getList_Long()); 95 assertSameList("The list of Long", expectedLong, ac.getList_Long()); 96 Assert.assertNotNull("The list of reference is null", ac.getList_ref()); 97 assertSameList("The list of reference", expectedRef, ac.getList_ref()); 98 99 Assert.assertNotNull("The set of Long is null", ac.getSet_Long()); 101 assertSameCollection("The set of Long", expectedLong, ac.getSet_Long()); 102 Assert.assertNotNull("The set of reference is null", ac.getSet_ref()); 103 assertSameCollection("The set of ref", expectedRef, ac.getSet_ref()); 104 105 commitTx(pm, task, threadId, txId); 106 107 res.endTest(); 108 } catch (JDOFatalException e) { 109 rollbackOnException(pm, e, res, task, threadId, txId); 110 } catch (Throwable e) { 111 stopOnError(pm, e, res, task, threadId, txId); 112 } finally { 113 closePM(pm, threadId, txId, task, res); 114 } 115 } 116 117 120 private void perform( 121 int nbThread, 122 int dbSize, 123 int nbTx, 124 int threadTimeout) { 125 perform(nbThread, nbTx, threadTimeout, new ACCtx(dbSize)); 126 } 127 128 132 public void testInteractive (){ 133 if (interactive) { 134 logger.log(BasicLevel.INFO, "testInteractive"); 135 perform(Integer.getInteger(THREAD, 1).intValue(), 136 Integer.getInteger(TX, 9).intValue(), 137 Integer.getInteger(TIMEOUT, 200000).intValue(), 138 new ACCtx(Integer.getInteger(DBSIZE, 1000).intValue()) 139 ); 140 } else { 141 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testInteractive"); 142 } 143 } 144 145 148 public void testCollectionConcurrencyTh1Tx100() { 149 if (!interactive) { 150 logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1Tx100"); 151 perform(1, 10000, 100, 1000000); 152 } else { 153 logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1Tx100"); 154 } 155 } 156 157 160 public void testCollectionConcurrencyTh1Tx1000() { 161 162 if (!interactive) { 163 logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1Tx1000"); 164 perform(1, 10000, 1000, 1000000); 165 } else { 166 logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1Tx1000"); 167 } 168 } 169 170 173 public void testCollectionConcurrencyTh1Tx10000() { 174 175 if (!interactive) { 176 logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1Tx10000"); 177 perform(1, 10000, 10000, 1000000); 178 } else { 179 logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1Tx10000"); 180 } 181 } 182 183 186 public void _testCollectionConcurrencyTh1Tx100000() { 187 188 if (!interactive) { 189 logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1Tx100000"); 190 perform(1, 10000, 100000, 1000000); 191 } else { 192 logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1Tx100000"); 193 } 194 } 195 196 199 public void testCollectionConcurrencyTh2Tx100() { 200 201 if (!interactive) { 202 logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh2Tx100"); 203 perform(2, 10000, 100, 1000000); 204 } else { 205 logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh2Tx100"); 206 } 207 208 } 209 210 213 public void testCollectionConcurrencyTh2Tx1000() { 214 215 if (!interactive) { 216 logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh2Tx1000"); 217 perform(2, 10000, 1000, 1000000); 218 } else { 219 logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh2Tx1000"); 220 } 221 } 222 223 226 public void testCollectionConcurrencyTh2Tx10000() { 227 228 if (!interactive) { 229 logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh2Tx10000"); 230 perform(2, 10000, 10000, 1000000); 231 } else { 232 logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh2Tx10000"); 233 } 234 } 235 236 239 public void _testCollectionConcurrencyTh2Tx100000() { 240 241 if (!interactive) { 242 logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh2Tx100000"); 243 perform(2, 10000, 100000, 1000000); 244 } else { 245 logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh2Tx100000"); 246 } 247 } 248 249 250 253 public void testCollectionConcurrencyTh10Tx1000() { 254 255 if (!interactive) { 256 logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh10Tx1000"); 257 perform(10, 10000, 1000, 1000000); 258 } else { 259 logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh10Tx1000"); 260 } 261 } 262 263 266 public void testCollectionConcurrencyTh10Tx10000() { 267 268 if (!interactive) { 269 logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh10Tx10000"); 270 perform(10, 10000, 10000, 1000000); 271 } else { 272 logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh10Tx10000"); 273 } 274 } 275 276 279 public void _testCollectionConcurrencyTh10Tx100000() { 280 281 if (!interactive) { 282 logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh10Tx100000"); 283 perform(10, 10000, 100000, 1000000); 284 } else { 285 logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh10Tx100000"); 286 } 287 } 288 289 292 public void testCollectionConcurrencyTh100Tx100() { 293 294 if (!interactive) { 295 logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh100Tx100"); 296 perform(100, 10000, 100, 1000000); 297 } else { 298 logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh100Tx100"); 299 } 300 } 301 302 305 public void testCollectionConcurrencyTh1000Tx1000() { 306 307 if (!interactive) { 308 logger.log(BasicLevel.INFO, "testCollectionConcurrencyTh1000Tx1000"); 309 perform(1000, 10000, 1000, 1000000); 310 } else { 311 logger.log(BasicLevel.INFO, "Interactive mode: ignore testCollectionConcurrencyTh1000Tx1000"); 312 } 313 } 314 315 } 316 | Popular Tags |