001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.stress;
018:
019: import org.objectweb.speedo.Alea;
020: import org.objectweb.speedo.pobjects.userid.LinkedIntUserId;
021: import org.objectweb.util.monolog.api.BasicLevel;
022:
023: import javax.jdo.Extent;
024: import javax.jdo.PersistenceManager;
025: import javax.jdo.JDOFatalException;
026: import javax.jdo.Query;
027:
028: import java.util.Collection;
029: import java.util.Iterator;
030:
031: import junit.framework.TestSuite;
032: import junit.textui.TestRunner;
033: import junit.framework.Assert;
034:
035: /**
036: * Stresses the query execution of Speedo.
037: *
038: * @author M. Guillemin
039: */
040: public class TestQuery extends LinkedIntUserIdHelper {
041: public static int RESULT_MAX = 1000;
042:
043: public TestQuery(String s) {
044: super (s);
045: }
046:
047: protected String getLoggerName() {
048: return STRESS_LOG_NAME + ".TestQuery";
049: }
050:
051: public static void main(String[] args) {
052: TestRunner.run(new TestSuite(TestQuery.class));
053: }
054:
055: protected void perform(StressHelper.Task task, int threadId,
056: int txId, Object _ctx, StressHelper.PerformResult res) {
057: LIUICtx ctx = (LIUICtx) _ctx;
058: PersistenceManager pm = getPM(task, threadId, txId);
059: try {
060: res.beginTest();
061: beginTx(pm, task, threadId, txId);
062: int min = Alea.rand(0, ctx.dbSize - RESULT_MAX);
063: if (min > ctx.dbSize - 1) {
064: min = 0;
065: }
066: int max = Alea.rand(min + 1, min + RESULT_MAX);
067: if (max > ctx.dbSize - 1) {
068: max = ctx.dbSize - 1;
069: }
070: if (debug) {
071: logger.log(BasicLevel.DEBUG, "Thread " + threadId
072: + " min = " + min + " / max = " + max);
073: }
074: Extent liui = pm.getExtent(LinkedIntUserId.class, false);
075: String filter = "((name>min) && (name<max))";
076: Query query = pm.newQuery(liui, filter);
077: query.declareParameters("Integer min, Integer max");
078: Collection cLinkedUsers = (Collection) query.execute(
079: new Integer(min), new Integer(max));
080: Iterator iterator = cLinkedUsers.iterator();
081: while (iterator.hasNext()) {
082: LinkedIntUserId lLinkedIntUserId = (LinkedIntUserId) iterator
083: .next();
084: int i = lLinkedIntUserId.getName();
085: if (debug) {
086: logger.log(BasicLevel.DEBUG, "Thread " + threadId
087: + " Name = " + i);
088: }
089: }
090: Assert.assertEquals("Bad query result size", max - min - 1,
091: cLinkedUsers.size());
092: query.closeAll();
093: commitTx(pm, task, threadId, txId);
094: res.endTest();
095: } catch (JDOFatalException e) {
096: rollbackOnException(pm, e, res, task, threadId, txId);
097: } catch (Throwable e) {
098: stopOnError(pm, e, res, task, threadId, txId);
099: } finally {
100: closePM(pm, threadId, txId, task, res);
101: }
102: }
103:
104: protected void performQuery(int nbThread, int dbSize, int nbTx,
105: int threadTimeout) {
106: perform(nbThread, nbTx, threadTimeout, new LIUICtx(dbSize));
107: }
108:
109: /**
110: * Tests the creation of a lot of persistent objects, with interactive
111: * setting of test parameteres (see file userconf/project.properties).
112: */
113: public void testQuery() {
114: if (interactive) {
115: perform(Integer.getInteger(THREAD, 10).intValue(), Integer
116: .getInteger(TX, 100).intValue(), Integer
117: .getInteger(TIMEOUT, 200000).intValue(),
118: new LIUICtx(Integer.getInteger(DBSIZE, 100000)
119: .intValue()));
120: }
121: }
122:
123: /**
124: * Tests 100 transactions where each of them execute 1 query on 100 objects using 1 thread.
125: */
126: public void testQueryTh1Tx100Qu1() {
127: if (!interactive) {
128: performQuery(1, 10000, 100, 1000000);
129: }
130: }
131:
132: /**
133: * Tests 1000 transactions where each of them execute 1 query on 1000 objects using 1 thread.
134: */
135:
136: public void testQueryTh1Tx1000Qu1() {
137: if (!interactive) {
138: performQuery(1, 10000, 1000, 1000000);
139: }
140: }
141:
142: /**
143: * Tests 10000 transactions where each of them execute 1 query on 10000 objects using 1 thread.
144: */
145:
146: public void testQueryTh1Tx10000Qu1() {
147: if (!interactive) {
148: performQuery(1, 10000, 10000, 1000000);
149: }
150: }
151:
152: /**
153: * Tests 100000 transactions where each of them execute 1 query on 100000 objects using 1 thread.
154: */
155:
156: public void testQueryTh1Tx100000Qu1() {
157: if (!interactive) {
158: performQuery(1, 10000, 100000, 1000000);
159: }
160: }
161:
162: /**
163: * Tests 100 transactions where each of them execute 1 query on 100 objects using 10 thread.
164: */
165: public void testQueryTh10Tx100Qu1() {
166: if (!interactive) {
167: performQuery(10, 10000, 100, 1000000);
168: }
169: }
170:
171: /**
172: * Tests 1000 transactions where each of them execute 1 query on 1000 objects using 10 thread.
173: */
174:
175: public void testQueryTh10Tx1000Qu1() {
176: if (!interactive) {
177: performQuery(10, 1000, 1000, 1000000);
178: }
179: }
180:
181: /**
182: * Tests 10000 transactions where each of them execute 1 query on 10000 objects using 10 thread.
183: */
184:
185: public void testQueryTh10Tx10000Qu1() {
186: if (!interactive) {
187: performQuery(10, 10000, 10000, 1000000);
188: }
189: }
190:
191: /**
192: * Tests 100000 transactions where each of them execute 1 query on 100000 objects using 10 thread.
193: */
194:
195: public void testQueryTh10Tx100000Qu1() {
196: if (!interactive) {
197: performQuery(10, 10000, 100000, 1000000);
198: }
199: }
200: }
|