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-one implementation by Speedo.
028: *
029: * @author M. Guillemin
030: */
031: public class TestRelation1_1Concurrency extends CDRelationHelper {
032:
033: public TestRelation1_1Concurrency(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_1Concurrency";
047: }
048:
049: protected int getNbSucc() {
050: return 2; // because d1, d2
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, true, getNbSucc());
062:
063: C c1 = (C) pm.getObjectById(cdctx.oidsC[oid], false);
064: C c2 = (C) pm.getObjectById(cdctx.oidsC[oid + 1], false);
065: D d1 = (D) pm.getObjectById(cdctx.oidsD[oid], false);
066: D d2 = (D) pm.getObjectById(cdctx.oidsD[oid + 1], false);
067:
068: c1.setD(d1);
069: assertTrue(d1.getC() == c1);
070: c2.setD(d2);
071: assertTrue(d2.getC() == c2);
072: c1.setD(d2);
073: assertTrue(d1.getC() == null);
074: assertTrue(d2.getC() == c1);
075: assertTrue(c2.getD() == null);
076: d1.setC(c2);
077: assertTrue(c2.getD() == d1);
078: d1.setC(c1);
079: assertTrue(c1.getD() == d1);
080: assertTrue(d2.getC() == null);
081: assertTrue(c2.getD() == null);
082:
083: commitTx(pm, task, threadId, txId);
084:
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: /**
096: * Tests the read of a lot of persistent objects, with interactive setting
097: * of test parameteres (see file userconf/project.properties).
098: */
099: public void testIntercative() {
100: if (interactive) {
101: logger.log(BasicLevel.INFO, "testInteractive");
102: perform(Integer.getInteger(THREAD, 1).intValue(), Integer
103: .getInteger(TX, 1).intValue(), Integer.getInteger(
104: TIMEOUT, 1).intValue(), new CDCtx(Integer
105: .getInteger(DBSIZE, 1000).intValue()));
106: } else {
107: logger.log(BasicLevel.INFO,
108: "Non Interactive mode: ignore testInteractive");
109: }
110: }
111:
112: /**
113: * Methode d'aiguillage
114: */
115: private void perform(int nbThread, int dbSize, int nbTx,
116: int threadTimeout) {
117: perform(nbThread, nbTx, threadTimeout, new CDCtx(dbSize));
118: }
119:
120: /**
121: * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
122: */
123: public void testRelation1_1ConcurrencyTh1Tx100() {
124: if (!interactive) {
125: logger.log(BasicLevel.INFO,
126: "testRelation1_1ConcurrencyTh1Tx100");
127: perform(1, 10000, 100, 1000000);
128: } else {
129: logger
130: .log(BasicLevel.INFO,
131: "Non Interactive mode: ignore testRelation1_1ConcurrencyTh1Tx100");
132: }
133: }
134:
135: /**
136: * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
137: */
138: public void testRelation1_1ConcurrencyTh1Tx1000() {
139: if (!interactive) {
140: logger.log(BasicLevel.INFO,
141: "testRelation1_1ConcurrencyTh1Tx1000");
142: perform(1, 10000, 1000, 1000000);
143: } else {
144: logger
145: .log(BasicLevel.INFO,
146: "Non Interactive mode: ignore testRelation1_1ConcurrencyTh1Tx1000");
147: }
148: }
149:
150: /**
151: * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
152: */
153: public void testRelation1_1ConcurrencyTh1Tx10000() {
154: if (!interactive) {
155: logger.log(BasicLevel.INFO,
156: "testRelation1_1ConcurrencyTh1Tx10000");
157: perform(1, 10000, 10000, 1000000);
158: } else {
159: logger
160: .log(BasicLevel.INFO,
161: "Non Interactive mode: ignore testRelation1_1ConcurrencyTh1Tx10000");
162: }
163: }
164:
165: /**
166: * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
167: */
168: public void testRelation1_1ConcurrencyTh2Tx100() {
169: if (!interactive) {
170: logger.log(BasicLevel.INFO,
171: "testRelation1_1ConcurrencyTh2Tx100");
172: perform(2, 10000, 100, 1000000);
173: } else {
174: logger
175: .log(BasicLevel.INFO,
176: "Non Interactive mode: ignore testRelation1_1ConcurrencyTh2Tx100");
177: }
178: }
179:
180: /**
181: * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
182: */
183: public void testRelation1_1ConcurrencyTh2Tx1000() {
184: if (!interactive) {
185: logger.log(BasicLevel.INFO,
186: "testRelation1_1ConcurrencyTh2Tx1000");
187: perform(2, 10000, 1000, 1000000);
188: } else {
189: logger
190: .log(BasicLevel.INFO,
191: "Non Interactive mode: ignore testRelation1_1ConcurrencyTh2Tx1000");
192: }
193: }
194:
195: /**
196: * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
197: */
198: public void testRelation1_1ConcurrencyTh2Tx10000() {
199: if (!interactive) {
200: logger.log(BasicLevel.INFO,
201: "testRelation1_1ConcurrencyTh2Tx10000");
202: perform(2, 10000, 10000, 1000000);
203: } else {
204: logger
205: .log(BasicLevel.INFO,
206: "Non Interactive mode: ignore testRelation1_1ConcurrencyTh2Tx10000");
207: }
208: }
209:
210: /**
211: * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
212: */
213: public void testRelation1_1ConcurrencyTh10Tx100() {
214: if (!interactive) {
215: logger.log(BasicLevel.INFO,
216: "testRelation1_1ConcurrencyTh10Tx100");
217: perform(10, 10000, 100, 1000000);
218: } else {
219: logger
220: .log(BasicLevel.INFO,
221: "Non Interactive mode: ignore testRelation1_1ConcurrencyTh10Tx100");
222: }
223: }
224:
225: /**
226: * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
227: */
228: public void testRelation1_1ConcurrencyTh10Tx1000() {
229: if (!interactive) {
230: logger.log(BasicLevel.INFO,
231: "testRelation1_1ConcurrencyTh10Tx1000");
232: perform(10, 10000, 1000, 1000000);
233: } else {
234: logger
235: .log(BasicLevel.INFO,
236: "Non Interactive mode: ignore testRelation1_1ConcurrencyTh10Tx1000");
237: }
238: }
239:
240: /**
241: * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
242: */
243: public void testRelation1_1ConcurrencyTh10Tx10000() {
244: if (!interactive) {
245: logger.log(BasicLevel.INFO,
246: "testRelation1_1ConcurrencyTh10Tx10000");
247: perform(10, 10000, 10000, 1000000);
248: } else {
249: logger
250: .log(BasicLevel.INFO,
251: "Non Interactive mode: ignore testRelation1_1ConcurrencyTh10Tx10000");
252: }
253: }
254: }
|