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 javax.jdo.JDOFatalException;
020: import javax.jdo.PersistenceManager;
021:
022: import org.objectweb.speedo.pobjects.relations.A;
023: import org.objectweb.speedo.pobjects.relations.B;
024:
025: /**
026: * Stress the relation one-one implementation by Speedo.
027: *
028: * @author M. Guillemin
029: */
030: public class TestRelation1_1 extends StressHelper {
031:
032: public TestRelation1_1(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 * 2;
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: B b1 = new B("b" + oid);
059: B b2 = new B("b" + oid + 1);
060: pm.makePersistent(a1);
061: pm.makePersistent(a2);
062: pm.makePersistent(b1);
063: pm.makePersistent(b2);
064: commitTx(pm, task, threadId, txId);
065:
066: a1.setB(b1);
067: assertTrue(b1.getA() == a1);
068: a2.setB(b2);
069: assertTrue(b2.getA() == a2);
070: a1.setB(b2);
071: assertTrue(b1.getA() == null);
072: assertTrue(b2.getA() == a1);
073: assertTrue(a2.getB() == null);
074: b1.setA(a2);
075: assertTrue(a2.getB() == b1);
076: b1.setA(a1);
077: assertTrue(a1.getB() == b1);
078: assertTrue(b2.getA() == null);
079: assertTrue(a2.getB() == null);
080:
081: // Delete persistent (speedoproxy)
082: beginTx(pm, task, threadId, txId);
083: pm.deletePersistent(a1);
084: pm.deletePersistent(a2);
085: pm.deletePersistent(b1);
086: pm.deletePersistent(b2);
087: commitTx(pm, task, threadId, txId);
088:
089: res.endTest();
090: } catch (JDOFatalException e) {
091: rollbackOnException(pm, e, res, task, threadId, txId);
092: } catch (Throwable e) {
093: stopOnError(pm, e, res, task, threadId, txId);
094: } finally {
095: closePM(pm, threadId, txId, task, res);
096: }
097: }
098:
099: /**
100: * Tests the read of a lot of persistent objects, with interactive setting
101: * of test parameteres (see file userconf/project.properties).
102: */
103: public void testRelation1_1() {
104: if (interactive) {
105: perform(Integer.getInteger(THREAD, 1).intValue(), Integer
106: .getInteger(TX, 1).intValue(), Integer.getInteger(
107: TIMEOUT, 1).intValue(), null);
108: }
109: }
110:
111: /**
112: * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
113: */
114: public void testRelation1_1Th1Tx100() {
115: if (!interactive) {
116: perform(1, 100, 1000000, null);
117: }
118: }
119:
120: /**
121: * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
122: */
123: public void testRelation1_1Th1Tx1000() {
124: if (!interactive) {
125: perform(1, 1000, 1000000, null);
126: }
127: }
128:
129: /**
130: * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
131: */
132: public void testRelation1_1Th1Tx10000() {
133: if (!interactive) {
134: perform(1, 10000, 1000000, null);
135: }
136: }
137:
138: /**
139: * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
140: */
141: public void testRelation1_1Th2Tx100() {
142: if (!interactive) {
143: perform(2, 100, 1000000, null);
144: }
145: }
146:
147: /**
148: * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
149: */
150: public void testRelation1_1Th2Tx1000() {
151: if (!interactive) {
152: perform(2, 1000, 1000000, null);
153: }
154: }
155:
156: /**
157: * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
158: */
159: public void testRelation1_1Th2Tx10000() {
160: if (!interactive) {
161: perform(2, 10000, 1000000, null);
162: }
163: }
164:
165: /**
166: * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
167: */
168: public void testRelation1_1Th10Tx100() {
169: if (!interactive) {
170: perform(10, 100, 1000000, null);
171: }
172: }
173:
174: /**
175: * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
176: */
177: public void testRelation1_1Th10Tx1000() {
178: if (!interactive) {
179: perform(10, 1000, 1000000, null);
180: }
181: }
182:
183: /**
184: * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
185: */
186: public void testRelation1_1Th10Tx10000() {
187: if (!interactive) {
188: perform(10, 10000, 1000000, null);
189: }
190: }
191: }
|