1 18 19 package org.objectweb.speedo.stress; 20 21 import java.util.ArrayList ; 22 import java.util.List ; 23 24 import javax.jdo.JDOFatalException; 25 import javax.jdo.PersistenceManager; 26 27 import junit.framework.Assert; 28 29 import org.objectweb.speedo.pobjects.collection.AllCollection; 30 import org.objectweb.util.monolog.api.BasicLevel; 31 32 37 public class TestCollection extends StressHelper { 38 static private int nbBeginTest = 0; 39 40 public TestCollection(String s) { 41 super(s); 42 } 43 44 protected String [] getClassNamesToInit() { 45 return new String []{AllCollection.class.getName()}; 46 } 47 48 protected String getLoggerName() { 49 return STRESS_LOG_NAME + ".TestCollection"; 50 } 51 52 protected void perform(Task task, int threadId, int txId, Object ctx, PerformResult res) { 53 synchronized (this){ 54 nbBeginTest++; 55 } 56 long oids = (nbBeginTest * 6); 57 PersistenceManager pm = getPM(task, threadId, txId); 58 try { 59 res.beginTest(); 60 beginTx(pm, task, threadId, txId); 62 long[] ls = new long[]{oids, oids + 1, oids + 2, oids + 3, oids + 4, oids + 5}; 63 long[] reverse = new long[]{oids + 5, oids + 4, oids + 3, oids + 2, oids + 1, oids}; 64 AllCollection ac = new AllCollection("stressCollection" + nbBeginTest); 65 ac.setLongs(ls); 66 ac.setRefs(new Object []{ac}); 67 pm.makePersistent(ac); 68 commitTx(pm, task, threadId, txId); 69 70 ac.setLongs(reverse); 72 ac.setRefs(new Object []{ac}); 73 74 List expectedLong = new ArrayList (reverse.length); 76 for (int i = 0; i < reverse.length; i++) { 77 expectedLong.add(new Long (reverse[i])); 78 } 79 80 List expectedRef = new ArrayList (1); 81 expectedRef.add(ac); 82 83 Assert.assertNotNull("The collection of Long is null", ac.getCol_Long()); 85 assertSameCollection("The collection of Long", expectedLong, ac.getCol_Long()); 86 Assert.assertNotNull("The collection of reference is null", ac.getCol_ref()); 87 assertSameCollection("The collection of ref", expectedRef, ac.getCol_ref()); 88 89 Assert.assertNotNull("The Hashset of Long is null", ac.getHset_Long()); 91 assertSameCollection("The Hashset of Long", expectedLong, ac.getHset_Long()); 92 Assert.assertNotNull("The Hashset of reference is null", ac.getHset_ref()); 93 assertSameCollection("The Hashset of ref", expectedRef, ac.getHset_ref()); 94 95 Assert.assertNotNull("The list of Long is null", ac.getList_Long()); 97 assertSameList("The list of Long", expectedLong, ac.getList_Long()); 98 Assert.assertNotNull("The list of reference is null", ac.getList_ref()); 99 assertSameList("The list of reference", expectedRef, ac.getList_ref()); 100 101 Assert.assertNotNull("The set of Long is null", ac.getSet_Long()); 103 assertSameCollection("The set of Long", expectedLong, ac.getSet_Long()); 104 Assert.assertNotNull("The set of reference is null", ac.getSet_ref()); 105 assertSameCollection("The set of ref", expectedRef, ac.getSet_ref()); 106 107 beginTx(pm, task, threadId, txId); 109 logger.log(BasicLevel.DEBUG, ac.getId() + " is being deleted"); 110 pm.deletePersistent(ac); 111 commitTx(pm, task, threadId, txId); 112 res.endTest(); 113 114 } catch (JDOFatalException e) { 115 rollbackOnException(pm, e, res, task, threadId, txId); 116 } catch (Throwable e) { 117 stopOnError(pm, e, res, task, threadId, txId); 118 } finally { 119 closePM(pm, threadId, txId, task, res); 120 } 121 } 122 123 127 public void testCollection() { 128 if (interactive) { 129 perform(Integer.getInteger(THREAD, 1).intValue(), 130 Integer.getInteger(TX, 9).intValue(), 131 Integer.getInteger(TIMEOUT, 200000).intValue(), null); 132 } 133 } 134 135 138 public void testCollectionTh1Tx100() { 139 if (!interactive) { 140 logger.log(BasicLevel.INFO, "testCollectionTh1Tx100"); 141 perform(1, 100, 1000000, null); 142 } 143 } 144 145 148 public void testCollectionTh1Tx1000() { 149 150 if (!interactive) { 151 logger.log(BasicLevel.INFO, "testCollectionTh1Tx1000"); 152 perform(1, 1000, 1000000, null); 153 } 154 } 155 156 159 public void testCollectionTh1Tx10000() { 160 161 if (!interactive) { 162 logger.log(BasicLevel.INFO, "testCollectionTh1Tx10000"); 163 perform(1, 10000, 1000000, null); 164 } 165 } 166 167 170 public void _testCollectionTh1Tx100000() { 171 172 if (!interactive) { 173 logger.log(BasicLevel.INFO, "testCollectionTh1Tx100000"); 174 perform(1, 100000, 1000000, null); 175 } 176 } 177 178 181 public void testCollectionTh2Tx100() { 182 183 if (!interactive) { 184 logger.log(BasicLevel.INFO, "testCollectionTh2Tx100"); 185 perform(2, 100, 1000000, null); 186 } 187 } 188 189 192 public void testCollectionTh2Tx1000() { 193 194 if (!interactive) { 195 logger.log(BasicLevel.INFO, "testCollectionTh2Tx1000"); 196 perform(2, 1000, 1000000, null); 197 } 198 } 199 200 203 public void testCollectionTh2Tx10000() { 204 205 if (!interactive) { 206 logger.log(BasicLevel.INFO, "testCollectionTh2Tx10000"); 207 perform(2, 10000, 1000000, null); 208 } 209 } 210 211 214 public void _testCollectionTh2Tx100000() { 215 216 if (!interactive) { 217 logger.log(BasicLevel.INFO, "testCollectionTh2Tx100000"); 218 perform(2, 100000, 1000000, null); 219 } 220 } 221 222 223 226 public void testCollectionTh10Tx1000() { 227 228 if (!interactive) { 229 logger.log(BasicLevel.INFO, "testCollectionTh10Tx1000"); 230 perform(10, 1000, 1000000, null); 231 } 232 } 233 234 237 public void testCollectionTh10Tx10000() { 238 239 if (!interactive) { 240 logger.log(BasicLevel.INFO, "testCollectionTh10Tx10000"); 241 perform(10, 10000, 1000000, null); 242 } 243 } 244 245 248 public void _testCollectionTh10Tx100000() { 249 250 if (!interactive) { 251 logger.log(BasicLevel.INFO, "testCollectionTh10Tx100000"); 252 perform(10, 100000, 1000000, null); 253 } 254 } 255 256 259 public void testCollectionTh100Tx100() { 260 261 if (!interactive) { 262 logger.log(BasicLevel.INFO, "testCollectionTh100Tx100"); 263 perform(100, 100, 1000000, null); 264 } 265 } 266 267 270 public void testCollectionTh1000Tx1000() { 271 272 if (!interactive) { 273 logger.log(BasicLevel.INFO, "testCollectionTh1000Tx1000"); 274 perform(1000, 1000, 1000000, null); 275 } 276 } 277 278 } 279 | Popular Tags |