1 18 19 package org.objectweb.speedo.stress; 20 21 import javax.jdo.JDOFatalException; 22 import javax.jdo.PersistenceManager; 23 24 import junit.framework.Assert; 25 26 import org.objectweb.speedo.Alea; 27 import org.objectweb.speedo.pobjects.userid.LinkedIntUserId; 28 import org.objectweb.util.monolog.api.BasicLevel; 29 30 34 public class TestSetObject extends LinkedIntUserIdHelper { 35 36 private String NBWRITE = getLoggerName() + ".nbwrite"; 37 private String NBWRITEPERSISTENT = getLoggerName() + ".nbwritepersistent"; 38 39 public TestSetObject(String s) { 40 super(s); 41 } 42 43 protected String getLoggerName() { 44 return STRESS_LOG_NAME + ".TestSetObject"; 45 } 46 47 class SetCtx extends LIUICtx{ 48 public int nbWrite; 49 public int nbWritePersistent; 50 51 public SetCtx(int dbSize, int nbWrite, int nbWritePersistent) { 52 super(dbSize); 53 this.nbWrite = nbWrite; 54 this.nbWritePersistent = nbWritePersistent; 55 } 56 } 57 58 protected void perform(Task task, 59 int threadId, 60 int txId, 61 Object ctx, 62 PerformResult res) { 63 SetCtx sctx = (SetCtx) ctx; 64 PersistenceManager pm = getPM(task, threadId, txId); 65 try { 66 res.beginTest(); 67 beginTx(pm, task, threadId, txId); 68 LinkedIntUserId oUserId; 71 int oid; 72 String f1 = Alea.randomstring(); 73 for (int no = 0; no < sctx.nbWrite; no++) { 74 oid = Alea.rand(0, sctx.dbSize - 1); 75 oUserId = (LinkedIntUserId) pm.getObjectById(sctx.oids[oid], false); 76 if (debug) { 77 logger.log(BasicLevel.DEBUG, "Writing object " + oid); 78 } 79 oUserId.writeF1(sctx.nbWritePersistent, f1); 80 Assert.assertEquals("Write error", f1, oUserId.getF1()); 81 } 82 commitTx(pm, task, threadId, txId); 83 res.endTest(); 84 } catch (JDOFatalException e) { 85 rollbackOnException(pm, e, res, task, threadId, txId); 86 } catch (Throwable e) { 87 stopOnError(pm, e, res, task, threadId, txId); 88 } finally { 89 closePM(pm, threadId, txId, task, res); 90 } 91 } 92 93 private void perform(int nbThread, 94 int dbSize, 95 int nbTx, 96 int nbWrite, 97 int nbWritePersistent, 98 int threadTimeout) { 99 if (!interactive) { 100 perform(nbThread, nbTx, threadTimeout, 101 new SetCtx(dbSize, nbWrite, nbWritePersistent)); 102 } 103 } 104 105 109 public void testInteractive() { 110 if (interactive) { 111 logger.log(BasicLevel.INFO, "testInteractive"); 112 perform(Integer.getInteger(THREAD, 0).intValue(), 113 Integer.getInteger(TX, 0).intValue(), 114 Integer.getInteger(TIMEOUT, 120000).intValue(), 115 new SetCtx( 116 Integer.getInteger(DBSIZE, 10000).intValue(), 117 Integer.getInteger(NBWRITE, 0).intValue(), 118 Integer.getInteger(NBWRITEPERSISTENT, 0).intValue())); 119 } else { 120 logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testInteractive"); 121 } 122 } 123 124 127 public void testSetObjectTh1Tx100nbW5() { 128 if (!interactive) { 129 logger.log(BasicLevel.INFO, "testSetObjectTh1Tx100nbW5"); 130 perform(1, 10000, 100, 10, 5, 120000); 131 } else { 132 logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh1Tx100nbW5"); 133 } 134 } 135 136 139 public void testSetObjectTh1Tx1000nbW5() { 140 if (!interactive) { 141 logger.log(BasicLevel.INFO, "testSetObjectTh1Tx1000nbW5"); 142 perform(1, 10000, 1000, 10, 5, 120000); 143 } else { 144 logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh1Tx1000nbW5"); 145 } 146 } 147 148 151 public void testSetObjectTh1Tx10000nbW5() { 152 if (!interactive) { 153 logger.log(BasicLevel.INFO, "testSetObjectTh1Tx10000nbW5"); 154 perform(1, 10000, 10000, 10, 5, 120000); 155 } else { 156 logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh1Tx10000nbW5"); 157 } 158 } 159 160 163 public void _testSetObjectTh1Tx100000nbW5() { 164 if (!interactive) { 165 logger.log(BasicLevel.INFO, "_testSetObjectTh1Tx100000nbW5"); 166 perform(1, 10000, 100000, 10, 5, 120000); 167 } else { 168 logger.log(BasicLevel.INFO, "Interactive mode: ignore _testSetObjectTh1Tx100000nbW5"); 169 } 170 } 171 172 175 public void testSetObjectTh100Tx100nbW5() { 176 if (!interactive) { 177 logger.log(BasicLevel.INFO, "testSetObjectTh100Tx100nbW5"); 178 perform(100, 10000, 100, 10, 5, 120000); 179 } else { 180 logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh100Tx100nbW5"); 181 } 182 } 183 184 187 public void testSetObjectTh100Tx1000nbW5() { 188 if (!interactive) { 189 logger.log(BasicLevel.INFO, "testSetObjectTh100Tx1000nbW5"); 190 perform(100, 10000, 1000, 100, 5, 120000); 191 } else { 192 logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh100Tx1000nbW5"); 193 } 194 } 195 196 199 public void testSetObjectTh100Tx10000nbW5() { 200 if (!interactive) { 201 logger.log(BasicLevel.INFO, "testSetObjectTh100Tx10000nbW5"); 202 perform(100, 10000, 10000, 1000, 5, 120000); 203 } else { 204 logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh100Tx10000nbW5"); 205 } 206 } 207 208 211 public void _testSetObjectTh100Tx100000nbW5() { 212 if (!interactive) { 213 logger.log(BasicLevel.INFO, "_testSetObjectTh100Tx100000nbW5"); 214 perform(100, 10000, 100000, 10000, 5, 120000); 215 } else { 216 logger.log(BasicLevel.INFO, "Interactive mode: ignore _testSetObjectTh100Tx100000nbW5"); 217 } 218 } 219 220 223 public void testSetObjectTh5Tx100nbW10() { 224 if (!interactive) { 225 logger.log(BasicLevel.INFO, "testSetObjectTh5Tx100nbW10"); 226 perform(5, 10000, 100, 10, 10, 120000); 227 } else { 228 logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh5Tx100nbW10"); 229 } 230 } 231 232 235 public void testSetObjectTh5Tx1000nbW10() { 236 if (!interactive) { 237 logger.log(BasicLevel.INFO, "testSetObjectTh5Tx1000nbW10"); 238 perform(5, 10000, 1000, 100, 10, 120000); 239 } else { 240 logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh5Tx1000nbW10"); 241 } 242 } 243 244 247 public void testSetObjectTh5Tx10000nbW10() { 248 if (!interactive) { 249 logger.log(BasicLevel.INFO, "testSetObjectTh5Tx10000nbW10"); 250 perform(5, 10000, 10000, 10, 5, 120000); 251 } else { 252 logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh5Tx10000nbW10"); 253 } 254 } 255 256 259 public void _testSetObjectTh5Tx100000nbW10() { 260 if (!interactive) { 261 logger.log(BasicLevel.INFO, "_testSetObjectTh5Tx100000nbW10"); 262 perform(5, 10000, 100000, 10, 5, 120000); 263 } else { 264 logger.log(BasicLevel.INFO, "Interactive mode: ignore _testSetObjectTh5Tx100000nbW10"); 265 } 266 } 267 } 268 | Popular Tags |