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 one-many implementation by Speedo.
028: *
029: * @author M. Guillemin
030: */
031: public class TestRelation1_NConcurrency extends CDRelationHelper {
032:
033: public TestRelation1_NConcurrency(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 + ".TestRelation1_NConcurrency";
047: }
048:
049: protected int getNbSucc() {
050: return 4; // because d1, d2, d3, d4
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: D d1 = (D) pm.getObjectById(cdctx.oidsD[oid], false);
067: D d2 = (D) pm.getObjectById(cdctx.oidsD[oid + 1], false);
068: D d3 = (D) pm.getObjectById(cdctx.oidsD[oid + 2], false);
069: D d4 = (D) pm.getObjectById(cdctx.oidsD[oid + 3], false);
070:
071: c1.getNds().add(d1);
072: assertTrue(d1.getNc() == c1);
073: c1.getNds().add(d2);
074: assertTrue(d2.getNc() == c1);
075:
076: c2.getNds().add(d3);
077: assertTrue(d3.getNc() == c2);
078: c2.getNds().add(d4);
079: assertTrue(d4.getNc() == c2);
080:
081: c1.getNds().add(d3);
082: assertTrue(d3.getNc() == c1);
083: assertTrue(!c2.getNds().contains(d3));
084:
085: c1.getNds().remove(d1);
086: assertTrue(d1.getNc() == null);
087:
088: d3.setNc(c2);
089: assertTrue(!c1.getNds().contains(d3));
090: assertTrue(c2.getNds().contains(d3));
091:
092: c1.setNds(c2.getNds());
093:
094: commitTx(pm, task, threadId, txId);
095:
096: assertTrue(!c1.getNds().contains(d1));
097: assertTrue(!c1.getNds().contains(d2));
098: assertTrue(c1.getNds().contains(d3));
099: assertTrue(c1.getNds().contains(d4));
100: assertTrue(c1.getNds().size() == 2);
101:
102: assertTrue(!c2.getNds().contains(d1));
103: assertTrue(!c2.getNds().contains(d2));
104: assertTrue(!c2.getNds().contains(d3));
105: assertTrue(!c2.getNds().contains(d4));
106:
107: assertTrue(d1.getNc() == null);
108: assertTrue(d2.getNc() == null);
109: assertTrue(d3.getNc() == c1);
110: assertTrue(d4.getNc() == c1);
111:
112: res.endTest();
113: } catch (JDOFatalException e) {
114: rollbackOnException(pm, e, res, task, threadId, txId);
115: } catch (Throwable e) {
116: stopOnError(pm, e, res, task, threadId, txId);
117: } finally {
118: closePM(pm, threadId, txId, task, res);
119: }
120: }
121:
122: /**
123: * Tests the read of a lot of persistent objects, with interactive setting
124: * of test parameteres (see file userconf/project.properties).
125: */
126: public void testInteractive() {
127: if (interactive) {
128: logger.log(BasicLevel.INFO, "testInteractive");
129: perform(Integer.getInteger(THREAD, 1).intValue(), Integer
130: .getInteger(TX, 1).intValue(), Integer.getInteger(
131: TIMEOUT, 1).intValue(), new CDCtx(Integer
132: .getInteger(DBSIZE, 1000).intValue()));
133: } else {
134: logger.log(BasicLevel.INFO,
135: "Non Interactive mode: ignore testInteractive");
136: }
137: }
138:
139: /**
140: * Methode d'aiguillage
141: */
142: private void perform(int nbThread, int dbSize, int nbTx,
143: int threadTimeout) {
144: perform(nbThread, nbTx, threadTimeout, new CDCtx(dbSize));
145: }
146:
147: /**
148: * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
149: */
150: public void testRelation1_NConcurrencyTh1Tx100() {
151: if (!interactive) {
152: logger.log(BasicLevel.INFO,
153: "testRelation1_NConcurrencyTh1Tx100");
154: perform(1, 10000, 100, 1000000);
155: } else {
156: logger
157: .log(BasicLevel.INFO,
158: "Interactive mode: ignore testRelation1_NConcurrencyTh1Tx100");
159: }
160: }
161:
162: /**
163: * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
164: */
165: public void testRelation1_NConcurrencyTh1Tx1000() {
166: if (!interactive) {
167: logger.log(BasicLevel.INFO,
168: "testRelation1_NConcurrencyTh1Tx1000");
169: perform(1, 10000, 1000, 1000000);
170: } else {
171: logger
172: .log(BasicLevel.INFO,
173: "Interactive mode: ignore testRelation1_NConcurrencyTh1Tx1000");
174: }
175: }
176:
177: /**
178: * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
179: */
180: public void testRelation1_NConcurrencyTh1Tx10000() {
181: if (!interactive) {
182: logger.log(BasicLevel.INFO,
183: "testRelation1_NConcurrencyTh1Tx10000");
184: perform(1, 10000, 10000, 1000000);
185: } else {
186: logger
187: .log(BasicLevel.INFO,
188: "Interactive mode: ignore testRelation1_NConcurrencyTh1Tx10000");
189: }
190: }
191:
192: /**
193: * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
194: */
195: public void testRelation1_NConcurrencyTh2Tx100() {
196: if (!interactive) {
197: logger.log(BasicLevel.INFO,
198: "testRelation1_NConcurrencyTh2Tx100");
199: perform(2, 10000, 100, 1000000);
200: } else {
201: logger
202: .log(BasicLevel.INFO,
203: "Interactive mode: ignore testRelation1_NConcurrencyTh2Tx100");
204: }
205: }
206:
207: /**
208: * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
209: */
210: public void testRelation1_NConcurrencyTh2Tx1000() {
211: if (!interactive) {
212: logger.log(BasicLevel.INFO,
213: "testRelation1_NConcurrencyTh2Tx1000");
214: perform(2, 10000, 1000, 1000000);
215: } else {
216: logger
217: .log(BasicLevel.INFO,
218: "Interactive mode: ignore testRelation1_NConcurrencyTh2Tx1000");
219: }
220: }
221:
222: /**
223: * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
224: */
225: public void testRelation1_NConcurrencyTh2Tx10000() {
226: if (!interactive) {
227: logger.log(BasicLevel.INFO,
228: "testRelation1_NConcurrencyTh2Tx10000");
229: perform(2, 10000, 10000, 1000000);
230: } else {
231: logger
232: .log(BasicLevel.INFO,
233: "Interactive mode: ignore testRelation1_NConcurrencyTh2Tx10000");
234: }
235: }
236:
237: /**
238: * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
239: */
240: public void testRelation1_NConcurrencyTh10Tx100() {
241: if (!interactive) {
242: logger.log(BasicLevel.INFO,
243: "testRelation1_NConcurrencyTh10Tx100");
244: perform(10, 10000, 100, 1000000);
245: } else {
246: logger
247: .log(BasicLevel.INFO,
248: "Interactive mode: ignore testRelation1_NConcurrencyTh10Tx100");
249: }
250: }
251:
252: /**
253: * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
254: */
255: public void testRelation1_NConcurrencyTh10Tx1000() {
256: if (!interactive) {
257: logger.log(BasicLevel.INFO,
258: "testRelation1_NConcurrencyTh10Tx1000");
259: perform(10, 10000, 1000, 1000000);
260: } else {
261: logger
262: .log(BasicLevel.INFO,
263: "Interactive mode: ignore testRelation1_NConcurrencyTh10Tx1000");
264: }
265: }
266:
267: /**
268: * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
269: */
270: public void testRelation1_NConcurrencyTh10Tx10000() {
271: if (!interactive) {
272: logger.log(BasicLevel.INFO,
273: "testRelation1_NConcurrencyTh10Tx10000");
274: perform(10, 10000, 10000, 1000000);
275: } else {
276: logger
277: .log(BasicLevel.INFO,
278: "Interactive mode: ignore testRelation1_NConcurrencyTh10Tx10000");
279: }
280: }
281: }
|