1 18 19 package org.objectweb.speedo.stress; 20 21 import org.objectweb.speedo.pobjects.relations.A; 22 import org.objectweb.speedo.pobjects.relations.B; 23 24 import javax.jdo.JDOFatalException; 25 import javax.jdo.PersistenceManager; 26 27 32 public class TestRelationN_M extends StressHelper { 33 34 public TestRelationN_M(String s) { 35 super(s); 36 } 37 38 protected String [] getClassNamesToInit() { 39 return new String []{ 40 org.objectweb.speedo.pobjects.relations.A.class.getName(), 41 org.objectweb.speedo.pobjects.relations.B.class.getName() 42 }; 43 } 44 45 protected String getLoggerName() { 46 return STRESS_LOG_NAME + ".TestRelation1_1"; 47 } 48 49 50 protected void perform(StressHelper.Task task, 51 int threadId, 52 int txId, 53 Object ctx, 54 StressHelper.PerformResult res) { 55 PersistenceManager pm = getPM(task, threadId, txId); 56 try { 57 res.beginTest(); 58 int oid = txId * 3; 59 beginTx(pm, task, threadId, txId); 60 A a1 = new A("a" + oid); 62 A a2 = new A("a" + oid + 1); 63 A a3 = new A("a" + oid + 2); 64 B b1 = new B("b" + oid); 65 B b2 = new B("b" + oid + 1); 66 B b3 = new B("b" + oid + 2); 67 pm.makePersistent(a1); 68 pm.makePersistent(a2); 69 pm.makePersistent(a3); 70 pm.makePersistent(b1); 71 pm.makePersistent(b2); 72 pm.makePersistent(b3); 73 Object oida1 = pm.getObjectId(a1); 74 Object oida2 = pm.getObjectId(a2); 75 Object oida3 = pm.getObjectId(a3); 76 Object oidb1 = pm.getObjectId(b1); 77 Object oidb2 = pm.getObjectId(b2); 78 Object oidb3 = pm.getObjectId(b3); 79 commitTx(pm, task, threadId, txId); 80 closePM(pm, threadId, txId, task, res); 81 82 pm = getPM(task, threadId, txId); 83 a1.getBs().add(b1); 84 assertTrue(b1.getAs().contains(a1)); 85 a1.getBs().add(b2); 86 assertTrue(b2.getAs().contains(a1)); 87 88 a2.getBs().add(b1); 89 assertTrue(b1.getAs().contains(a2)); 90 a2.getBs().add(b2); 91 assertTrue(b2.getAs().contains(a2)); 92 a2.getBs().add(b3); 93 assertTrue(b3.getAs().contains(a2)); 94 95 a3.getBs().add(b2); 96 assertTrue(b2.getAs().contains(a3)); 97 a3.getBs().add(b3); 98 assertTrue(b3.getAs().contains(a3)); 99 100 a1.getBs().add(b3); 101 assertTrue(b3.getAs().contains(a1)); 102 103 a1.getBs().remove(b1); 104 assertTrue(!b1.getAs().contains(a1)); 105 106 b2.getAs().remove(a2); 107 assertTrue(!a2.getBs().contains(b2)); 108 109 a1.setBs(a2.getBs()); 110 closePM(pm, threadId, txId, task, res); 112 113 pm = getPM(task, threadId, txId); 114 assertTrue(a1.getBs().contains(b1)); 115 assertTrue(!a1.getBs().contains(b2)); 116 assertTrue(a1.getBs().contains(b3)); 117 118 assertTrue(a2.getBs().contains(b1)); 119 assertTrue(!a2.getBs().contains(b2)); 120 assertTrue(a2.getBs().contains(b3)); 121 122 assertTrue(!a3.getBs().contains(b1)); 123 assertTrue(a3.getBs().contains(b2)); 124 assertTrue(a3.getBs().contains(b3)); 125 126 assertTrue(b1.getAs().contains(a1)); 127 assertTrue(b1.getAs().contains(a2)); 128 assertTrue(!b1.getAs().contains(a3)); 129 130 assertTrue(!b2.getAs().contains(a1)); 131 assertTrue(!b2.getAs().contains(a2)); 132 assertTrue(b2.getAs().contains(a3)); 133 134 assertTrue(b3.getAs().contains(a1)); 135 assertTrue(b3.getAs().contains(a2)); 136 assertTrue(b3.getAs().contains(a3)); 137 closePM(pm, threadId, txId, task, res); 138 pm = getPM(task, threadId, txId); 139 beginTx(pm, task, threadId, txId); 140 pm.deletePersistent(pm.getObjectById(oidb3, false)); 141 commitTx(pm, task, threadId, txId); 142 closePM(pm, threadId, txId, task, res); 143 pm = getPM(task, threadId, txId); 144 145 assertTrue(a1.getBs().size() == 1); 146 assertTrue(a1.getBs().contains(b1)); 147 assertTrue(a2.getBs().size() == 1); 148 assertTrue(a2.getBs().contains(b1)); 149 assertTrue(a3.getBs().size() == 1); 150 assertTrue(a3.getBs().contains(b2)); 151 152 assertTrue(b1.getAs().contains(a1)); 153 assertTrue(b1.getAs().contains(a2)); 154 assertTrue(!b1.getAs().contains(a3)); 155 assertTrue(!b2.getAs().contains(a1)); 156 assertTrue(!b2.getAs().contains(a2)); 157 assertTrue(b2.getAs().contains(a3)); 158 159 beginTx(pm, task, threadId, txId); 160 pm.deletePersistent(pm.getObjectById(oida1, false)); 161 pm.deletePersistent(pm.getObjectById(oida2, false)); 162 pm.deletePersistent(pm.getObjectById(oida3, false)); 163 pm.deletePersistent(pm.getObjectById(oidb1, false)); 164 pm.deletePersistent(pm.getObjectById(oidb2, false)); 165 commitTx(pm, task, threadId, txId); 166 167 res.endTest(); 168 } catch (JDOFatalException e) { 169 rollbackOnException(pm, e, res, task, threadId, txId); 170 } catch (Throwable e) { 171 stopOnError(pm, e, res, task, threadId, txId); 172 } finally { 173 closePM(pm, threadId, txId, task, res); 174 } 175 } 176 177 178 182 public void testRelationN_M() { 183 if (interactive) { 184 perform(Integer.getInteger(THREAD, 1).intValue(), 185 Integer.getInteger(TX, 1).intValue(), 186 Integer.getInteger(TIMEOUT, 1).intValue(), null); 187 } 188 } 189 190 193 public void testRelationN_MTh1Tx100() { 194 if (!interactive) { 195 perform(1, 100, 1000000, null); 196 } 197 } 198 199 202 public void testRelationN_MTh1Tx1000() { 203 if (!interactive) { 204 perform(1, 1000, 1000000, null); 205 } 206 } 207 208 211 public void testRelationN_MTh1Tx10000() { 212 if (!interactive) { 213 perform(1, 10000, 1000000, null); 214 } 215 } 216 217 220 public void testRelationN_MTh2Tx100() { 221 if (!interactive) { 222 perform(2, 100, 1000000, null); 223 } 224 } 225 226 229 public void testRelationN_MTh2Tx1000() { 230 if (!interactive) { 231 perform(2, 1000, 1000000, null); 232 } 233 } 234 235 238 public void testRelationN_MTh2Tx10000() { 239 if (!interactive) { 240 perform(2, 10000, 1000000, null); 241 } 242 } 243 244 247 public void testRelationN_MTh10Tx100() { 248 if (!interactive) { 249 perform(10, 100, 1000000, null); 250 } 251 } 252 253 256 public void testRelationN_MTh10Tx1000() { 257 if (!interactive) { 258 perform(10, 1000, 1000000, null); 259 } 260 } 261 262 265 public void testRelationN_MTh10Tx10000() { 266 if (!interactive) { 267 perform(10, 10000, 1000000, null); 268 } 269 } 270 } 271 | Popular Tags |