KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > stress > TestRelationN_M


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package org.objectweb.speedo.stress;
20
21 import org.objectweb.speedo.pobjects.relations.A;
22 import org.objectweb.speedo.pobjects.relations.B;
23
24 import javax.jdo.JDOFatalException;
25 import javax.jdo.PersistenceManager;
26
27 /**
28  * Stress the relation many-many implementation by Speedo.
29  *
30  * @author M. Guillemin
31  */

32 public class TestRelationN_M extends StressHelper {
33
34     public TestRelationN_M(String JavaDoc s) {
35         super(s);
36     }
37
38     protected String JavaDoc[] getClassNamesToInit() {
39         return new String JavaDoc[]{
40             org.objectweb.speedo.pobjects.relations.A.class.getName(),
41             org.objectweb.speedo.pobjects.relations.B.class.getName()
42         };
43     }
44
45     protected String JavaDoc getLoggerName() {
46         return STRESS_LOG_NAME + ".TestRelation1_1";
47     }
48
49
50     protected void perform(StressHelper.Task task,
51                            int threadId,
52                            int txId,
53                            Object JavaDoc ctx,
54                            StressHelper.PerformResult res) {
55         PersistenceManager pm = getPM(task, threadId, txId);
56         try {
57             res.beginTest();
58             int oid = txId * 3;
59             beginTx(pm, task, threadId, txId);
60             // Execute first transaction (makePersistent)
61
A a1 = new A("a" + oid);
62             A a2 = new A("a" + oid + 1);
63             A a3 = new A("a" + oid + 2);
64             B b1 = new B("b" + oid);
65             B b2 = new B("b" + oid + 1);
66             B b3 = new B("b" + oid + 2);
67             pm.makePersistent(a1);
68             pm.makePersistent(a2);
69             pm.makePersistent(a3);
70             pm.makePersistent(b1);
71             pm.makePersistent(b2);
72             pm.makePersistent(b3);
73             Object JavaDoc oida1 = pm.getObjectId(a1);
74             Object JavaDoc oida2 = pm.getObjectId(a2);
75             Object JavaDoc oida3 = pm.getObjectId(a3);
76             Object JavaDoc oidb1 = pm.getObjectId(b1);
77             Object JavaDoc oidb2 = pm.getObjectId(b2);
78             Object JavaDoc oidb3 = pm.getObjectId(b3);
79             commitTx(pm, task, threadId, txId);
80             closePM(pm, threadId, txId, task, res);
81
82             pm = getPM(task, threadId, txId);
83             a1.getBs().add(b1);
84             assertTrue(b1.getAs().contains(a1));
85             a1.getBs().add(b2);
86             assertTrue(b2.getAs().contains(a1));
87
88             a2.getBs().add(b1);
89             assertTrue(b1.getAs().contains(a2));
90             a2.getBs().add(b2);
91             assertTrue(b2.getAs().contains(a2));
92             a2.getBs().add(b3);
93             assertTrue(b3.getAs().contains(a2));
94
95             a3.getBs().add(b2);
96             assertTrue(b2.getAs().contains(a3));
97             a3.getBs().add(b3);
98             assertTrue(b3.getAs().contains(a3));
99
100             a1.getBs().add(b3);
101             assertTrue(b3.getAs().contains(a1));
102
103             a1.getBs().remove(b1);
104             assertTrue(!b1.getAs().contains(a1));
105
106             b2.getAs().remove(a2);
107             assertTrue(!a2.getBs().contains(b2));
108
109             a1.setBs(a2.getBs());
110             // reload objects before testing effects of the above assignement
111
closePM(pm, threadId, txId, task, res);
112
113             pm = getPM(task, threadId, txId);
114             assertTrue(a1.getBs().contains(b1));
115             assertTrue(!a1.getBs().contains(b2));
116             assertTrue(a1.getBs().contains(b3));
117
118             assertTrue(a2.getBs().contains(b1));
119             assertTrue(!a2.getBs().contains(b2));
120             assertTrue(a2.getBs().contains(b3));
121
122             assertTrue(!a3.getBs().contains(b1));
123             assertTrue(a3.getBs().contains(b2));
124             assertTrue(a3.getBs().contains(b3));
125
126             assertTrue(b1.getAs().contains(a1));
127             assertTrue(b1.getAs().contains(a2));
128             assertTrue(!b1.getAs().contains(a3));
129
130             assertTrue(!b2.getAs().contains(a1));
131             assertTrue(!b2.getAs().contains(a2));
132             assertTrue(b2.getAs().contains(a3));
133
134             assertTrue(b3.getAs().contains(a1));
135             assertTrue(b3.getAs().contains(a2));
136             assertTrue(b3.getAs().contains(a3));
137             closePM(pm, threadId, txId, task, res);
138             pm = getPM(task, threadId, txId);
139             beginTx(pm, task, threadId, txId);
140             pm.deletePersistent(pm.getObjectById(oidb3, false));
141             commitTx(pm, task, threadId, txId);
142             closePM(pm, threadId, txId, task, res);
143             pm = getPM(task, threadId, txId);
144
145             assertTrue(a1.getBs().size() == 1);
146             assertTrue(a1.getBs().contains(b1));
147             assertTrue(a2.getBs().size() == 1);
148             assertTrue(a2.getBs().contains(b1));
149             assertTrue(a3.getBs().size() == 1);
150             assertTrue(a3.getBs().contains(b2));
151
152             assertTrue(b1.getAs().contains(a1));
153             assertTrue(b1.getAs().contains(a2));
154             assertTrue(!b1.getAs().contains(a3));
155             assertTrue(!b2.getAs().contains(a1));
156             assertTrue(!b2.getAs().contains(a2));
157             assertTrue(b2.getAs().contains(a3));
158
159             beginTx(pm, task, threadId, txId);
160             pm.deletePersistent(pm.getObjectById(oida1, false));
161             pm.deletePersistent(pm.getObjectById(oida2, false));
162             pm.deletePersistent(pm.getObjectById(oida3, false));
163             pm.deletePersistent(pm.getObjectById(oidb1, false));
164             pm.deletePersistent(pm.getObjectById(oidb2, false));
165             commitTx(pm, task, threadId, txId);
166
167             res.endTest();
168         } catch (JDOFatalException e) {
169             rollbackOnException(pm, e, res, task, threadId, txId);
170         } catch (Throwable JavaDoc e) {
171             stopOnError(pm, e, res, task, threadId, txId);
172         } finally {
173             closePM(pm, threadId, txId, task, res);
174         }
175     }
176
177
178     /**
179      * Tests the read of a lot of persistent objects, with interactive setting
180      * of test parameteres (see file userconf/project.properties).
181      */

182     public void testRelationN_M() {
183         if (interactive) {
184             perform(Integer.getInteger(THREAD, 1).intValue(),
185                     Integer.getInteger(TX, 1).intValue(),
186                     Integer.getInteger(TIMEOUT, 1).intValue(), null);
187         }
188     }
189
190     /**
191      * Tests 100 transactions where each of them stress 1 persistent object using 1 thread.
192      */

193     public void testRelationN_MTh1Tx100() {
194         if (!interactive) {
195             perform(1, 100, 1000000, null);
196         }
197     }
198
199     /**
200      * Tests 1000 transactions where each of them stress 1 persistent object using 1 thread.
201      */

202     public void testRelationN_MTh1Tx1000() {
203         if (!interactive) {
204             perform(1, 1000, 1000000, null);
205         }
206     }
207
208     /**
209      * Tests 10000 transactions where each of them stress 1 persistent object using 1 thread.
210      */

211     public void testRelationN_MTh1Tx10000() {
212         if (!interactive) {
213             perform(1, 10000, 1000000, null);
214         }
215     }
216
217     /**
218      * Tests 100 transactions where each of them stress 1 persistent object using 2 thread.
219      */

220     public void testRelationN_MTh2Tx100() {
221         if (!interactive) {
222             perform(2, 100, 1000000, null);
223         }
224     }
225
226     /**
227      * Tests 1000 transactions where each of them stress 1 persistent object using 2 thread.
228      */

229     public void testRelationN_MTh2Tx1000() {
230         if (!interactive) {
231             perform(2, 1000, 1000000, null);
232         }
233     }
234
235     /**
236      * Tests 10000 transactions where each of them stress 1 persistent object using 2 thread.
237      */

238     public void testRelationN_MTh2Tx10000() {
239         if (!interactive) {
240             perform(2, 10000, 1000000, null);
241         }
242     }
243
244     /**
245      * Tests 100 transactions where each of them stress 1 persistent object using 10 thread.
246      */

247     public void testRelationN_MTh10Tx100() {
248         if (!interactive) {
249             perform(10, 100, 1000000, null);
250         }
251     }
252
253     /**
254      * Tests 1000 transactions where each of them stress 1 persistent object using 10 thread.
255      */

256     public void testRelationN_MTh10Tx1000() {
257         if (!interactive) {
258             perform(10, 1000, 1000000, null);
259         }
260     }
261
262     /**
263      * Tests 10000 transactions where each of them stress 1 persistent object using 10 thread.
264      */

265     public void testRelationN_MTh10Tx10000() {
266         if (!interactive) {
267             perform(10, 10000, 1000000, null);
268         }
269     }
270 }
271
Popular Tags