1 24 package org.objectweb.jalisto.test.query.bench; 25 26 import junit.framework.Test; 27 import org.objectweb.jalisto.se.api.ClassDescription; 28 import org.objectweb.jalisto.se.api.query.Query; 29 import org.objectweb.jalisto.se.api.query.Constraint; 30 import org.objectweb.jalisto.se.test.data.BookWithAuthor; 31 import org.objectweb.jalisto.se.test.workbench.JalistoTestCase; 32 import org.objectweb.jalisto.se.test.workbench.JalistoTestSuite; 33 import org.objectweb.jalisto.se.test.workbench.JalistoTimer; 34 35 public class EvolutionTestCase extends JalistoTestCase { 36 public EvolutionTestCase() { 37 } 38 39 public EvolutionTestCase(String name) { 40 super(name); 41 } 42 43 public static Test suite() { 44 JalistoTestSuite suite = new JalistoTestSuite(); 45 EvolutionTestCase tc = (EvolutionTestCase) newTestCase(suite, new EvolutionTestCase()); 46 47 tc.initSession(); 48 tc.define(BookWithAuthor.getMetaDescription()); 49 50 tc.evolutionTest(50); 51 52 return suite; 53 } 54 55 58 59 public void evolutionTest(int nbrExecution) { 60 int[] intValues = {1000, 5000, 10000, 20000}; 61 String title1 = BookWithAuthor.titles[0]; 62 String title2 = BookWithAuthor.titles[1]; 63 64 Query query1 = queryManager.query(); 65 query1.constrain(BookWithAuthor.class); 66 query1.descend("title").constrain(title1).equal(); 67 68 Query query2 = queryManager.query(); 69 query2.constrain(BookWithAuthor.class); 70 Constraint c1 = query2.descend("title").constrain(title1).equal(); 71 Constraint c2 = query2.descend("title").constrain(title2).equal(); 72 c1.or(c2); 73 74 Query[] queries = {query1, query2}; 75 76 float[][] resultTimes = new float[intValues.length][queries.length]; 77 78 for (int i = 0; i < intValues.length; i++) { 79 for (int j = 0; j < queries.length; j++) { 80 cleanUp(BookWithAuthor.class); 81 populateBookWithAuthor(intValues[i]); 82 83 for (int k = 0; k < nbrExecution; k++) { 84 JalistoTimer.timerStart("evolutionTest"); 85 tx.begin(); 86 queries[j].execute(); 87 tx.commit(); 88 JalistoTimer.timerStop("evolutionTest", false); 89 } 90 resultTimes[i][j] = JalistoTimer.getAverage("evolutionTest"); 91 JalistoTimer.clean("evolutionTest"); 92 } 93 } 94 95 StringBuffer sb = new StringBuffer (); 96 for (int i = 0; i < resultTimes.length; i++) { 97 sb.append(intValues[i]).append(" : "); 98 float[] f = resultTimes[i]; 99 for (int j = 0; j < f.length; j++) { 100 sb.append(String.valueOf(f[j]) + " \t"); 101 } 102 sb.append("\n"); 103 } 104 105 System.out.println(sb.toString()); 106 107 cleanUp(BookWithAuthor.class); 108 } 109 110 111 114 115 public void initSession() { 116 super.initSession(false); 117 } 118 119 public void define(ClassDescription classDescription) { 120 super.define(classDescription); 121 } 122 } 123 | Popular Tags |