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 TestRelation1_NConcurrency extends CDRelationHelper { 34 35 public TestRelation1_NConcurrency(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 + ".TestRelation1_NConcurrency"; 48 } 49 50 protected int getNbSucc() { 51 return 4; } 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 D d1 = (D) pm.getObjectById(cdctx.oidsD[oid], false); 70 D d2 = (D) pm.getObjectById(cdctx.oidsD[oid+1], false); 71 D d3 = (D) pm.getObjectById(cdctx.oidsD[oid+2], false); 72 D d4 = (D) pm.getObjectById(cdctx.oidsD[oid+3], false); 73 74 c1.getNds().add(d1); 75 assertTrue(d1.getNc() == c1); 76 c1.getNds().add(d2); 77 assertTrue(d2.getNc() == c1); 78 79 c2.getNds().add(d3); 80 assertTrue(d3.getNc() == c2); 81 c2.getNds().add(d4); 82 assertTrue(d4.getNc() == c2); 83 84 c1.getNds().add(d3); 85 assertTrue(d3.getNc() == c1); 86 assertTrue(!c2.getNds().contains(d3)); 87 88 c1.getNds().remove(d1); 89 assertTrue(d1.getNc() == null); 90 91 d3.setNc(c2); 92 assertTrue(!c1.getNds().contains(d3)); 93 assertTrue(c2.getNds().contains(d3)); 94 95 c1.setNds(c2.getNds()); 96 97 commitTx(pm, task, threadId, txId); 98 99 assertTrue(!c1.getNds().contains(d1)); 100 assertTrue(!c1.getNds().contains(d2)); 101 assertTrue(c1.getNds().contains(d3)); 102 assertTrue(c1.getNds().contains(d4)); 103 assertTrue(c1.getNds().size() == 2); 104 105 assertTrue(!c2.getNds().contains(d1)); 106 assertTrue(!c2.getNds().contains(d2)); 107 assertTrue(!c2.getNds().contains(d3)); 108 assertTrue(!c2.getNds().contains(d4)); 109 110 assertTrue(d1.getNc() == null); 111 assertTrue(d2.getNc() == null); 112 assertTrue(d3.getNc() == c1); 113 assertTrue(d4.getNc() == c1); 114 115 res.endTest(); 116 } catch (JDOFatalException e) { 117 rollbackOnException(pm, e, res, task, threadId, txId); 118 } catch (Throwable e) { 119 stopOnError(pm, e, res, task, threadId, txId); 120 } finally { 121 closePM(pm, threadId, txId, task, res); 122 } 123 } 124 125 126 130 public void testInteractive() { 131 if (interactive) { 132 logger.log(BasicLevel.INFO, "testInteractive"); 133 perform(Integer.getInteger(THREAD, 1).intValue(), 134 Integer.getInteger(TX, 1).intValue(), 135 Integer.getInteger(TIMEOUT, 1).intValue(), 136 new CDCtx(Integer.getInteger(DBSIZE, 1000).intValue())); 137 } else { 138 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testInteractive"); 139 } 140 } 141 142 145 private void perform( 146 int nbThread, 147 int dbSize, 148 int nbTx, 149 int threadTimeout) { 150 perform(nbThread, nbTx, threadTimeout, new CDCtx(dbSize)); 151 } 152 153 156 public void testRelation1_NConcurrencyTh1Tx100() { 157 if (!interactive) { 158 logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh1Tx100"); 159 perform(1, 10000, 100, 1000000); 160 } else { 161 logger.log(BasicLevel.INFO, "Interactive mode: ignore testRelation1_NConcurrencyTh1Tx100"); 162 } 163 } 164 165 168 public void testRelation1_NConcurrencyTh1Tx1000() { 169 if (!interactive) { 170 logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh1Tx1000"); 171 perform(1, 10000, 1000, 1000000); 172 } else { 173 logger.log(BasicLevel.INFO, "Interactive mode: ignore testRelation1_NConcurrencyTh1Tx1000"); 174 } 175 } 176 177 180 public void testRelation1_NConcurrencyTh1Tx10000() { 181 if (!interactive) { 182 logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh1Tx10000"); 183 perform(1, 10000, 10000, 1000000); 184 } else { 185 logger.log(BasicLevel.INFO, "Interactive mode: ignore testRelation1_NConcurrencyTh1Tx10000"); 186 } 187 } 188 189 192 public void testRelation1_NConcurrencyTh2Tx100() { 193 if (!interactive) { 194 logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh2Tx100"); 195 perform(2, 10000, 100, 1000000); 196 } else { 197 logger.log(BasicLevel.INFO, "Interactive mode: ignore testRelation1_NConcurrencyTh2Tx100"); 198 } 199 } 200 201 204 public void testRelation1_NConcurrencyTh2Tx1000() { 205 if (!interactive) { 206 logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh2Tx1000"); 207 perform(2, 10000, 1000, 1000000); 208 } else { 209 logger.log(BasicLevel.INFO, "Interactive mode: ignore testRelation1_NConcurrencyTh2Tx1000"); 210 } 211 } 212 213 216 public void testRelation1_NConcurrencyTh2Tx10000() { 217 if (!interactive) { 218 logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh2Tx10000"); 219 perform(2, 10000, 10000, 1000000); 220 } else { 221 logger.log(BasicLevel.INFO, "Interactive mode: ignore testRelation1_NConcurrencyTh2Tx10000"); 222 } 223 } 224 225 228 public void testRelation1_NConcurrencyTh10Tx100() { 229 if (!interactive) { 230 logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh10Tx100"); 231 perform(10, 10000, 100, 1000000); 232 } else { 233 logger.log(BasicLevel.INFO, "Interactive mode: ignore testRelation1_NConcurrencyTh10Tx100"); 234 } 235 } 236 237 240 public void testRelation1_NConcurrencyTh10Tx1000() { 241 if (!interactive) { 242 logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh10Tx1000"); 243 perform(10, 10000, 1000, 1000000); 244 } else { 245 logger.log(BasicLevel.INFO, "Interactive mode: ignore testRelation1_NConcurrencyTh10Tx1000"); 246 } 247 } 248 249 252 public void testRelation1_NConcurrencyTh10Tx10000() { 253 if (!interactive) { 254 logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh10Tx10000"); 255 perform(10, 10000, 10000, 1000000); 256 } else { 257 logger.log(BasicLevel.INFO, "Interactive mode: ignore testRelation1_NConcurrencyTh10Tx10000"); 258 } 259 } 260 } 261 | Popular Tags |