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.pobjects.relations.C;
020: import org.objectweb.speedo.pobjects.relations.D;
021: import org.objectweb.util.monolog.api.BasicLevel;
022:
023: import javax.jdo.JDOFatalException;
024: import javax.jdo.PersistenceManager;
025:
026: /**
027: * Stress the relation many-many implementation by Speedo.
028: *
029: * @author M. Guillemin
030: */
031: public class TestRelationN_MConcurrency extends CDRelationHelper {
032:
033: public TestRelationN_MConcurrency(String s) {
034: super (s);
035: }
036:
037: protected String[] getClassNamesToInit() {
038: return new String[] {
039: org.objectweb.speedo.pobjects.relations.C.class
040: .getName(),
041: org.objectweb.speedo.pobjects.relations.D.class
042: .getName() };
043: }
044:
045: protected String getLoggerName() {
046: return STRESS_LOG_NAME + ".TestRelationN_MConcurrency";
047: }
048:
049: protected int getNbSucc() {
050: return 3; // because d1, d2, d3
051: }
052:
053: protected void perform(StressHelper.Task task, int threadId,
054: int txId, Object ctx, StressHelper.PerformResult res) {
055: CDCtx cdctx = (CDCtx) ctx;
056: PersistenceManager pm = getPM(task, threadId, txId);
057: try {
058: res.beginTest();
059: beginTx(pm, task, threadId, txId);
060:
061: int oid = getOid(cdctx, (task.txToExecute.length == 0),
062: getNbSucc());
063:
064: C c1 = (C) pm.getObjectById(cdctx.oidsC[oid], false);
065: C c2 = (C) pm.getObjectById(cdctx.oidsC[oid + 1], false);
066: C c3 = (C) pm.getObjectById(cdctx.oidsC[oid + 2], false);
067: D d1 = (D) pm.getObjectById(cdctx.oidsD[oid], false);
068: D d2 = (D) pm.getObjectById(cdctx.oidsD[oid + 1], false);
069: D d3 = (D) pm.getObjectById(cdctx.oidsD[oid + 2], false);
070:
071: c1.getDs().add(d1);
072: assertTrue(d1.getCs().contains(c1));
073: c1.getDs().add(d2);
074: assertTrue(d2.getCs().contains(c1));
075:
076: c2.getDs().add(d1);
077: assertTrue(d1.getCs().contains(c2));
078: c2.getDs().add(d2);
079: assertTrue(d2.getCs().contains(c2));
080: c2.getDs().add(d3);
081: assertTrue(d3.getCs().contains(c2));
082:
083: c3.getDs().add(d2);
084: assertTrue(d2.getCs().contains(c3));
085: c3.getDs().add(d3);
086: assertTrue(d3.getCs().contains(c3));
087:
088: c1.getDs().add(d3);
089: assertTrue(d3.getCs().contains(c1));
090:
091: c1.getDs().remove(d1);
092: assertTrue(!d1.getCs().contains(c1));
093:
094: d2.getCs().remove(c2);
095: assertTrue(!c2.getDs().contains(d2));
096:
097: c1.setDs(c2.getDs());
098:
099: commitTx(pm, task, threadId, txId);
100:
101: assertTrue(c1.getDs().contains(d1));
102: assertTrue(!c1.getDs().contains(d2));
103: assertTrue(c1.getDs().contains(d3));
104:
105: assertTrue(c2.getDs().contains(d1));
106: assertTrue(!c2.getDs().contains(d2));
107: assertTrue(c2.getDs().contains(d3));
108:
109: assertTrue(!c3.getDs().contains(d1));
110: assertTrue(c3.getDs().contains(d2));
111: assertTrue(c3.getDs().contains(d3));
112:
113: assertTrue(d1.getCs().contains(c1));
114: assertTrue(d1.getCs().contains(c2));
115: assertTrue(!d1.getCs().contains(c3));
116:
117: assertTrue(!d2.getCs().contains(c1));
118: assertTrue(!d2.getCs().contains(c2));
119: assertTrue(d2.getCs().contains(c3));
120:
121: assertTrue(d3.getCs().contains(c1));
122: assertTrue(d3.getCs().contains(c2));
123: assertTrue(d3.getCs().contains(c3));
124:
125: res.endTest();
126: } catch (JDOFatalException e) {
127: rollbackOnException(pm, e, res, task, threadId, txId);
128: } catch (Throwable e) {
129: stopOnError(pm, e, res, task, threadId, txId);
130: } finally {
131: closePM(pm, threadId, txId, task, res);
132: }
133: }
134:
135: /**
136: * Tests the read of a lot of persistent objects, with interactive setting
137: * of test parameteres (see file userconf/project.properties).
138: */
139: public void testInteractive() {
140: if (interactive) {
141: logger.log(BasicLevel.INFO, "testInteractive");
142: perform(Integer.getInteger(THREAD, 1).intValue(), Integer
143: .getInteger(TX, 1).intValue(), Integer.getInteger(
144: TIMEOUT, 1).intValue(), new CDCtx(Integer
145: .getInteger(DBSIZE, 1000).intValue()));
146: } else {
147: logger.log(BasicLevel.INFO,
148: "Non Interactive mode: ignore testInteractive");
149: }
150: }
151:
152: /**
153: * Methode d'aiguillage
154: */
155: private void perform(int nbThread, int dbSize, int nbTx,
156: int threadTimeout) {
157: perform(nbThread, nbTx, threadTimeout, new CDCtx(dbSize));
158: }
159:
160: /**
161: * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
162: */
163: public void testRelationN_MConcurrencyTh1Tx100() {
164: if (!interactive) {
165: logger.log(BasicLevel.INFO,
166: "testRelation1_NConcurrencyTh1Tx100");
167: perform(1, 10000, 100, 1000000);
168: } else {
169: logger
170: .log(BasicLevel.INFO,
171: "Non Interactive mode: ignore testRelation1_NConcurrencyTh1Tx100");
172: }
173: }
174:
175: /**
176: * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
177: */
178: public void testRelationN_MConcurrencyTh1Tx1000() {
179: if (!interactive) {
180: logger.log(BasicLevel.INFO,
181: "testRelationN_MConcurrencyTh1Tx1000");
182: perform(1, 10000, 1000, 1000000);
183: } else {
184: logger
185: .log(BasicLevel.INFO,
186: "Non Interactive mode: ignore testRelationN_MConcurrencyTh1Tx1000");
187: }
188: }
189:
190: /**
191: * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
192: */
193: public void testRelationN_MConcurrencyTh1Tx10000() {
194: if (!interactive) {
195: logger.log(BasicLevel.INFO,
196: "testRelationN_MConcurrencyTh1Tx10000");
197: perform(1, 10000, 10000, 1000000);
198: } else {
199: logger
200: .log(BasicLevel.INFO,
201: "Non Interactive mode: ignore testRelationN_MConcurrencyTh1Tx10000");
202: }
203: }
204:
205: /**
206: * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
207: */
208: public void testRelationN_MConcurrencyTh2Tx100() {
209: if (!interactive) {
210: logger.log(BasicLevel.INFO,
211: "testRelationN_MConcurrencyTh2Tx100");
212: perform(2, 10000, 100, 1000000);
213: } else {
214: logger
215: .log(BasicLevel.INFO,
216: "Non Interactive mode: ignore testRelationN_MConcurrencyTh2Tx100");
217: }
218: }
219:
220: /**
221: * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
222: */
223: public void testRelationN_MConcurrencyTh2Tx1000() {
224: if (!interactive) {
225: logger.log(BasicLevel.INFO,
226: "testRelationN_MConcurrencyTh2Tx1000");
227: perform(2, 10000, 1000, 1000000);
228: } else {
229: logger
230: .log(BasicLevel.INFO,
231: "Non Interactive mode: ignore testRelationN_MConcurrencyTh2Tx1000");
232: }
233: }
234:
235: /**
236: * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
237: */
238: public void testRelationN_MConcurrencyTh2Tx10000() {
239: if (!interactive) {
240: logger.log(BasicLevel.INFO,
241: "testRelationN_MConcurrencyTh2Tx10000");
242: perform(2, 10000, 10000, 1000000);
243: } else {
244: logger
245: .log(BasicLevel.INFO,
246: "Non Interactive mode: ignore testRelationN_MConcurrencyTh2Tx10000");
247: }
248: }
249:
250: /**
251: * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
252: */
253: public void testRelationN_MConcurrencyTh10Tx100() {
254: if (!interactive) {
255: logger.log(BasicLevel.INFO,
256: "testRelationN_MConcurrencyTh10Tx100");
257: perform(10, 10000, 100, 1000000);
258: } else {
259: logger
260: .log(BasicLevel.INFO,
261: "Non Interactive mode: ignore testRelationN_MConcurrencyTh10Tx100");
262: }
263: }
264:
265: /**
266: * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
267: */
268: public void testRelationN_MConcurrencyTh10Tx1000() {
269: if (!interactive) {
270: logger.log(BasicLevel.INFO,
271: "testRelationN_MConcurrencyTh10Tx1000");
272: perform(10, 10000, 1000, 1000000);
273: } else {
274: logger
275: .log(BasicLevel.INFO,
276: "Non Interactive mode: ignore testRelationN_MConcurrencyTh10Tx1000");
277: }
278: }
279:
280: /**
281: * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
282: */
283: public void testRelationN_MConcurrencyTh10Tx10000() {
284: if (!interactive) {
285: logger.log(BasicLevel.INFO,
286: "testRelationN_MConcurrencyTh10Tx10000");
287: perform(10, 10000, 10000, 1000000);
288: } else {
289: logger
290: .log(BasicLevel.INFO,
291: "Non Interactive mode: ignore testRelationN_MConcurrencyTh10Tx10000");
292: }
293: }
294: }
|