1 18 19 package org.objectweb.speedo.stress; 20 21 import org.objectweb.speedo.pobjects.relations.C; 22 import org.objectweb.speedo.pobjects.relations.D; 23 import org.objectweb.util.monolog.api.BasicLevel; 24 25 import javax.jdo.JDOFatalException; 26 import javax.jdo.PersistenceManager; 27 28 33 public class TestRelationN_MConcurrency extends CDRelationHelper { 34 35 public TestRelationN_MConcurrency(String s) { 36 super(s); 37 } 38 39 protected String [] getClassNamesToInit() { 40 return new String []{ 41 org.objectweb.speedo.pobjects.relations.C.class.getName(), 42 org.objectweb.speedo.pobjects.relations.D.class.getName() 43 }; 44 } 45 46 protected String getLoggerName() { 47 return STRESS_LOG_NAME + ".TestRelationN_MConcurrency"; 48 } 49 50 protected int getNbSucc() { 51 return 3; } 53 54 protected void perform(StressHelper.Task task, 55 int threadId, 56 int txId, 57 Object ctx, 58 StressHelper.PerformResult res) { 59 CDCtx cdctx = (CDCtx) ctx; 60 PersistenceManager pm = getPM(task, threadId, txId); 61 try { 62 res.beginTest(); 63 beginTx(pm, task, threadId, txId); 64 65 int oid = getOid(cdctx, (task.txToExecute.length==0), getNbSucc()); 66 67 C c1 = (C) pm.getObjectById(cdctx.oidsC[oid], false); 68 C c2 = (C) pm.getObjectById(cdctx.oidsC[oid+1], false); 69 C c3 = (C) pm.getObjectById(cdctx.oidsC[oid+2], false); 70 D d1 = (D) pm.getObjectById(cdctx.oidsD[oid], false); 71 D d2 = (D) pm.getObjectById(cdctx.oidsD[oid+1], false); 72 D d3 = (D) pm.getObjectById(cdctx.oidsD[oid+2], false); 73 74 c1.getDs().add(d1); 75 assertTrue(d1.getCs().contains(c1)); 76 c1.getDs().add(d2); 77 assertTrue(d2.getCs().contains(c1)); 78 79 c2.getDs().add(d1); 80 assertTrue(d1.getCs().contains(c2)); 81 c2.getDs().add(d2); 82 assertTrue(d2.getCs().contains(c2)); 83 c2.getDs().add(d3); 84 assertTrue(d3.getCs().contains(c2)); 85 86 c3.getDs().add(d2); 87 assertTrue(d2.getCs().contains(c3)); 88 c3.getDs().add(d3); 89 assertTrue(d3.getCs().contains(c3)); 90 91 c1.getDs().add(d3); 92 assertTrue(d3.getCs().contains(c1)); 93 94 c1.getDs().remove(d1); 95 assertTrue(!d1.getCs().contains(c1)); 96 97 d2.getCs().remove(c2); 98 assertTrue(!c2.getDs().contains(d2)); 99 100 c1.setDs(c2.getDs()); 101 102 commitTx(pm, task, threadId, txId); 103 104 assertTrue(c1.getDs().contains(d1)); 105 assertTrue(!c1.getDs().contains(d2)); 106 assertTrue(c1.getDs().contains(d3)); 107 108 assertTrue(c2.getDs().contains(d1)); 109 assertTrue(!c2.getDs().contains(d2)); 110 assertTrue(c2.getDs().contains(d3)); 111 112 assertTrue(!c3.getDs().contains(d1)); 113 assertTrue(c3.getDs().contains(d2)); 114 assertTrue(c3.getDs().contains(d3)); 115 116 assertTrue(d1.getCs().contains(c1)); 117 assertTrue(d1.getCs().contains(c2)); 118 assertTrue(!d1.getCs().contains(c3)); 119 120 assertTrue(!d2.getCs().contains(c1)); 121 assertTrue(!d2.getCs().contains(c2)); 122 assertTrue(d2.getCs().contains(c3)); 123 124 assertTrue(d3.getCs().contains(c1)); 125 assertTrue(d3.getCs().contains(c2)); 126 assertTrue(d3.getCs().contains(c3)); 127 128 res.endTest(); 129 } catch (JDOFatalException e) { 130 rollbackOnException(pm, e, res, task, threadId, txId); 131 } catch (Throwable e) { 132 stopOnError(pm, e, res, task, threadId, txId); 133 } finally { 134 closePM(pm, threadId, txId, task, res); 135 } 136 } 137 138 139 143 public void testInteractive() { 144 if (interactive) { 145 logger.log(BasicLevel.INFO, "testInteractive"); 146 perform(Integer.getInteger(THREAD, 1).intValue(), 147 Integer.getInteger(TX, 1).intValue(), 148 Integer.getInteger(TIMEOUT, 1).intValue(), 149 new CDCtx(Integer.getInteger(DBSIZE, 1000).intValue())); 150 } else { 151 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testInteractive"); 152 } 153 } 154 155 158 private void perform( 159 int nbThread, 160 int dbSize, 161 int nbTx, 162 int threadTimeout) { 163 perform(nbThread, nbTx, threadTimeout, new CDCtx(dbSize)); 164 } 165 166 169 public void testRelationN_MConcurrencyTh1Tx100() { 170 if (!interactive) { 171 logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh1Tx100"); 172 perform(1, 10000, 100, 1000000); 173 } else { 174 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelation1_NConcurrencyTh1Tx100"); 175 } 176 } 177 178 181 public void testRelationN_MConcurrencyTh1Tx1000() { 182 if (!interactive) { 183 logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh1Tx1000"); 184 perform(1, 10000, 1000, 1000000); 185 } else { 186 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh1Tx1000"); 187 } 188 } 189 190 193 public void testRelationN_MConcurrencyTh1Tx10000() { 194 if (!interactive) { 195 logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh1Tx10000"); 196 perform(1, 10000, 10000, 1000000); 197 } else { 198 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh1Tx10000"); 199 } 200 } 201 202 205 public void testRelationN_MConcurrencyTh2Tx100() { 206 if (!interactive) { 207 logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh2Tx100"); 208 perform(2, 10000, 100, 1000000); 209 } else { 210 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh2Tx100"); 211 } 212 } 213 214 217 public void testRelationN_MConcurrencyTh2Tx1000() { 218 if (!interactive) { 219 logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh2Tx1000"); 220 perform(2, 10000, 1000, 1000000); 221 } else { 222 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh2Tx1000"); 223 } 224 } 225 226 229 public void testRelationN_MConcurrencyTh2Tx10000() { 230 if (!interactive) { 231 logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh2Tx10000"); 232 perform(2, 10000, 10000, 1000000); 233 } else { 234 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh2Tx10000"); 235 } 236 } 237 238 241 public void testRelationN_MConcurrencyTh10Tx100() { 242 if (!interactive) { 243 logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh10Tx100"); 244 perform(10, 10000, 100, 1000000); 245 } else { 246 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh10Tx100"); 247 } 248 } 249 250 253 public void testRelationN_MConcurrencyTh10Tx1000() { 254 if (!interactive) { 255 logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh10Tx1000"); 256 perform(10, 10000, 1000, 1000000); 257 } else { 258 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh10Tx1000"); 259 } 260 } 261 262 265 public void testRelationN_MConcurrencyTh10Tx10000() { 266 if (!interactive) { 267 logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh10Tx10000"); 268 perform(10, 10000, 10000, 1000000); 269 } else { 270 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh10Tx10000"); 271 } 272 } 273 } 274 | Popular Tags |