KickJava   Java API By Example, From Geeks To Geeks.

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


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 one-many implementation by Speedo.
29  *
30  * @author M. Guillemin
31  */

32 public class TestRelation1_N extends StressHelper {
33
34     public TestRelation1_N(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 * 4;
59             beginTx(pm, task, threadId, txId);
60
61             // Execute first transaction (makePersistent)
62
A a1 = new A("a" + oid);
63             A a2 = new A("a" + oid + 1);
64
65             B b1 = new B("b" + oid);
66             B b2 = new B("b" + oid + 1);
67             B b3 = new B("b" + oid + 2);
68             B b4 = new B("b" + oid + 3);
69
70             pm.makePersistent(a1);
71             pm.makePersistent(a2);
72             pm.makePersistent(b1);
73             pm.makePersistent(b2);
74             pm.makePersistent(b3);
75             pm.makePersistent(b4);
76             Object JavaDoc oida1 = pm.getObjectId(a1);
77             Object JavaDoc oida2 = pm.getObjectId(a2);
78             Object JavaDoc oidb1 = pm.getObjectId(b1);
79             Object JavaDoc oidb2 = pm.getObjectId(b2);
80             Object JavaDoc oidb3 = pm.getObjectId(b3);
81             Object JavaDoc oidb4 = pm.getObjectId(b4);
82
83             // validate (make speedoproxy)
84
commitTx(pm, task, threadId, txId);
85
86             a1.getNbs().add(b1);
87             assertTrue(b1.getNa() == a1);
88             a1.getNbs().add(b2);
89             assertTrue(b2.getNa() == a1);
90
91             a2.getNbs().add(b3);
92             assertTrue(b3.getNa() == a2);
93             a2.getNbs().add(b4);
94             assertTrue(b4.getNa() == a2);
95
96             a1.getNbs().add(b3);
97             assertTrue(b3.getNa() == a1);
98             assertTrue(!a2.getNbs().contains(b3));
99
100             a1.getNbs().remove(b1);
101             assertTrue(b1.getNa() == null);
102
103             b3.setNa(a2);
104             assertTrue(!a1.getNbs().contains(b3));
105             assertTrue(a2.getNbs().contains(b3));
106
107             a1.setNbs(a2.getNbs());
108
109             // reload objects before testing effects of the above assignement
110
pm.close();
111             pm = pmf.getPersistenceManager();
112
113             assertTrue(!a1.getNbs().contains(b1));
114             assertTrue(!a1.getNbs().contains(b2));
115             assertTrue(a1.getNbs().contains(b3));
116             assertTrue(a1.getNbs().contains(b4));
117             assertTrue(a1.getNbs().size() == 2);
118
119             assertTrue(!a2.getNbs().contains(b1));
120             assertTrue(!a2.getNbs().contains(b2));
121             assertTrue(!a2.getNbs().contains(b3));
122             assertTrue(!a2.getNbs().contains(b4));
123
124             assertTrue(b1.getNa() == null);
125             assertTrue(b2.getNa() == null);
126             assertTrue(b3.getNa() == a1);
127             assertTrue(b4.getNa() == a1);
128
129             // Delete persistent (speedoproxy)
130
beginTx(pm, task, threadId, txId);
131             pm.deletePersistent(pm.getObjectById(oidb3, false));
132             assertTrue("reverse reference of b3.na (a1.nbs) must not contain b3",
133                     !a1.getNbs().contains(b3));
134             commitTx(pm, task, threadId, txId);
135             pm.close();
136
137             pm = pmf.getPersistenceManager();
138             assertTrue("reverse reference of b3.na (a1.nbs) must not contain b3",
139                     !a1.getNbs().contains(b3));
140
141             beginTx(pm, task, threadId, txId);
142             pm.deletePersistent(pm.getObjectById(oida1, false));
143             pm.deletePersistent(pm.getObjectById(oida2, false));
144             pm.deletePersistent(pm.getObjectById(oidb1, false));
145             pm.deletePersistent(pm.getObjectById(oidb2, false));
146             pm.deletePersistent(pm.getObjectById(oidb4, false));
147             commitTx(pm, task, threadId, txId);
148
149             res.endTest();
150         } catch (JDOFatalException e) {
151             rollbackOnException(pm, e, res, task, threadId, txId);
152         } catch (Throwable JavaDoc e) {
153             stopOnError(pm, e, res, task, threadId, txId);
154         } finally {
155             closePM(pm, threadId, txId, task, res);
156         }
157     }
158
159
160     /**
161      * Tests the read of a lot of persistent objects, with interactive setting
162      * of test parameteres (see file userconf/project.properties).
163      */

164     public void testRelation1_N() {
165         if (interactive) {
166             perform(Integer.getInteger(THREAD, 1).intValue(),
167                     Integer.getInteger(TX, 1).intValue(),
168                     Integer.getInteger(TIMEOUT, 1).intValue(), null);
169         }
170     }
171
172     /**
173      * Tests 100 transactions where each of them stress 1_N linked persistents objects using 1 thread.
174      */

175     public void testRelation1_NTh1Tx100() {
176         if (!interactive) {
177             perform(1, 100, 1000000, null);
178         }
179     }
180
181     /**
182      * Tests 1000 transactions where each of them stress 1_N linked persistents objects using 1 thread.
183      */

184     public void testRelation1_NTh1Tx1000() {
185         if (!interactive) {
186             perform(1, 1000, 1000000, null);
187         }
188     }
189
190     /**
191      * Tests 10000 transactions where each of them stress 1_N linked persistents objects using 1 thread.
192      */

193     public void testRelation1_NTh1Tx10000() {
194         if (!interactive) {
195             perform(1, 10000, 1000000, null);
196         }
197     }
198
199     /**
200      * Tests 100 transactions where each of them stress 1_N linked persistents objects using 2 thread.
201      */

202     public void testRelation1_NTh2Tx100() {
203         if (!interactive) {
204             perform(2, 100, 1000000, null);
205         }
206     }
207
208     /**
209      * Tests 1000 transactions where each of them stress 1_N linked persistents objects using 2 thread.
210      */

211     public void testRelation1_NTh2Tx1000() {
212         if (!interactive) {
213             perform(2, 1000, 1000000, null);
214         }
215     }
216
217     /**
218      * Tests 10000 transactions where each of them stress 1_N linked persistents objects using 2 thread.
219      */

220     public void testRelation1_NTh2Tx10000() {
221         if (!interactive) {
222             perform(2, 10000, 1000000, null);
223         }
224     }
225
226     /**
227      * Tests 100 transactions where each of them stress 1_N linked persistents objects using 10 thread.
228      */

229     public void testRelation1_NTh10Tx100() {
230         if (!interactive) {
231             perform(10, 100, 1000000, null);
232         }
233     }
234
235     /**
236      * Tests 1000 transactions where each of them stress 1_N linked persistents objects using 10 thread.
237      */

238     public void testRelation1_NTh10Tx1000() {
239         if (!interactive) {
240             perform(10, 1000, 1000000, null);
241         }
242     }
243
244     /**
245      * Tests 10000 transactions where each of them stress 1_N linked persistents objects using 10 thread.
246      */

247     public void testRelation1_NTh10Tx10000() {
248         if (!interactive) {
249             perform(10, 10000, 1000000, null);
250         }
251     }
252
253
254 }
255
Popular Tags