KickJava   Java API By Example, From Geeks To Geeks.

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


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.C;
22 import org.objectweb.speedo.pobjects.relations.D;
23 import org.objectweb.util.monolog.api.BasicLevel;
24
25 import javax.jdo.JDOFatalException;
26 import javax.jdo.PersistenceManager;
27
28 /**
29  * Stress the relation many-many implementation by Speedo.
30  *
31  * @author M. Guillemin
32  */

33 public class TestRelationN_MConcurrency extends CDRelationHelper {
34
35     public TestRelationN_MConcurrency(String JavaDoc s) {
36         super(s);
37     }
38
39     protected String JavaDoc[] getClassNamesToInit() {
40         return new String JavaDoc[]{
41             org.objectweb.speedo.pobjects.relations.C.class.getName(),
42             org.objectweb.speedo.pobjects.relations.D.class.getName()
43         };
44     }
45
46     protected String JavaDoc getLoggerName() {
47         return STRESS_LOG_NAME + ".TestRelationN_MConcurrency";
48     }
49
50     protected int getNbSucc() {
51         return 3; // because d1, d2, d3
52
}
53     
54     protected void perform(StressHelper.Task task,
55                            int threadId,
56                            int txId,
57                            Object JavaDoc ctx,
58                            StressHelper.PerformResult res) {
59         CDCtx cdctx = (CDCtx) ctx;
60         PersistenceManager pm = getPM(task, threadId, txId);
61         try {
62             res.beginTest();
63             beginTx(pm, task, threadId, txId);
64
65             int oid = getOid(cdctx, (task.txToExecute.length==0), getNbSucc());
66             
67             C c1 = (C) pm.getObjectById(cdctx.oidsC[oid], false);
68             C c2 = (C) pm.getObjectById(cdctx.oidsC[oid+1], false);
69             C c3 = (C) pm.getObjectById(cdctx.oidsC[oid+2], false);
70             D d1 = (D) pm.getObjectById(cdctx.oidsD[oid], false);
71             D d2 = (D) pm.getObjectById(cdctx.oidsD[oid+1], false);
72             D d3 = (D) pm.getObjectById(cdctx.oidsD[oid+2], false);
73
74             c1.getDs().add(d1);
75             assertTrue(d1.getCs().contains(c1));
76             c1.getDs().add(d2);
77             assertTrue(d2.getCs().contains(c1));
78
79             c2.getDs().add(d1);
80             assertTrue(d1.getCs().contains(c2));
81             c2.getDs().add(d2);
82             assertTrue(d2.getCs().contains(c2));
83             c2.getDs().add(d3);
84             assertTrue(d3.getCs().contains(c2));
85
86             c3.getDs().add(d2);
87             assertTrue(d2.getCs().contains(c3));
88             c3.getDs().add(d3);
89             assertTrue(d3.getCs().contains(c3));
90
91             c1.getDs().add(d3);
92             assertTrue(d3.getCs().contains(c1));
93
94             c1.getDs().remove(d1);
95             assertTrue(!d1.getCs().contains(c1));
96
97             d2.getCs().remove(c2);
98             assertTrue(!c2.getDs().contains(d2));
99
100             c1.setDs(c2.getDs());
101             
102             commitTx(pm, task, threadId, txId);
103             
104             assertTrue(c1.getDs().contains(d1));
105             assertTrue(!c1.getDs().contains(d2));
106             assertTrue(c1.getDs().contains(d3));
107
108             assertTrue(c2.getDs().contains(d1));
109             assertTrue(!c2.getDs().contains(d2));
110             assertTrue(c2.getDs().contains(d3));
111
112             assertTrue(!c3.getDs().contains(d1));
113             assertTrue(c3.getDs().contains(d2));
114             assertTrue(c3.getDs().contains(d3));
115
116             assertTrue(d1.getCs().contains(c1));
117             assertTrue(d1.getCs().contains(c2));
118             assertTrue(!d1.getCs().contains(c3));
119
120             assertTrue(!d2.getCs().contains(c1));
121             assertTrue(!d2.getCs().contains(c2));
122             assertTrue(d2.getCs().contains(c3));
123
124             assertTrue(d3.getCs().contains(c1));
125             assertTrue(d3.getCs().contains(c2));
126             assertTrue(d3.getCs().contains(c3));
127             
128             res.endTest();
129         } catch (JDOFatalException e) {
130             rollbackOnException(pm, e, res, task, threadId, txId);
131         } catch (Throwable JavaDoc e) {
132             stopOnError(pm, e, res, task, threadId, txId);
133         } finally {
134             closePM(pm, threadId, txId, task, res);
135         }
136     }
137
138
139     /**
140      * Tests the read of a lot of persistent objects, with interactive setting
141      * of test parameteres (see file userconf/project.properties).
142      */

143     public void testInteractive() {
144         if (interactive) {
145             logger.log(BasicLevel.INFO, "testInteractive");
146             perform(Integer.getInteger(THREAD, 1).intValue(),
147                     Integer.getInteger(TX, 1).intValue(),
148                     Integer.getInteger(TIMEOUT, 1).intValue(),
149                     new CDCtx(Integer.getInteger(DBSIZE, 1000).intValue()));
150         } else {
151             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testInteractive");
152         }
153     }
154
155     /**
156      * Methode d'aiguillage
157      */

158     private void perform(
159             int nbThread,
160             int dbSize,
161             int nbTx,
162             int threadTimeout) {
163         perform(nbThread, nbTx, threadTimeout, new CDCtx(dbSize));
164     }
165
166     /**
167      * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
168      */

169     public void testRelationN_MConcurrencyTh1Tx100() {
170         if (!interactive) {
171             logger.log(BasicLevel.INFO, "testRelation1_NConcurrencyTh1Tx100");
172             perform(1, 10000, 100, 1000000);
173         } else {
174             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelation1_NConcurrencyTh1Tx100");
175         }
176     }
177
178     /**
179      * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
180      */

181     public void testRelationN_MConcurrencyTh1Tx1000() {
182         if (!interactive) {
183             logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh1Tx1000");
184             perform(1, 10000, 1000, 1000000);
185         } else {
186             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh1Tx1000");
187         }
188     }
189
190     /**
191      * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
192      */

193     public void testRelationN_MConcurrencyTh1Tx10000() {
194         if (!interactive) {
195             logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh1Tx10000");
196             perform(1, 10000, 10000, 1000000);
197         } else {
198             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh1Tx10000");
199         }
200     }
201
202     /**
203      * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
204      */

205     public void testRelationN_MConcurrencyTh2Tx100() {
206         if (!interactive) {
207             logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh2Tx100");
208             perform(2, 10000, 100, 1000000);
209         } else {
210             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh2Tx100");
211         }
212     }
213
214     /**
215      * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
216      */

217     public void testRelationN_MConcurrencyTh2Tx1000() {
218         if (!interactive) {
219             logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh2Tx1000");
220             perform(2, 10000, 1000, 1000000);
221         } else {
222             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh2Tx1000");
223         }
224     }
225
226     /**
227      * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 2 thread.
228      */

229     public void testRelationN_MConcurrencyTh2Tx10000() {
230         if (!interactive) {
231             logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh2Tx10000");
232             perform(2, 10000, 10000, 1000000);
233         } else {
234             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh2Tx10000");
235         }
236     }
237
238     /**
239      * Tests 100 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
240      */

241     public void testRelationN_MConcurrencyTh10Tx100() {
242         if (!interactive) {
243             logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh10Tx100");
244             perform(10, 10000, 100, 1000000);
245         } else {
246             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh10Tx100");
247         }
248     }
249
250     /**
251      * Tests 1000 transactions where each of them stress 1_1 linked persistents objects using 10 thread.
252      */

253     public void testRelationN_MConcurrencyTh10Tx1000() {
254         if (!interactive) {
255             logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh10Tx1000");
256             perform(10, 10000, 1000, 1000000);
257         } else {
258             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh10Tx1000");
259         }
260     }
261
262     /**
263      * Tests 10000 transactions where each of them stress 1_1 linked persistents objects using 1 thread.
264      */

265     public void testRelationN_MConcurrencyTh10Tx10000() {
266         if (!interactive) {
267             logger.log(BasicLevel.INFO, "testRelationN_MConcurrencyTh10Tx10000");
268             perform(10, 10000, 10000, 1000000);
269         } else {
270             logger.log(BasicLevel.INFO, "Non Interactive mode: ignore testRelationN_MConcurrencyTh10Tx10000");
271         }
272     }
273 }
274
Popular Tags