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 javax.jdo.JDOFatalException;
020: import javax.jdo.PersistenceManager;
021:
022: import junit.framework.Assert;
023:
024: import org.objectweb.speedo.Alea;
025: import org.objectweb.speedo.pobjects.userid.LinkedIntUserId;
026: import org.objectweb.util.monolog.api.BasicLevel;
027:
028: /**
029: * Stresses the write access function of Speedo.
030: * @author M. Guillemin
031: */
032: public class TestSetObject extends LinkedIntUserIdHelper {
033:
034: private String NBWRITE = getLoggerName() + ".nbwrite";
035: private String NBWRITEPERSISTENT = getLoggerName()
036: + ".nbwritepersistent";
037:
038: public TestSetObject(String s) {
039: super (s);
040: }
041:
042: protected String getLoggerName() {
043: return STRESS_LOG_NAME + ".TestSetObject";
044: }
045:
046: class SetCtx extends LIUICtx {
047: public int nbWrite;
048: public int nbWritePersistent;
049:
050: public SetCtx(int dbSize, int nbWrite, int nbWritePersistent) {
051: super (dbSize);
052: this .nbWrite = nbWrite;
053: this .nbWritePersistent = nbWritePersistent;
054: }
055: }
056:
057: protected void perform(Task task, int threadId, int txId,
058: Object ctx, PerformResult res) {
059: SetCtx sctx = (SetCtx) ctx;
060: PersistenceManager pm = getPM(task, threadId, txId);
061: try {
062: res.beginTest();
063: beginTx(pm, task, threadId, txId);
064: // Execute one transaction
065: // Do nbWrite access to a persistent
066: LinkedIntUserId oUserId;
067: int oid;
068: String f1 = Alea.randomstring();
069: for (int no = 0; no < sctx.nbWrite; no++) {
070: oid = Alea.rand(0, sctx.dbSize - 1);
071: oUserId = (LinkedIntUserId) pm.getObjectById(
072: sctx.oids[oid], false);
073: if (debug) {
074: logger.log(BasicLevel.DEBUG, "Writing object "
075: + oid);
076: }
077: oUserId.writeF1(sctx.nbWritePersistent, f1);
078: Assert.assertEquals("Write error", f1, oUserId.getF1());
079: }
080: commitTx(pm, task, threadId, txId);
081: res.endTest();
082: } catch (JDOFatalException e) {
083: rollbackOnException(pm, e, res, task, threadId, txId);
084: } catch (Throwable e) {
085: stopOnError(pm, e, res, task, threadId, txId);
086: } finally {
087: closePM(pm, threadId, txId, task, res);
088: }
089: }
090:
091: private void perform(int nbThread, int dbSize, int nbTx,
092: int nbWrite, int nbWritePersistent, int threadTimeout) {
093: if (!interactive) {
094: perform(nbThread, nbTx, threadTimeout, new SetCtx(dbSize,
095: nbWrite, nbWritePersistent));
096: }
097: }
098:
099: /**
100: * Tests the read of a lot of persistent objects, with interactive
101: * setting of test parameteres (see file userconf/project.properties).
102: */
103: public void testInteractive() {
104: if (interactive) {
105: logger.log(BasicLevel.INFO, "testInteractive");
106: perform(Integer.getInteger(THREAD, 0).intValue(), Integer
107: .getInteger(TX, 0).intValue(), Integer.getInteger(
108: TIMEOUT, 120000).intValue(), new SetCtx(Integer
109: .getInteger(DBSIZE, 10000).intValue(), Integer
110: .getInteger(NBWRITE, 0).intValue(), Integer
111: .getInteger(NBWRITEPERSISTENT, 0).intValue()));
112: } else {
113: logger.log(BasicLevel.INFO,
114: "Non Interactive mode: ignore testInteractive");
115: }
116: }
117:
118: /**
119: * Tests 100 transactions where each of them do 5 write access on 10 objects among 100 using 1 thread.
120: */
121: public void testSetObjectTh1Tx100nbW5() {
122: if (!interactive) {
123: logger.log(BasicLevel.INFO, "testSetObjectTh1Tx100nbW5");
124: perform(1, 10000, 100, 10, 5, 120000);
125: } else {
126: logger
127: .log(BasicLevel.INFO,
128: "Interactive mode: ignore testSetObjectTh1Tx100nbW5");
129: }
130: }
131:
132: /**
133: * Tests 1000 transactions where each of them do 5 write access on 10 objects among 1000 using 1 thread.
134: */
135: public void testSetObjectTh1Tx1000nbW5() {
136: if (!interactive) {
137: logger.log(BasicLevel.INFO, "testSetObjectTh1Tx1000nbW5");
138: perform(1, 10000, 1000, 10, 5, 120000);
139: } else {
140: logger
141: .log(BasicLevel.INFO,
142: "Interactive mode: ignore testSetObjectTh1Tx1000nbW5");
143: }
144: }
145:
146: /**
147: * Tests 10.000 transactions where each of them do 5 write access on 10 objects among 10.000 using 1 thread.
148: */
149: public void testSetObjectTh1Tx10000nbW5() {
150: if (!interactive) {
151: logger.log(BasicLevel.INFO, "testSetObjectTh1Tx10000nbW5");
152: perform(1, 10000, 10000, 10, 5, 120000);
153: } else {
154: logger
155: .log(BasicLevel.INFO,
156: "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
166: .log(BasicLevel.INFO,
167: "_testSetObjectTh1Tx100000nbW5");
168: perform(1, 10000, 100000, 10, 5, 120000);
169: } else {
170: logger
171: .log(BasicLevel.INFO,
172: "Interactive mode: ignore _testSetObjectTh1Tx100000nbW5");
173: }
174: }
175:
176: /**
177: * Tests 100 transactions where each of them do 5 write access on 10 objects among 100 using 100 thread.
178: */
179: public void testSetObjectTh100Tx100nbW5() {
180: if (!interactive) {
181: logger.log(BasicLevel.INFO, "testSetObjectTh100Tx100nbW5");
182: perform(100, 10000, 100, 10, 5, 120000);
183: } else {
184: logger
185: .log(BasicLevel.INFO,
186: "Interactive mode: ignore testSetObjectTh100Tx100nbW5");
187: }
188: }
189:
190: /**
191: * Tests 1000 transactions where each of them do 5 write access on 100 objects among 1000 using 100 thread.
192: */
193: public void testSetObjectTh100Tx1000nbW5() {
194: if (!interactive) {
195: logger.log(BasicLevel.INFO, "testSetObjectTh100Tx1000nbW5");
196: perform(100, 10000, 1000, 100, 5, 120000);
197: } else {
198: logger
199: .log(BasicLevel.INFO,
200: "Interactive mode: ignore testSetObjectTh100Tx1000nbW5");
201: }
202: }
203:
204: /**
205: * Tests 10.000 transactions where each of them do 5 write access on 1000 objects among 10.000 using 100 thread.
206: */
207: public void testSetObjectTh100Tx10000nbW5() {
208: if (!interactive) {
209: logger
210: .log(BasicLevel.INFO,
211: "testSetObjectTh100Tx10000nbW5");
212: perform(100, 10000, 10000, 1000, 5, 120000);
213: } else {
214: logger
215: .log(BasicLevel.INFO,
216: "Interactive mode: ignore testSetObjectTh100Tx10000nbW5");
217: }
218: }
219:
220: /**
221: * Tests 100.000 transactions where each of them do 5 write access on 10000 objects among 100.000 using 100 thread.
222: */
223: public void _testSetObjectTh100Tx100000nbW5() {
224: if (!interactive) {
225: logger.log(BasicLevel.INFO,
226: "_testSetObjectTh100Tx100000nbW5");
227: perform(100, 10000, 100000, 10000, 5, 120000);
228: } else {
229: logger
230: .log(BasicLevel.INFO,
231: "Interactive mode: ignore _testSetObjectTh100Tx100000nbW5");
232: }
233: }
234:
235: /**
236: * Tests 100 transactions where each of them do 10 write access on 10 objects among 100 using 5 thread.
237: */
238: public void testSetObjectTh5Tx100nbW10() {
239: if (!interactive) {
240: logger.log(BasicLevel.INFO, "testSetObjectTh5Tx100nbW10");
241: perform(5, 10000, 100, 10, 10, 120000);
242: } else {
243: logger
244: .log(BasicLevel.INFO,
245: "Interactive mode: ignore testSetObjectTh5Tx100nbW10");
246: }
247: }
248:
249: /**
250: * Tests 1000 transactions where each of them do 10 write access on 100 objects among 1000 using 5 thread.
251: */
252: public void testSetObjectTh5Tx1000nbW10() {
253: if (!interactive) {
254: logger.log(BasicLevel.INFO, "testSetObjectTh5Tx1000nbW10");
255: perform(5, 10000, 1000, 100, 10, 120000);
256: } else {
257: logger
258: .log(BasicLevel.INFO,
259: "Interactive mode: ignore testSetObjectTh5Tx1000nbW10");
260: }
261: }
262:
263: /**
264: * Tests 10.000 transactions where each of them do 5 write access on 10 objects among 10.000 using 5 thread.
265: */
266: public void testSetObjectTh5Tx10000nbW10() {
267: if (!interactive) {
268: logger.log(BasicLevel.INFO, "testSetObjectTh5Tx10000nbW10");
269: perform(5, 10000, 10000, 10, 5, 120000);
270: } else {
271: logger
272: .log(BasicLevel.INFO,
273: "Interactive mode: ignore testSetObjectTh5Tx10000nbW10");
274: }
275: }
276:
277: /**
278: * Tests 100.000 transactions where each of them do 5 write access on 10 objects among 100.000 using 5 thread.
279: */
280: public void _testSetObjectTh5Tx100000nbW10() {
281: if (!interactive) {
282: logger.log(BasicLevel.INFO,
283: "_testSetObjectTh5Tx100000nbW10");
284: perform(5, 10000, 100000, 10, 5, 120000);
285: } else {
286: logger
287: .log(BasicLevel.INFO,
288: "Interactive mode: ignore _testSetObjectTh5Tx100000nbW10");
289: }
290: }
291: }
|