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.A;
020: import org.objectweb.speedo.pobjects.relations.B;
021:
022: import javax.jdo.JDOFatalException;
023: import javax.jdo.PersistenceManager;
024:
025: /**
026: * Stress the relation many-many implementation by Speedo.
027: *
028: * @author M. Guillemin
029: */
030: public class TestRelationN_M extends StressHelper {
031:
032: public TestRelationN_M(String s) {
033: super (s);
034: }
035:
036: protected String[] getClassNamesToInit() {
037: return new String[] {
038: org.objectweb.speedo.pobjects.relations.A.class
039: .getName(),
040: org.objectweb.speedo.pobjects.relations.B.class
041: .getName() };
042: }
043:
044: protected String getLoggerName() {
045: return STRESS_LOG_NAME + ".TestRelation1_1";
046: }
047:
048: protected void perform(StressHelper.Task task, int threadId,
049: int txId, Object ctx, StressHelper.PerformResult res) {
050: PersistenceManager pm = getPM(task, threadId, txId);
051: try {
052: res.beginTest();
053: int oid = txId * 3;
054: beginTx(pm, task, threadId, txId);
055: // Execute first transaction (makePersistent)
056: A a1 = new A("a" + oid);
057: A a2 = new A("a" + oid + 1);
058: A a3 = new A("a" + oid + 2);
059: B b1 = new B("b" + oid);
060: B b2 = new B("b" + oid + 1);
061: B b3 = new B("b" + oid + 2);
062: pm.makePersistent(a1);
063: pm.makePersistent(a2);
064: pm.makePersistent(a3);
065: pm.makePersistent(b1);
066: pm.makePersistent(b2);
067: pm.makePersistent(b3);
068: Object oida1 = pm.getObjectId(a1);
069: Object oida2 = pm.getObjectId(a2);
070: Object oida3 = pm.getObjectId(a3);
071: Object oidb1 = pm.getObjectId(b1);
072: Object oidb2 = pm.getObjectId(b2);
073: Object oidb3 = pm.getObjectId(b3);
074: commitTx(pm, task, threadId, txId);
075: closePM(pm, threadId, txId, task, res);
076:
077: pm = getPM(task, threadId, txId);
078: a1.getBs().add(b1);
079: assertTrue(b1.getAs().contains(a1));
080: a1.getBs().add(b2);
081: assertTrue(b2.getAs().contains(a1));
082:
083: a2.getBs().add(b1);
084: assertTrue(b1.getAs().contains(a2));
085: a2.getBs().add(b2);
086: assertTrue(b2.getAs().contains(a2));
087: a2.getBs().add(b3);
088: assertTrue(b3.getAs().contains(a2));
089:
090: a3.getBs().add(b2);
091: assertTrue(b2.getAs().contains(a3));
092: a3.getBs().add(b3);
093: assertTrue(b3.getAs().contains(a3));
094:
095: a1.getBs().add(b3);
096: assertTrue(b3.getAs().contains(a1));
097:
098: a1.getBs().remove(b1);
099: assertTrue(!b1.getAs().contains(a1));
100:
101: b2.getAs().remove(a2);
102: assertTrue(!a2.getBs().contains(b2));
103:
104: a1.setBs(a2.getBs());
105: // reload objects before testing effects of the above assignement
106: closePM(pm, threadId, txId, task, res);
107:
108: pm = getPM(task, threadId, txId);
109: assertTrue(a1.getBs().contains(b1));
110: assertTrue(!a1.getBs().contains(b2));
111: assertTrue(a1.getBs().contains(b3));
112:
113: assertTrue(a2.getBs().contains(b1));
114: assertTrue(!a2.getBs().contains(b2));
115: assertTrue(a2.getBs().contains(b3));
116:
117: assertTrue(!a3.getBs().contains(b1));
118: assertTrue(a3.getBs().contains(b2));
119: assertTrue(a3.getBs().contains(b3));
120:
121: assertTrue(b1.getAs().contains(a1));
122: assertTrue(b1.getAs().contains(a2));
123: assertTrue(!b1.getAs().contains(a3));
124:
125: assertTrue(!b2.getAs().contains(a1));
126: assertTrue(!b2.getAs().contains(a2));
127: assertTrue(b2.getAs().contains(a3));
128:
129: assertTrue(b3.getAs().contains(a1));
130: assertTrue(b3.getAs().contains(a2));
131: assertTrue(b3.getAs().contains(a3));
132: closePM(pm, threadId, txId, task, res);
133: pm = getPM(task, threadId, txId);
134: beginTx(pm, task, threadId, txId);
135: pm.deletePersistent(pm.getObjectById(oidb3, false));
136: commitTx(pm, task, threadId, txId);
137: closePM(pm, threadId, txId, task, res);
138: pm = getPM(task, threadId, txId);
139:
140: assertTrue(a1.getBs().size() == 1);
141: assertTrue(a1.getBs().contains(b1));
142: assertTrue(a2.getBs().size() == 1);
143: assertTrue(a2.getBs().contains(b1));
144: assertTrue(a3.getBs().size() == 1);
145: assertTrue(a3.getBs().contains(b2));
146:
147: assertTrue(b1.getAs().contains(a1));
148: assertTrue(b1.getAs().contains(a2));
149: assertTrue(!b1.getAs().contains(a3));
150: assertTrue(!b2.getAs().contains(a1));
151: assertTrue(!b2.getAs().contains(a2));
152: assertTrue(b2.getAs().contains(a3));
153:
154: beginTx(pm, task, threadId, txId);
155: pm.deletePersistent(pm.getObjectById(oida1, false));
156: pm.deletePersistent(pm.getObjectById(oida2, false));
157: pm.deletePersistent(pm.getObjectById(oida3, false));
158: pm.deletePersistent(pm.getObjectById(oidb1, false));
159: pm.deletePersistent(pm.getObjectById(oidb2, false));
160: commitTx(pm, task, threadId, txId);
161:
162: res.endTest();
163: } catch (JDOFatalException e) {
164: rollbackOnException(pm, e, res, task, threadId, txId);
165: } catch (Throwable e) {
166: stopOnError(pm, e, res, task, threadId, txId);
167: } finally {
168: closePM(pm, threadId, txId, task, res);
169: }
170: }
171:
172: /**
173: * Tests the read of a lot of persistent objects, with interactive setting
174: * of test parameteres (see file userconf/project.properties).
175: */
176: public void testRelationN_M() {
177: if (interactive) {
178: perform(Integer.getInteger(THREAD, 1).intValue(), Integer
179: .getInteger(TX, 1).intValue(), Integer.getInteger(
180: TIMEOUT, 1).intValue(), null);
181: }
182: }
183:
184: /**
185: * Tests 100 transactions where each of them stress 1 persistent object using 1 thread.
186: */
187: public void testRelationN_MTh1Tx100() {
188: if (!interactive) {
189: perform(1, 100, 1000000, null);
190: }
191: }
192:
193: /**
194: * Tests 1000 transactions where each of them stress 1 persistent object using 1 thread.
195: */
196: public void testRelationN_MTh1Tx1000() {
197: if (!interactive) {
198: perform(1, 1000, 1000000, null);
199: }
200: }
201:
202: /**
203: * Tests 10000 transactions where each of them stress 1 persistent object using 1 thread.
204: */
205: public void testRelationN_MTh1Tx10000() {
206: if (!interactive) {
207: perform(1, 10000, 1000000, null);
208: }
209: }
210:
211: /**
212: * Tests 100 transactions where each of them stress 1 persistent object using 2 thread.
213: */
214: public void testRelationN_MTh2Tx100() {
215: if (!interactive) {
216: perform(2, 100, 1000000, null);
217: }
218: }
219:
220: /**
221: * Tests 1000 transactions where each of them stress 1 persistent object using 2 thread.
222: */
223: public void testRelationN_MTh2Tx1000() {
224: if (!interactive) {
225: perform(2, 1000, 1000000, null);
226: }
227: }
228:
229: /**
230: * Tests 10000 transactions where each of them stress 1 persistent object using 2 thread.
231: */
232: public void testRelationN_MTh2Tx10000() {
233: if (!interactive) {
234: perform(2, 10000, 1000000, null);
235: }
236: }
237:
238: /**
239: * Tests 100 transactions where each of them stress 1 persistent object using 10 thread.
240: */
241: public void testRelationN_MTh10Tx100() {
242: if (!interactive) {
243: perform(10, 100, 1000000, null);
244: }
245: }
246:
247: /**
248: * Tests 1000 transactions where each of them stress 1 persistent object using 10 thread.
249: */
250: public void testRelationN_MTh10Tx1000() {
251: if (!interactive) {
252: perform(10, 1000, 1000000, null);
253: }
254: }
255:
256: /**
257: * Tests 10000 transactions where each of them stress 1 persistent object using 10 thread.
258: */
259: public void testRelationN_MTh10Tx10000() {
260: if (!interactive) {
261: perform(10, 10000, 1000000, null);
262: }
263: }
264: }
|