1 18 package org.objectweb.speedo.runtime.query; 19 20 import java.util.Collection ; 21 import java.util.Iterator ; 22 23 import javax.jdo.Extent; 24 import javax.jdo.PersistenceManager; 25 import javax.jdo.Query; 26 27 import org.objectweb.speedo.SpeedoTestHelper; 28 import org.objectweb.speedo.pobjects.basic.BasicA; 29 import org.objectweb.util.monolog.api.BasicLevel; 30 31 32 37 public class TestBillionQueries extends SpeedoTestHelper { 38 39 public TestBillionQueries() { 40 super("TestBillonQueries"); 41 } 42 43 public TestBillionQueries(String n) { 44 super(n); 45 } 46 47 protected String getLoggerName() { 48 return SpeedoTestHelper.LOG_NAME + ".TestBillionQueries"; 49 } 50 51 public void testLotOfQueryWithClose100_100() { 52 testLotOfQuery(true, 100, 100); 53 } 54 public void testLotOfQueryWithoutClose100_100() { 55 testLotOfQuery(false, 100, 100); 56 } 57 58 public void testLotOfQueryWithClose10_10() { 59 testLotOfQuery(true, 10, 10); 60 } 61 62 public void testLotOfQuery(boolean withclose, final int NB_PM, final int NB_QUERY) { 63 logger.log(BasicLevel.INFO, "testLotOfQuery(" + withclose 64 + ", pm:" + NB_PM + ", query: "+ NB_QUERY +") is running ..."); 65 PersistenceManager pm = pmf.getPersistenceManager(); 66 pm.currentTransaction().begin(); 67 for(int i=0; i<20; i++) { 68 BasicA ba = new BasicA(); 69 ba.writeF1("testBillionQuery_" + i); 70 pm.makePersistent(ba); 71 } 72 pm.currentTransaction().commit(); 73 pm.close(); 74 for(int i=0; i<NB_PM; i++) { 75 logger.log(BasicLevel.DEBUG, "PM: " + i); 76 pm = pmf.getPersistenceManager(); 77 for(int j=0; j<NB_QUERY; j++) { 78 Query q = pm.newQuery(BasicA.class); 79 q.setFilter("f1.startsWith(p1)"); 80 q.declareParameters("String p1"); 81 Collection c = (Collection ) q.execute("dep"); 82 for (Iterator it = c.iterator(); it.hasNext();) { 83 it.next(); 84 } 85 q.closeAll(); 86 } 87 pm.close(); 88 } 89 pm = pmf.getPersistenceManager(); 90 pm.currentTransaction().begin(); 91 Extent e = pm.getExtent(BasicA.class); 92 for(Iterator it = e.iterator(); it.hasNext();) { 93 pm.deletePersistent(it.next()); 94 } 95 pm.currentTransaction().commit(); 96 pm.close(); 97 } 98 } 99 | Popular Tags |