KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.jdo.JDOFatalException;
22 import javax.jdo.PersistenceManager;
23
24 import junit.framework.Assert;
25
26 import org.objectweb.speedo.Alea;
27 import org.objectweb.speedo.pobjects.userid.LinkedIntUserId;
28 import org.objectweb.util.monolog.api.BasicLevel;
29
30 /**
31  * Stresses the write access function of Speedo.
32  * @author M. Guillemin
33  */

34 public class TestSetObject extends LinkedIntUserIdHelper {
35
36     private String JavaDoc NBWRITE = getLoggerName() + ".nbwrite";
37     private String JavaDoc NBWRITEPERSISTENT = getLoggerName() + ".nbwritepersistent";
38
39     public TestSetObject(String JavaDoc s) {
40         super(s);
41     }
42
43     protected String JavaDoc getLoggerName() {
44         return STRESS_LOG_NAME + ".TestSetObject";
45     }
46
47     class SetCtx extends LIUICtx{
48         public int nbWrite;
49         public int nbWritePersistent;
50
51         public SetCtx(int dbSize, int nbWrite, int nbWritePersistent) {
52             super(dbSize);
53             this.nbWrite = nbWrite;
54             this.nbWritePersistent = nbWritePersistent;
55         }
56     }
57
58     protected void perform(Task task,
59                            int threadId,
60                            int txId,
61                            Object JavaDoc ctx,
62                            PerformResult res) {
63         SetCtx sctx = (SetCtx) ctx;
64         PersistenceManager pm = getPM(task, threadId, txId);
65         try {
66             res.beginTest();
67             beginTx(pm, task, threadId, txId);
68             // Execute one transaction
69
// Do nbWrite access to a persistent
70
LinkedIntUserId oUserId;
71             int oid;
72             String JavaDoc f1 = Alea.randomstring();
73             for (int no = 0; no < sctx.nbWrite; no++) {
74                 oid = Alea.rand(0, sctx.dbSize - 1);
75                 oUserId = (LinkedIntUserId) pm.getObjectById(sctx.oids[oid], false);
76                 if (debug) {
77                     logger.log(BasicLevel.DEBUG, "Writing object " + oid);
78                 }
79                 oUserId.writeF1(sctx.nbWritePersistent, f1);
80                 Assert.assertEquals("Write error", f1, oUserId.getF1());
81             }
82             commitTx(pm, task, threadId, txId);
83             res.endTest();
84         } catch (JDOFatalException e) {
85             rollbackOnException(pm, e, res, task, threadId, txId);
86         } catch (Throwable JavaDoc e) {
87             stopOnError(pm, e, res, task, threadId, txId);
88         } finally {
89             closePM(pm, threadId, txId, task, res);
90         }
91     }
92
93     private void perform(int nbThread,
94                          int dbSize,
95                          int nbTx,
96                          int nbWrite,
97                          int nbWritePersistent,
98                          int threadTimeout) {
99         if (!interactive) {
100             perform(nbThread, nbTx, threadTimeout,
101                     new SetCtx(dbSize, nbWrite, nbWritePersistent));
102         }
103     }
104
105     /**
106      * Tests the read of a lot of persistent objects, with interactive
107      * setting 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, 0).intValue(),
113                     Integer.getInteger(TX, 0).intValue(),
114                     Integer.getInteger(TIMEOUT, 120000).intValue(),
115                     new SetCtx(
116                             Integer.getInteger(DBSIZE, 10000).intValue(),
117                             Integer.getInteger(NBWRITE, 0).intValue(),
118                             Integer.getInteger(NBWRITEPERSISTENT, 0).intValue()));
119         } else {
120             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testInteractive");
121         }
122     }
123
124     /**
125      * Tests 100 transactions where each of them do 5 write access on 10 objects among 100 using 1 thread.
126      */

127     public void testSetObjectTh1Tx100nbW5() {
128         if (!interactive) {
129             logger.log(BasicLevel.INFO, "testSetObjectTh1Tx100nbW5");
130             perform(1, 10000, 100, 10, 5, 120000);
131         } else {
132             logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh1Tx100nbW5");
133         }
134     }
135
136     /**
137      * Tests 1000 transactions where each of them do 5 write access on 10 objects among 1000 using 1 thread.
138      */

139     public void testSetObjectTh1Tx1000nbW5() {
140         if (!interactive) {
141             logger.log(BasicLevel.INFO, "testSetObjectTh1Tx1000nbW5");
142             perform(1, 10000, 1000, 10, 5, 120000);
143         } else {
144             logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh1Tx1000nbW5");
145         }
146     }
147
148     /**
149      * Tests 10.000 transactions where each of them do 5 write access on 10 objects among 10.000 using 1 thread.
150      */

151     public void testSetObjectTh1Tx10000nbW5() {
152         if (!interactive) {
153             logger.log(BasicLevel.INFO, "testSetObjectTh1Tx10000nbW5");
154             perform(1, 10000, 10000, 10, 5, 120000);
155         } else {
156             logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh1Tx10000nbW5");
157         }
158     }
159
160     /**
161      * Tests 100.000 transactions where each of them do 5 write access on 10 objects among 100.000 using 1 thread.
162      */

163     public void _testSetObjectTh1Tx100000nbW5() {
164         if (!interactive) {
165             logger.log(BasicLevel.INFO, "_testSetObjectTh1Tx100000nbW5");
166             perform(1, 10000, 100000, 10, 5, 120000);
167         } else {
168             logger.log(BasicLevel.INFO, "Interactive mode: ignore _testSetObjectTh1Tx100000nbW5");
169         }
170     }
171
172     /**
173      * Tests 100 transactions where each of them do 5 write access on 10 objects among 100 using 100 thread.
174      */

175     public void testSetObjectTh100Tx100nbW5() {
176         if (!interactive) {
177             logger.log(BasicLevel.INFO, "testSetObjectTh100Tx100nbW5");
178             perform(100, 10000, 100, 10, 5, 120000);
179         } else {
180             logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh100Tx100nbW5");
181         }
182     }
183
184     /**
185      * Tests 1000 transactions where each of them do 5 write access on 100 objects among 1000 using 100 thread.
186      */

187     public void testSetObjectTh100Tx1000nbW5() {
188         if (!interactive) {
189             logger.log(BasicLevel.INFO, "testSetObjectTh100Tx1000nbW5");
190             perform(100, 10000, 1000, 100, 5, 120000);
191         } else {
192             logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh100Tx1000nbW5");
193         }
194     }
195
196     /**
197      * Tests 10.000 transactions where each of them do 5 write access on 1000 objects among 10.000 using 100 thread.
198      */

199     public void testSetObjectTh100Tx10000nbW5() {
200         if (!interactive) {
201             logger.log(BasicLevel.INFO, "testSetObjectTh100Tx10000nbW5");
202             perform(100, 10000, 10000, 1000, 5, 120000);
203         } else {
204             logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh100Tx10000nbW5");
205         }
206     }
207
208     /**
209      * Tests 100.000 transactions where each of them do 5 write access on 10000 objects among 100.000 using 100 thread.
210      */

211     public void _testSetObjectTh100Tx100000nbW5() {
212         if (!interactive) {
213             logger.log(BasicLevel.INFO, "_testSetObjectTh100Tx100000nbW5");
214             perform(100, 10000, 100000, 10000, 5, 120000);
215         } else {
216             logger.log(BasicLevel.INFO, "Interactive mode: ignore _testSetObjectTh100Tx100000nbW5");
217         }
218     }
219
220     /**
221      * Tests 100 transactions where each of them do 10 write access on 10 objects among 100 using 5 thread.
222      */

223     public void testSetObjectTh5Tx100nbW10() {
224         if (!interactive) {
225             logger.log(BasicLevel.INFO, "testSetObjectTh5Tx100nbW10");
226             perform(5, 10000, 100, 10, 10, 120000);
227         } else {
228             logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh5Tx100nbW10");
229         }
230     }
231
232     /**
233      * Tests 1000 transactions where each of them do 10 write access on 100 objects among 1000 using 5 thread.
234      */

235     public void testSetObjectTh5Tx1000nbW10() {
236         if (!interactive) {
237             logger.log(BasicLevel.INFO, "testSetObjectTh5Tx1000nbW10");
238             perform(5, 10000, 1000, 100, 10, 120000);
239         } else {
240             logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh5Tx1000nbW10");
241         }
242     }
243
244     /**
245      * Tests 10.000 transactions where each of them do 5 write access on 10 objects among 10.000 using 5 thread.
246      */

247     public void testSetObjectTh5Tx10000nbW10() {
248         if (!interactive) {
249             logger.log(BasicLevel.INFO, "testSetObjectTh5Tx10000nbW10");
250             perform(5, 10000, 10000, 10, 5, 120000);
251         } else {
252             logger.log(BasicLevel.INFO, "Interactive mode: ignore testSetObjectTh5Tx10000nbW10");
253         }
254     }
255
256     /**
257      * Tests 100.000 transactions where each of them do 5 write access on 10 objects among 100.000 using 5 thread.
258      */

259     public void _testSetObjectTh5Tx100000nbW10() {
260         if (!interactive) {
261             logger.log(BasicLevel.INFO, "_testSetObjectTh5Tx100000nbW10");
262             perform(5, 10000, 100000, 10, 5, 120000);
263         } else {
264             logger.log(BasicLevel.INFO, "Interactive mode: ignore _testSetObjectTh5Tx100000nbW10");
265         }
266     }
267 }
268
Popular Tags