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 TestRelation1_N extends StressHelper { 33 34 public TestRelation1_N(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 * 4; 59 beginTx(pm, task, threadId, txId); 60 61 A a1 = new A("a" + oid); 63 A a2 = new A("a" + oid + 1); 64 65 B b1 = new B("b" + oid); 66 B b2 = new B("b" + oid + 1); 67 B b3 = new B("b" + oid + 2); 68 B b4 = new B("b" + oid + 3); 69 70 pm.makePersistent(a1); 71 pm.makePersistent(a2); 72 pm.makePersistent(b1); 73 pm.makePersistent(b2); 74 pm.makePersistent(b3); 75 pm.makePersistent(b4); 76 Object oida1 = pm.getObjectId(a1); 77 Object oida2 = pm.getObjectId(a2); 78 Object oidb1 = pm.getObjectId(b1); 79 Object oidb2 = pm.getObjectId(b2); 80 Object oidb3 = pm.getObjectId(b3); 81 Object oidb4 = pm.getObjectId(b4); 82 83 commitTx(pm, task, threadId, txId); 85 86 a1.getNbs().add(b1); 87 assertTrue(b1.getNa() == a1); 88 a1.getNbs().add(b2); 89 assertTrue(b2.getNa() == a1); 90 91 a2.getNbs().add(b3); 92 assertTrue(b3.getNa() == a2); 93 a2.getNbs().add(b4); 94 assertTrue(b4.getNa() == a2); 95 96 a1.getNbs().add(b3); 97 assertTrue(b3.getNa() == a1); 98 assertTrue(!a2.getNbs().contains(b3)); 99 100 a1.getNbs().remove(b1); 101 assertTrue(b1.getNa() == null); 102 103 b3.setNa(a2); 104 assertTrue(!a1.getNbs().contains(b3)); 105 assertTrue(a2.getNbs().contains(b3)); 106 107 a1.setNbs(a2.getNbs()); 108 109 pm.close(); 111 pm = pmf.getPersistenceManager(); 112 113 assertTrue(!a1.getNbs().contains(b1)); 114 assertTrue(!a1.getNbs().contains(b2)); 115 assertTrue(a1.getNbs().contains(b3)); 116 assertTrue(a1.getNbs().contains(b4)); 117 assertTrue(a1.getNbs().size() == 2); 118 119 assertTrue(!a2.getNbs().contains(b1)); 120 assertTrue(!a2.getNbs().contains(b2)); 121 assertTrue(!a2.getNbs().contains(b3)); 122 assertTrue(!a2.getNbs().contains(b4)); 123 124 assertTrue(b1.getNa() == null); 125 assertTrue(b2.getNa() == null); 126 assertTrue(b3.getNa() == a1); 127 assertTrue(b4.getNa() == a1); 128 129 beginTx(pm, task, threadId, txId); 131 pm.deletePersistent(pm.getObjectById(oidb3, false)); 132 assertTrue("reverse reference of b3.na (a1.nbs) must not contain b3", 133 !a1.getNbs().contains(b3)); 134 commitTx(pm, task, threadId, txId); 135 pm.close(); 136 137 pm = pmf.getPersistenceManager(); 138 assertTrue("reverse reference of b3.na (a1.nbs) must not contain b3", 139 !a1.getNbs().contains(b3)); 140 141 beginTx(pm, task, threadId, txId); 142 pm.deletePersistent(pm.getObjectById(oida1, false)); 143 pm.deletePersistent(pm.getObjectById(oida2, false)); 144 pm.deletePersistent(pm.getObjectById(oidb1, false)); 145 pm.deletePersistent(pm.getObjectById(oidb2, false)); 146 pm.deletePersistent(pm.getObjectById(oidb4, false)); 147 commitTx(pm, task, threadId, txId); 148 149 res.endTest(); 150 } catch (JDOFatalException e) { 151 rollbackOnException(pm, e, res, task, threadId, txId); 152 } catch (Throwable e) { 153 stopOnError(pm, e, res, task, threadId, txId); 154 } finally { 155 closePM(pm, threadId, txId, task, res); 156 } 157 } 158 159 160 164 public void testRelation1_N() { 165 if (interactive) { 166 perform(Integer.getInteger(THREAD, 1).intValue(), 167 Integer.getInteger(TX, 1).intValue(), 168 Integer.getInteger(TIMEOUT, 1).intValue(), null); 169 } 170 } 171 172 175 public void testRelation1_NTh1Tx100() { 176 if (!interactive) { 177 perform(1, 100, 1000000, null); 178 } 179 } 180 181 184 public void testRelation1_NTh1Tx1000() { 185 if (!interactive) { 186 perform(1, 1000, 1000000, null); 187 } 188 } 189 190 193 public void testRelation1_NTh1Tx10000() { 194 if (!interactive) { 195 perform(1, 10000, 1000000, null); 196 } 197 } 198 199 202 public void testRelation1_NTh2Tx100() { 203 if (!interactive) { 204 perform(2, 100, 1000000, null); 205 } 206 } 207 208 211 public void testRelation1_NTh2Tx1000() { 212 if (!interactive) { 213 perform(2, 1000, 1000000, null); 214 } 215 } 216 217 220 public void testRelation1_NTh2Tx10000() { 221 if (!interactive) { 222 perform(2, 10000, 1000000, null); 223 } 224 } 225 226 229 public void testRelation1_NTh10Tx100() { 230 if (!interactive) { 231 perform(10, 100, 1000000, null); 232 } 233 } 234 235 238 public void testRelation1_NTh10Tx1000() { 239 if (!interactive) { 240 perform(10, 1000, 1000000, null); 241 } 242 } 243 244 247 public void testRelation1_NTh10Tx10000() { 248 if (!interactive) { 249 perform(10, 10000, 1000000, null); 250 } 251 } 252 253 254 } 255 | Popular Tags |