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.PersistenceManager;
024: import javax.jdo.JDOFatalException;
025:
026: /**
027: * Stresses the read access function of Speedo.
028: *
029: * @author M. Guillemin/S.Rodiere
030: */
031: public class TestGetObject extends LinkedIntUserIdHelper {
032:
033: private String NBREAD = getLoggerName() + ".nbread";
034: private String NBREADPERSISTENT = getLoggerName()
035: + ".nbreadpersistent";
036:
037: public class GetCtx extends LIUICtx {
038: public int nbRead;
039: public int nbReadPersistent;
040: public ObjectStatistic stat = new ObjectStatistic();
041:
042: public GetCtx(int dbSize, int nbRead, int nbReadPersistent) {
043: super (dbSize);
044: this .nbRead = nbRead;
045: this .nbReadPersistent = nbReadPersistent;
046: }
047:
048: public String toString() {
049: return super .toString() + " / nbRead = " + nbRead
050: + " / nbReadPersistent = " + nbReadPersistent;
051: }
052: }
053:
054: public TestGetObject(String s) {
055: super (s);
056: }
057:
058: protected String getLoggerName() {
059: return STRESS_LOG_NAME + ".TestGetObject";
060: }
061:
062: protected void perform(Task task, int threadId, int txId,
063: Object ctx, PerformResult res) {
064: GetCtx gctx = (GetCtx) ctx;
065: PersistenceManager pm = getPM(task, threadId, txId);
066: try {
067: res.beginTest();
068: beginTx(pm, task, threadId, txId);
069: // Execute one transaction: do nbRead access to a persistent
070: LinkedIntUserId oUserId;
071: for (int no = 0; no < gctx.nbRead; no++) {
072: int oid = Alea.rand(0, gctx.dbSize - 1);
073: gctx.stat.touch(new Integer(oid));
074: if (debug) {
075: logger.log(BasicLevel.DEBUG, "Reading object "
076: + oid);
077: }
078: oUserId = (LinkedIntUserId) pm.getObjectById(
079: gctx.oids[oid], false);
080: assertNotNull("Null object (oid = " + oid + ")",
081: oUserId);
082: oUserId.readName(gctx.nbReadPersistent);
083: }
084: commitTx(pm, task, threadId, txId);
085: res.endTest();
086: } catch (JDOFatalException e) {
087: rollbackOnException(pm, e, res, task, threadId, txId);
088: } catch (Throwable e) {
089: stopOnError(pm, e, res, task, threadId, txId);
090: } finally {
091: closePM(pm, threadId, txId, task, res);
092: }
093: }
094:
095: protected void logStatistic(TaskManager tm, long exectime,
096: Object _ctx) {
097: GetCtx ctx = (GetCtx) _ctx;
098: logger.log(BasicLevel.INFO, getLogPrefix()
099: + "\tGetObject: objects read:"
100: + ctx.stat.getAccessedOid().size() + ", nb access: "
101: + 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(), Integer
113: .getInteger(TX, 100).intValue(), Integer
114: .getInteger(TIMEOUT, 200000).intValue(),
115: new GetCtx(Integer.getInteger(DBSIZE, 1000)
116: .intValue(), Integer.getInteger(NBREAD, 10)
117: .intValue(), Integer.getInteger(
118: NBREADPERSISTENT, 10).intValue()));
119: } else {
120: logger.log(BasicLevel.INFO,
121: "Non Interactive mode: ignore testInteractive");
122: }
123: }
124:
125: private void perform(int nbThread, int dbSize, int nbTx,
126: int nbRead, int nbReadPersistent, int threadTimeout) {
127: perform(nbThread, nbTx, threadTimeout, new GetCtx(dbSize,
128: nbRead, nbReadPersistent));
129: }
130:
131: /**
132: * Tests 100 transactions where each of them read 1 object with 1 read
133: * using 1 thread.
134: */
135: public void testGetObjectTh1Tx100Re1Rp1() {
136: if (!interactive) {
137: logger.log(BasicLevel.INFO, "testGetObjectTh1Tx100Re1Rp1");
138: perform(1, 10000, 100, 1, 1, 1000000);
139: } else {
140: logger
141: .log(BasicLevel.INFO,
142: "Interactive mode: ignore testGetObjectTh1Tx100Re1Rp1");
143: }
144: }
145:
146: /**
147: * Tests 100 transactions where each of them read 1 object with 1 read
148: * using 2 thread.
149: */
150: public void testGetObjectTh2Tx100Re1Rp1() {
151: if (!interactive) {
152: logger.log(BasicLevel.INFO, "testGetObjectTh2Tx100Re1Rp1");
153: perform(2, 10000, 100, 1, 1, 1000000);
154: } else {
155: logger
156: .log(BasicLevel.INFO,
157: "Interactive mode: ignore testGetObjectTh2Tx100Re1Rp1");
158: }
159: }
160:
161: /**
162: * Tests 100 transactions where each of them read 1 object with 10 read
163: * using 1 thread.
164: */
165: public void testGetObjectTh1Tx100Re1Rp10() {
166: if (!interactive) {
167: logger.log(BasicLevel.INFO, "testGetObjectTh1Tx100Re1Rp10");
168: perform(1, 10000, 100, 1, 10, 1000000);
169: } else {
170: logger
171: .log(BasicLevel.INFO,
172: "Interactive mode: ignore testGetObjectTh1Tx100Re1Rp10");
173: }
174: }
175:
176: /**
177: * Tests 100 transactions where each of them read 1 object with 10 read
178: * using 2 thread.
179: */
180: public void testGetObjectTh2Tx100Re1Rp10() {
181: if (!interactive) {
182: logger.log(BasicLevel.INFO, "testGetObjectTh2Tx100Re1Rp10");
183: perform(2, 10000, 100, 1, 10, 1000000);
184: } else {
185: logger
186: .log(BasicLevel.INFO,
187: "Interactive mode: ignore testGetObjectTh2Tx100Re1Rp10");
188: }
189: }
190:
191: /**
192: * Tests 100 transactions where each of them read 1 object with 10 read
193: * using 10 thread.
194: */
195: public void testGetObjectTh10Tx100Re1Rp10() {
196: if (!interactive) {
197: logger
198: .log(BasicLevel.INFO,
199: "testGetObjectTh10Tx100Re1Rp10");
200: perform(10, 10000, 100, 1, 10, 1000000);
201: } else {
202: logger
203: .log(BasicLevel.INFO,
204: "Interactive mode: ignore testGetObjectTh10Tx100Re1Rp10");
205: }
206: }
207:
208: /**
209: * Tests 1000 transactions where each of them read 100 object with 100
210: read
211: * using 1 thread.
212: */
213: public void testGetObjectTh1Tx1000Re10Rp100() {
214: if (!interactive) {
215: logger.log(BasicLevel.INFO,
216: "testGetObjectTh1Tx1000Re10Rp100");
217: perform(1, 10000, 1000, 10, 100, 1000000);
218: } else {
219: logger
220: .log(BasicLevel.INFO,
221: "Interactive mode: ignore testGetObjectTh1Tx1000Re10Rp100");
222: }
223: }
224:
225: /**
226: * Tests 1000 transactions where each of them read 100 object with 100
227: read
228: * using 2 thread.
229: */
230: public void testGetObjectTh2Tx1000Re10Rp100() {
231: if (!interactive) {
232: logger.log(BasicLevel.INFO,
233: "testGetObjectTh2Tx1000Re10Rp100");
234: perform(2, 10000, 1000, 10, 100, 1000000);
235: } else {
236: logger
237: .log(BasicLevel.INFO,
238: "Interactive mode: ignore testGetObjectTh2Tx1000Re10Rp100");
239: }
240: }
241:
242: /**
243: * Tests 1000 transactions where each of them read 100 object with 100
244: read
245: * using 10 thread.
246: */
247: public void testGetObjectTh10Tx1000Re10Rp100() {
248: if (!interactive) {
249: logger.log(BasicLevel.INFO,
250: "testGetObjectTh10Tx1000Re10Rp100");
251: perform(10, 10000, 1000, 10, 100, 1000000);
252: } else {
253: logger
254: .log(BasicLevel.INFO,
255: "Interactive mode: ignore testGetObjectTh10Tx1000Re10Rp100");
256: }
257: }
258:
259: /**
260: * Tests 10000 transactions where each of them read 100 object with 100
261: read
262: * using 1 thread.
263: */
264: public void testGetObjectTh1Tx100Re100Rp100() {
265: if (!interactive) {
266: logger.log(BasicLevel.INFO,
267: "testGetObjectTh1Tx100Re100Rp100");
268: perform(1, 10000, 100, 100, 100, 1000000);
269: } else {
270: logger
271: .log(BasicLevel.INFO,
272: "Interactive mode: ignore testGetObjectTh1Tx100Re100Rp100");
273: }
274: }
275:
276: /**
277: * Tests 10000 transactions where each of them read 100 object with 100
278: read
279: * using 2 thread.
280: */
281: public void testGetObjectTh2Tx100Re100Rp100() {
282: if (!interactive) {
283: logger.log(BasicLevel.INFO,
284: "testGetObjectTh2Tx100Re100Rp100");
285: perform(2, 10000, 100, 100, 100, 1000000);
286: } else {
287: logger
288: .log(BasicLevel.INFO,
289: "Interactive mode: ignore testGetObjectTh2Tx100Re100Rp100");
290: }
291: }
292:
293: /**
294: * Tests 10000 transactions where each of them read 100 object with
295: 100
296: * read using 3 thread.
297: */
298: public void testGetObjectTh3Tx100Re100Rp100() {
299: if (!interactive) {
300: logger.log(BasicLevel.INFO,
301: "testGetObjectTh3Tx100Re100Rp100");
302: perform(3, 10000, 100, 100, 100, 1000000);
303: } else {
304: logger
305: .log(BasicLevel.INFO,
306: "Interactive mode: ignore testGetObjectTh3Tx100Re100Rp100");
307: }
308: }
309:
310: /**
311: * Tests 10000 transactions where each of them read 100 object with 100
312: read
313: * using 10 thread.
314: */
315: public void testGetObjectTh10Tx100Re100Rp100() {
316: if (!interactive) {
317: logger.log(BasicLevel.INFO,
318: "testGetObjectTh10Tx100Re100Rp100");
319: perform(10, 10000, 100, 100, 100, 1000000);
320: } else {
321: logger
322: .log(BasicLevel.INFO,
323: "Interactive mode: ignore testGetObjectTh10Tx100Re100Rp100");
324: }
325: }
326:
327: /**
328: * Tests 10000 transactions where each of them read 100 object with
329: 10000
330: * read using 1 thread.
331: */
332: public void testGetObjectTh1Tx100Re100Rp10000() {
333: if (!interactive) {
334: logger.log(BasicLevel.INFO,
335: "testGetObjectTh1Tx100Re100Rp10000");
336: perform(1, 10000, 100, 100, 10000, 1000000);
337: } else {
338: logger
339: .log(BasicLevel.INFO,
340: "Interactive mode: ignore testGetObjectTh1Tx100Re100Rp10000");
341: }
342: }
343:
344: /**
345: * Tests 10000 transactions where each of them read 100 object with
346: 10000
347: * read using 3 thread.
348: */
349: public void testGetObjectTh3Tx100Re100Rp10000() {
350: if (!interactive) {
351: logger.log(BasicLevel.INFO,
352: "testGetObjectTh3Tx100Re100Rp10000");
353: perform(3, 10000, 100, 100, 10000, 1000000);
354: } else {
355: logger
356: .log(BasicLevel.INFO,
357: "Interactive mode: ignore testGetObjectTh3Tx100Re100Rp10000");
358: }
359: }
360:
361: /**
362: * Tests 10000 transactions where each of them read 100 object with
363: 100
364: * read using 100 thread.
365: */
366: public void testGetObjectTh100Tx100Re100Rp100() {
367: if (!interactive) {
368: logger.log(BasicLevel.INFO,
369: "testGetObjectTh100Tx100Re100Rp100");
370: perform(100, 10000, 100, 100, 100, 1000000);
371: } else {
372: logger
373: .log(BasicLevel.INFO,
374: "Interactive mode: ignore testGetObjectTh100Tx100Re100Rp100");
375: }
376: }
377:
378: /**
379: * Tests 1000 transactions where each of them read 100 object with
380: 100
381: * read using 1 thread.
382: */
383: public void testGetObjectTh1000Tx100Re100Rp100() {
384: if (!interactive) {
385: logger.log(BasicLevel.INFO,
386: "testGetObjectTh1000Tx100Re100Rp100");
387: perform(100, 10000, 1000, 100, 100, 1000000);
388: } else {
389: logger
390: .log(BasicLevel.INFO,
391: "Interactive mode: ignore testGetObjectTh1000Tx100Re100Rp100");
392: }
393: }
394: }
|