1 24 package org.objectweb.jalisto.test.core.suite; 25 26 import junit.framework.Test; 27 import org.objectweb.jalisto.se.test.data.Book; 28 import org.objectweb.jalisto.se.test.workbench.JalistoTestCase; 29 import org.objectweb.jalisto.se.test.workbench.JalistoTestSuite; 30 import org.objectweb.jalisto.se.test.workbench.JalistoTimer; 31 32 import java.util.ArrayList ; 33 import java.util.Random ; 34 35 public class StabilityTestCase extends JalistoTestCase { 36 37 public StabilityTestCase() { 38 } 39 40 public StabilityTestCase(String name) { 41 super(name); 42 } 43 44 public static Test suite() { 45 JalistoTestSuite suite = new JalistoTestSuite(); 46 StabilityTestCase tc = (StabilityTestCase) newTestCase(suite, new StabilityTestCase()); 47 48 tc.define(); 49 tc.cleanUp(); 50 tc.populate(5000); 51 tc.stabilityTest(200, 10000); 52 tc.cleanUp(); 53 54 return suite; 55 } 56 57 60 61 public void populate(int nbr) { 62 tx.begin(); 63 for (int i = 0; i < nbr; i++) { 64 oids.add(session.createObject(Book.newBook().toArray(), Book.class)); 65 } 66 tx.commit(); 67 } 68 69 public void stabilityTest(int nbrCreate, int nbrIt) { 70 Random random = new Random (); 71 String timerName = "Stability test execution cycle"; 72 JalistoTimer.createTimer(timerName); 73 74 for (int c = 0; c < nbrIt; c++) { 75 if ((c != 0) && ((c % 50) == 0)) { 76 session.reorganize(); 77 JalistoTimer.summary(); 78 JalistoTimer.clean(timerName); 79 } 80 81 JalistoTimer.timerStart(timerName); 82 tx.begin(); 83 for (int i = 0; i < nbrCreate; i++) { 84 Object [] bookInArray = Book.newBook().toArray(); 85 Object oid = session.createObject(bookInArray, Book.class); 86 oids.add(oid); 87 } 88 tx.commit(); 89 90 tx.begin(); 91 for (int i = 0; i < nbrCreate; i++) { 92 int index = random.nextInt(oids.size()); 93 Object oid = oids.get(index); 94 session.readObjectByOid(oid); 95 } 96 tx.commit(); 97 98 tx.begin(); 99 for (int i = 0; i < nbrCreate; i++) { 100 int index = random.nextInt(oids.size()); 101 Object oid = oids.get(index); 102 session.deleteObjectByOid(oid); 103 oids.remove(index); 104 } 105 tx.commit(); 106 JalistoTimer.timerStop(timerName, false); 107 } 108 } 109 110 111 private ArrayList oids = null; 112 113 116 117 public void define() { 118 super.initSession(false); 119 super.define(Book.getMetaDescription()); 120 } 121 122 public void cleanUp() { 123 super.cleanUp(Book.class); 124 } 125 } 126 | Popular Tags |