01: /**
02: * Copyright (C) 2001-2005 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package org.objectweb.speedo.runtime.query;
18:
19: import java.util.Collection;
20: import java.util.Iterator;
21:
22: import javax.jdo.Extent;
23: import javax.jdo.PersistenceManager;
24: import javax.jdo.Query;
25:
26: import org.objectweb.speedo.SpeedoTestHelper;
27: import org.objectweb.speedo.pobjects.basic.BasicA;
28: import org.objectweb.util.monolog.api.BasicLevel;
29:
30: /**
31: *
32: *
33: * @author S.Chassande-Barrioz
34: */
35: public class TestBillionQueries extends SpeedoTestHelper {
36:
37: public TestBillionQueries() {
38: super ("TestBillonQueries");
39: }
40:
41: public TestBillionQueries(String n) {
42: super (n);
43: }
44:
45: protected String getLoggerName() {
46: return SpeedoTestHelper.LOG_NAME + ".TestBillionQueries";
47: }
48:
49: public void testLotOfQueryWithClose100_100() {
50: testLotOfQuery(true, 100, 100);
51: }
52:
53: public void testLotOfQueryWithoutClose100_100() {
54: testLotOfQuery(false, 100, 100);
55: }
56:
57: public void testLotOfQueryWithClose10_10() {
58: testLotOfQuery(true, 10, 10);
59: }
60:
61: public void testLotOfQuery(boolean withclose, final int NB_PM,
62: final int NB_QUERY) {
63: logger.log(BasicLevel.INFO, "testLotOfQuery(" + withclose
64: + ", pm:" + NB_PM + ", query: " + NB_QUERY
65: + ") is running ...");
66: PersistenceManager pm = pmf.getPersistenceManager();
67: pm.currentTransaction().begin();
68: for (int i = 0; i < 20; i++) {
69: BasicA ba = new BasicA();
70: ba.writeF1("testBillionQuery_" + i);
71: pm.makePersistent(ba);
72: }
73: pm.currentTransaction().commit();
74: pm.close();
75: for (int i = 0; i < NB_PM; i++) {
76: logger.log(BasicLevel.DEBUG, "PM: " + i);
77: pm = pmf.getPersistenceManager();
78: for (int j = 0; j < NB_QUERY; j++) {
79: Query q = pm.newQuery(BasicA.class);
80: q.setFilter("f1.startsWith(p1)");
81: q.declareParameters("String p1");
82: Collection c = (Collection) q.execute("dep");
83: for (Iterator it = c.iterator(); it.hasNext();) {
84: it.next();
85: }
86: q.closeAll();
87: }
88: pm.close();
89: }
90: pm = pmf.getPersistenceManager();
91: pm.currentTransaction().begin();
92: Extent e = pm.getExtent(BasicA.class);
93: for (Iterator it = e.iterator(); it.hasNext();) {
94: pm.deletePersistent(it.next());
95: }
96: pm.currentTransaction().commit();
97: pm.close();
98: }
99: }
|