1 24 package org.objectweb.jalisto.test.query.bench; 25 26 import junit.framework.Test; 27 import org.objectweb.jalisto.se.api.Transaction; 28 import org.objectweb.jalisto.se.api.internal.SessionInternal; 29 import org.objectweb.jalisto.se.JalistoFactory; 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 import java.util.ArrayList ; 36 import java.util.Iterator ; 37 import java.util.Random ; 38 39 public class BenchMonoMultiQuery extends JalistoTestCase { 40 ArrayList oids = null; 41 42 public BenchMonoMultiQuery() { 43 } 44 45 public BenchMonoMultiQuery(String name) { 46 super(name); 47 } 48 49 public static Test suite() { 50 JalistoTestSuite suite = new JalistoTestSuite(); 51 BenchMonoMultiQuery tc = (BenchMonoMultiQuery) newTestCase(suite, new BenchMonoMultiQuery()); 52 53 tc.stabilityTest(true, "mono", 5000, 500, 2000); 54 55 57 return suite; 58 } 59 60 63 64 public void stabilityTest(boolean isMono, String message, int nbrBook, int nbrAction, int nbrExecution) { 65 SessionInternal workingSession = null; 66 67 if (isMono) { 68 workingSession = (SessionInternal) JalistoFactory.getSession("jalisto-query.properties"); 69 System.out.println("is mono : " + workingSession.getProperties().isMonoImplementation()); 70 } else { 71 workingSession = (SessionInternal) JalistoFactory.getSession("jalisto-query-multi.properties"); 72 System.out.println("is mono : " + workingSession.getProperties().isMonoImplementation()); 73 } 74 75 Transaction workingTransaction = workingSession.currentTransaction(); 76 workingSession.defineClass(BookWithAuthor.getMetaDescription()); 77 78 oids = new ArrayList (); 79 80 workingTransaction.begin(); 81 for (int i = 0; i < nbrBook; i++) { 82 oids.add(workingSession.createObject(BookWithAuthor.newBook().toArray(), BookWithAuthor.class)); 83 } 84 workingTransaction.commit(); 85 86 Random random = new Random (); 87 String createName = message + " : create time for " + nbrAction + " objects"; 88 String readName = message + " : read time for " + nbrAction + " objects"; 89 String updateName = message + " : update time for " + nbrAction + " objects"; 90 String deleteName = message + " : delete time for " + nbrAction + " objects"; 91 String extentName = message + " : get one extent for " + nbrAction + " objects"; 92 JalistoTimer.createTimer(createName); 93 JalistoTimer.createTimer(readName); 94 JalistoTimer.createTimer(updateName); 95 JalistoTimer.createTimer(deleteName); 96 JalistoTimer.createTimer(extentName); 97 98 for (int c = 0; c < nbrExecution; c++) { 99 if ((c != 0) && ((c % 50) == 0)) { 100 workingSession.reorganize(); 101 } 102 103 113 JalistoTimer.timerStart(readName); 114 workingTransaction.begin(); 115 for (int i = 0; i < nbrAction; i++) { 116 int index = random.nextInt(oids.size()); 117 Object oid = oids.get(index); 118 workingSession.readObjectByOid(oid); 119 } 120 workingTransaction.commit(); 121 JalistoTimer.timerStop(readName, false); 122 123 134 } 145 146 workingTransaction.begin(); 147 Iterator extent = workingSession.getExtent(BookWithAuthor.class).readFully().iterator(); 148 while (extent.hasNext()) { 149 workingSession.deleteObjectByOid(extent.next()); 150 } 151 workingTransaction.commit(); 152 workingSession.reorganize(); 153 154 JalistoTimer.summary(createName); 155 JalistoTimer.summary(readName); 156 JalistoTimer.summary(updateName); 157 JalistoTimer.summary(deleteName); 158 JalistoTimer.summary(extentName); 159 JalistoTimer.summary("pouet"); 160 } 161 162 } 163 | Popular Tags |