KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > stress > TestQuery


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * 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  */

18
19 package org.objectweb.speedo.stress;
20
21 import org.objectweb.speedo.Alea;
22 import org.objectweb.speedo.pobjects.userid.LinkedIntUserId;
23 import org.objectweb.util.monolog.api.BasicLevel;
24
25 import javax.jdo.Extent;
26 import javax.jdo.PersistenceManager;
27 import javax.jdo.JDOFatalException;
28 import javax.jdo.Query;
29
30 import java.util.Collection JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 import junit.framework.TestSuite;
34 import junit.textui.TestRunner;
35 import junit.framework.Assert;
36
37 /**
38  * Stresses the query execution of Speedo.
39  *
40  * @author M. Guillemin
41  */

42 public class TestQuery extends LinkedIntUserIdHelper {
43     public static int RESULT_MAX = 1000;
44
45     public TestQuery(String JavaDoc s) {
46         super(s);
47     }
48
49     protected String JavaDoc getLoggerName() {
50         return STRESS_LOG_NAME + ".TestQuery";
51     }
52
53     public static void main(String JavaDoc[] args) {
54         TestRunner.run(new TestSuite(TestQuery.class));
55     }
56
57     protected void perform(StressHelper.Task task,
58                            int threadId,
59                            int txId,
60                            Object JavaDoc _ctx,
61                            StressHelper.PerformResult res) {
62         LIUICtx ctx = (LIUICtx) _ctx;
63         PersistenceManager pm = getPM(task, threadId, txId);
64         try {
65             res.beginTest();
66             beginTx(pm, task, threadId, txId);
67             int min = Alea.rand(0, ctx.dbSize - RESULT_MAX);
68             if (min > ctx.dbSize - 1) {
69                 min = 0;
70             }
71             int max = Alea.rand(min + 1, min + RESULT_MAX);
72             if (max > ctx.dbSize - 1) {
73                 max = ctx.dbSize - 1;
74             }
75             if (debug) {
76                 logger.log(BasicLevel.DEBUG, "Thread " + threadId
77                         + " min = " + min + " / max = " + max);
78             }
79             Extent liui = pm.getExtent(LinkedIntUserId.class, false);
80             String JavaDoc filter = "((name>min) && (name<max))";
81             Query query = pm.newQuery(liui, filter);
82             query.declareParameters("Integer min, Integer max");
83             Collection JavaDoc cLinkedUsers = (Collection JavaDoc) query.execute(new Integer JavaDoc(min), new Integer JavaDoc(max));
84             Iterator JavaDoc iterator = cLinkedUsers.iterator();
85             while (iterator.hasNext()) {
86                 LinkedIntUserId lLinkedIntUserId = (LinkedIntUserId) iterator.next();
87                 int i = lLinkedIntUserId.getName();
88                 if (debug) {
89                     logger.log(BasicLevel.DEBUG, "Thread " + threadId
90                             + " Name = " + i);
91                 }
92             }
93             Assert.assertEquals("Bad query result size", max - min - 1, cLinkedUsers.size());
94             query.closeAll();
95             commitTx(pm, task, threadId, txId);
96             res.endTest();
97         } catch (JDOFatalException e) {
98             rollbackOnException(pm, e, res, task, threadId, txId);
99         } catch (Throwable JavaDoc e) {
100             stopOnError(pm, e, res, task, threadId, txId);
101         } finally {
102             closePM(pm, threadId, txId, task, res);
103         }
104     }
105
106     protected void performQuery(int nbThread,
107                                 int dbSize,
108                                 int nbTx,
109                                 int threadTimeout) {
110         perform(nbThread, nbTx, threadTimeout, new LIUICtx(dbSize));
111     }
112
113
114     /**
115      * Tests the creation of a lot of persistent objects, with interactive
116      * setting of test parameteres (see file userconf/project.properties).
117      */

118     public void testQuery() {
119         if (interactive) {
120             perform(Integer.getInteger(THREAD, 10).intValue(),
121                     Integer.getInteger(TX, 100).intValue(),
122                     Integer.getInteger(TIMEOUT, 200000).intValue(),
123                     new LIUICtx(
124                             Integer.getInteger(DBSIZE, 100000).intValue()));
125         }
126     }
127
128     /**
129      * Tests 100 transactions where each of them execute 1 query on 100 objects using 1 thread.
130      */

131     public void testQueryTh1Tx100Qu1() {
132         if (!interactive) {
133             performQuery(1, 10000, 100, 1000000);
134         }
135     }
136
137     /**
138      * Tests 1000 transactions where each of them execute 1 query on 1000 objects using 1 thread.
139      */

140
141     public void testQueryTh1Tx1000Qu1() {
142         if (!interactive) {
143             performQuery(1, 10000, 1000, 1000000);
144         }
145     }
146
147     /**
148      * Tests 10000 transactions where each of them execute 1 query on 10000 objects using 1 thread.
149      */

150
151     public void testQueryTh1Tx10000Qu1() {
152         if (!interactive) {
153             performQuery(1, 10000, 10000, 1000000);
154         }
155     }
156
157     /**
158      * Tests 100000 transactions where each of them execute 1 query on 100000 objects using 1 thread.
159      */

160
161     public void testQueryTh1Tx100000Qu1() {
162         if (!interactive) {
163             performQuery(1, 10000, 100000, 1000000);
164         }
165     }
166
167     /**
168      * Tests 100 transactions where each of them execute 1 query on 100 objects using 10 thread.
169      */

170     public void testQueryTh10Tx100Qu1() {
171         if (!interactive) {
172             performQuery(10, 10000, 100, 1000000);
173         }
174     }
175
176     /**
177      * Tests 1000 transactions where each of them execute 1 query on 1000 objects using 10 thread.
178      */

179
180     public void testQueryTh10Tx1000Qu1() {
181         if (!interactive) {
182             performQuery(10, 1000, 1000, 1000000);
183         }
184     }
185
186     /**
187      * Tests 10000 transactions where each of them execute 1 query on 10000 objects using 10 thread.
188      */

189
190     public void testQueryTh10Tx10000Qu1() {
191         if (!interactive) {
192             performQuery(10, 10000, 10000, 1000000);
193         }
194     }
195
196     /**
197      * Tests 100000 transactions where each of them execute 1 query on 100000 objects using 10 thread.
198      */

199
200     public void testQueryTh10Tx100000Qu1() {
201         if (!interactive) {
202             performQuery(10, 10000, 100000, 1000000);
203         }
204     }
205 }
206
Popular Tags