KickJava   Java API By Example, From Geeks To Geeks.

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


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.PersistenceManager;
26 import javax.jdo.JDOFatalException;
27
28 /**
29  * Stresses the read access function of Speedo.
30  *
31  * @author M. Guillemin/S.Rodiere
32  */

33 public class TestGetObject extends LinkedIntUserIdHelper {
34
35     private String JavaDoc NBREAD = getLoggerName() + ".nbread";
36     private String JavaDoc NBREADPERSISTENT = getLoggerName() + ".nbreadpersistent";
37
38     public class GetCtx extends LIUICtx {
39         public int nbRead;
40         public int nbReadPersistent;
41         public ObjectStatistic stat = new ObjectStatistic();
42
43         public GetCtx(int dbSize, int nbRead, int nbReadPersistent) {
44             super(dbSize);
45             this.nbRead = nbRead;
46             this.nbReadPersistent = nbReadPersistent;
47         }
48
49         public String JavaDoc toString() {
50             return super.toString() + " / nbRead = " + nbRead
51                     + " / nbReadPersistent = " + nbReadPersistent;
52         }
53     }
54
55     public TestGetObject(String JavaDoc s) {
56         super(s);
57     }
58
59     protected String JavaDoc getLoggerName() {
60         return STRESS_LOG_NAME + ".TestGetObject";
61     }
62
63     protected void perform(Task task,
64                            int threadId,
65                            int txId,
66                            Object JavaDoc ctx,
67                            PerformResult res) {
68         GetCtx gctx = (GetCtx) ctx;
69         PersistenceManager pm = getPM(task, threadId, txId);
70         try {
71             res.beginTest();
72             beginTx(pm, task, threadId, txId);
73             // Execute one transaction: do nbRead access to a persistent
74
LinkedIntUserId oUserId;
75             for (int no = 0; no < gctx.nbRead; no++) {
76                 int oid = Alea.rand(0, gctx.dbSize - 1);
77                 gctx.stat.touch(new Integer JavaDoc(oid));
78                 if (debug) {
79                     logger.log(BasicLevel.DEBUG, "Reading object " + oid);
80                 }
81                 oUserId = (LinkedIntUserId)
82                         pm.getObjectById(gctx.oids[oid], false);
83                 assertNotNull("Null object (oid = " + oid + ")", oUserId);
84                 oUserId.readName(gctx.nbReadPersistent);
85             }
86             commitTx(pm, task, threadId, txId);
87             res.endTest();
88         } catch (JDOFatalException e) {
89             rollbackOnException(pm, e, res, task, threadId, txId);
90         } catch (Throwable JavaDoc e) {
91             stopOnError(pm, e, res, task, threadId, txId);
92         } finally {
93             closePM(pm, threadId, txId, task, res);
94         }
95     }
96
97     protected void logStatistic(TaskManager tm, long exectime, Object JavaDoc _ctx) {
98         GetCtx ctx = (GetCtx) _ctx;
99         logger.log(BasicLevel.INFO, getLogPrefix() + "\tGetObject: objects read:"
100                 + ctx.stat.getAccessedOid().size()
101                 + ", nb access: " + ctx.stat.getNbAccess());
102         super.logStatistic(tm, exectime, ctx);
103     }
104
105     /**
106      * Tests the read of a lot of persistent objects, with interactive setting
107      * of test parameteres (see file userconf/project.properties).
108      */

109     public void testInteractive() {
110         if (interactive) {
111             logger.log(BasicLevel.INFO, "testInteractive");
112             perform(Integer.getInteger(THREAD, 10).intValue(),
113                     Integer.getInteger(TX, 100).intValue(),
114                     Integer.getInteger(TIMEOUT, 200000).intValue(),
115                     new GetCtx(
116                             Integer.getInteger(DBSIZE, 1000).intValue(),
117                             Integer.getInteger(NBREAD, 10).intValue(),
118                             Integer.getInteger(NBREADPERSISTENT, 10).intValue()));
119         } else {
120             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testInteractive");
121         }
122     }
123
124     private void perform(
125             int nbThread,
126             int dbSize,
127             int nbTx,
128             int nbRead,
129             int nbReadPersistent,
130             int threadTimeout) {
131         perform(nbThread, nbTx, threadTimeout,
132                 new GetCtx(dbSize, nbRead, nbReadPersistent));
133     }
134
135     /**
136      * Tests 100 transactions where each of them read 1 object with 1 read
137      * using 1 thread.
138      */

139     public void testGetObjectTh1Tx100Re1Rp1() {
140         if (!interactive) {
141             logger.log(BasicLevel.INFO, "testGetObjectTh1Tx100Re1Rp1");
142             perform(1, 10000, 100, 1, 1, 1000000);
143         } else {
144             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh1Tx100Re1Rp1");
145         }
146     }
147
148     /**
149      * Tests 100 transactions where each of them read 1 object with 1 read
150      * using 2 thread.
151      */

152     public void testGetObjectTh2Tx100Re1Rp1() {
153         if (!interactive) {
154             logger.log(BasicLevel.INFO, "testGetObjectTh2Tx100Re1Rp1");
155             perform(2, 10000, 100, 1, 1, 1000000);
156         } else {
157             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh2Tx100Re1Rp1");
158         }
159     }
160
161
162     /**
163      * Tests 100 transactions where each of them read 1 object with 10 read
164      * using 1 thread.
165      */

166     public void testGetObjectTh1Tx100Re1Rp10() {
167         if (!interactive) {
168             logger.log(BasicLevel.INFO, "testGetObjectTh1Tx100Re1Rp10");
169             perform(1, 10000, 100, 1, 10, 1000000);
170         } else {
171             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh1Tx100Re1Rp10");
172         }
173     }
174
175     /**
176      * Tests 100 transactions where each of them read 1 object with 10 read
177      * using 2 thread.
178      */

179     public void testGetObjectTh2Tx100Re1Rp10() {
180         if (!interactive) {
181             logger.log(BasicLevel.INFO, "testGetObjectTh2Tx100Re1Rp10");
182             perform(2, 10000, 100, 1, 10, 1000000);
183         } else {
184             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh2Tx100Re1Rp10");
185         }
186     }
187
188     /**
189      * Tests 100 transactions where each of them read 1 object with 10 read
190      * using 10 thread.
191      */

192     public void testGetObjectTh10Tx100Re1Rp10() {
193         if (!interactive) {
194             logger.log(BasicLevel.INFO, "testGetObjectTh10Tx100Re1Rp10");
195             perform(10, 10000, 100, 1, 10, 1000000);
196         } else {
197             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh10Tx100Re1Rp10");
198         }
199     }
200
201     /**
202      * Tests 1000 transactions where each of them read 100 object with 100
203      read
204      * using 1 thread.
205      */

206     public void testGetObjectTh1Tx1000Re10Rp100() {
207         if (!interactive) {
208             logger.log(BasicLevel.INFO, "testGetObjectTh1Tx1000Re10Rp100");
209             perform(1, 10000, 1000, 10, 100, 1000000);
210         } else {
211             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh1Tx1000Re10Rp100");
212         }
213     }
214
215     /**
216      * Tests 1000 transactions where each of them read 100 object with 100
217      read
218      * using 2 thread.
219      */

220     public void testGetObjectTh2Tx1000Re10Rp100() {
221         if (!interactive) {
222             logger.log(BasicLevel.INFO, "testGetObjectTh2Tx1000Re10Rp100");
223             perform(2, 10000, 1000, 10, 100, 1000000);
224         } else {
225             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh2Tx1000Re10Rp100");
226         }
227     }
228
229     /**
230      * Tests 1000 transactions where each of them read 100 object with 100
231      read
232      * using 10 thread.
233      */

234     public void testGetObjectTh10Tx1000Re10Rp100() {
235         if (!interactive) {
236             logger.log(BasicLevel.INFO, "testGetObjectTh10Tx1000Re10Rp100");
237             perform(10, 10000, 1000, 10, 100, 1000000);
238         } else {
239             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh10Tx1000Re10Rp100");
240         }
241     }
242
243     /**
244      * Tests 10000 transactions where each of them read 100 object with 100
245      read
246      * using 1 thread.
247      */

248     public void testGetObjectTh1Tx100Re100Rp100() {
249         if (!interactive) {
250             logger.log(BasicLevel.INFO, "testGetObjectTh1Tx100Re100Rp100");
251             perform(1, 10000, 100, 100, 100, 1000000);
252         } else {
253             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh1Tx100Re100Rp100");
254         }
255     }
256
257     /**
258      * Tests 10000 transactions where each of them read 100 object with 100
259      read
260      * using 2 thread.
261      */

262     public void testGetObjectTh2Tx100Re100Rp100() {
263         if (!interactive) {
264             logger.log(BasicLevel.INFO, "testGetObjectTh2Tx100Re100Rp100");
265             perform(2, 10000, 100, 100, 100, 1000000);
266         } else {
267             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh2Tx100Re100Rp100");
268         }
269     }
270
271     /**
272      * Tests 10000 transactions where each of them read 100 object with
273      100
274      * read using 3 thread.
275      */

276     public void testGetObjectTh3Tx100Re100Rp100() {
277         if (!interactive) {
278             logger.log(BasicLevel.INFO, "testGetObjectTh3Tx100Re100Rp100");
279             perform(3, 10000, 100, 100, 100, 1000000);
280         } else {
281             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh3Tx100Re100Rp100");
282         }
283     }
284
285     /**
286      * Tests 10000 transactions where each of them read 100 object with 100
287      read
288      * using 10 thread.
289      */

290     public void testGetObjectTh10Tx100Re100Rp100() {
291         if (!interactive) {
292             logger.log(BasicLevel.INFO, "testGetObjectTh10Tx100Re100Rp100");
293             perform(10, 10000, 100, 100, 100, 1000000);
294         } else {
295             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh10Tx100Re100Rp100");
296         }
297     }
298
299
300     /**
301      * Tests 10000 transactions where each of them read 100 object with
302      10000
303      * read using 1 thread.
304      */

305     public void testGetObjectTh1Tx100Re100Rp10000() {
306         if (!interactive) {
307             logger.log(BasicLevel.INFO, "testGetObjectTh1Tx100Re100Rp10000");
308             perform(1, 10000, 100, 100, 10000, 1000000);
309         } else {
310             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh1Tx100Re100Rp10000");
311         }
312     }
313
314     /**
315      * Tests 10000 transactions where each of them read 100 object with
316      10000
317      * read using 3 thread.
318      */

319     public void testGetObjectTh3Tx100Re100Rp10000() {
320         if (!interactive) {
321             logger.log(BasicLevel.INFO, "testGetObjectTh3Tx100Re100Rp10000");
322             perform(3, 10000, 100, 100, 10000, 1000000);
323         } else {
324             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh3Tx100Re100Rp10000");
325         }
326     }
327
328     /**
329      * Tests 10000 transactions where each of them read 100 object with
330      100
331      * read using 100 thread.
332      */

333     public void testGetObjectTh100Tx100Re100Rp100() {
334         if (!interactive) {
335             logger.log(BasicLevel.INFO, "testGetObjectTh100Tx100Re100Rp100");
336             perform(100, 10000, 100, 100, 100, 1000000);
337         } else {
338             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh100Tx100Re100Rp100");
339         }
340     }
341
342     /**
343      * Tests 1000 transactions where each of them read 100 object with
344      100
345      * read using 1 thread.
346      */

347     public void testGetObjectTh1000Tx100Re100Rp100() {
348         if (!interactive) {
349             logger.log(BasicLevel.INFO, "testGetObjectTh1000Tx100Re100Rp100");
350             perform(100, 10000, 1000, 100, 100, 1000000);
351         } else {
352             logger.log(BasicLevel.INFO, "Interactive mode: ignore testGetObjectTh1000Tx100Re100Rp100");
353         }
354     }
355 }
356
Popular Tags