1 24 package org.objectweb.jalisto.test.query.bench; 25 26 import org.objectweb.jalisto.test.query.JalistoQueryTestCase; 27 import junit.framework.Test; 28 import org.objectweb.jalisto.se.api.ClassDescription; 29 import org.objectweb.jalisto.se.test.data.BookWithAuthor; 30 import org.objectweb.jalisto.se.test.workbench.JalistoTestSuite; 31 import org.objectweb.jalisto.se.test.workbench.JalistoTimer; 32 33 import java.util.ArrayList ; 34 import java.util.Random ; 35 36 public class IndexCostTestCase extends JalistoQueryTestCase { 37 static int call = 0; 38 39 public IndexCostTestCase() { 40 } 41 42 public IndexCostTestCase(String name) { 43 super(name); 44 } 45 46 public static Test suite() { 47 JalistoTestSuite suite = new JalistoTestSuite(); 48 IndexCostTestCase tc = (IndexCostTestCase) newTestCase(suite, new IndexCostTestCase()); 49 50 tc.initSession(); 51 tc.define(BookWithAuthor.getMetaDescription()); 52 53 tc.deleteIndex(BookWithAuthor.class, "title"); 54 tc.cleanUp(BookWithAuthor.class); 55 56 tc.populateBookWithAuthor(5000); 57 tc.stabilityTest(200, 201); 58 59 tc.buildIndex(BookWithAuthor.class, "title"); 60 tc.stabilityTest(200, 201); 61 62 tc.printIndex(BookWithAuthor.class, "title"); 63 64 return suite; 65 } 66 67 70 71 public void stabilityTest(int nbrCreate, int nbrIt) { 72 ArrayList oids = new ArrayList (); 73 Random random = new Random (); 74 String timerName = " time for call " + (call++); 75 String createName = "create" + timerName; 76 String deleteName = "delete" + timerName; 77 JalistoTimer.createTimer(createName); 78 JalistoTimer.createTimer(deleteName); 79 80 for (int c = 0; c < nbrIt; c++) { 81 if ((c != 0) && ((c % 100) == 0)) { 82 session.reorganize(); 83 JalistoTimer.summary(); 84 JalistoTimer.clean(createName); 85 JalistoTimer.clean(deleteName); 86 } 87 88 JalistoTimer.timerStart(createName); 89 tx.begin(); 90 for (int i = 0; i < nbrCreate; i++) { 91 Object [] bookInArray = BookWithAuthor.newBook().toArray(); 92 Object oid = session.createObject(bookInArray, BookWithAuthor.class); 93 oids.add(oid); 94 } 95 tx.commit(); 96 JalistoTimer.timerStop(createName, false); 97 98 JalistoTimer.timerStart(deleteName); 99 tx.begin(); 100 for (int i = 0; i < nbrCreate; i++) { 101 int index = random.nextInt(oids.size()); 102 Object oid = oids.get(index); 103 session.deleteObjectByOid(oid); 104 oids.remove(index); 105 } 106 tx.commit(); 107 JalistoTimer.timerStop(deleteName, false); 108 } 109 110 JalistoTimer.removeTimer(createName); 111 JalistoTimer.removeTimer(deleteName); 112 } 113 114 115 118 119 public void initSession() { 120 super.initSession(false); 121 } 122 123 public void define(ClassDescription classDescription) { 124 super.define(classDescription); 125 } 126 127 public void cleanUp(Class aClass) { 128 super.cleanUp(aClass); 129 } 130 131 public void populateBookWithAuthor(int nbr) { 132 super.populateBookWithAuthor(nbr); 133 } 134 135 public void buildIndex(Class aClass, String fieldName) { 136 super.buildIndex(aClass, fieldName); 137 } 138 139 public void deleteIndex(Class aClass, String fieldName) { 140 super.deleteIndex(aClass, fieldName); 141 } 142 143 public void printIndex(Class aClass, String fieldName) { 144 super.printIndex(aClass, fieldName); 145 } 146 } 147 | Popular Tags |