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 java.util.ArrayList;
020: import java.util.List;
021:
022: import javax.jdo.JDOFatalException;
023: import javax.jdo.PersistenceManager;
024:
025: import junit.framework.Assert;
026: import org.objectweb.speedo.Alea;
027: import org.objectweb.speedo.pobjects.collection.AllCollection;
028: import org.objectweb.util.monolog.api.BasicLevel;
029:
030: /**
031: * Stress the collection access function of Speedo.
032: *
033: * @author M.Guillemin
034: */
035: public class TestCollectionConcurrency extends AllCollectionHelper {
036:
037: public TestCollectionConcurrency(String s) {
038: super (s);
039: logger.log(BasicLevel.INFO, "TestCollectionConcurrency");
040: }
041:
042: protected String[] getClassNamesToInit() {
043: return new String[] { AllCollection.class.getName() };
044: }
045:
046: protected String getLoggerName() {
047: return STRESS_LOG_NAME + ".TestCollectionConcurrency";
048: }
049:
050: protected void perform(Task task, int threadId, int txId,
051: Object ctx, PerformResult res) {
052: long _oids = (txId * 6);
053: ACCtx acctx = (ACCtx) ctx;
054: PersistenceManager pm = getPM(task, threadId, txId);
055: try {
056: res.beginTest();
057:
058: long[] reverse = new long[] { _oids + 5, _oids + 4,
059: _oids + 3, _oids + 2, _oids + 1, _oids };
060: // Reverse a persistent Collections at random
061: int oid = Alea.rand(0, acctx.dbSize - 1);
062: beginTx(pm, task, threadId, txId);
063: AllCollection ac = (AllCollection) pm.getObjectById(
064: acctx.oids[oid], false);
065:
066: // Reverse the data
067: logger.log(BasicLevel.DEBUG, "reverse data of "
068: + ac.getId());
069: ac.setLongs(reverse);
070: ac.setRefs(new Object[] { ac });
071:
072: // Verify result
073: List expectedLong = new ArrayList(reverse.length);
074: for (int i = 0; i < reverse.length; i++) {
075: expectedLong.add(new Long(reverse[i]));
076: }
077:
078: List expectedRef = new ArrayList(1);
079: expectedRef.add(ac);
080:
081: //Collection
082: Assert.assertNotNull("The collection of Long is null", ac
083: .getCol_Long());
084: assertSameCollection("The collection of Long",
085: expectedLong, ac.getCol_Long());
086: Assert.assertNotNull("The collection of reference is null",
087: ac.getCol_ref());
088: assertSameCollection("The collection of ref", expectedRef,
089: ac.getCol_ref());
090:
091: //HashSet
092: Assert.assertNotNull("The Hashset of Long is null", ac
093: .getHset_Long());
094: assertSameCollection("The Hashset of Long", expectedLong,
095: ac.getHset_Long());
096: Assert.assertNotNull("The Hashset of reference is null", ac
097: .getHset_ref());
098: assertSameCollection("The Hashset of ref", expectedRef, ac
099: .getHset_ref());
100:
101: //List
102: Assert.assertNotNull("The list of Long is null", ac
103: .getList_Long());
104: assertSameList("The list of Long", expectedLong, ac
105: .getList_Long());
106: Assert.assertNotNull("The list of reference is null", ac
107: .getList_ref());
108: assertSameList("The list of reference", expectedRef, ac
109: .getList_ref());
110:
111: //Set
112: Assert.assertNotNull("The set of Long is null", ac
113: .getSet_Long());
114: assertSameCollection("The set of Long", expectedLong, ac
115: .getSet_Long());
116: Assert.assertNotNull("The set of reference is null", ac
117: .getSet_ref());
118: assertSameCollection("The set of ref", expectedRef, ac
119: .getSet_ref());
120:
121: commitTx(pm, task, threadId, txId);
122:
123: res.endTest();
124: } catch (JDOFatalException e) {
125: rollbackOnException(pm, e, res, task, threadId, txId);
126: } catch (Throwable e) {
127: stopOnError(pm, e, res, task, threadId, txId);
128: } finally {
129: closePM(pm, threadId, txId, task, res);
130: }
131: }
132:
133: /**
134: * Methode d'aiguillage
135: */
136: private void perform(int nbThread, int dbSize, int nbTx,
137: int threadTimeout) {
138: perform(nbThread, nbTx, threadTimeout, new ACCtx(dbSize));
139: }
140:
141: /**
142: * Tests the modification of a lot of persistent Collection objects, with interactive
143: * setting of test parameteres (see file userconf/project.properties).
144: */
145: public void testInteractive() {
146: if (interactive) {
147: logger.log(BasicLevel.INFO, "testInteractive");
148: perform(Integer.getInteger(THREAD, 1).intValue(), Integer
149: .getInteger(TX, 9).intValue(), Integer.getInteger(
150: TIMEOUT, 200000).intValue(), new ACCtx(Integer
151: .getInteger(DBSIZE, 1000).intValue()));
152: } else {
153: logger.log(BasicLevel.INFO,
154: "Non Interactive mode: ignore testInteractive");
155: }
156: }
157:
158: /**
159: * Tests 100 transactions which stress collections using 1 thread.
160: */
161: public void testCollectionConcurrencyTh1Tx100() {
162: if (!interactive) {
163: logger.log(BasicLevel.INFO,
164: "testCollectionConcurrencyTh1Tx100");
165: perform(1, 10000, 100, 1000000);
166: } else {
167: logger
168: .log(BasicLevel.INFO,
169: "Interactive mode: ignore testCollectionConcurrencyTh1Tx100");
170: }
171: }
172:
173: /**
174: * Tests 1.000 transactions which stress collections using 1 thread.
175: */
176: public void testCollectionConcurrencyTh1Tx1000() {
177:
178: if (!interactive) {
179: logger.log(BasicLevel.INFO,
180: "testCollectionConcurrencyTh1Tx1000");
181: perform(1, 10000, 1000, 1000000);
182: } else {
183: logger
184: .log(BasicLevel.INFO,
185: "Interactive mode: ignore testCollectionConcurrencyTh1Tx1000");
186: }
187: }
188:
189: /**
190: * Tests 10.000 transactions which stress collections using 1 thread.
191: */
192: public void testCollectionConcurrencyTh1Tx10000() {
193:
194: if (!interactive) {
195: logger.log(BasicLevel.INFO,
196: "testCollectionConcurrencyTh1Tx10000");
197: perform(1, 10000, 10000, 1000000);
198: } else {
199: logger
200: .log(BasicLevel.INFO,
201: "Interactive mode: ignore testCollectionConcurrencyTh1Tx10000");
202: }
203: }
204:
205: /**
206: * Tests 100.000 transactions which stress collections using 1 thread.
207: */
208: public void _testCollectionConcurrencyTh1Tx100000() {
209:
210: if (!interactive) {
211: logger.log(BasicLevel.INFO,
212: "testCollectionConcurrencyTh1Tx100000");
213: perform(1, 10000, 100000, 1000000);
214: } else {
215: logger
216: .log(BasicLevel.INFO,
217: "Interactive mode: ignore testCollectionConcurrencyTh1Tx100000");
218: }
219: }
220:
221: /**
222: * Tests 100 transactions which stress collections using 2 thread.
223: */
224: public void testCollectionConcurrencyTh2Tx100() {
225:
226: if (!interactive) {
227: logger.log(BasicLevel.INFO,
228: "testCollectionConcurrencyTh2Tx100");
229: perform(2, 10000, 100, 1000000);
230: } else {
231: logger
232: .log(BasicLevel.INFO,
233: "Interactive mode: ignore testCollectionConcurrencyTh2Tx100");
234: }
235:
236: }
237:
238: /**
239: * Tests 1000 transactions which stress collections using 2 thread.
240: */
241: public void testCollectionConcurrencyTh2Tx1000() {
242:
243: if (!interactive) {
244: logger.log(BasicLevel.INFO,
245: "testCollectionConcurrencyTh2Tx1000");
246: perform(2, 10000, 1000, 1000000);
247: } else {
248: logger
249: .log(BasicLevel.INFO,
250: "Interactive mode: ignore testCollectionConcurrencyTh2Tx1000");
251: }
252: }
253:
254: /**
255: * Tests 10.000 transactions which stress collections using 2 thread.
256: */
257: public void testCollectionConcurrencyTh2Tx10000() {
258:
259: if (!interactive) {
260: logger.log(BasicLevel.INFO,
261: "testCollectionConcurrencyTh2Tx10000");
262: perform(2, 10000, 10000, 1000000);
263: } else {
264: logger
265: .log(BasicLevel.INFO,
266: "Interactive mode: ignore testCollectionConcurrencyTh2Tx10000");
267: }
268: }
269:
270: /**
271: * Tests 100.000 transactions which stress collections using 2 thread.
272: */
273: public void _testCollectionConcurrencyTh2Tx100000() {
274:
275: if (!interactive) {
276: logger.log(BasicLevel.INFO,
277: "testCollectionConcurrencyTh2Tx100000");
278: perform(2, 10000, 100000, 1000000);
279: } else {
280: logger
281: .log(BasicLevel.INFO,
282: "Interactive mode: ignore testCollectionConcurrencyTh2Tx100000");
283: }
284: }
285:
286: /**
287: * Tests 1000 transactions which stress collections using 10 thread.
288: */
289: public void testCollectionConcurrencyTh10Tx1000() {
290:
291: if (!interactive) {
292: logger.log(BasicLevel.INFO,
293: "testCollectionConcurrencyTh10Tx1000");
294: perform(10, 10000, 1000, 1000000);
295: } else {
296: logger
297: .log(BasicLevel.INFO,
298: "Interactive mode: ignore testCollectionConcurrencyTh10Tx1000");
299: }
300: }
301:
302: /**
303: * Tests 10.000 transactions which stress collections using 10 thread.
304: */
305: public void testCollectionConcurrencyTh10Tx10000() {
306:
307: if (!interactive) {
308: logger.log(BasicLevel.INFO,
309: "testCollectionConcurrencyTh10Tx10000");
310: perform(10, 10000, 10000, 1000000);
311: } else {
312: logger
313: .log(BasicLevel.INFO,
314: "Interactive mode: ignore testCollectionConcurrencyTh10Tx10000");
315: }
316: }
317:
318: /**
319: * Tests 100.000 transactions which stress collections using 10 thread.
320: */
321: public void _testCollectionConcurrencyTh10Tx100000() {
322:
323: if (!interactive) {
324: logger.log(BasicLevel.INFO,
325: "testCollectionConcurrencyTh10Tx100000");
326: perform(10, 10000, 100000, 1000000);
327: } else {
328: logger
329: .log(BasicLevel.INFO,
330: "Interactive mode: ignore testCollectionConcurrencyTh10Tx100000");
331: }
332: }
333:
334: /**
335: * Tests 100 transactions which stress collections using 100 thread.
336: */
337: public void testCollectionConcurrencyTh100Tx100() {
338:
339: if (!interactive) {
340: logger.log(BasicLevel.INFO,
341: "testCollectionConcurrencyTh100Tx100");
342: perform(100, 10000, 100, 1000000);
343: } else {
344: logger
345: .log(BasicLevel.INFO,
346: "Interactive mode: ignore testCollectionConcurrencyTh100Tx100");
347: }
348: }
349:
350: /**
351: * Tests 1000 transactions which stress collections using 1000 thread.
352: */
353: public void testCollectionConcurrencyTh1000Tx1000() {
354:
355: if (!interactive) {
356: logger.log(BasicLevel.INFO,
357: "testCollectionConcurrencyTh1000Tx1000");
358: perform(1000, 10000, 1000, 1000000);
359: } else {
360: logger
361: .log(BasicLevel.INFO,
362: "Interactive mode: ignore testCollectionConcurrencyTh1000Tx1000");
363: }
364: }
365:
366: }
|